From 18d1b9f1daa7d2307b5a7e2a2a88901b24822a92 Mon Sep 17 00:00:00 2001 From: Diego d'Ambra Date: Thu, 4 Sep 2008 11:38:54 +0000 Subject: [PATCH] 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 --- Changes | 4 ++++ qpsmtpd-async | 30 +++++++++++++++--------------- qpsmtpd-prefork | 28 ++++++++++++++-------------- 3 files changed, 33 insertions(+), 29 deletions(-) diff --git a/Changes b/Changes index ab44986..c5c531f 100644 --- a/Changes +++ b/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. diff --git a/qpsmtpd-async b/qpsmtpd-async index 467909c..e2986e8 100755 --- a/qpsmtpd-async +++ b/qpsmtpd-async @@ -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 '. diff --git a/qpsmtpd-prefork b/qpsmtpd-prefork index e839959..705f4ff 100755 --- a/qpsmtpd-prefork +++ b/qpsmtpd-prefork @@ -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();