Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
emulab
emulab-devel
Commits
696fb08d
Commit
696fb08d
authored
Jul 18, 2014
by
Mike Hibler
Browse files
Employ Stupid Shell Tricks to get exit status out of pipeline command.
parent
1277718c
Changes
1
Hide whitespace changes
Inline
Side-by-side
os/create-image
View file @
696fb08d
#!/usr/bin/perl -wT
#
# Copyright (c) 2000-201
2
University of Utah and the Flux Group.
# Copyright (c) 2000-201
4
University of Utah and the Flux Group.
#
# {{{EMULAB-LICENSE
#
...
...
@@ -50,18 +50,23 @@ delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};
#
# No configure vars.
#
my
$sudo
;
my
$sudo
=
""
;
my
$zipper
=
"
/usr/local/bin/imagezip
";
my
$uploader
=
"
/usr/local/bin/frisupload
";
my
$slice
=
"";
my
$device
;
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
")
{
$sudo
=
"
$path
/sudo
";
last
;
$sudo
=
"
$path
/sudo
";
last
;
}
}
}
# Frisbee master server params
...
...
@@ -168,8 +173,11 @@ if ($^O eq 'linux') {
#
# 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
))
{
# use basic shell sleezy trick to capture exit status from imagezip
$cmd
=
"
(
$cmd
|| echo
\$
? > /tmp/imagezip.stat )
";
$cmd
.=
"
|
$uploader
-S
$iserver
-F
$imageid
-
";
}
...
...
@@ -178,9 +186,20 @@ if (defined($imageid)) {
# with proper trust should be able to zip up a disk. sudo will fail
# 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
"
command: '
$sudo
$cmd
'
\n
";
print
STDERR
"
command: '
$cmd
'
\n
";
print
STDERR
"
status:
$stat
\n
";
print
STDERR
"
izstatus:
$izstat
\n
"
if
(
$izstat
);
exit
1
;
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment