Discussion:
[Bug-wget] exit status problem with pipe
Peng Yu
2018-10-21 19:47:39 UTC
Permalink
Hi,

wget returns the following exit code when it is dealing with pipe. But
it does not follow the common practice. Should this behavior be fixed?

$ wget -qO- http://httpbin.org/get | echo

$ echo ${PIPESTATUS[@]}
3 0
$ seq 10 | echo

$ echo ${PIPESTATUS[@]}
141 0
--
Regards,
Peng
Darshit Shah
2018-10-22 20:02:20 UTC
Permalink
This is difficult to do correctly for network applications. Is there any
particular reason you're looking for identifying if Wget was killed by SIGPIPE?

The problem here is that a closed socket will also result in a SIGPIPE on unix
systems. But in such a case, we don't want to kill the application. As a
result, we simply ignore the SIGPIPE handler. So when Wget dies in the command
you shared, its not really killed by SIGPIPE. Hence, in theory, it would be
incorrect for Wget to exit with a code of 141.
Post by Peng Yu
Hi,
wget returns the following exit code when it is dealing with pipe. But
it does not follow the common practice. Should this behavior be fixed?
$ wget -qO- http://httpbin.org/get | echo
3 0
$ seq 10 | echo
141 0
--
Regards,
Peng
--
Thanking You,
Darshit Shah
PGP Fingerprint: 7845 120B 07CB D8D6 ECE5 FF2B 2A17 43ED A91A 35B6
Peng Yu
2018-10-22 20:30:18 UTC
Permalink
Can wget at least allow 141 for pipes but not sockets? Many GNU tools
(such coreutiles) uses 141 for pipe signals. I'd like other programs
to follow the same convention so that I can use the exit_status for
error checking.
Post by Darshit Shah
This is difficult to do correctly for network applications. Is there any
particular reason you're looking for identifying if Wget was killed by SIGPIPE?
The problem here is that a closed socket will also result in a SIGPIPE on unix
systems. But in such a case, we don't want to kill the application. As a
result, we simply ignore the SIGPIPE handler. So when Wget dies in the command
you shared, its not really killed by SIGPIPE. Hence, in theory, it would be
incorrect for Wget to exit with a code of 141.
Post by Peng Yu
Hi,
wget returns the following exit code when it is dealing with pipe. But
it does not follow the common practice. Should this behavior be fixed?
$ wget -qO- http://httpbin.org/get | echo
3 0
$ seq 10 | echo
141 0
--
Regards,
Peng
--
Thanking You,
Darshit Shah
PGP Fingerprint: 7845 120B 07CB D8D6 ECE5 FF2B 2A17 43ED A91A 35B6
--
Regards,
Peng
Loading...