Commit dfd200a6 authored by Leigh Stoller's avatar Leigh Stoller

Use autoflush interface to turn off buffering of stdout/stderr when

redirecting output.
parent c47cad29
......@@ -107,6 +107,8 @@ post-install:
chmod u+s $(INSTALL_SBINDIR)/setgroups
chown root $(INSTALL_LIBEXECDIR)/console_setup
chmod u+s $(INSTALL_LIBEXECDIR)/console_setup
chown root $(INSTALL_LIBEXECDIR)/spewlogfile
chmod u+s $(INSTALL_LIBEXECDIR)/spewlogfile
chown root $(INSTALL_BINDIR)/node_reboot
chmod u+s $(INSTALL_BINDIR)/node_reboot
chown root $(INSTALL_BINDIR)/node_update
......
......@@ -8,6 +8,8 @@
use English;
use Getopt::Std;
use Fcntl;
use IO::Handle;
#
# Create a batch experiment.
......@@ -247,14 +249,7 @@ sub dosomething($$)
# we can remove it when the child ends. The child could remove it, but
# since it is open in the child, it has the tendency to stick around.
#
$logname = `mktemp /tmp/$dowhat-batch-$pid-$eid.XXXXXX`;
# Note different taint check (allow /).
if ($logname =~ /^([-\@\w.\/]+)$/) {
$logname = $1;
} else {
die "Bad data in $logname";
}
$logname = TBExptCreateLogFile($pid, $eid, "${dowhat}-batch");
#
# Start up a child to run the guts. The parent waits. If the
......@@ -270,12 +265,26 @@ sub dosomething($$)
print "Child PID $childpid exited with exit status $status\n";
sleep(5);
#
# Move the temporary log file into the experiment directory and
# change the name in the DB. This makes it available to the web
# interface later on if desired.
#
# The exp dir might be gone if the batch was killed/canceled.
#
if (-e $dirname) {
my $fname = "$dirname/tbdata/${dowhat}-batch.log";
system("cp -pf $logname $fname");
TBExptCloseLogFile($pid, $eid);
TBExptSetLogFile($pid, $eid, $fname);
}
unlink($logname);
return $status;
}
openlog($logname);
TBExptSetLogFile($pid, $eid, $logname);
TBExptOpenLogFile($pid, $eid);
#
# Get some user information.
......@@ -578,6 +587,9 @@ sub openlog($)
open(STDOUT, ">> $logname") or
fatal("opening $logname for STDOUT: $!");
STDOUT->autoflush(1);
STDERR->autoflush(1);
return 0;
}
......
......@@ -248,15 +248,10 @@ if (! UserDBInfo($expt_head_login, \$expt_head_name, \$expt_head_email)) {
# If not in batch mode, go into the background. Parent exits.
#
if (! $batch) {
$logname = `mktemp /tmp/end-$pid-$eid.XXXXXX`;
$logname = TBExptCreateLogFile($pid, $eid, "end");
TBExptSetLogFile($pid, $eid, $logname);
TBExptOpenLogFile($pid, $eid);
if ($logname =~ /^([-\@\w.\/]+)$/) {
$logname = $1;
}
else {
die("Bad data in logfile name: $logname");
}
if (TBBackGround($logname)) {
#
# Parent exits normally
......@@ -366,7 +361,18 @@ sub fatal($)
"Bcc: $TBOPS",
($logname));
#
# Move the temporary log file into the experiment directory so its kept.
#
if (defined($logname)) {
#
# Move the temporary log file into the experiment directory and
# change the name in the DB. This makes it available to the web
# interface later on if desired.
#
system("cp -pf $logname $expt_path/tbdata/endexp.log");
TBExptCloseLogFile($pid, $eid);
TBExptSetLogFile($pid, $eid, "$expt_path/tbdata/endexp.log");
unlink("$logname");
}
exit(-1);
......
......@@ -8,6 +8,8 @@
use English;
use POSIX qw(strftime);
use Fcntl;
use IO::Handle;
package libtestbed;
use Exporter;
......@@ -195,6 +197,12 @@ sub TBBackGround($)
open(STDERR, ">> $logname") or die("opening $logname for STDERR: $!");
open(STDOUT, ">> $logname") or die("opening $logname for STDOUT: $!");
#
# Turn off line buffering on output
#
STDOUT->autoflush(1);
STDERR->autoflush(1);
return 0;
}
......
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