diff options
-rw-r--r-- | ChangeLog | 8 | ||||
-rw-r--r-- | builtin.c | 8 | ||||
-rw-r--r-- | io.c | 15 | ||||
-rw-r--r-- | test/ChangeLog | 2 | ||||
-rw-r--r-- | test/Makefile.am | 4 | ||||
-rw-r--r-- | test/sigpipe1.awk | 13 | ||||
-rw-r--r-- | test/sigpipe1.ok | 3 |
7 files changed, 52 insertions, 1 deletions
@@ -3,6 +3,14 @@ * str_array.c (str_lookup): Remove MAYBE_NUM from subscript flags. Bug reported by Andres Legarra <Andres.Legarra@toulouse.inra.fr>. + Unrelated: Fix issues with SIGPIPE. Reported by + Ian Jackson <ijackson@chiark.greenend.org.uk>. + + * builtin.c (do_system): Reset/restore SIGPIPE to/from default around + call to system. + * io.c (redirect, gawk_popen [PIPES_SIMULATED]): Same. + + 2016-05-12 Eli Zaretskii <eliz@gnu.org> * nonposix.h: Add prototypes for Posix functions emulated in pc/* @@ -2092,6 +2092,10 @@ do_system(int nargs) cmd[tmp->stlen] = '\0'; os_restore_mode(fileno(stdin)); +#ifdef SIGPIPE + signal(SIGPIPE, SIG_DFL); +#endif + status = system(cmd); /* * 3/2016. What to do with ret? It's never simple. @@ -2123,8 +2127,12 @@ do_system(int nargs) } else ret = 0; /* shouldn't get here */ } + if ((BINMODE & BINMODE_INPUT) != 0) os_setbinmode(fileno(stdin), O_BINARY); +#ifdef SIGPIPE + signal(SIGPIPE, SIG_IGN); +#endif cmd[tmp->stlen] = save; } @@ -894,9 +894,15 @@ redirect(NODE *redir_exp, int redirtype, int *errflg) (void) flush_io(); os_restore_mode(fileno(stdin)); +#ifdef SIGPIPE + signal(SIGPIPE, SIG_DFL); +#endif if ((rp->output.fp = popen(str, binmode("w"))) == NULL) fatal(_("can't open pipe `%s' for output (%s)"), str, strerror(errno)); +#ifdef SIGPIPE + signal(SIGPIPE, SIG_IGN); +#endif /* set close-on-exec */ os_close_on_exec(fileno(rp->output.fp), str, "pipe", "to"); @@ -2403,9 +2409,18 @@ gawk_popen(const char *cmd, struct redirect *rp) FILE *current; os_restore_mode(fileno(stdin)); +#ifdef SIGPIPE + signal(SIGPIPE, SIG_DFL); +#endif + current = popen(cmd, binmode("r")); + if ((BINMODE & BINMODE_INPUT) != 0) os_setbinmode(fileno(stdin), O_BINARY); +#ifdef SIGPIPE + signal(SIGPIPE, SIG_IGN); +#endif + if (current == NULL) return NULL; os_close_on_exec(fileno(current), cmd, "pipe", "from"); diff --git a/test/ChangeLog b/test/ChangeLog index e9ea5770..927d23f6 100644 --- a/test/ChangeLog +++ b/test/ChangeLog @@ -2,6 +2,8 @@ * Makefile.am (arrayind1): New test. * arrayind1.awk, arrayind1.in, arrayind1.ok: New files. + * Makefile.am (sigpipe1): New test. + * sigpipe1.awk, sigpipe1.ok: New files. 2016-04-27 Arnold D. Robbins <arnold@skeeve.com> diff --git a/test/Makefile.am b/test/Makefile.am index 07637e12..1d5f8907 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -894,6 +894,8 @@ EXTRA_DIST = \ sclifin.ok \ shadow.awk \ shadow.ok \ + sigpipe1.awk \ + sigpipe1.ok \ sort1.awk \ sort1.ok \ sortempty.awk \ @@ -1076,7 +1078,7 @@ BASIC_TESTS = \ regexprange regrange reindops \ reparse resplit rri1 rs rscompat rsnul1nl rsnulbig rsnulbig2 rstest1 rstest2 \ rstest3 rstest4 rstest5 rswhite \ - scalar sclforin sclifin sortempty sortglos splitargv splitarr splitdef \ + scalar sclforin sclifin sigpipe1 sortempty sortglos splitargv splitarr splitdef \ splitvar splitwht strcat1 strnum1 strtod subamp subi18n \ subsepnm subslash substr swaplns synerr1 synerr2 tradanch tweakfld \ uninit2 uninit3 uninit4 uninit5 uninitialized unterm uparrfs \ diff --git a/test/sigpipe1.awk b/test/sigpipe1.awk new file mode 100644 index 00000000..9b23f390 --- /dev/null +++ b/test/sigpipe1.awk @@ -0,0 +1,13 @@ +BEGIN { + print "system" + command = "yes | true" + system(command) + + print "pipe to command" + print "hi" | command + close(command) + + print "pipe from command" + command | getline x + close(command) +} diff --git a/test/sigpipe1.ok b/test/sigpipe1.ok new file mode 100644 index 00000000..6596f076 --- /dev/null +++ b/test/sigpipe1.ok @@ -0,0 +1,3 @@ +system +pipe to command +pipe from command |