Commit 846fa180 authored by Leigh Stoller's avatar Leigh Stoller

Minor exit status fixes.

parent ea0b9b90
...@@ -15,6 +15,15 @@ use Getopt::Std; ...@@ -15,6 +15,15 @@ use Getopt::Std;
# supplied, an experiment shell is created (this is currently an admin # supplied, an experiment shell is created (this is currently an admin
# only option). # only option).
# #
# Exit codes are important; they tell the web page what has happened so
# it can say something useful to the user. Fatal errors are mostly done
# with die(), but expected errors use this routine. At some point we will
# use the DB to communicate the actual error.
#
# $status < 0 - Fatal error. Something went wrong we did not expect.
# $status = 0 - Everything okay.
# $status > 0 - Expected error. User not allowed for some reason.
#
sub usage() sub usage()
{ {
die("Usage: batchexp [-i [-f]] [-x expires] [-E description] [-g gid] ". die("Usage: batchexp [-i [-f]] [-x expires] [-E description] [-g gid] ".
...@@ -45,6 +54,7 @@ my $tbdata = "tbdata"; ...@@ -45,6 +54,7 @@ my $tbdata = "tbdata";
my $immediate= 0; my $immediate= 0;
my $frontend = 0; my $frontend = 0;
my $quiet = 0; my $quiet = 0;
my $errorstat=-1;
my $dbuid; my $dbuid;
my @row; my @row;
...@@ -257,6 +267,8 @@ chmod(0664, "$nsfile"); ...@@ -257,6 +267,8 @@ chmod(0664, "$nsfile");
# will display any errors. # will display any errors.
# #
if (system("$parser -n $pid $gid $eid $nsfile") != 0) { if (system("$parser -n $pid $gid $eid $nsfile") != 0) {
# Obey exit status protocol for web page.
$errorstat = 1;
fatal("NS Parse failed!"); fatal("NS Parse failed!");
} }
...@@ -296,6 +308,8 @@ if ($immediate) { ...@@ -296,6 +308,8 @@ if ($immediate) {
if ($quiet); if ($quiet);
if (system("$startexp $optargs -g $gid $pid $eid $nsfile")) { if (system("$startexp $optargs -g $gid $pid $eid $nsfile")) {
# Obey exit status protocol for web page.
$errorstat = 1;
fatal("Failed to start experiment $pid/$eid!"); fatal("Failed to start experiment $pid/$eid!");
} }
} }
...@@ -306,6 +320,8 @@ else { ...@@ -306,6 +320,8 @@ else {
# at it. # at it.
# #
if (system("$startexp -f -b -g $gid $pid $eid $nsfile")) { if (system("$startexp -f -b -g $gid $pid $eid $nsfile")) {
# Obey exit status protocol for web page.
$errorstat = 1;
fatal("Failed to preload batch experiment $pid/$eid!"); fatal("Failed to preload batch experiment $pid/$eid!");
} }
# And drop the batch into the queue unless the user was preloading # And drop the batch into the queue unless the user was preloading
...@@ -348,7 +364,7 @@ sub fatal($) ...@@ -348,7 +364,7 @@ sub fatal($)
# #
TBExptDestroy($pid, $eid); TBExptDestroy($pid, $eid);
exit(-1); exit($errorstat);
} }
# #
......
...@@ -427,7 +427,7 @@ sub fatal() ...@@ -427,7 +427,7 @@ sub fatal()
# case the user tries to muck with it. # case the user tries to muck with it.
# #
if ($nodetach) { if ($nodetach) {
exit(0); exit($errorstat);
} }
# #
......
...@@ -834,7 +834,7 @@ if ($delnsfile) { ...@@ -834,7 +834,7 @@ if ($delnsfile) {
# Fatal Error. Report to the user, even though there is not much he can # Fatal Error. Report to the user, even though there is not much he can
# do with the error. Also reports to tbops. # do with the error. Also reports to tbops.
# #
if ($retval) { if ($retval < 0) {
SUEXECERROR(SUEXEC_ACTION_DIE); SUEXECERROR(SUEXEC_ACTION_DIE);
# #
# Never returns ... # Never returns ...
...@@ -842,6 +842,16 @@ if ($retval) { ...@@ -842,6 +842,16 @@ if ($retval) {
die(""); die("");
} }
# User error. Tell user and exit.
if ($retval) {
echo "<br>";
echo "<h3>Experiment could not be created</h3>";
echo "<blockquote><pre>$suexec_output<pre></blockquote>";
PAGEFOOTER();
exit();
}
# add reasons to db, since we don't want to pass these on the command line. # add reasons to db, since we don't want to pass these on the command line.
if ($formfields[exp_noswap_reason]) { if ($formfields[exp_noswap_reason]) {
......
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