Skip to content

Commit

Permalink
clusterd: Remove double-forks
Browse files Browse the repository at this point in the history
In two places we used double forks, probably so that we don't need to
reap. Now children are reaped in the main loop, so remove the extra
forks.
  • Loading branch information
donald committed Jan 29, 2025
1 parent 1264eb2 commit 9a2eaf9
Showing 1 changed file with 14 additions and 24 deletions.
38 changes: 14 additions & 24 deletions clusterd/clusterd
Original file line number Diff line number Diff line change
Expand Up @@ -880,10 +880,6 @@ sub udp_rx_exec {
return;
}
unless ($pid) {
$pid=fork;
defined $pid or exit 1;
$pid and exit;

open STDOUT,'>','/dev/null';
open STDERR,'>','/dev/null';
alarm(60);
Expand Down Expand Up @@ -1366,30 +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;
waitpid $pid, 0;
}

sub run_cmd {
Expand Down

0 comments on commit 9a2eaf9

Please sign in to comment.