From 68ddd4ec3c1275c66e01172498055817cbb10f04 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Tue, 11 Dec 2018 15:52:31 +0000 Subject: 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; --- shell/ash.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'shell') 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) #endif st = WTERMSIG(status); if (sigonly) { -#ifdef SIGPIPE if (st == SIGINT || st == SIGPIPE) -#else - if (st == SIGINT) -#endif goto out; #if JOBS if (WIFSTOPPED(status)) @@ -14951,7 +14947,7 @@ forkshell_openhere(struct forkshell *fs) ignoresig(SIGQUIT); //signal(SIGQUIT, SIG_IGN); ignoresig(SIGHUP); //signal(SIGHUP, SIG_IGN); ignoresig(SIGTSTP); //signal(SIGTSTP, SIG_IGN); - //signal(SIGPIPE, SIG_DFL); + signal(SIGPIPE, SIG_DFL); if (redir->type == NHERE) { size_t len = strlen(redir->nhere.doc->narg.text); full_write(pip[1], redir->nhere.doc->narg.text, len); -- cgit v1.2.3-55-g6feb