Skip to content

Fight zombies! #437

Merged
merged 5 commits into from
Jan 29, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
63 changes: 24 additions & 39 deletions clusterd/clusterd
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ sub run {
for (@WRITER) { vec($wvec,$_->[0]->fileno,1)=1 } ;
for (@EXCEPT) { vec($evec,$_->[0]->fileno,1)=1 } ;

wait;
my $ready=select($rvec,$wvec,$evec,1);
if ($ready>0) {
for (my $i=0;$i<@READER;$i++) {
Expand Down Expand Up @@ -782,7 +783,7 @@ sub push_amd_tar {
exec 'tar','cf',$filename,'.';
die "$!\n";
}
wait;
waitpid $pid, 0;
$? and return;

my $fh=new IO::File $filename,'<' or return warn "$filename: $!\n";
Expand All @@ -795,7 +796,7 @@ sub push_amd_tar {
exec 'gzip','-f',$filename;
die "$!\n";
}
wait;
waitpid $pid, 0;
$? and return;

$filename='/tmp/amd.tar.gz';
Expand Down Expand Up @@ -879,19 +880,13 @@ sub udp_rx_exec {
return;
}
unless ($pid) {
$pid=fork;
defined $pid or exit 1;
$pid and exit;

open STDIN,'<','/dev/null';
open STDOUT,'>','/dev/null';
open STDERR,'>','/dev/null';
alarm(60);
chdir '/';
exec '/bin/sh','-c',$CMD{$cmd};
exit 1;
}
wait;
}

sub udp_rx_exec2 {
Expand All @@ -902,7 +897,6 @@ sub udp_rx_exec2 {
return;
}
if ($pid == 0) {
open STDIN,'<','/dev/null';
alarm(60);
chdir '/';
for my $cmd (@cmd) {
Expand Down Expand Up @@ -974,13 +968,13 @@ sub udp_rx_amdtardata {
exec 'tar','xzf',$st_want->name;
die "$!\n";
}
}
wait;
$? and return;
waitpid $pid, 0;
$? and return;

warn "installed /etc/amd - ",Digest::MD5::md5_hex($digest),"\n";
$INSTALLED_DIGEST=$digest;
system '/sbin/make-automaps';
warn "installed /etc/amd - ",Digest::MD5::md5_hex($digest),"\n";
$INSTALLED_DIGEST=$digest;
system '/sbin/make-automaps';
}
}

our ($machine,$SYS_lchown,$SYS_mknod);
Expand Down Expand Up @@ -1368,31 +1362,24 @@ sub clp_rx_LSOF {
return;
}
unless ($pid) {
my $pid=fork;
defined $pid or die "$!\n";
unless ($pid) {
$socket->blocking(1);
# -n inhibits the conversion of network numbers to host names for network files.
# -b causes lsof to avoid kernel functions that might block - lstat(2), readlink(2), and stat(2).
# -w disables warning messages.
open P,'timeout -k 92s 90s lsof -n -b -w|' or die "$!\n";
while (<P>) {
next if defined $pattern && index($_,$pattern)<0;
$socket->send(pack('n',length($_)).$_,0);
}
close P;
if ($?) {
$_=sprintf("** lsof timout/error on %s\n",$my_hostname);
$socket->send(pack('n',length($_)).$_,0);
}
close $socket;
exit;
$socket->blocking(1);
# -n inhibits the conversion of network numbers to host names for network files.
# -b causes lsof to avoid kernel functions that might block - lstat(2), readlink(2), and stat(2).
# -w disables warning messages.
open P,'timeout -k 92s 90s lsof -n -b -w|' or die "$!\n";
while (<P>) {
next if defined $pattern && index($_,$pattern)<0;
$socket->send(pack('n',length($_)).$_,0);
}
close P;
if ($?) {
$_=sprintf("** lsof timout/error on %s\n",$my_hostname);
$socket->send(pack('n',length($_)).$_,0);
}
close $socket;
exit;
}
close $socket;
wait;
return 1;
}

sub run_cmd {
Expand All @@ -1411,7 +1398,6 @@ sub run_cmd {
warn "exec ".join(' ',@cmd)."\n";
$opipe->writer();
$epipe->writer();
open STDIN,'<','/dev/null';
open STDOUT,'>&',$opipe;
open STDERR,'>&',$epipe;
exec @cmd;
Expand Down Expand Up @@ -1540,7 +1526,6 @@ sub clp_rx_CMD {
my ($socket,@args)=@_;
run_cmd($socket,@args);
close $socket;
return 1;
}

# send_tcp_cp($socket,$cb,$timeout,@args)
Expand Down Expand Up @@ -2020,7 +2005,6 @@ FILE:
}
}
}
open STDIN, '<', '/dev/null';
chdir '/';
alarm(60);
for my $cmd (@$post_ary) {
Expand Down Expand Up @@ -2166,6 +2150,7 @@ if (defined $options{'push'}) {
udp_broadcast_message($donald_s,'reexport');
} elsif (defined $options{'daemon'}) {
$SIG{PIPE}='IGNORE';
open STDIN,'<','/dev/null';

$donald_s=new My::Select::INET(Proto=>'udp',Broadcast=>1,LocalPort=>$UDP_PORT) or die "$!\n";
$donald_s->receive_data(\&udp_message,$donald_s);
Expand Down