summaryrefslogtreecommitdiff
path: root/zgrep.in
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2023-02-03 01:19:44 -0800
committerPaul Eggert <eggert@cs.ucla.edu>2023-02-03 01:26:07 -0800
commit75dac03adcdf79b8d38a87bf29f50bcde9fa46a5 (patch)
tree37821cee94a2e66f3833feb43ab7725aa6490601 /zgrep.in
parent54d039eb3665aedf46fc2f84052162724b7e5aa7 (diff)
downloadgzip-75dac03adcdf79b8d38a87bf29f50bcde9fa46a5.tar.gz
gzip: fix exit status on broken pipe
Fix gzip to behave like cat etc. when outputting to a broken pipe: i.e., exit with nonzero status if SIGPIPE is ignored, and be terminated by SIGPIPE otherwise. * NEWS: Mention this. * gzip.c: Do not install signal handlers unless creating an output file, for which signal handlers are needed. This avoids gzip having to deal with signal handlers when outputting to stdout. (exiting_signal): Remove. All uses removed. (main): Do not install signal handlers at first. (create_outfile): Instead, install them only when needed. (finish_up_gzip): New function, which generalizes abort_gzip. (abort_gzip): Use it. * tests/pipe-output: New test. * tests/Makefile.am (TESTS): Add it. * util.c (EPIPE): Default to 0. (write_error): Just warn if it is a pipe error, and suppress that warning if quiet. In any event exit with status 2 (warning), not status 1 (error). * zgrep.in: Treat gzip status 141 like status 2; it is a broken pipe either way.
Diffstat (limited to 'zgrep.in')
-rw-r--r--zgrep.in4
1 files changed, 2 insertions, 2 deletions
diff --git a/zgrep.in b/zgrep.in
index 7aeee6c..504cca1 100644
--- a/zgrep.in
+++ b/zgrep.in
@@ -253,9 +253,9 @@ do
)
r=$?
- # Ignore gzip status 2, as it is just a warning.
+ # Ignore gzip status 2 or 141, as it is just a warning or broken pipe.
# gzip status 1 is an error, like grep status 2.
- test $gzip_status -eq 2 && gzip_status=0
+ { test $gzip_status -eq 2 || test $gzip_status -eq 141; } && gzip_status=0
test $gzip_status -eq 1 && gzip_status=2
# Use the more serious of the grep and gzip statuses.