summaryrefslogtreecommitdiff
path: root/main/utils.c
diff options
context:
space:
mode:
authorMatt Jordan <mjordan@digium.com>2015-12-13 13:13:55 -0600
committerMatt Jordan <mjordan@digium.com>2015-12-13 13:26:29 -0600
commit9a96a86e2d95645f05b160d2efc942c1a3c129d2 (patch)
treef0db0feb896228e5a63e8622b30bfde4307418b9 /main/utils.c
parentceebdfce40d278d17ecfb82afdffc41a8cc1cc94 (diff)
main/utils: Don't emit an ERROR message if the read end of a pipe closes
An ERROR or WARNING message should generally indicate that something has gone wrong in Asterisk. In the case of writing to a file descriptor, Asterisk is not in control of when the far end closes its reading on a file descriptor. If the far end does close the file descriptor in an unclean fashion, this isn't a bug or error in Asterisk, particularly when the situation can be gracefully handled in Asterisk. Currently, when this happens, a user would see the following somewhat cryptic ERROR message: "utils.c: write() returned error: Broken pipe" There's a few problems with this: (1) It doesn't provide any context, other than 'something broke a pipe' (2) As noted, it isn't actually an error in Asterisk (3) It can get rather spammy if the thing breaking the pipe occurs often, such as a FastAGI server (4) Spammy ERROR messages make Asterisk appear to be having issues, or can even mask legitimate issues This patch changes ast_carefulwrite to only log an ERROR if we actually had one that was reasonably under our control. For debugging purposes, we still emit a debug message if we detect that the far side has stopped reading. Change-Id: Ia503bb1efcec685fa6f3017bedf98061f8e1b566
Diffstat (limited to 'main/utils.c')
-rw-r--r--main/utils.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/main/utils.c b/main/utils.c
index 74932b8c2..db3e4babe 100644
--- a/main/utils.c
+++ b/main/utils.c
@@ -1399,7 +1399,13 @@ int ast_carefulwrite(int fd, char *s, int len, int timeoutms)
if (res < 0 && errno != EAGAIN && errno != EINTR) {
/* fatal error from write() */
- ast_log(LOG_ERROR, "write() returned error: %s\n", strerror(errno));
+ if (errno == EPIPE) {
+#ifndef STANDALONE
+ ast_debug(1, "write() failed due to reading end being closed: %s\n", strerror(errno));
+#endif
+ } else {
+ ast_log(LOG_ERROR, "write() returned error: %s\n", strerror(errno));
+ }
return -1;
}