summaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorMarc Espie <espie@cvs.openbsd.org>2008-03-10 13:11:58 +0000
committerMarc Espie <espie@cvs.openbsd.org>2008-03-10 13:11:58 +0000
commitfd0bc9c96195042929bfae41e87dc3134db1ca73 (patch)
tree6aabb546387fa50cf0ec4b04530e1734592ce413 /usr.sbin
parent3e6cb544d270177f802eacd9c7bcfe3f73166e81 (diff)
print better error message if child dies... with extra dark magic to grab
signal names from POSIX.
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/pkg_add/OpenBSD/Error.pm71
1 files changed, 66 insertions, 5 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/Error.pm b/usr.sbin/pkg_add/OpenBSD/Error.pm
index 34c523f0f91..0f8d8d052fc 100644
--- a/usr.sbin/pkg_add/OpenBSD/Error.pm
+++ b/usr.sbin/pkg_add/OpenBSD/Error.pm
@@ -1,5 +1,5 @@
# ex:ts=8 sw=4:
-# $OpenBSD: Error.pm,v 1.11 2007/06/04 14:40:39 espie Exp $
+# $OpenBSD: Error.pm,v 1.12 2008/03/10 13:11:57 espie Exp $
#
# Copyright (c) 2004 Marc Espie <espie@openbsd.org>
#
@@ -25,11 +25,70 @@ our @EXPORT=qw(System VSystem Copy Fatal Warn Usage set_usage
our ($FileName, $Line, $FullMessage);
+my @signal_name = ();
+
+sub fillup_names
+{
+ {
+ # XXX force autoload
+ package verylocal;
+
+ require POSIX;
+ POSIX->import(qw(signal_h));
+ }
+
+ for my $sym (keys %POSIX::) {
+ next unless $sym =~ /^SIG([A-Z].*)/;
+ $signal_name[eval "&POSIX::$sym()"] = $1;
+ }
+ # extra BSD signals
+ $signal_name[5] = 'TRAP';
+ $signal_name[7] = 'IOT';
+ $signal_name[10] = 'BUS';
+ $signal_name[12] = 'SYS';
+ $signal_name[16] = 'URG';
+ $signal_name[23] = 'IO';
+ $signal_name[24] = 'XCPU';
+ $signal_name[25] = 'XFSZ';
+ $signal_name[26] = 'VTALRM';
+ $signal_name[27] = 'PROF';
+ $signal_name[28] = 'WINCH';
+ $signal_name[29] = 'INFO';
+}
+
+sub find_signal
+{
+ my $number = shift;
+
+ if (@signal_name == 0) {
+ fillup_names();
+ }
+
+ return $signal_name[$number] || $number;
+}
+
+sub child_error
+{
+ my $error = $?;
+
+ my $extra = "";
+
+ if ($error & 128) {
+ $extra = " (core dumped)";
+ }
+ if ($error & 127) {
+ return "killed by signal ". find_signal($error & 127).$extra;
+ } else {
+ return "exit(". ($error >> 8) . ")$extra";
+ }
+}
+
sub System
{
my $r = system(@_);
if ($r != 0) {
- print "system(", join(", ", @_), ") failed: $?\n";
+ print "system(", join(", ", @_), ") failed: ", child_error(),
+ "\n";
}
return $r;
}
@@ -43,7 +102,7 @@ sub VSystem
print "Running ", join(' ', @_);
my $r = system(@_);
if ($r != 0) {
- print "... failed: $?\n";
+ print "... failed: ", child_error(), "\n";
} else {
print "\n";
}
@@ -131,11 +190,13 @@ sub system
$state->print($_);
}
if (!close $grab) {
- $state->print("system(", join(", ", @_), ") failed: $! $?\n");
+ $state->print("system(", join(", ", @_), ") failed: $! ",
+ child_error(), "\n");
}
return $?;
} else {
- $state->print("system(", join(", ", @_), ") was not run: $! $?\n");
+ $state->print("system(", join(", ", @_),
+ ") was not run: $!", child_error(), "\n");
}
}