diff options
author | Ian Jackson <ijackson@chiark.greenend.org.uk> | 2016-07-16 23:10:27 +0100 |
---|---|---|
committer | Ian Jackson <ijackson@chiark.greenend.org.uk> | 2016-07-17 13:46:14 +0100 |
commit | 0658281163715a24c940509ebb8b0a7493e33787 (patch) | |
tree | 083e71018282942a6968dfab55af98e96467449f /dgit | |
parent | 6bce7517ee43b52e0a23c74dec8f5d0bcb7d0668 (diff) |
Subprocess error handling: Initialise $? to -1
When system(3perl) fails due to syscall error, it sets only $!. When
it succeeds it sets only $? and sometimes trashes $!. Conversely,
close of a popened filehandle always sets both in all cases.
Document this in a comment.
So when using system and relying on $?/$! (rather than looking at
system's return value), such as when about to use failedcmd, it's
necessary to initialise $? to -1.
Fix the three call sites where system might be followed by failedcmd
but this wasn't done.
Diffstat (limited to 'dgit')
-rwxr-xr-x | dgit | 10 |
1 files changed, 5 insertions, 5 deletions
@@ -398,7 +398,7 @@ our ($dscdata,$dscurl,$dsc,$dsc_checked,$skew_warning_vsn); sub runcmd { debugcmd "+",@_; - $!=0; $?=0; + $!=0; $?=-1; failedcmd @_ if system @_; } @@ -1782,9 +1782,9 @@ sub check_not_dirty () { my @cmd = (@git, qw(diff --quiet HEAD)); debugcmd "+",@cmd; - $!=0; $?=0; system @cmd; - return if !$! && !$?; - if (!$! && $?==256) { + $!=0; $?=-1; system @cmd; + return if !$?; + if ($?==256) { fail "working tree is dirty (does not match HEAD)"; } else { failedcmd @cmd; @@ -2015,7 +2015,7 @@ END my $diffopt = $debuglevel>0 ? '--exit-code' : '--quiet'; my @diffcmd = (@git, qw(diff), $diffopt, $tree); debugcmd "+",@diffcmd; - $!=0; $?=0; + $!=0; $?=-1; my $r = system @diffcmd; if ($r) { if ($r==256) { |