prefork, forkserver: restart on SIGHUP: * reset to defaults * clear config cache * reload all plugins (includes compiling, register()/init())

git-svn-id: https://svn.perl.org/qpsmtpd/trunk@927 958fd67b-6ff1-0310-b445-bb7760255be9
This commit is contained in:
Hanno Hecker 2008-06-15 09:28:02 +00:00 committed by Ask Bjørn Hansen
parent 28f4cd51c1
commit a64742cc7c
4 changed files with 29 additions and 3 deletions

View File

@ -15,9 +15,27 @@ my %defaults = (
timeout => 1200, timeout => 1200,
); );
my $_config_cache = {}; my $_config_cache = {};
my %config_dir_memo;
#DashProfiler->add_profile("qpsmtpd"); #DashProfiler->add_profile("qpsmtpd");
#my $SAMPLER = DashProfiler->prepare("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 { sub DESTROY {
#warn $_ for DashProfiler->profile_as_text("qpsmtpd"); #warn $_ for DashProfiler->profile_as_text("qpsmtpd");
@ -27,7 +45,6 @@ sub version { $VERSION };
sub TRACE_LEVEL { $TraceLevel }; # leave for plugin compatibility sub TRACE_LEVEL { $TraceLevel }; # leave for plugin compatibility
my $LOGGING_LOADED = 0;
sub hooks { $hooks; } sub hooks { $hooks; }
@ -146,7 +163,6 @@ sub config {
} }
} }
my %config_dir_memo;
sub config_dir { sub config_dir {
my ($self, $config) = @_; my ($self, $config) = @_;
if (exists $config_dir_memo{$config}) { if (exists $config_dir_memo{$config}) {

View File

@ -37,6 +37,7 @@ sub new {
my (%commands); @commands{@commands} = ('') x @commands; my (%commands); @commands{@commands} = ('') x @commands;
# this list of valid commands should probably be a method or a set of methods # this list of valid commands should probably be a method or a set of methods
$self->{_commands} = \%commands; $self->{_commands} = \%commands;
$self->SUPER::_restart(%args) if $args{restart}; # calls Qpsmtpd::_restart()
$self; $self;
} }

View File

@ -218,6 +218,13 @@ if ($PID_FILE) {
$qpsmtpd->spool_dir; $qpsmtpd->spool_dir;
$qpsmtpd->size_threshold; $qpsmtpd->size_threshold;
$SIG{HUP} = sub {
$qpsmtpd = Qpsmtpd::TcpServer->new('restart' => 1);
$qpsmtpd->load_plugins;
$qpsmtpd->spool_dir;
$qpsmtpd->size_threshold;
};
while (1) { while (1) {
REAPER(); REAPER();
my $running = scalar keys %childstatus; my $running = scalar keys %childstatus;

View File

@ -252,6 +252,7 @@ sub run {
# Hup handler # Hup handler
$SIG{HUP} = sub { $SIG{HUP} = sub {
# reload qpmstpd plugins # reload qpmstpd plugins
$qpsmtpd = $qpsmtpd_base = qpsmtpd_instance('restart' => 1); # reload plugins...
$qpsmtpd->load_plugins; $qpsmtpd->load_plugins;
kill 'HUP' => keys %children; kill 'HUP' => keys %children;
info("reload daemon requested"); info("reload daemon requested");
@ -457,7 +458,8 @@ sub respond_client {
# arg0: void # arg0: void
# ret0: ref to qpsmtpd_instance # ret0: ref to qpsmtpd_instance
sub qpsmtpd_instance { sub qpsmtpd_instance {
my $qpsmtpd = Qpsmtpd::TcpServer::Prefork->new(); my %args = @_;
my $qpsmtpd = Qpsmtpd::TcpServer::Prefork->new(%args);
$qpsmtpd->load_plugins; $qpsmtpd->load_plugins;
$qpsmtpd->spool_dir; $qpsmtpd->spool_dir;
$qpsmtpd->size_threshold; $qpsmtpd->size_threshold;