diff options
author | Lasse Collin <lasse.collin@tukaani.org> | 2012-02-22 14:02:34 +0200 |
---|---|---|
committer | Lasse Collin <lasse.collin@tukaani.org> | 2012-05-24 18:52:48 +0300 |
commit | b7ad23fa78646036c0290cd91eada939c9a31526 (patch) | |
tree | 179391c951724e31ae20bd024ae361b75d5acaea /src/scripts/xzgrep.in | |
parent | Update THANKS. (diff) | |
download | xz-b7ad23fa78646036c0290cd91eada939c9a31526.tar.xz |
Fix exit status of xzgrep when grepping binary files.
When grepping binary files, grep may exit before it has
read all the input. In this case, gzip -q returns 2 (eating
SIGPIPE), but xz and bzip2 show SIGPIPE as the exit status
(e.g. 141). This causes wrong exit status when grepping
xz- or bzip2-compressed binary files.
The fix checks for the special exit status that indicates SIGPIPE.
It uses kill -l which should be supported everywhere since it
is in both SUSv2 (1997) and POSIX.1-2008.
Thanks to James Buren for the bug report.
Diffstat (limited to 'src/scripts/xzgrep.in')
-rw-r--r-- | src/scripts/xzgrep.in | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/src/scripts/xzgrep.in b/src/scripts/xzgrep.in index ae30725c..515b516a 100644 --- a/src/scripts/xzgrep.in +++ b/src/scripts/xzgrep.in @@ -194,7 +194,8 @@ for i; do fi >&3 5>&- ) r=$? - test "$xz_status" -eq 0 || test "$xz_status" -eq 2 || r=2 + test "$xz_status" -eq 0 || test "$xz_status" -eq 2 \ + || test "$(kill -l "$xz_status" 2> /dev/null)" = "PIPE" || r=2 test $res -lt $r && res=$r done exit $res |