freeze_if_want_freeze ($cleanpid);
select (undef, undef, undef, 0.1);
}
- Log (undef, "Cleanup command exited $?");
+ Log (undef, "Cleanup command exited ".exit_status_s($?));
}
# if $local_repo is already initialized:
`$gitcmd init --bare`;
if ($?) {
- croak("Error: $gitcmd init --bare exited $?");
+ croak("Error: $gitcmd init --bare exited ".exit_status_s($?));
}
# If $treeish looks like a hash (or abbrev hash) we look it up in
# do that with tags/branches though -- those change over time, so
# they should always be resolved by the remote repo.)
if ($treeish =~ /^[0-9a-f]{3,40}$/s) {
- my $sha1 = `$gitcmd rev-list -n1 ''\Q$treeish\E`;
+ # Hide stderr because it's normal for this to fail:
+ my $sha1 = `$gitcmd rev-list -n1 ''\Q$treeish\E 2>/dev/null`;
if ($? == 0 &&
$sha1 =~ /^$treeish/ && # Don't use commit 123 @ branch abc!
- $sha1 =~ /^([0-9a-f]{40})$/) {
+ $sha1 =~ /^([0-9a-f]{40})$/s) {
$commit = $1;
Log(undef, "Commit $commit already present in $local_repo");
}
Log(undef, "Fetching objects from $repo to $local_repo");
`$gitcmd fetch --no-progress --tags ''\Q$repo\E \Q+refs/heads/*:refs/heads/*\E`;
if ($?) {
- croak("Error: `$gitcmd fetch` exited $?");
+ croak("Error: `$gitcmd fetch` exited ".exit_status_s($?));
}
}
my $gitcmd = "git --git-dir=\Q$repo\E";
my $sha1 = `$gitcmd rev-list -n1 ''\Q$treeish\E`;
unless ($? == 0 && $sha1 =~ /^([0-9a-f]{40})$/) {
- croak("`$gitcmd rev-list` exited $?, '$treeish' not found. Giving up.");
+ croak("`$gitcmd rev-list` exited "
+ .exit_status_s($?)
+ .", '$treeish' not found. Giving up.");
}
$commit = $1;
Log(undef, "Version $treeish is commit $commit");
$ENV{"CRUNCH_SRC_COMMIT"} = $commit;
$git_archive = `$gitcmd archive ''\Q$commit\E`;
if ($?) {
- croak("Error: $gitcmd archive exited $?");
+ croak("Error: $gitcmd archive exited ".exit_status_s($?));
}
}
freeze_if_want_freeze ($installpid);
select (undef, undef, undef, 0.1);
}
- Log (undef, "Install script exited $?");
+ Log (undef, "Install script exited ".exit_status_s($?));
}
if (!$have_slurm)
}
if ($? != 0)
{
- croak("Installing Docker image from $docker_locator returned exit code $?");
+ croak("Installing Docker image from $docker_locator exited "
+ .exit_status_s($?));
}
}
my $childstatus = $?;
my $exitvalue = $childstatus >> 8;
- my $exitinfo = sprintf("exit %d signal %d%s",
- $exitvalue,
- $childstatus & 127,
- ($childstatus & 128 ? ' core dump' : ''));
+ my $exitinfo = "exit ".exit_status_s($childstatus);
$Jobstep->{'arvados_task'}->reload;
my $task_success = $Jobstep->{'arvados_task'}->{success};
my $cmd = "arv-put --portable-data-hash --retries $retry_count " .
"--filename ''\Q$keep_logfile\E " . quotemeta($local_logfile->filename);
my $loglocator = `$cmd`;
- die "system $cmd failed: $?" if $?;
+ die "system $cmd exited ".exit_status_s($?) if $?;
chomp($loglocator);
$local_logfile = undef; # the temp file is automatically deleted
return ($retries > 3) ? $retries : 3;
}
+sub exit_status_s {
+ # Given a $?, return a human-readable exit code string like "0" or
+ # "1" or "0 with signal 1" or "1 with signal 11".
+ my $exitcode = shift;
+ my $s = $exitcode >> 8;
+ if ($exitcode & 0x7f) {
+ $s .= " with signal " . ($exitcode & 0x7f);
+ }
+ if ($exitcode & 0x80) {
+ $s .= " with core dump";
+ }
+ return $s;
+}
+
__DATA__
#!/usr/bin/perl