From 6f8775499f6b0f70472c9449bf4f4da483e4cadb Mon Sep 17 00:00:00 2001 From: Kurtis Rader Date: Fri, 6 Jan 2017 23:51:49 -0800 Subject: [PATCH] don't warn about EPIPE errors Emitting warnings about EPIPE errors when writing to stdout or stderr is more annoying than helpful. So suppress that specific warning message. Fixes #2516 --- src/common.cpp | 2 ++ src/postfork.cpp | 18 +++++++++++++----- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/common.cpp b/src/common.cpp index bdc476ec2..6e9604227 100644 --- a/src/common.cpp +++ b/src/common.cpp @@ -511,6 +511,8 @@ long read_blocked(int fd, void *buf, size_t count) { return res; } +/// Loop a write request while failure is non-critical. Return -1 and set errno in case of critical +/// error. ssize_t write_loop(int fd, const char *buff, size_t count) { size_t out_cum = 0; while (out_cum < count) { diff --git a/src/postfork.cpp b/src/postfork.cpp index 41fe0e30b..06bb81d02 100644 --- a/src/postfork.cpp +++ b/src/postfork.cpp @@ -499,15 +499,23 @@ void safe_report_exec_error(int err, const char *actual_cmd, const char *const * /// Perform output from builtins. May be called from a forked child, so don't do anything that may /// allocate memory, etc. bool do_builtin_io(const char *out, size_t outlen, const char *err, size_t errlen) { + int saved_errno = 0; bool success = true; if (out && outlen && write_loop(STDOUT_FILENO, out, outlen) < 0) { - int e = errno; - debug_safe(0, "Error while writing to stdout"); - safe_perror("write_loop"); + saved_errno = errno; + if (errno != EPIPE) { + debug_safe(0, "Error while writing to stdout"); + errno = saved_errno; + safe_perror("write_loop"); + } success = false; - errno = e; } - if (err && errlen && write_loop(STDERR_FILENO, err, errlen) < 0) success = false; + if (err && errlen && write_loop(STDERR_FILENO, err, errlen) < 0) { + saved_errno = errno; + success = false; + } + + errno = saved_errno; return success; }