linux-image: Make user hook failure handling consistent across maintainer scripts
- Use system_failure_message() to generate the error message - Exit using "die", not passing up the exit code (which will be 0 in case the process was terminated by signal!) - Remove redundant path lookup since system() already does that
This commit is contained in:
parent
f71765e064
commit
78007e962c
|
@ -551,25 +551,14 @@ if (($arch eq "mips" || $arch eq "mipsel")
|
|||
|
||||
# set the env var stem
|
||||
$ENV{'STEM'} = "linux";
|
||||
|
||||
sub run_hook {
|
||||
my $type = shift;
|
||||
my $script = shift;
|
||||
|
||||
print STDERR "Running $script.\n";
|
||||
system ("$script $version $realimageloc$kimage-$version") &&
|
||||
print STDERR "User $type hook script [$script] ";
|
||||
if ($?) {
|
||||
if ($? == -1) {
|
||||
print STDERR "failed to execute: $!\n";
|
||||
}
|
||||
elsif ($? & 127) {
|
||||
printf STDERR "died with signal %d, %s coredump\n",
|
||||
($? & 127), ($? & 128) ? 'with' : 'without';
|
||||
}
|
||||
else {
|
||||
printf STDERR "exited with value %d\n", $? >> 8;
|
||||
}
|
||||
exit $? >> 8;
|
||||
if (system ("$script $version $realimageloc$kimage-$version")) {
|
||||
die ("$script failed: " . system_failure_message());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
use strict;
|
||||
use warnings;
|
||||
use Cwd 'abs_path';
|
||||
use POSIX ();
|
||||
|
||||
# Debconf may not be around here.
|
||||
my $have_debconf = 0;
|
||||
|
@ -146,48 +147,23 @@ sub image_magic {
|
|||
# set the env var stem
|
||||
$ENV{'STEM'} = "linux";
|
||||
|
||||
sub exec_script {
|
||||
my $type = shift;
|
||||
my $script = shift;
|
||||
print STDERR "Running $type hook script $script.\n";
|
||||
system ("$script $version $realimageloc$kimage-$version") &&
|
||||
print STDERR "User $type hook script [$script] ";
|
||||
if ($?) {
|
||||
if ($? == -1) {
|
||||
print STDERR "failed to execute: $!\n";
|
||||
}
|
||||
elsif ($? & 127) {
|
||||
printf STDERR "died with signal %d, %s coredump\n",
|
||||
($? & 127), ($? & 128) ? 'with' : 'without';
|
||||
}
|
||||
else {
|
||||
printf STDERR "exited with value %d\n", $? >> 8;
|
||||
}
|
||||
sub system_failure_message {
|
||||
if ($? < 0) {
|
||||
return "$!";
|
||||
} elsif (POSIX::WIFSIGNALED($?)) {
|
||||
return sprintf('signal %d', POSIX::WTERMSIG($?));
|
||||
} else {
|
||||
return sprintf('exit code %d', POSIX::WEXITSTATUS($?));
|
||||
}
|
||||
}
|
||||
|
||||
sub run_hook {
|
||||
my $type = shift;
|
||||
my $script = shift;
|
||||
if ($script =~ m,^/,) {
|
||||
# Full path provided for the hook script
|
||||
if (-x "$script") {
|
||||
&exec_script($type,$script);
|
||||
}
|
||||
else {
|
||||
warn "The provided $type hook script [$script] could not be run.\n";
|
||||
}
|
||||
}
|
||||
else {
|
||||
# Look for it in a safe path
|
||||
for my $path ('/bin', '/sbin', '/usr/bin', '/usr/sbin') {
|
||||
if (-x "$path/$script") {
|
||||
&exec_script($type, "$path/$script");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
# No luck
|
||||
print STDERR "Could not find $type hook script [$script].\n";
|
||||
warn "Looked in: '/bin', '/sbin', '/usr/bin', '/usr/sbin'\n";
|
||||
|
||||
print STDERR "Running $script.\n";
|
||||
if (system ("$script $version $realimageloc$kimage-$version")) {
|
||||
die ("$script failed: " . system_failure_message());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#
|
||||
use strict;
|
||||
use warnings;
|
||||
use POSIX ();
|
||||
|
||||
use Debconf::Client::ConfModule qw(:all);
|
||||
version('2.0');
|
||||
|
@ -39,56 +40,28 @@ if (-r "$CONF_LOC" && -f "$CONF_LOC" ) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
# set the env var stem
|
||||
$ENV{'STEM'} = "linux";
|
||||
|
||||
sub exec_script {
|
||||
my $type = shift;
|
||||
my $script = shift;
|
||||
print STDERR "Running $type hook script $script.\n";
|
||||
system ("$script $version $realimageloc$kimage-$version") &&
|
||||
print STDERR "User $type hook script [$script] ";
|
||||
if ($?) {
|
||||
if ($? == -1) {
|
||||
print STDERR "failed to execute: $!\n";
|
||||
}
|
||||
elsif ($? & 127) {
|
||||
printf STDERR "died with signal %d, %s coredump\n",
|
||||
($? & 127), ($? & 128) ? 'with' : 'without';
|
||||
}
|
||||
else {
|
||||
printf STDERR "exited with value %d\n", $? >> 8;
|
||||
}
|
||||
exit $? >> 8;
|
||||
}
|
||||
}
|
||||
sub run_hook {
|
||||
my $type = shift;
|
||||
my $script = shift;
|
||||
if ($script =~ m,^/,) {
|
||||
# Full path provided for the hook script
|
||||
if (-x "$script") {
|
||||
&exec_script($type,$script);
|
||||
}
|
||||
else {
|
||||
die "The provided $type hook script [$script] could not be run.\n";
|
||||
}
|
||||
}
|
||||
else {
|
||||
# Look for it in a safe path
|
||||
for my $path ('/bin', '/sbin', '/usr/bin', '/usr/sbin') {
|
||||
if (-x "$path/$script") {
|
||||
&exec_script($type, "$path/$script");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
# No luck
|
||||
print STDERR "Could not find $type hook script [$script].\n";
|
||||
die "Looked in: '/bin', '/sbin', '/usr/bin', '/usr/sbin'\n";
|
||||
sub system_failure_message {
|
||||
if ($? < 0) {
|
||||
return "$!";
|
||||
} elsif (POSIX::WIFSIGNALED($?)) {
|
||||
return sprintf('signal %d', POSIX::WTERMSIG($?));
|
||||
} else {
|
||||
return sprintf('exit code %d', POSIX::WEXITSTATUS($?));
|
||||
}
|
||||
}
|
||||
|
||||
sub run_hook {
|
||||
my $type = shift;
|
||||
my $script = shift;
|
||||
|
||||
print STDERR "Running $script.\n";
|
||||
if (system ("$script $version $realimageloc$kimage-$version")) {
|
||||
die ("$script failed: " . system_failure_message());
|
||||
}
|
||||
}
|
||||
|
||||
my $options;
|
||||
for (@ARGV) {
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#
|
||||
use strict;
|
||||
use warnings;
|
||||
use POSIX ();
|
||||
use Debconf::Client::ConfModule qw(:all);
|
||||
version('2.0');
|
||||
my $capb=capb("backup");
|
||||
|
@ -80,56 +81,28 @@ if ($running eq $version) {
|
|||
|
||||
chdir("/") or die "could not chdir to /:$!\n";
|
||||
|
||||
|
||||
# set the env var stem
|
||||
$ENV{'STEM'} = "linux";
|
||||
|
||||
sub exec_script {
|
||||
my $type = shift;
|
||||
my $script = shift;
|
||||
print STDERR "Running $type hook script $script.\n";
|
||||
system ("$script $version $realimageloc$kimage-$version") &&
|
||||
print STDERR "User $type hook script [$script] ";
|
||||
if ($?) {
|
||||
if ($? == -1) {
|
||||
print STDERR "failed to execute: $!\n";
|
||||
}
|
||||
elsif ($? & 127) {
|
||||
printf STDERR "died with signal %d, %s coredump\n",
|
||||
($? & 127), ($? & 128) ? 'with' : 'without';
|
||||
}
|
||||
else {
|
||||
printf STDERR "exited with value %d\n", $? >> 8;
|
||||
}
|
||||
exit $? >> 8;
|
||||
}
|
||||
}
|
||||
sub run_hook {
|
||||
my $type = shift;
|
||||
my $script = shift;
|
||||
if ($script =~ m,^/,) {
|
||||
# Full path provided for the hook script
|
||||
if (-x "$script") {
|
||||
&exec_script($type,$script);
|
||||
}
|
||||
else {
|
||||
die "The provided $type hook script [$script] could not be run.\n";
|
||||
}
|
||||
}
|
||||
else {
|
||||
# Look for it in a safe path
|
||||
for my $path ('/bin', '/sbin', '/usr/bin', '/usr/sbin') {
|
||||
if (-x "$path/$script") {
|
||||
&exec_script($type, "$path/$script");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
# No luck
|
||||
print STDERR "Could not find $type hook script [$script].\n";
|
||||
die "Looked in: '/bin', '/sbin', '/usr/bin', '/usr/sbin'\n";
|
||||
sub system_failure_message {
|
||||
if ($? < 0) {
|
||||
return "$!";
|
||||
} elsif (POSIX::WIFSIGNALED($?)) {
|
||||
return sprintf('signal %d', POSIX::WTERMSIG($?));
|
||||
} else {
|
||||
return sprintf('exit code %d', POSIX::WEXITSTATUS($?));
|
||||
}
|
||||
}
|
||||
|
||||
sub run_hook {
|
||||
my $type = shift;
|
||||
my $script = shift;
|
||||
|
||||
print STDERR "Running $script.\n";
|
||||
if (system ("$script $version $realimageloc$kimage-$version")) {
|
||||
die ("$script failed: " . system_failure_message());
|
||||
}
|
||||
}
|
||||
|
||||
my $options;
|
||||
for (@ARGV) {
|
||||
|
|
Loading…
Reference in New Issue