diff options
author | Ron Yorston <rmy@pobox.com> | 2018-12-11 15:52:31 +0000 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2018-12-11 15:52:31 +0000 |
commit | 68ddd4ec3c1275c66e01172498055817cbb10f04 (patch) | |
tree | e31826ae839535bef102a7ad61bc0e029b20ffae /shell | |
parent | 6c3fd20e67cab2331b1e862c03eeb95a70625454 (diff) | |
download | busybox-w32-68ddd4ec3c1275c66e01172498055817cbb10f04.tar.gz busybox-w32-68ddd4ec3c1275c66e01172498055817cbb10f04.tar.bz2 busybox-w32-68ddd4ec3c1275c66e01172498055817cbb10f04.zip |
win32: emulate SIGPIPE
The code to check whether a write error is due to a broken pipe
can now either:
- return with error EPIPE;
- cause the process to exit with code 128+SIGPIPE.
The default is the latter but the behaviour can be changed by issuing
signal(SIGPIPE, SIG_IGN) and signal(SIGPIPE, SIG_DFL) calls.
No actual signal is involved so kill can't send SIGPIPE and handlers
other than SIG_IGN and SIG_DFL aren't supported.
This does, however, avoid unsightly 'broken pipe' errors from commands
like the example in GitHub issue #99:
dd if=/dev/urandom | tr -dc _A-Z-a-z-0-9 | head -c${1:-32};echo;
Diffstat (limited to 'shell')
-rw-r--r-- | shell/ash.c | 6 |
1 files changed, 1 insertions, 5 deletions
diff --git a/shell/ash.c b/shell/ash.c index 22dedc1b6..2e3b22850 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
@@ -4410,11 +4410,7 @@ sprint_status48(char *s, int status, int sigonly) | |||
4410 | #endif | 4410 | #endif |
4411 | st = WTERMSIG(status); | 4411 | st = WTERMSIG(status); |
4412 | if (sigonly) { | 4412 | if (sigonly) { |
4413 | #ifdef SIGPIPE | ||
4414 | if (st == SIGINT || st == SIGPIPE) | 4413 | if (st == SIGINT || st == SIGPIPE) |
4415 | #else | ||
4416 | if (st == SIGINT) | ||
4417 | #endif | ||
4418 | goto out; | 4414 | goto out; |
4419 | #if JOBS | 4415 | #if JOBS |
4420 | if (WIFSTOPPED(status)) | 4416 | if (WIFSTOPPED(status)) |
@@ -14951,7 +14947,7 @@ forkshell_openhere(struct forkshell *fs) | |||
14951 | ignoresig(SIGQUIT); //signal(SIGQUIT, SIG_IGN); | 14947 | ignoresig(SIGQUIT); //signal(SIGQUIT, SIG_IGN); |
14952 | ignoresig(SIGHUP); //signal(SIGHUP, SIG_IGN); | 14948 | ignoresig(SIGHUP); //signal(SIGHUP, SIG_IGN); |
14953 | ignoresig(SIGTSTP); //signal(SIGTSTP, SIG_IGN); | 14949 | ignoresig(SIGTSTP); //signal(SIGTSTP, SIG_IGN); |
14954 | //signal(SIGPIPE, SIG_DFL); | 14950 | signal(SIGPIPE, SIG_DFL); |
14955 | if (redir->type == NHERE) { | 14951 | if (redir->type == NHERE) { |
14956 | size_t len = strlen(redir->nhere.doc->narg.text); | 14952 | size_t len = strlen(redir->nhere.doc->narg.text); |
14957 | full_write(pip[1], redir->nhere.doc->narg.text, len); | 14953 | full_write(pip[1], redir->nhere.doc->narg.text, len); |