You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spamassassin.apache.org by si...@apache.org on 2007/07/04 22:31:14 UTC
svn commit: r553325 - in /spamassassin/branches/3.2: MANIFEST spamd/spamd.raw
Author: sidney
Date: Wed Jul 4 13:31:13 2007
New Revision: 553325
URL: http://svn.apache.org/viewvc?view=rev&rev=553325
Log:
bug5419: kill -HUP of pidof spamd causes the ps name to change from spamd to perl
Modified:
spamassassin/branches/3.2/MANIFEST
spamassassin/branches/3.2/spamd/spamd.raw
Modified: spamassassin/branches/3.2/MANIFEST
URL: http://svn.apache.org/viewvc/spamassassin/branches/3.2/MANIFEST?view=diff&rev=553325&r1=553324&r2=553325
==============================================================================
--- spamassassin/branches/3.2/MANIFEST (original)
+++ spamassassin/branches/3.2/MANIFEST Wed Jul 4 13:31:13 2007
@@ -500,3 +500,5 @@
t/root_spamd_x.t
t/root_spamd_x_paranoid.t
t/spamc_H.t
+t/spamc_x_E_R.t
+t/spamc_x_e.t
Modified: spamassassin/branches/3.2/spamd/spamd.raw
URL: http://svn.apache.org/viewvc/spamassassin/branches/3.2/spamd/spamd.raw?view=diff&rev=553325&r1=553324&r2=553325
==============================================================================
--- spamassassin/branches/3.2/spamd/spamd.raw (original)
+++ spamassassin/branches/3.2/spamd/spamd.raw Wed Jul 4 13:31:13 2007
@@ -205,6 +205,8 @@
# somehow -- untaint the dir to be on the safe side.
my $ORIG_CWD = Mail::SpamAssassin::Util::untaint_var( Cwd::cwd() );
+prepare_for_sighup_restart();
+
# Parse the command line
Getopt::Long::Configure("bundling");
GetOptions(
@@ -961,28 +963,7 @@
$scaling->main_server_poll($opt{'server-scale-period'});
}
- if ( defined $got_sighup ) {
- if (defined($opt{'pidfile'})) {
- unlink($opt{'pidfile'}) || warn "spamd: cannot unlink $opt{'pidfile'}: $!\n";
- }
-
- # leave Client fds active, and do not kill children; they can still
- # service clients until they exit. But restart the listener anyway.
- # And close the logfile, so the new instance can reopen it.
- Mail::SpamAssassin::Logger::close_log();
- chdir($ORIG_CWD)
- || die "spamd: restart failed: chdir failed: ${ORIG_CWD}: $!\n";
-
- # ensure we re-run spamd using the right perl interpreter, and
- # with the right switches (taint mode and warnings) (bug 5255)
- my $perl = Mail::SpamAssassin::Util::untaint_var($^X);
- my @execs = ( $perl, "-T", "-w", $ORIG_ARG0, @ORIG_ARGV );
- warn "spamd: restarting using '" . join (' ', @execs) . "'\n";
- exec @execs;
-
- # should not get past that...
- die "spamd: restart failed: exec failed: " . join (' ', @execs) . ": $!\n";
- }
+ ( defined $got_sighup ) and do_sighup_restart();
for (my $i = keys %children; $i < $childlimit; $i++) {
spawn();
@@ -2561,6 +2542,51 @@
((defined $fd_inet ? 1 : 0) +
(defined $fd_unix ? 1 : 0) +
(defined $fd_ssl ? 1 : 0)) > 1;
+}
+
+# do this in advance, since we want to minimize work when SIGHUP
+# is received
+my $perl_from_hashbang_line;
+sub prepare_for_sighup_restart {
+ # it'd be great if we could introspect the interpreter to figure this
+ # out, but bizarrely it seems unavailable.
+ if (open (IN, "<$ORIG_ARG0")) {
+ my $l = <IN>;
+ close IN;
+ if ($l && $l =~ /^#!\s*(\S+)\s*.*?$/) {
+ $perl_from_hashbang_line = $1;
+ }
+ }
+}
+
+sub do_sighup_restart {
+ if (defined($opt{'pidfile'})) {
+ unlink($opt{'pidfile'}) || warn "spamd: cannot unlink $opt{'pidfile'}: $!\n";
+ }
+
+ # leave Client fds active, and do not kill children; they can still
+ # service clients until they exit. But restart the listener anyway.
+ # And close the logfile, so the new instance can reopen it.
+ Mail::SpamAssassin::Logger::close_log();
+ chdir($ORIG_CWD)
+ or die "spamd: restart failed: chdir failed: ${ORIG_CWD}: $!\n";
+
+ # ensure we re-run spamd using the right perl interpreter, and
+ # with the right switches (taint mode and warnings) (bug 5255)
+ my $perl = Mail::SpamAssassin::Util::untaint_var($^X);
+ my @execs = ( $perl, "-T", "-w", $ORIG_ARG0, @ORIG_ARGV );
+
+ if ($perl eq $perl_from_hashbang_line) {
+ # we're using the same perl as the script uses on the #! line;
+ # we can safely just exec the script
+ @execs = ( $ORIG_ARG0, @ORIG_ARGV );
+ }
+
+ warn "spamd: restarting using '" . join (' ', @execs) . "'\n";
+ exec @execs;
+
+ # should not get past that...
+ die "spamd: restart failed: exec failed: " . join (' ', @execs) . ": $!\n";
}
__DATA__