From: Ian Jackson Date: Fri, 19 Aug 2022 22:43:28 +0000 (+0100) Subject: prefork-interp: fixes X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?a=commitdiff_plain;h=72430ff865803c3e008fd166ba532a5e678c8e82;p=chiark-utils.git prefork-interp: fixes Signed-off-by: Ian Jackson --- diff --git a/perl/Prefork.pm b/perl/Prefork.pm index 6792b9a..d41d72f 100644 --- a/perl/Prefork.pm +++ b/perl/Prefork.pm @@ -211,12 +211,6 @@ sub initialisation_complete { close_call_fds(); - my $flags = fcntl(LISTEN, F_GETFL, 0) - or fail_log("F_GETFL listen socket: $!"); - $flags |= O_NONBLOCK; - fcntl(LISTEN, F_SETFL, $flags) - or fail_log("F_SETFL listen socket: $!"); - my $errcount = 0; local $0 = "$0 [server]"; @@ -227,17 +221,18 @@ sub initialisation_complete { my $full = %children >= $num_servers; my $got = waitpid -1, ($full ? 0 : WNOHANG); $got >= 0 or fail_log("failed to wait for monitor(s)"); - last if $got == 0; - if ($?) { - syslog(LOG_WARNING, + if ($got) { + if ($?) { + syslog(LOG_WARNING, "$0 prefork [$$]: monitor process [$got] failed with wait status $?"); - } - if (!exists $children{$got}) { - syslog(LOG_WARNING, + } + if (!exists $children{$got}) { + syslog(LOG_WARNING, "$0 prefork [$$]: monitor process [$got] wasn't one of ours?!"); + } + delete $children{$got}; + next; } - delete $children{$got}; - next; } # select for accepting or housekeeping timeout @@ -248,7 +243,11 @@ sub initialisation_complete { my $nfound = select($rbits, '', $ebits, ($opts{idle_timeout} // 1000000)); # Idle timeout? - if (!$nfound) { _exit(0); } + last if $nfound == 0; + if ($nfound < 0) { + next if $! == EINTR; + fail_log("select failed: $!"); + } # Has the watcher told us to shut down, or died with a message ? my $msgbuf = ''; @@ -257,7 +256,7 @@ sub initialisation_complete { chomp $msgbuf; fail_log("watcher: $msgbuf"); } elsif ($r == 0) { - _exit(0); + last; } elsif ($! == EINTR || $! == EAGAIN || $! == EWOULDBLOCK) { } else { fail_log("watcher stderr read: $!"); @@ -280,12 +279,11 @@ sub initialisation_complete { } else { syslog(LOG_WARNING, "$0 prefork [$$]: accept failed: $!"); if ($errcount > ($opts{max_errors} // 100)) { - syslog(LOG_ERR, - "$0 prefork [$$]: too many accept failures, quitting"); - _exit(16); + fail_log("too many accept failures, quitting"); } } } + _exit(0); } 1;