https://issues.apache.org/SpamAssassin/show_bug.cgi?id=5950
--- Comment #10 from Justin Mason <[EMAIL PROTECTED]> 2008-08-05 12:51:25 PST
---
(In reply to comment #8)
> (in reply to comment #7)
> >and for that to abort waiting, if the child itself exits.
>
> I've been reading about how to use SIGCHLD to do that and it seems
> complicated.
> Example code I found uses a SIGCHLD handler, uses waitpid(-1, &WNOHANG) and
> checks WIFEXITED($?) to avoid responding to a SIGCHLD sent when the child is
> suspended but not exited. Worst, I see that WNOHANG is not supported on all
> platforms and I didn't see an alternative way of doing this that does not
> require a non-blocking waitpid().
thankfully perl insulates us from the hard stuff a lot here -- see
child_handler() for a sane WNOHANG check. there's no need to deal with
SIGCHLD, or indeed modify that at all. the logic would be (warning, messy
p-code):
# in daemonize()
$got_pidfile = 0; # global
$SIG{'USR2'} = \&got_pidfile;
defined( my $pid = fork ) or die "spamd: cannot fork: $!\n";
# this code is new:
if ($pid) { #parent
for my $retry (0 .. $somenumber) {
sleep 1;
if ($got_pidfile) { last; }
my $waited = waitpid($pid, WNOHANG);
if ($waited == $pid) {
last; # pid has exited
} else {
warn "waitpid failed: $!";
}
}
if (!$got_pidfile) {
die "child process exited or timed out without producing a PID file";
} else {
exit 0;
}
}
else {
delete $SIG{'USR2'};
}
exit if $pid;
setsid or die "spamd: cannot start new session: $!\n";
[..etc.]
sub got_pidfile {
$got_pidfile = 1;
}
> It seems to me that for this purpose it would work fine to wait no more than,
> say 5 seconds. All we are doing is making sure that the parent process does
> not
> exit before the log entry (and pid file) is written by the child so that the
> invoking shell script does not have to bother waiting for it. If the log entry
> is not written by the child in the first few seconds (probably even in the
> first second) then something is wrong anyway and it will probably not be
> written.
5 secs is pretty short under extremely heavy load.... but 30 would be plenty
IMO ;)
--
Configure bugmail:
https://issues.apache.org/SpamAssassin/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.