View | Details | Raw Unified | Return to bug 5419
Collapse All | Expand All

(-)spamd/spamd.raw (-22 / +48 lines)
Lines 205-210 Link Here
205
# somehow -- untaint the dir to be on the safe side.
205
# somehow -- untaint the dir to be on the safe side.
206
my $ORIG_CWD = Mail::SpamAssassin::Util::untaint_var( Cwd::cwd() );
206
my $ORIG_CWD = Mail::SpamAssassin::Util::untaint_var( Cwd::cwd() );
207
207
208
prepare_for_sighup_restart();
209
208
# Parse the command line
210
# Parse the command line
209
Getopt::Long::Configure("bundling");
211
Getopt::Long::Configure("bundling");
210
GetOptions(
212
GetOptions(
Lines 961-989 Link Here
961
    $scaling->main_server_poll($opt{'server-scale-period'});
963
    $scaling->main_server_poll($opt{'server-scale-period'});
962
  }
964
  }
963
965
964
  if ( defined $got_sighup ) {
966
  ( defined $got_sighup ) and do_sighup_restart();
965
    if (defined($opt{'pidfile'})) {
966
      unlink($opt{'pidfile'}) || warn "spamd: cannot unlink $opt{'pidfile'}: $!\n";
967
    }
968
967
969
    # leave Client fds active, and do not kill children; they can still
970
    # service clients until they exit.  But restart the listener anyway.
971
    # And close the logfile, so the new instance can reopen it.
972
    Mail::SpamAssassin::Logger::close_log();
973
    chdir($ORIG_CWD)
974
      || die "spamd: restart failed: chdir failed: ${ORIG_CWD}: $!\n";
975
976
    # ensure we re-run spamd using the right perl interpreter, and
977
    # with the right switches (taint mode and warnings) (bug 5255)
978
    my $perl = Mail::SpamAssassin::Util::untaint_var($^X);
979
    my @execs = ( $perl, "-T", "-w", $ORIG_ARG0, @ORIG_ARGV );
980
    warn "spamd: restarting using '" . join (' ', @execs) . "'\n";
981
    exec @execs;
982
983
    # should not get past that...
984
    die "spamd: restart failed: exec failed: " . join (' ', @execs) . ": $!\n";
985
  }
986
987
  for (my $i = keys %children; $i < $childlimit; $i++) {
968
  for (my $i = keys %children; $i < $childlimit; $i++) {
988
    spawn();
969
    spawn();
989
  }
970
  }
Lines 2563-2568 Link Here
2563
      (defined $fd_ssl  ? 1 : 0)) > 1;
2544
      (defined $fd_ssl  ? 1 : 0)) > 1;
2564
}
2545
}
2565
2546
2547
# do this in advance, since we want to minimize work when SIGHUP
2548
# is received
2549
my $perl_from_hashbang_line;
2550
sub prepare_for_sighup_restart {
2551
  # it'd be great if we could introspect the interpreter to figure this
2552
  # out, but bizarrely it seems unavailable.
2553
  if (open (IN, "<$ORIG_ARG0")) {
2554
    my $l = <IN>;
2555
    close IN;
2556
    if ($l && $l =~ /^#!\s*(\S+)\s*.*?$/) {
2557
      $perl_from_hashbang_line = $1;
2558
    }
2559
  }
2560
}
2561
2562
sub do_sighup_restart {
2563
  if (defined($opt{'pidfile'})) {
2564
    unlink($opt{'pidfile'}) || warn "spamd: cannot unlink $opt{'pidfile'}: $!\n";
2565
  }
2566
2567
  # leave Client fds active, and do not kill children; they can still
2568
  # service clients until they exit.  But restart the listener anyway.
2569
  # And close the logfile, so the new instance can reopen it.
2570
  Mail::SpamAssassin::Logger::close_log();
2571
  chdir($ORIG_CWD)
2572
    or die "spamd: restart failed: chdir failed: ${ORIG_CWD}: $!\n";
2573
2574
  # ensure we re-run spamd using the right perl interpreter, and
2575
  # with the right switches (taint mode and warnings) (bug 5255)
2576
  my $perl = Mail::SpamAssassin::Util::untaint_var($^X);
2577
  my @execs = ( $perl, "-T", "-w", $ORIG_ARG0, @ORIG_ARGV );
2578
2579
  if ($perl eq $perl_from_hashbang_line) {
2580
    # we're using the same perl as the script uses on the #! line;
2581
    # we can safely just exec the script
2582
    @execs = ( $ORIG_ARG0, @ORIG_ARGV );
2583
  }
2584
2585
  warn "spamd: restarting using '" . join (' ', @execs) . "'\n";
2586
  exec @execs;
2587
2588
  # should not get past that...
2589
  die "spamd: restart failed: exec failed: " . join (' ', @execs) . ": $!\n";
2590
}
2591
2566
__DATA__
2592
__DATA__
2567
2593
2568
=head1 NAME
2594
=head1 NAME

Return to bug 5419