Commit c47cad29 authored by Leigh Stoller's avatar Leigh Stoller

Add a few functions for dealing with experiment setup/teardown log

files so that they can be viewed later from the web interface.
parent 77ca32bb
......@@ -96,6 +96,7 @@ use Exporter;
TBUnixGroupList TBOSID TBImageID TBdbfork VnameToNodeid TBExpLocked
TBIsNodeRemote TBExptSetLogFile TBExptClearLogFile TBExptGetLogFile
TBIsNodeVirtual TBControlNetIP TBPhysNodeID
TBExptOpenLogFile TBExptCloseLogFile TBExptCreateLogFile
TBDB_WIDEAREA_LOCALNODE
TBWideareaNodeID
......@@ -483,8 +484,8 @@ sub TBAdmin(;$)
# No one is considered an admin unless they have the magic environment
# variable set (so that you have to be a bit more explict about wanting
# admin privs.) Use the withadminprivs script to get this variable set.
# Also check with HTTP_ at the front of the name, since this is required
# to get it through suexec from the web scripts.
# Also check with HTTP_ at the front of the name, since this is required
# to get it through suexec from the web scripts.
#
if (!($ENV{WITH_TB_ADMIN_PRIVS} || $ENV{HTTP_WITH_TB_ADMIN_PRIVS})) {
return 0;
......@@ -1658,23 +1659,47 @@ sub TBExptClearLogFile($$)
{
my ($pid, $eid) = @_;
DBQueryFatal("update experiments set logfile=NULL ".
DBQueryFatal("update experiments set logfile=NULL,logfile_open=0 ".
"where pid='$pid' and eid='$eid'");
}
#
# Flag the logfile as either open or closed. This allows the spew code
# to determine when the log is no longer being appended to. Is there a
# system oriented way to do this?
#
# usage TBExptOpenLogFile(char *pid, char *eid)
# usage TBExptCloseLogFile(char *pid, char *eid)
#
sub TBExptOpenLogFile($$)
{
my ($pid, $eid) = @_;
DBQueryFatal("update experiments set logfile_open=1 ".
"where pid='$pid' and eid='$eid'");
}
sub TBExptCloseLogFile($$)
{
my ($pid, $eid) = @_;
DBQueryFatal("update experiments set logfile_open=0 ".
"where pid='$pid' and eid='$eid'");
}
#
# Get the current logfile for an experiment.
#
# usage TBExptGetLogFile(char *pid, char *eid, char \*logname)
# usage TBExptGetLogFile(char *pid, char *eid, char \*logname, int \isopen)
# Return 1 if there is a valid logname, and sets logname.
# Return 0 if no logfile or error.
#
sub TBExptGetLogFile($$$)
sub TBExptGetLogFile($$$$)
{
my ($pid, $eid, $logname) = @_;
my ($pid, $eid, $logname, $isopen) = @_;
my $query_result =
DBQueryFatal("select logfile from experiments ".
DBQueryFatal("select logfile,logfile_open from experiments ".
"where pid='$pid' and eid='$eid'");
if ($query_result->numrows == 0) {
......@@ -1683,11 +1708,39 @@ sub TBExptGetLogFile($$$)
my @row = $query_result->fetchrow_array();
if (defined($row[0])) {
$$logname = $row[0];
$$isopen = $row[1];
return 1;
}
return 0;
}
#
# Create a temp logfile name for an experiment, create it, and untaint it!
# Note that we create the file in /tmp initially, mostly as a convenience,
# and then move it into the experiment directory later.
#
sub TBExptCreateLogFile($$$)
{
my($pid, $eid, $prefix) = @_;
my $logname;
$logname = `mktemp /tmp/${prefix}-${pid}-${eid}.XXXXXX`;
if ($logname =~ /^([-\@\w\.\/]+)$/) {
$logname = $1;
}
else {
die("*** $0:\n".
" Bad data in logfile name: $logname");
}
chmod(0640, $logname) or
die("*** $0:\n".
" Could not chmod $logname to 0640: $!\n");
return $logname;
}
#
# Get the control network IP for a node (underlying physical node!).
#
......
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