From 9a2eaf985ebc8566bb15ff9a3e50c908c8a69fe1 Mon Sep 17 00:00:00 2001 From: Donald Buczek Date: Wed, 29 Jan 2025 12:59:43 +0100 Subject: [PATCH] clusterd: Remove double-forks 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. --- clusterd/clusterd | 38 ++++++++++++++------------------------ 1 file changed, 14 insertions(+), 24 deletions(-) diff --git a/clusterd/clusterd b/clusterd/clusterd index 5d82389..8e53815 100755 --- a/clusterd/clusterd +++ b/clusterd/clusterd @@ -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); @@ -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 (

) { - 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 (

) { + 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 {