Commit f2cd4415 authored by Leigh B. Stoller's avatar Leigh B. Stoller
Browse files

Add LogStart() and LogEnd(), which just changes how the email is sent.

Rather then "auditing" (sending to testbed-audit) send to testbed-logs.
parent 35effe1b
......@@ -2,7 +2,7 @@
#
# EMULAB-COPYRIGHT
# Copyright (c) 2000-2004 University of Utah and the Flux Group.
# Copyright (c) 2000-2004, 2006 University of Utah and the Flux Group.
# All rights reserved.
#
......@@ -11,7 +11,8 @@ use Exporter;
@ISA = "Exporter";
@EXPORT =
qw ( AuditStart AuditEnd AuditAbort AuditFork AuditSetARGV );
qw ( AuditStart AuditEnd AuditAbort AuditFork AuditSetARGV
LogStart LogEnd );
# After package decl.
use English;
......@@ -34,6 +35,8 @@ my $USERNAME = "Unknown";
my $GCOS = "Unknown";
my @SAVEARGV = @ARGV;
my $SAVEPID = $PID;
my $SAVE_STDOUT;
my $SAVE_STDERR;
# Indicates, this script is being audited.
my $auditing = 0;
......@@ -41,6 +44,9 @@ my $auditing = 0;
# Where the log is going. When not defined, do not send it in email!
my $logfile;
# Logonly, not to audit list.
my $logonly = 0;
# Untainted scriptname for email below.
if ($PROGRAM_NAME =~ /^([-\w\.\/]+)$/) {
$SCRIPTNAME = basename($1);
......@@ -61,9 +67,9 @@ if (my ($name,undef,undef,undef,undef,undef,$gcos) = getpwuid($UID)) {
# into which the log should be written. The return value is non-zero in the
# parent, and zero in the child (if detaching).
#
sub AuditStart($;$)
sub AuditStart($;$$)
{
my($daemon, $logname) = @_;
my($daemon, $logname, $logging) = @_;
#
# If we are already auditing, then do not audit a child script. This
......@@ -74,6 +80,11 @@ sub AuditStart($;$)
return;
}
# Logging instead of "auditing" ...
if (defined($logging)) {
$logonly = $logging;
}
#
# If this is an interactive session, then do not bother with a log
# file. Just send it to the output and hope the user is smart enough to
......@@ -132,6 +143,12 @@ sub AuditStart($;$)
chmod(0664, $logfile);
}
# Save old stderr and stdout.
open(OLDOUT, ">&", \*STDOUT);
$SAVE_STDOUT = *OLDOUT;
open(OLDERR, ">&", \*STDERR);
$SAVE_STDERR = *OLDERR;
open(STDOUT, ">> $logfile") or
die("opening $logfile for STDOUT: $!");
open(STDERR, ">> $logfile") or
......@@ -146,6 +163,19 @@ sub AuditStart($;$)
return 0;
}
# Logging, not auditing.
sub LogStart($;$)
{
my($daemon, $logname) = @_;
return AuditStart($daemon, $logname, 1);
}
sub LogEnd()
{
return AuditEnd();
}
#
# Finish an Audit.
#
......@@ -226,7 +256,9 @@ sub SendAuditMail($)
}
my $FROM = "$GCOS <${USERNAME}\@${OURDOMAIN}>";
SENDMAIL($TBAUDIT, $subject, $body, $FROM, undef, ());
if (! $logonly) {
SENDMAIL($TBAUDIT, $subject, $body, $FROM, undef, ());
}
# Success and no log ...
if ($exitstatus == 0 && !(defined($logfile) && -s $logfile)) {
......@@ -255,6 +287,9 @@ sub SendAuditMail($)
unlink($logfile)
if (defined($logfile));
}
open(STDOUT, ">&", $SAVE_STDOUT);
open(STDERR, ">&", $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