Permalink
Browse files

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: http://svn.perl.org/qpsmtpd/trunk@938 958fd67b-6ff1-0310-b445-bb7760255be9
  • Loading branch information...
1 parent 4d2ecbf commit 714211e886a42337fdca06ff6f94f4bb78aeed03 radu committed Sep 4, 2008
Showing with 33 additions and 29 deletions.
  1. +4 −0 Changes
  2. +15 −15 qpsmtpd-async
  3. +14 −14 qpsmtpd-prefork
View
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.
View
30 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 '.
View
28 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();

0 comments on commit 714211e

Please sign in to comment.