diff options
author | Philip Hazel <ph10@hermes.cam.ac.uk> | 2005-01-27 15:00:38 +0000 |
---|---|---|
committer | Philip Hazel <ph10@hermes.cam.ac.uk> | 2005-01-27 15:00:38 +0000 |
commit | 76a2d7bad2f69787569f842d9d154524c4758ce3 (patch) | |
tree | 95a087f0eeba36cf2885d5886296e099556c6b36 /src | |
parent | fe5b5d0bae5dfd455dfded22bd3c0eede07f7288 (diff) |
Arrange for output from Perl's "warn" to go to the mainlog by default.
Diffstat (limited to 'src')
-rw-r--r-- | src/src/daemon.c | 35 | ||||
-rw-r--r-- | src/src/perl.c | 17 |
2 files changed, 38 insertions, 14 deletions
diff --git a/src/src/daemon.c b/src/src/daemon.c index 1c274d732..88dd69d21 100644 --- a/src/src/daemon.c +++ b/src/src/daemon.c @@ -1,4 +1,4 @@ -/* $Cambridge: exim/src/src/daemon.c,v 1.5 2005/01/04 10:37:55 ph10 Exp $ */ +/* $Cambridge: exim/src/src/daemon.c,v 1.6 2005/01/27 15:00:39 ph10 Exp $ */ /************************************************* * Exim - an Internet mail transport agent * @@ -1124,26 +1124,35 @@ if (daemon_listen) } } -/* We now close all open file descriptors that we know about, and disconnect -from the controlling terminal, unless background_daemon is unset. This is -always unset when debugging, but can also be forced. Most modern Unixes seem to -have setsid() for getting rid of the controlling terminal. For any OS that -doesn't, setsid() can be #defined as a no-op, or as something else. */ +/* The variable background_daemon is always false when debugging, but +can also be forced false in order to keep a non-debugging daemon in the +foreground. If background_daemon is true, close all open file descriptors that +we know about, but then re-open stdin, stdout, and stderr to /dev/null. + +This is protection against any called functions (in libraries, or in +Perl, or whatever) that think they can write to stderr (or stdout). Before this +was added, it was quite likely that an SMTP connection would use one of these +file descriptors, in which case writing random stuff to it caused chaos. + +Then disconnect from the controlling terminal, Most modern Unixes seem to have +setsid() for getting rid of the controlling terminal. For any OS that doesn't, +setsid() can be #defined as a no-op, or as something else. */ if (background_daemon) { - log_close_all(); /* Just in case anything was logged earlier */ - search_tidyup(); /* Just in case any were used in reading the config. */ - close(0); /* Get rid of stdin/stdout/stderr */ + log_close_all(); /* Just in case anything was logged earlier */ + search_tidyup(); /* Just in case any were used in reading the config. */ + close(0); /* Get rid of stdin/stdout/stderr */ close(1); close(2); + exim_nullstd(); /* Connect stdin/stdout/stderr to /dev/null */ log_stderr = NULL; /* So no attempt to copy paniclog output */ /* If the parent process of this one has pid == 1, we are re-initializing the - daemon as the result of a SIGHUP. In this case, there is no need to do any - forking, because the controlling terminal has long gone. Otherwise, fork, - in case current process is a process group leader (see 'man setsid' for an - explanation). */ + daemon as the result of a SIGHUP. In this case, there is no need to do + anything, because the controlling terminal has long gone. Otherwise, fork, in + case current process is a process group leader (see 'man setsid' for an + explanation) before calling setsid(). */ if (getppid() != 1) { diff --git a/src/src/perl.c b/src/src/perl.c index a22fe6f40..5bb7ad360 100644 --- a/src/src/perl.c +++ b/src/src/perl.c @@ -1,4 +1,4 @@ -/* $Cambridge: exim/src/src/perl.c,v 1.2 2004/12/20 11:46:21 ph10 Exp $ */ +/* $Cambridge: exim/src/src/perl.c,v 1.3 2005/01/27 15:00:39 ph10 Exp $ */ /************************************************* * Exim - an Internet mail transport agent * @@ -109,6 +109,21 @@ init_perl(uschar *startup_code) perl_run(interp_perl); { dSP; + + /*********************************************************************/ + /* These lines by PH added to make "warn" output go to the Exim log; I + hope this doesn't break anything. */ + + sv = newSVpv( + "$SIG{__WARN__} = sub { my($s) = $_[0];" + "$s =~ s/\\n$//;" + "Exim::log_write($s) };", 0); + PUSHMARK(SP); + perl_eval_sv(sv, G_SCALAR|G_DISCARD|G_KEEPERR); + SvREFCNT_dec(sv); + if (SvTRUE(ERRSV)) return US SvPV(ERRSV, len); + /*********************************************************************/ + sv = newSVpv(CS startup_code, 0); PUSHMARK(SP); perl_eval_sv(sv, G_SCALAR|G_DISCARD|G_KEEPERR); |