Mailing List Archive

svn commit: r452678 - in /spamassassin/branches/3.1: lib/Mail/SpamAssassin/SpamdForkScaling.pm spamd/spamd.raw t/spamd_hup.t
Author: dos
Date: Tue Oct 3 16:41:03 2006
New Revision: 452678

URL: http://svn.apache.org/viewvc?view=rev&rev=452678
Log:
bug 5081: sometimes, SIGHUPing spamd would leave one child process still alive due to a race in the SIGHUP handler and the preforking code. fixed

Modified:
spamassassin/branches/3.1/lib/Mail/SpamAssassin/SpamdForkScaling.pm
spamassassin/branches/3.1/spamd/spamd.raw
spamassassin/branches/3.1/t/spamd_hup.t

Modified: spamassassin/branches/3.1/lib/Mail/SpamAssassin/SpamdForkScaling.pm
URL: http://svn.apache.org/viewvc/spamassassin/branches/3.1/lib/Mail/SpamAssassin/SpamdForkScaling.pm?view=diff&rev=452678&r1=452677&r2=452678
==============================================================================
--- spamassassin/branches/3.1/lib/Mail/SpamAssassin/SpamdForkScaling.pm (original)
+++ spamassassin/branches/3.1/lib/Mail/SpamAssassin/SpamdForkScaling.pm Tue Oct 3 16:41:03 2006
@@ -122,6 +122,15 @@
$self->compute_lowest_child_pid();
}

+# this is called by SIGTERM and SIGHUP handlers, to ensure that new
+# kids aren't added while the main code is killing the old ones
+# and planning to exit.
+#
+sub set_exiting_flag {
+ my ($self) = @_;
+ $self->{am_exiting} = 1;
+}
+
sub child_error_kill {
my ($self, $pid, $sock) = @_;

@@ -651,6 +660,9 @@

sub adapt_num_children {
my ($self) = @_;
+
+ # don't start up new kids while main is working at killing the old ones
+ return if $self->{am_exiting};

my $kids = $self->{kids};
my $statestr = '';

Modified: spamassassin/branches/3.1/spamd/spamd.raw
URL: http://svn.apache.org/viewvc/spamassassin/branches/3.1/spamd/spamd.raw?view=diff&rev=452678&r1=452677&r2=452678
==============================================================================
--- spamassassin/branches/3.1/spamd/spamd.raw (original)
+++ spamassassin/branches/3.1/spamd/spamd.raw Tue Oct 3 16:41:03 2006
@@ -629,12 +629,12 @@
my $gid = -1;
if ($owner) {
my ($login,$pass,$puid,$pgid) = getpwnam($owner)
- or die "spamd: $owner not in passwd database\n";
+ or die "spamd: $owner not in passwd database\n";
$uid = $puid;
}
if ($group) {
my ($name,$pass,$ggid,$members) = getgrnam($group)
- or die "spamd: $group not in group database\n";
+ or die "spamd: $group not in group database\n";
$gid = $ggid;
}
if (!chown $uid, $gid, $path) {
@@ -660,7 +660,7 @@
);
dbg("spamd: creating SSL socket:\n" . join("\n", map { " $_: " . (defined $socket{$_} ? $socket{$_} : "(undef)") } sort keys %socket));
$server = new IO::Socket::SSL(%socket)
- || die "spamd: could not create SSL socket on $addr:$port: $!\n";
+ || die "spamd: could not create SSL socket on $addr:$port: $!\n";
}
else {
my %socket = (
@@ -2004,6 +2004,9 @@
}

$SIG{CHLD} = 'DEFAULT'; # we're going to kill our children
+ if ($scaling) {
+ $scaling->set_exiting_flag(); # don't start new ones
+ }
kill 'INT' => keys %children;
exit 0;
}
@@ -2046,6 +2049,10 @@
info("spamd: server hit by SIG$sig, restarting");

$SIG{CHLD} = 'DEFAULT'; # we're going to kill our children
+ if ($scaling) {
+ $scaling->set_exiting_flag(); # don't start new ones
+ }
+
foreach (keys %children) {
kill 'INT' => $_;
my $pid = waitpid($_, 0);

Modified: spamassassin/branches/3.1/t/spamd_hup.t
URL: http://svn.apache.org/viewvc/spamassassin/branches/3.1/t/spamd_hup.t?view=diff&rev=452678&r1=452677&r2=452678
==============================================================================
--- spamassassin/branches/3.1/t/spamd_hup.t (original)
+++ spamassassin/branches/3.1/t/spamd_hup.t Tue Oct 3 16:41:03 2006
@@ -69,7 +69,7 @@
chomp $npid;
close(PID);
} else {
- print "Could not open pid file ${pid_file}: $!\n";
+ die "Could not open pid file ${pid_file}: $!\n";
}
#} until ($npid != $opid or $timeout == 0);
return $npid;