summaryrefslogtreecommitdiff
path: root/scripts/build_pkgs
diff options
context:
space:
mode:
authorTodd C. Miller <Todd.Miller@sudo.ws>2022-12-07 07:44:44 -0700
committerTodd C. Miller <Todd.Miller@sudo.ws>2022-12-07 07:44:44 -0700
commit1a4d900861ec874c95911b5fc8e4ff81d7c224e8 (patch)
tree5b29348d09437a8926b1ea622cc5849824dd5a07 /scripts/build_pkgs
parent6464873204fdd08a3d6355f2dd8171149fc46112 (diff)
downloadsudo-1a4d900861ec874c95911b5fc8e4ff81d7c224e8.tar.gz
Defer installing the SIGCHLD handler until after non-job commands run.
Lock the socket dir to avoid races in open_persistent_connection(). Also avoid using "ssh -f" since that may return before the socket is created. Strip carriage returns from log when running in a pty.
Diffstat (limited to 'scripts/build_pkgs')
-rwxr-xr-xscripts/build_pkgs30
1 files changed, 19 insertions, 11 deletions
diff --git a/scripts/build_pkgs b/scripts/build_pkgs
index 75f130073..0452e4e28 100755
--- a/scripts/build_pkgs
+++ b/scripts/build_pkgs
@@ -135,7 +135,6 @@ my $INFO = "INFO";
$INFO = "USR1" unless exists $SIG{INFO};
$SIG{$INFO} = \&info;
-$SIG{CHLD} = \&reaper;
$SIG{HUP} = \&shut_down;
$SIG{INT} = \&shut_down;
$SIG{QUIT} = \&shut_down;
@@ -177,6 +176,10 @@ foreach my $vm_host (keys %vm_servers) {
}
}
+# We want to catch the jobs as they finish but not any of the other
+# commands started via run() or system() above.
+$SIG{CHLD} = \&reaper;
+
# We limit the number of concurrent jobs a single host can support.
# In the future, this may be set on a per-host basis.
# If a host already is at the limit, we queue the job until a worker
@@ -625,6 +628,7 @@ sub run_remote_command {
for (;;) {
pump $h;
if (defined($outbuf)) {
+ $outbuf =~ s/\r+$//gm;
print $output $outbuf;
undef $outbuf;
}
@@ -645,16 +649,24 @@ sub open_persistent_connection {
my ($outbuf, @cmdline);
# Handle user@host form
- my @tmp = split(/\@/, $dest);
- my $host = pop(@tmp);
+ $dest =~ /([^@]+)$/;
+ my $host = $1;
- my @ssh_opts = qw(-f -M -N -oControlPersist=yes);
+ my @ssh_opts = qw(-M -N -oControlPersist=yes);
push(@ssh_opts, "-S", "$sockets/$host");
push(@ssh_opts, "-oProxyCommand=$proxy") if defined($proxy);
+ # Lock socket dir to prevent race conditions
+ sysopen(SOCKDIR, $sockets, O_RDONLY) || die "$0: unable to open $sockets: $!\n";
+ flock(SOCKDIR, LOCK_EX) || die "$0: unable to lock $sockets: $!\n";
+
if (-S "$sockets/$host") {
@cmdline = ("ssh", "-S", "$sockets/$host", "-Ocheck", $host);
run(\@cmdline, '<', \undef, '>&', \$outbuf, debug => $debug);
+ if ($outbuf =~ /^Master running/) {
+ close(SOCKDIR);
+ return 0;
+ }
return 0 if $outbuf =~ /^Master running/;
unlink("$sockets/$host");
}
@@ -662,15 +674,11 @@ sub open_persistent_connection {
@cmdline = ssh_cmdline($dest, undef, @ssh_opts);
run(\@cmdline, '<', \undef, '>&', \$outbuf, debug => $debug);
if (length($outbuf) > 0) {
- if ($outbuf =~ /already exists, disabling multiplexing/) {
- # We may lose the race to create the socket, that's OK.
- $? = 0;
- } else {
- $output = \*STDERR unless defined($output);
- print $output $outbuf;
- }
+ $output = \*STDERR unless defined($output);
+ print $output $outbuf;
}
+ close(SOCKDIR);
return $?;
}