a bit more love for the control socket
- try to create it as %L/dpb-$$ by default. If we can't, no biggie. If the user explicitly asked for a control socket, we DO abort otherwise. - if CONTROL is explicitly empty, do not load the extra code. - try to remove the socket at exit - add a new wipehost command, that will try to kill any job on that host (if some remain), then zap all locks and affinity info related to that host "it's dead jim"
This commit is contained in:
parent
de5e757ff7
commit
587eb9c193
@ -1,7 +1,7 @@
|
||||
#! /usr/bin/perl
|
||||
|
||||
# ex:ts=8 sw=4:
|
||||
# $OpenBSD: dpb,v 1.129 2019/05/15 13:51:07 espie Exp $
|
||||
# $OpenBSD: dpb,v 1.130 2019/07/01 08:59:41 espie Exp $
|
||||
#
|
||||
# Copyright (c) 2010-2013 Marc Espie <espie@openbsd.org>
|
||||
#
|
||||
@ -98,6 +98,7 @@ sub affinityclass
|
||||
my $subdirlist = {};
|
||||
|
||||
my $master_pid = $$;
|
||||
my $state;
|
||||
|
||||
my $cleanup =
|
||||
sub {
|
||||
@ -106,6 +107,7 @@ my $cleanup =
|
||||
$> = 0;
|
||||
DPB::Core->cleanup($S // "INT", 0);
|
||||
}
|
||||
eval { $state->{external}->cleanup; };
|
||||
};
|
||||
|
||||
for my $S (qw(INT HUP TERM QUIT)) {
|
||||
@ -118,7 +120,7 @@ for my $S (qw(INT HUP TERM QUIT)) {
|
||||
|
||||
DPB::Trace->setup(\%SIG, $cleanup);
|
||||
|
||||
my $state = DPB::State->new;
|
||||
$state = DPB::State->new;
|
||||
$state->handle_options;
|
||||
my $reporter = DPB::Reporter->new($state, "main", "DPB::Core");
|
||||
DPB::Trace->set_reporter($reporter);
|
||||
@ -342,6 +344,7 @@ if ($state->{scan_only}) {
|
||||
|
||||
$reporter->reset;
|
||||
DPB::Core->cleanup;
|
||||
$state->{external}->cleanup;
|
||||
print "Elapsed time=", show_time(time-$starttime),"\n";
|
||||
print $state->engine->report;
|
||||
$state->engine->end_dump($state->logger->append('dump'));
|
||||
|
@ -1,5 +1,5 @@
|
||||
# ex:ts=8 sw=4:
|
||||
# $OpenBSD: Config.pm,v 1.80 2019/05/09 11:08:55 espie Exp $
|
||||
# $OpenBSD: Config.pm,v 1.81 2019/07/01 08:59:41 espie Exp $
|
||||
#
|
||||
# Copyright (c) 2010-2013 Marc Espie <espie@openbsd.org>
|
||||
#
|
||||
@ -214,11 +214,17 @@ sub parse_command_line
|
||||
$state->{logdir} = $state->{subst}->value('LOGDIR');
|
||||
}
|
||||
if ($state->define_present('CONTROL')) {
|
||||
require DPB::External;
|
||||
$state->{external} = DPB::External->server($state);
|
||||
if ($state->{subst}->value('CONTROL') ne '') {
|
||||
require DPB::External;
|
||||
$state->{external} = DPB::External->server($state);
|
||||
die if !defined $state->{external};
|
||||
}
|
||||
} else {
|
||||
$state->{external} = DPB::ExternalStub->new;
|
||||
require DPB::External;
|
||||
$state->{subst}->add('CONTROL', "%L/dpb-".$$);
|
||||
$state->{external} = DPB::External->server($state);
|
||||
}
|
||||
$state->{external} //= DPB::ExternalStub->new;
|
||||
if ($state->{opt}{s}) {
|
||||
$state->{wantsize} = 1;
|
||||
} elsif ($state->define_present('WANTSIZE')) {
|
||||
@ -466,4 +472,8 @@ sub receive_commands
|
||||
{
|
||||
}
|
||||
|
||||
sub cleanup
|
||||
{
|
||||
}
|
||||
|
||||
1;
|
||||
|
@ -1,5 +1,5 @@
|
||||
# ex:ts=8 sw=4:
|
||||
# $OpenBSD: Core.pm,v 1.96 2019/05/19 17:34:18 espie Exp $
|
||||
# $OpenBSD: Core.pm,v 1.97 2019/07/01 08:59:41 espie Exp $
|
||||
#
|
||||
# Copyright (c) 2010-2013 Marc Espie <espie@openbsd.org>
|
||||
#
|
||||
@ -312,6 +312,22 @@ sub cleanup
|
||||
}
|
||||
}
|
||||
|
||||
sub wipehost
|
||||
{
|
||||
my ($class, $h) = @_;
|
||||
my @pids;
|
||||
my $r = $class->repository;
|
||||
$class->walk_host_jobs($h, sub {
|
||||
my ($pid, $job) = @_;
|
||||
push @pids, $pid;
|
||||
});
|
||||
for my $pid (@pids) {
|
||||
local $> = 0;
|
||||
$class->kill('KILL', $pid);
|
||||
delete $r->{$pid};
|
||||
}
|
||||
}
|
||||
|
||||
sub debug_dump
|
||||
{
|
||||
my $self = shift;
|
||||
@ -494,17 +510,23 @@ sub repository
|
||||
}
|
||||
|
||||
|
||||
sub walk_same_host_jobs
|
||||
sub walk_host_jobs
|
||||
{
|
||||
my ($self, $sub) = @_;
|
||||
my ($self, $h, $sub) = @_;
|
||||
while (my ($pid, $core) = each %{$self->repository}) {
|
||||
next if $core->hostname ne $self->hostname;
|
||||
next if $core->hostname ne $h;
|
||||
# XXX only interested in "real" jobs now
|
||||
next if !defined $core->job->{v};
|
||||
&$sub($pid, $core->job);
|
||||
}
|
||||
}
|
||||
|
||||
sub walk_same_host_jobs
|
||||
{
|
||||
my ($self, $sub) = @_;
|
||||
return $self->walk_host_jobs($self->hostname, $sub);
|
||||
}
|
||||
|
||||
sub same_host_jobs
|
||||
{
|
||||
my $self = shift;
|
||||
|
@ -1,5 +1,5 @@
|
||||
# ex:ts=8 sw=4:
|
||||
# $OpenBSD: External.pm,v 1.18 2019/05/15 13:55:46 espie Exp $
|
||||
# $OpenBSD: External.pm,v 1.19 2019/07/01 08:59:41 espie Exp $
|
||||
#
|
||||
# Copyright (c) 2017 Marc Espie <espie@openbsd.org>
|
||||
#
|
||||
@ -30,28 +30,43 @@ sub server
|
||||
my ($class, $state) = @_;
|
||||
|
||||
my $o = bless {state => $state,
|
||||
subdirlist => {}}, $class;
|
||||
my $path = $state->expand_path($state->{subst}->value('CONTROL'));
|
||||
subdirlist => {},
|
||||
path => $state->expand_path($state->{subst}->value('CONTROL'))
|
||||
}, $class;
|
||||
|
||||
# this ensures the socket belongs to log_user.
|
||||
$state->{log_user}->run_as(
|
||||
sub {
|
||||
unlink($path);
|
||||
unlink($o->{path});
|
||||
$o->{server} = IO::Socket::UNIX->new(
|
||||
Type => SOCK_STREAM,
|
||||
Local => $path);
|
||||
Local => $o->{path});
|
||||
if (!defined $o->{server}) {
|
||||
$state->fatal("Can't create socket named #1: #2",
|
||||
$path, $!);
|
||||
$state->errsay("Can't create socket named #1: #2",
|
||||
$o->{path}, $!);
|
||||
}
|
||||
if (!chmod 0700, $o->{path}) {
|
||||
$state->errsay(
|
||||
"Can't enforce permissions for socket #1:#2",
|
||||
$o->{path}, $!);
|
||||
unlink($o->{path});
|
||||
delete $o->{server};
|
||||
}
|
||||
chmod 0700, $path or
|
||||
$state->fatal("Can't enforce permissions for socket #1:#2",
|
||||
$path, $!);
|
||||
});
|
||||
# NOW we can listen
|
||||
$o->{server}->listen;
|
||||
$o->{select} = IO::Select->new($o->{server});
|
||||
return $o;
|
||||
if (defined $o->{server}) {
|
||||
# NOW we can listen
|
||||
$o->{server}->listen;
|
||||
$o->{select} = IO::Select->new($o->{server});
|
||||
return $o;
|
||||
} else {
|
||||
return undef;
|
||||
}
|
||||
}
|
||||
|
||||
sub cleanup
|
||||
{
|
||||
my $self = shift;
|
||||
$self->{state}{log_user}->unlink($self->{path});
|
||||
}
|
||||
|
||||
sub status
|
||||
@ -101,6 +116,21 @@ sub wipe
|
||||
}
|
||||
}
|
||||
|
||||
sub wipehost
|
||||
{
|
||||
my ($self, $fh, $h) = @_;
|
||||
# kill the stuff that's running
|
||||
DPB::Core->wipehost($h);
|
||||
my $state = $self->{state};
|
||||
# zap the locks as well
|
||||
$state->locker->wipehost($h);
|
||||
for my $p (DPB::PkgPath->seen) {
|
||||
next unless defined $p->{affinity};
|
||||
next unless $p->{affinity} eq $h;
|
||||
$state->{affinity}->unmark($p);
|
||||
}
|
||||
}
|
||||
|
||||
sub handle_command
|
||||
{
|
||||
my ($self, $line, $fh) = @_;
|
||||
@ -137,6 +167,10 @@ sub handle_command
|
||||
for my $p (split(/\s+/, $1)) {
|
||||
$self->wipe($fh, $1);
|
||||
}
|
||||
} elsif ($line =~ m/^wipehost\s+(.*)/) {
|
||||
for my $p (split(/\s+/, $1)) {
|
||||
$self->wipehost($fh, $1);
|
||||
}
|
||||
} elsif ($line =~ m/^help\b/) {
|
||||
$fh->print(
|
||||
"Commands:\n",
|
||||
@ -146,7 +180,8 @@ sub handle_command
|
||||
"\tdontclean <pkgpath>...\n",
|
||||
"\tstats\n",
|
||||
"\tstatus <fullpkgpath>...\n",
|
||||
"\twipe <fullpkgpath>...\n"
|
||||
"\twipe <fullpkgpath>...\n",
|
||||
"\twipehost <hostname>...\n"
|
||||
);
|
||||
} else {
|
||||
$fh->print("Unknown command or bad syntax: ", $line, " (help for details)\n");
|
||||
|
@ -1,5 +1,5 @@
|
||||
# ex:ts=8 sw=4:
|
||||
# $OpenBSD: Locks.pm,v 1.51 2019/05/12 16:37:52 espie Exp $
|
||||
# $OpenBSD: Locks.pm,v 1.52 2019/07/01 08:59:41 espie Exp $
|
||||
#
|
||||
# Copyright (c) 2010-2013 Marc Espie <espie@openbsd.org>
|
||||
#
|
||||
@ -210,6 +210,20 @@ sub scan_lockdir
|
||||
}
|
||||
}
|
||||
|
||||
sub wipehost
|
||||
{
|
||||
my ($self, $h) = @_;
|
||||
my @wipe;
|
||||
$self->scan_lockdir(
|
||||
sub {
|
||||
my $i = shift;
|
||||
push(@wipe, $i->{filename}) if $i->{host} eq $h;
|
||||
});
|
||||
for my $f (@wipe) {
|
||||
$self->unlink($f);
|
||||
}
|
||||
}
|
||||
|
||||
sub clean_old_locks
|
||||
{
|
||||
my ($self, $state) = @_;
|
||||
|
Loading…
x
Reference in New Issue
Block a user