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