Commit b5db8735 authored by Leigh Stoller's avatar Leigh Stoller

Fix the AuditFork() to prevent the loss of STDERR. Turns out

(something I just managed to remember) is that if you call the shell
without STDERR=2, then the shell has no place to send STDERR. The
only way to get this correct is to use POSIX::dup2 instead of the
standard perl open function. Well, I bet there is a way (or 10 ways)
to do this, but this is one that stumbled onto. libaudit does a lot
of descriptor messing around.

BTW; this is also why we sometimes lose STDERR from the XMLRPC server.
parent a2715c10
......@@ -20,7 +20,7 @@ use Exporter;
# After package decl.
use English;
use POSIX qw(isatty setsid);
use POSIX qw(isatty setsid dup2);
use File::Basename;
use IO::Handle;
use Carp;
......@@ -308,14 +308,25 @@ sub AuditFork()
if (!$daemon && $PERL_VERSION >= 5.008) {
close($libaudit::SAVE_STDOUT);
close($libaudit::SAVE_STDERR);
$libaudit::SAVE_STDOUT = 0;
$libaudit::SAVE_STDERR = 0;
}
close(STDOUT);
close(STDERR);
open(STDOUT, ">> $logfile") or
die("opening $logfile for STDOUT: $!");
open(STDERR, ">> $logfile") or
die("opening $logfile for STDERR: $!");
if (0) {
open(STDOUT, ">> $logfile") or
die("opening $logfile for STDOUT: $!");
open(STDERR, ">> $logfile") or
die("opening $logfile for STDERR: $!");
}
else {
open(LOG, "> $logfile") or
die("opening $logfile for $logfile: $!");
POSIX::dup2(fileno(LOG), 1);
POSIX::dup2(fileno(LOG), 2);
}
#
# Turn off line buffering on output
......@@ -354,7 +365,7 @@ sub SendAuditMail($)
&libtblog::tblog_find_error();
}
if (!$daemon && $PERL_VERSION >= 5.008) {
if (!$daemon && $PERL_VERSION >= 5.008 && $libaudit::SAVE_STDOUT) {
eval("open(STDOUT, \">&\", \$libaudit::SAVE_STDOUT); ".
"open(STDERR, \">&\", \$libaudit::SAVE_STDERR);");
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment