gzip: fix exit status on broken pipe
commit75dac03adcdf79b8d38a87bf29f50bcde9fa46a5
authorPaul Eggert <eggert@cs.ucla.edu>
Fri, 3 Feb 2023 09:19:44 +0000 (3 01:19 -0800)
committerPaul Eggert <eggert@cs.ucla.edu>
Fri, 3 Feb 2023 09:26:07 +0000 (3 01:26 -0800)
tree37821cee94a2e66f3833feb43ab7725aa6490601
parent54d039eb3665aedf46fc2f84052162724b7e5aa7
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.
NEWS
gzip.c
gzip.h
tests/Makefile.am
tests/pipe-output [new file with mode: 0755]
util.c
zgrep.in