Commit 696fb08d authored by Mike Hibler's avatar Mike Hibler

Employ Stupid Shell Tricks to get exit status out of pipeline command.

parent 1277718c
#!/usr/bin/perl -wT #!/usr/bin/perl -wT
# #
# Copyright (c) 2000-2012 University of Utah and the Flux Group. # Copyright (c) 2000-2014 University of Utah and the Flux Group.
# #
# {{{EMULAB-LICENSE # {{{EMULAB-LICENSE
# #
...@@ -50,18 +50,23 @@ delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'}; ...@@ -50,18 +50,23 @@ delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};
# #
# No configure vars. # No configure vars.
# #
my $sudo; my $sudo = "";
my $zipper = "/usr/local/bin/imagezip"; my $zipper = "/usr/local/bin/imagezip";
my $uploader = "/usr/local/bin/frisupload"; my $uploader = "/usr/local/bin/frisupload";
my $slice = ""; my $slice = "";
my $device; my $device;
my $filename; my $filename;
for my $path (qw#/usr/local/bin /usr/bin#) { #
# If we are running as a user, then we will need sudo
#
if ($EUID != 0) {
for my $path (qw#/usr/local/bin /usr/bin#) {
if (-e "$path/sudo") { if (-e "$path/sudo") {
$sudo = "$path/sudo"; $sudo = "$path/sudo";
last; last;
} }
}
} }
# Frisbee master server params # Frisbee master server params
...@@ -168,8 +173,11 @@ if ($^O eq 'linux') { ...@@ -168,8 +173,11 @@ if ($^O eq 'linux') {
# #
# If imageid is defined, we use the frisbee uploader. # If imageid is defined, we use the frisbee uploader.
# #
my $cmd = "$zipper $slice $device $filename"; my $cmd = "$sudo $zipper $slice $device $filename";
if (defined($imageid)) { if (defined($imageid)) {
# use basic shell sleezy trick to capture exit status from imagezip
$cmd = "( $cmd || echo \$? > /tmp/imagezip.stat )";
$cmd .= " | $uploader -S $iserver -F $imageid -"; $cmd .= " | $uploader -S $iserver -F $imageid -";
} }
...@@ -178,9 +186,20 @@ if (defined($imageid)) { ...@@ -178,9 +186,20 @@ if (defined($imageid)) {
# with proper trust should be able to zip up a disk. sudo will fail # with proper trust should be able to zip up a disk. sudo will fail
# if the user is not in the proper group. # if the user is not in the proper group.
# #
if (system("$sudo $cmd")) { if (system("$cmd") || -e "/tmp/imagezip.stat") {
my $stat = sprintf("0x%04x", $?);
my $izstat = 0;
if (-e "/tmp/imagezip.stat") {
$izstat = `cat /tmp/imagezip.stat`;
chomp($izstat);
}
$izstat = sprintf("0x%04x", $izstat);
print STDERR "*** Failed to create image!\n"; print STDERR "*** Failed to create image!\n";
print STDERR " command: '$sudo $cmd'\n"; print STDERR " command: '$cmd'\n";
print STDERR " status: $stat\n";
print STDERR " izstatus: $izstat\n"
if ($izstat);
exit 1; exit 1;
} }
......
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