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

Clean up temporary files used in modify. The temp dirs were being

created in /tmp and left behind. I've moved them to the expwork
directory instead, and added a routine in the library to clear them
out.

Clear out the nsfile (stored in /tmp) used in modify. The web page was
creating a temp file, but never removing it. swapexp now copies the
nsfile in so that the web page can remove the temporary after the
script exits. The temp is placed in the expwork directory as well, but
left behind for debugging.

When swapmod fails, send along the nsfile in the email message.
parent cd71ae9c
...@@ -140,6 +140,12 @@ if (system("gzip -9 $backname")) { ...@@ -140,6 +140,12 @@ if (system("gzip -9 $backname")) {
fatal("gzip $backname failed!"); fatal("gzip $backname failed!");
} }
# Should do this too, but right now I do it by hand ...
if (0) {
system("find . \( -name 'tbdb.*.gz' \) ".
"-mtime +45 -print -delete");
}
if (! chdir($LOGDIR)) { if (! chdir($LOGDIR)) {
fatal("Could not chdir to $LOGDIR: $!"); fatal("Could not chdir to $LOGDIR: $!");
} }
...@@ -163,7 +169,8 @@ if (0) { ...@@ -163,7 +169,8 @@ if (0) {
"-mtime +35 -print -delete"); "-mtime +35 -print -delete");
} }
#SENDMAIL("stoller", "DB Backup Finished", "", undef, undef, ($logname)); #SENDMAIL("stoller@flux.utah.edu",
# "DB Backup Finished", "", undef, undef, ($logname));
unlink("$logname"); unlink("$logname");
exit 0; exit 0;
......
...@@ -118,21 +118,6 @@ if (@ARGV != (($inout eq "modify") ? 3 : 2)) { ...@@ -118,21 +118,6 @@ if (@ARGV != (($inout eq "modify") ? 3 : 2)) {
my $pid = $ARGV[0]; my $pid = $ARGV[0];
my $eid = $ARGV[1]; my $eid = $ARGV[1];
my $nsfile;
if ($inout eq "modify") {
$nsfile = $ARGV[2];
#
# Untaint nsfile argument; Allow slash.
#
if ($nsfile =~ /^([-\w.\/]+)$/) {
$nsfile = $1;
} else {
die("Tainted nsfile name: $nsfile");
}
}
# #
# Untaint the arguments. # Untaint the arguments.
# #
...@@ -151,6 +136,22 @@ else { ...@@ -151,6 +136,22 @@ else {
my $repfile = "$eid.report"; my $repfile = "$eid.report";
my $workdir = TBExptWorkDir($pid, $eid); my $workdir = TBExptWorkDir($pid, $eid);
my $userdir = TBExptUserDir($pid, $eid); my $userdir = TBExptUserDir($pid, $eid);
my $tempnsfile;
my $modnsfile;
if ($inout eq "modify") {
$tempnsfile = $ARGV[2];
#
# Untaint nsfile argument; Allow slash.
#
if ($tempnsfile =~ /^([-\w.\/]+)$/) {
$tempnsfile = $1;
} else {
die("Tainted nsfile name: $tempnsfile");
}
$modnsfile = "$eid-modify.ns";
}
# #
# Verify user and get his DB uid. # Verify user and get his DB uid.
...@@ -388,6 +389,18 @@ if (! UserDBInfo($expt_head_login, \$expt_head_name, \$expt_head_email)) { ...@@ -388,6 +389,18 @@ if (! UserDBInfo($expt_head_login, \$expt_head_name, \$expt_head_email)) {
$expt_head_email = $TBOPS; $expt_head_email = $TBOPS;
} }
#
# Before going to background, we have to copy out the NS file!
#
if ($inout eq "modify") {
unlink($modnsfile);
if (system("/bin/cp", "$tempnsfile", "$modnsfile")) {
die("*** $0:\n".
" Could not copy $tempnsfile to $modnsfile");
}
chmod(0664, "$modnsfile");
}
# #
# If not in batch mode, go into the background. Parent exits. # If not in batch mode, go into the background. Parent exits.
# #
...@@ -466,7 +479,7 @@ elsif ($inout eq "modify") { ...@@ -466,7 +479,7 @@ elsif ($inout eq "modify") {
TBDB_STATS_SWAPMODIFY, 0, TBDB_STATS_FLAGS_PREMODIFY); TBDB_STATS_SWAPMODIFY, 0, TBDB_STATS_FLAGS_PREMODIFY);
print "Backing up old experiment state ... " . TBTimeStamp() . "\n"; print "Backing up old experiment state ... " . TBTimeStamp() . "\n";
if (TBExptBackupVirtualState($pid, $eid, $$)) { if (TBExptBackupVirtualState($pid, $eid)) {
fatal("*** $0:\n". fatal("*** $0:\n".
" Could not backup experiment state; cannot safely continue!\n"); " Could not backup experiment state; cannot safely continue!\n");
} }
...@@ -478,7 +491,7 @@ elsif ($inout eq "modify") { ...@@ -478,7 +491,7 @@ elsif ($inout eq "modify") {
# #
# Rerun tbprerun if modifying. # Rerun tbprerun if modifying.
# #
if (system("$tbdir/tbprerun -m $pid $eid $nsfile") != 0) { if (system("$tbdir/tbprerun -m $pid $eid $modnsfile") != 0) {
$modifyError = "tbprerun failed!"; $modifyError = "tbprerun failed!";
} }
...@@ -519,7 +532,8 @@ elsif ($inout eq "modify") { ...@@ -519,7 +532,8 @@ elsif ($inout eq "modify") {
system("prerender -r $pid $eid"); system("prerender -r $pid $eid");
TBExptRemoveVirtualState($pid, $eid ); TBExptRemoveVirtualState($pid, $eid );
if (0 == TBExptRestoreVirtualState($pid, $eid, $$)) { if (TBExptRestoreVirtualState($pid, $eid) == 0) {
TBExptClearBackupState($pid, $eid);
# Must deal with the prerender explicitly since it runs background. # Must deal with the prerender explicitly since it runs background.
system("prerender -t $pid $eid"); system("prerender -t $pid $eid");
fatal("*** Update aborted; old state restored.\n"); fatal("*** Update aborted; old state restored.\n");
...@@ -529,6 +543,7 @@ elsif ($inout eq "modify") { ...@@ -529,6 +543,7 @@ elsif ($inout eq "modify") {
fatal("*** Experiment state could not be restored!\n"); fatal("*** Experiment state could not be restored!\n");
} }
} }
TBExptClearBackupState($pid, $eid);
} }
else { # $inout eq "restart" assumed. else { # $inout eq "restart" assumed.
print STDOUT "Running tbrestart with arguments: $pid $eid\n"; print STDOUT "Running tbrestart with arguments: $pid $eid\n";
...@@ -587,15 +602,16 @@ if ($batch) { ...@@ -587,15 +602,16 @@ if ($batch) {
# #
if ($inout eq "modify") { if ($inout eq "modify") {
$nsdata_string = `cat $nsfile`; $nsdata_string = `cat $modnsfile`;
if (defined($nsdata_string)) { if (defined($nsdata_string)) {
$nsdata_string = DBQuoteSpecial($nsdata_string); $nsdata_string = DBQuoteSpecial($nsdata_string);
DBQueryWarn("delete from nsfiles WHERE eid='$eid' and pid='$pid'"); DBQueryWarn("delete from nsfiles WHERE eid='$eid' and pid='$pid'");
DBQueryWarn("insert into nsfiles (pid, eid, nsfile) ". DBQueryWarn("insert into nsfiles (pid, eid, nsfile) ".
"VALUES('$pid', '$eid', $nsdata_string)"); "VALUES('$pid', '$eid', $nsdata_string)");
} else { }
print "Warning!! Couldn't read nsfile '$nsfile'!\n"; else {
print "Warning!! Could not read nsfile '$modnsfile'!\n";
} }
} }
...@@ -733,7 +749,7 @@ sub fatal($) ...@@ -733,7 +749,7 @@ sub fatal($)
($idleswap ? $TBOPS : "$user_name <$user_email>"), ($idleswap ? $TBOPS : "$user_name <$user_email>"),
"Cc: $expt_head_name <$expt_head_email>\n". "Cc: $expt_head_name <$expt_head_email>\n".
"Cc: $TBOPS", "Cc: $TBOPS",
($logname)); (($logname), (defined($modnsfile) ? ($modnsfile) : ())));
if ($hosed) { if ($hosed) {
# #
...@@ -750,6 +766,3 @@ sub fatal($) ...@@ -750,6 +766,3 @@ sub fatal($)
exit($errorstat); exit($errorstat);
} }
...@@ -240,7 +240,7 @@ if (! $errors) { ...@@ -240,7 +240,7 @@ if (! $errors) {
if (! $errors) { if (! $errors) {
if ($swapop eq "update") { if ($swapop eq "update") {
print STDERR "Backing up physical state...\n"; print STDERR "Backing up physical state...\n";
TBExptBackupPhysicalState($pid,$eid,$$); TBExptBackupPhysicalState($pid,$eid);
$errors = doSwapout(UPDATE); $errors = doSwapout(UPDATE);
if (! $errors) { if (! $errors) {
...@@ -298,7 +298,7 @@ if (! $errors) { ...@@ -298,7 +298,7 @@ if (! $errors) {
if ($canStillRecover) { if ($canStillRecover) {
print STDERR "Recovering physical state...\n"; print STDERR "Recovering physical state...\n";
my $recoverErrors = TBExptRestorePhysicalState($pid,$eid,$$); my $recoverErrors = TBExptRestorePhysicalState($pid,$eid);
if ($recoverErrors) { if ($recoverErrors) {
print STDERR "Could not restore backed-up physical state; "; print STDERR "Could not restore backed-up physical state; ";
$canStillRecover = 0; $canStillRecover = 0;
......
...@@ -190,6 +190,9 @@ if (! isset($go)) { ...@@ -190,6 +190,9 @@ if (! isset($go)) {
$result = exec("$TBSUEXEC_PATH $uid $unix_gid ". $result = exec("$TBSUEXEC_PATH $uid $unix_gid ".
"webswapexp $rebootswitch -s modify $pid $eid $nsfile", "webswapexp $rebootswitch -s modify $pid $eid $nsfile",
$output, $retval); $output, $retval);
# It has been copied out by the program!
unlink($nsfile);
if ($retval) { if ($retval) {
echo "<br /><br />\n". echo "<br /><br />\n".
......
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