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
This commit is contained in:
Kurtis Rader 2017-01-06 23:51:49 -08:00
parent 430d82bd4f
commit 6f8775499f
2 changed files with 15 additions and 5 deletions

View file

@ -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) {

View file

@ -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;
}