From c7f7295dbd260099a58eefeea9594995672fd170 Mon Sep 17 00:00:00 2001 From: Sergey Poznyakoff Date: Thu, 19 Apr 2018 15:23:49 +0300 Subject: Always report incorrect termination of a subprocess --- acmeman | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/acmeman b/acmeman index 99f158a..e6fee16 100755 --- a/acmeman +++ b/acmeman @@ -627,6 +627,20 @@ sub prep_dir { } } +sub runcmd { + my $cmd = shift; + debug(1, "running $cmd"); + unless ($dry_run) { + system($cmd); + if ($? == -1) { + error("$cmd: failed to execute: $!"); + } elsif ($? & 127) { + error("$cmd: died on signal ".($? & 127)); + } elsif (my $code = ($? >> 8)) { + error("$cmd: exited with code $code"); + } + } +} sub debug_to_loglevel { my @lev = ('err', 'info', 'debug'); @@ -1185,17 +1199,7 @@ foreach my $vhost (@domlist) { if ($force || domain_cert_expires($vhost)) { if (register_domain_certificate($vhost)) { if (my $cmd = $vhost->postrenew) { - debug(1, "running $cmd"); - unless ($dry_run) { - system($cmd); - if ($? == -1) { - error("$cmd: failed to execute: $!"); - } elsif ($? & 127) { - error("$cmd: died on signal ".($? & 127)); - } elsif (my $code = ($? >> 8)) { - error("$cmd: exited with code $code"); - } - } + runcmd($cmd); } else { $renewed++; } @@ -1206,8 +1210,7 @@ foreach my $vhost (@domlist) { if ($renewed) { if ($config->isset(qw(core postrenew))) { foreach my $cmd ($config->get(qw(core postrenew))) { - debug(1, "running $cmd"); - system($cmd) unless $dry_run; + runcmd($cmd); } } else { error("certificates changed, but no postrenew command is defined (core.postrenew)"); -- cgit v1.2.1