Skip to content

Commit

Permalink
prefork, forkserver: restart on SIGHUP: * reset to defaults * clear c…
Browse files Browse the repository at this point in the history
…onfig cache * reload all plugins (includes compiling, register()/init())

git-svn-id: https://svn.perl.org/qpsmtpd/trunk@927 958fd67b-6ff1-0310-b445-bb7760255be9
  • Loading branch information
vetinari authored and abh committed Jun 15, 2008
1 parent 28f4cd5 commit a64742c
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
20 changes: 18 additions & 2 deletions lib/Qpsmtpd.pm
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,27 @@ my %defaults = (
timeout => 1200,
);
my $_config_cache = {};
my %config_dir_memo;

#DashProfiler->add_profile("qpsmtpd");
#my $SAMPLER = DashProfiler->prepare("qpsmtpd");
my $LOGGING_LOADED = 0;

sub _restart {
my $self = shift;
my %args = @_;
if ($args{restart}) {
# reset all global vars to defaults
$self->clear_config_cache;
$hooks = {};
$LOGGING_LOADED = 0;
%config_dir_memo = ();
$TraceLevel = LOGWARN;
$Spool_dir = undef;
$Size_threshold = undef;
}
}


sub DESTROY {
#warn $_ for DashProfiler->profile_as_text("qpsmtpd");
Expand All @@ -27,7 +45,6 @@ sub version { $VERSION };

sub TRACE_LEVEL { $TraceLevel }; # leave for plugin compatibility

my $LOGGING_LOADED = 0;

sub hooks { $hooks; }

Expand Down Expand Up @@ -146,7 +163,6 @@ sub config {
}
}

my %config_dir_memo;
sub config_dir {
my ($self, $config) = @_;
if (exists $config_dir_memo{$config}) {
Expand Down
1 change: 1 addition & 0 deletions lib/Qpsmtpd/SMTP.pm
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ sub new {
my (%commands); @commands{@commands} = ('') x @commands;
# this list of valid commands should probably be a method or a set of methods
$self->{_commands} = \%commands;
$self->SUPER::_restart(%args) if $args{restart}; # calls Qpsmtpd::_restart()
$self;
}

Expand Down
7 changes: 7 additions & 0 deletions qpsmtpd-forkserver
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,13 @@ if ($PID_FILE) {
$qpsmtpd->spool_dir;
$qpsmtpd->size_threshold;

$SIG{HUP} = sub {
$qpsmtpd = Qpsmtpd::TcpServer->new('restart' => 1);
$qpsmtpd->load_plugins;
$qpsmtpd->spool_dir;
$qpsmtpd->size_threshold;
};

while (1) {
REAPER();
my $running = scalar keys %childstatus;
Expand Down
4 changes: 3 additions & 1 deletion qpsmtpd-prefork
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ sub run {
# Hup handler
$SIG{HUP} = sub {
# reload qpmstpd plugins
$qpsmtpd = $qpsmtpd_base = qpsmtpd_instance('restart' => 1); # reload plugins...
$qpsmtpd->load_plugins;
kill 'HUP' => keys %children;
info("reload daemon requested");
Expand Down Expand Up @@ -457,7 +458,8 @@ sub respond_client {
# arg0: void
# ret0: ref to qpsmtpd_instance
sub qpsmtpd_instance {
my $qpsmtpd = Qpsmtpd::TcpServer::Prefork->new();
my %args = @_;
my $qpsmtpd = Qpsmtpd::TcpServer::Prefork->new(%args);
$qpsmtpd->load_plugins;
$qpsmtpd->spool_dir;
$qpsmtpd->size_threshold;
Expand Down

0 comments on commit a64742c

Please sign in to comment.