From 9eb357e008385176a44b695e6117f95b2ea104a7 Mon Sep 17 00:00:00 2001 From: "Andrew J. Schorr" Date: Tue, 30 Nov 2021 15:15:20 -0500 Subject: Flush output to redirections before closing to detect output errors. --- io.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'io.c') diff --git a/io.c b/io.c index 91c94d9b..bcaff3c3 100644 --- a/io.c +++ b/io.c @@ -1375,6 +1375,9 @@ close_redir(struct redirect *rp, bool exitwarn, two_way_close_type how) if (rp == NULL) return 0; + if ((rp->flag & RED_WRITE) && rp->output.fp) + /* flush before closing to leverage special error handling */ + efflush(rp->output.fp, "flush", rp); if (rp->output.fp == stdout || rp->output.fp == stderr) goto checkwarn; /* bypass closing, remove from list */ -- cgit v1.2.3 From f77e1318c515d495ac9c08bdfdf2dadf79a9649f Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Wed, 1 Dec 2021 22:42:07 +0200 Subject: Convert w32_maybe_set_errno to os_maybe_set_errno. --- io.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) (limited to 'io.c') diff --git a/io.c b/io.c index bcaff3c3..0da8699e 100644 --- a/io.c +++ b/io.c @@ -1463,10 +1463,8 @@ non_fatal_flush_std_file(FILE *fp) bool is_fatal = ! is_non_fatal_std(fp); if (is_fatal) { -#ifdef __MINGW32__ - if (errno == 0 || errno == EINVAL) - w32_maybe_set_errno(); -#endif + os_maybe_set_errno(); + if (errno == EPIPE) die_via_sigpipe(); else @@ -1563,10 +1561,8 @@ close_io(bool *stdio_problem, bool *got_EPIPE) *stdio_problem = false; /* we don't warn about stdout/stderr if EPIPE, but we do error exit */ if (fflush(stdout) != 0) { -#ifdef __MINGW32__ - if (errno == 0 || errno == EINVAL) - w32_maybe_set_errno(); -#endif + os_maybe_set_errno(); + if (errno != EPIPE) warning(_("error writing standard output: %s"), strerror(errno)); else @@ -1576,10 +1572,8 @@ close_io(bool *stdio_problem, bool *got_EPIPE) *stdio_problem = true; } if (fflush(stderr) != 0) { -#ifdef __MINGW32__ - if (errno == 0 || errno == EINVAL) - w32_maybe_set_errno(); -#endif + os_maybe_set_errno(); + if (errno != EPIPE) warning(_("error writing standard error: %s"), strerror(errno)); else -- cgit v1.2.3