Detach and daemonize only after reading the configuration and loading the plugins, to give the init scripts a chance to detect failed startups due to broken configuration or plugins.
git-svn-id: https://svn.perl.org/qpsmtpd/trunk@938 958fd67b-6ff1-0310-b445-bb7760255be9
This commit is contained in:
parent
0d96de470d
commit
18d1b9f1da
4
Changes
4
Changes
@ -1,3 +1,7 @@
|
||||
async, prefork: detach and daemonize only after reading the configuration
|
||||
and loading the plugins, to give the init scripts a chance to detect
|
||||
failed startups due to broken configuration or plugins (Diego d'Ambra)
|
||||
|
||||
plugins/tls: close the file descriptor for the SSL socket
|
||||
|
||||
Set the Return-Path header when queuing into maildir mailboxes.
|
||||
|
@ -248,21 +248,6 @@ sub run_as_server {
|
||||
IO::Handle::blocking($CONFIG_SERVER, 0);
|
||||
binmode($CONFIG_SERVER, ':raw');
|
||||
|
||||
if ($DETACH) {
|
||||
open STDIN, '/dev/null' or die "/dev/null: $!";
|
||||
open STDOUT, '>/dev/null' or die "/dev/null: $!";
|
||||
open STDERR, '>&STDOUT' or die "open(stderr): $!";
|
||||
defined (my $pid = fork) or die "fork: $!";
|
||||
exit 0 if $pid;
|
||||
POSIX::setsid or die "setsid: $!";
|
||||
}
|
||||
|
||||
if ($PID_FILE) {
|
||||
open PID, ">$PID_FILE" || die "$PID_FILE: $!";
|
||||
print PID $$,"\n";
|
||||
close PID;
|
||||
}
|
||||
|
||||
# Drop priviledges
|
||||
my (undef, undef, $quid, $qgid) = getpwnam $USER or
|
||||
die "unable to determine uid/gid for $USER\n";
|
||||
@ -285,6 +270,21 @@ sub run_as_server {
|
||||
my $plugin_loader = Qpsmtpd::SMTP->new();
|
||||
$plugin_loader->load_plugins;
|
||||
|
||||
if ($DETACH) {
|
||||
open STDIN, '/dev/null' or die "/dev/null: $!";
|
||||
open STDOUT, '>/dev/null' or die "/dev/null: $!";
|
||||
open STDERR, '>&STDOUT' or die "open(stderr): $!";
|
||||
defined (my $pid = fork) or die "fork: $!";
|
||||
exit 0 if $pid;
|
||||
POSIX::setsid or die "setsid: $!";
|
||||
}
|
||||
|
||||
if ($PID_FILE) {
|
||||
open PID, ">$PID_FILE" || die "$PID_FILE: $!";
|
||||
print PID $$,"\n";
|
||||
close PID;
|
||||
}
|
||||
|
||||
$plugin_loader->log(LOGINFO, 'Running as user '.
|
||||
(getpwuid($>) || $>) .
|
||||
', group '.
|
||||
|
@ -150,20 +150,6 @@ if ($pid_file) {
|
||||
}
|
||||
}
|
||||
|
||||
if ($detach) {
|
||||
open STDIN, '/dev/null' or die "/dev/null: $!";
|
||||
open STDOUT, '>/dev/null' or die "/dev/null: $!";
|
||||
open STDERR, '>&STDOUT' or die "open(stderr): $!";
|
||||
defined (my $pid = fork) or die "fork: $!";
|
||||
exit 0 if $pid;
|
||||
POSIX::setsid or die "setsid: $!";
|
||||
}
|
||||
|
||||
if ($pid_file) {
|
||||
print PID $$,"\n";
|
||||
close PID;
|
||||
}
|
||||
|
||||
run();
|
||||
|
||||
#start daemon
|
||||
@ -262,6 +248,20 @@ sub run {
|
||||
# after each connection
|
||||
$qpsmtpd = $qpsmtpd_base = qpsmtpd_instance();
|
||||
|
||||
if ($detach) {
|
||||
open STDIN, '/dev/null' or die "/dev/null: $!";
|
||||
open STDOUT, '>/dev/null' or die "/dev/null: $!";
|
||||
open STDERR, '>&STDOUT' or die "open(stderr): $!";
|
||||
defined (my $pid = fork) or die "fork: $!";
|
||||
exit 0 if $pid;
|
||||
POSIX::setsid or die "setsid: $!";
|
||||
}
|
||||
|
||||
if ($pid_file) {
|
||||
print PID $$,"\n";
|
||||
close PID;
|
||||
}
|
||||
|
||||
# child reaper
|
||||
$SIG{CHLD} = \&reaper;
|
||||
spawn_children();
|
||||
|
Loading…
Reference in New Issue
Block a user