mirror of https://git.tukaani.org/xz.git
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.
This commit is contained in:
parent
41cafb2bf9
commit
cff070aba6
|
@ -195,7 +195,8 @@ for i; do
|
||||||
fi >&3 5>&-
|
fi >&3 5>&-
|
||||||
)
|
)
|
||||||
r=$?
|
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
|
test $res -lt $r && res=$r
|
||||||
done
|
done
|
||||||
exit $res
|
exit $res
|
||||||
|
|
Loading…
Reference in New Issue