1 From 06fe8e801efc0e6a098d93cf104157fb4ef705e8 Mon Sep 17 00:00:00 2001
2 From: "Arnold D. Robbins" <arnold@skeeve.com>
3 Date: Sun, 17 Jun 2018 21:52:28 +0300
4 Subject: [PATCH] Fix a corner case with EPIPE to stdout/stderr.
11 4 files changed, 16 insertions(+), 5 deletions(-)
13 diff --git a/awk.h b/awk.h
14 index 36e71f2..cdf683d 100644
17 @@ -1581,7 +1581,7 @@ extern struct redirect *redirect_string(const char *redir_exp_str,
18 int *errflg, int extfd, bool failure_fatal);
19 extern NODE *do_close(int nargs);
20 extern int flush_io(void);
21 -extern int close_io(bool *stdio_problem);
22 +extern int close_io(bool *stdio_problem, bool *got_EPIPE);
23 typedef enum { CLOSE_ALL, CLOSE_TO, CLOSE_FROM } two_way_close_type;
24 extern int close_rp(struct redirect *rp, two_way_close_type how);
25 extern int devopen_simple(const char *name, const char *mode, bool try_real_open);
26 diff --git a/debug.c b/debug.c
27 index 3e76ae6..a587d8f 100644
30 @@ -5398,11 +5398,11 @@ save_options(const char *file)
35 + bool stdio_problem, got_EPIPE;
36 struct command_source *cs;
38 (void) nextfile(& curfile, true); /* close input data file */
39 - (void) close_io(& stdio_problem);
40 + (void) close_io(& stdio_problem, & got_EPIPE);
41 if (cur_srcfile->fd != INVALID_HANDLE) {
42 close(cur_srcfile->fd);
43 cur_srcfile->fd = INVALID_HANDLE;
44 diff --git a/interpret.h b/interpret.h
45 index 20fcb7a..8408a53 100644
48 @@ -110,6 +110,7 @@ top:
51 bool stdio_problem = false;
52 + bool got_EPIPE = false;
54 /* avoid false source indications */
56 @@ -125,7 +126,7 @@ top:
57 * and pipes, in that it doesn't affect their exit status.
58 * So we no longer do either.
60 - (void) close_io(& stdio_problem);
61 + (void) close_io(& stdio_problem, & got_EPIPE);
63 * However, we do want to exit non-zero if there was a problem
64 * with stdout/stderr, so we reinstate a slightly different
65 @@ -135,6 +136,9 @@ top:
75 diff --git a/io.c b/io.c
76 index 1a1d8cc..faccb4b 100644
79 @@ -1474,12 +1474,13 @@ flush_io()
80 /* close_io --- close all open files, called when exiting */
83 -close_io(bool *stdio_problem)
84 +close_io(bool *stdio_problem, bool *got_EPIPE)
87 struct redirect *next;
90 + *stdio_problem = *got_EPIPE = false;
92 for (rp = red_head; rp != NULL; rp = next) {
94 @@ -1505,6 +1506,9 @@ close_io(bool *stdio_problem)
97 warning(_("error writing standard output (%s)"), strerror(errno));
102 *stdio_problem = true;
104 @@ -1515,6 +1519,9 @@ close_io(bool *stdio_problem)
107 warning(_("error writing standard error (%s)"), strerror(errno));
112 *stdio_problem = true;