]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
ast_careful_fwrite to support EPIPE gracefully 27/4827/2
authorkkm <kkm@smartaction.com>
Wed, 18 Jan 2017 02:46:43 +0000 (18:46 -0800)
committerKirill Katsnelson <kkm@smartaction.com>
Fri, 27 Jan 2017 03:08:54 +0000 (21:08 -0600)
When a reading end of the network socket is closed by an AMI manager,
the EPIPE is signaled when writing to our end, resulting in the
spurious log error message

  ast_careful_fwrite: fwrite() returned error: Broken pipe

Previously EPIPE was handled in ast_carefulwrite() a few lines above,
but not in this function.

ASTERISK-26753

Change-Id: I6a67335cd6526608bb9b78f796c626b1677664b8

main/utils.c

index 1ca77ce74884ec5bbdd2cf1fa9452e117566f082..14d529cf449094b078a09c5d95f04b7d6d4fde58 100644 (file)
@@ -1448,7 +1448,9 @@ int ast_careful_fwrite(FILE *f, int fd, const char *src, size_t len, int timeout
 
                if (ferror(f) && errno != EINTR && errno != EAGAIN) {
                        /* fatal error from fwrite() */
-                       if (!feof(f)) {
+                       if (errno == EPIPE) {
+                               ast_debug(1, "fwrite() failed due to reading end being closed: EPIPE\n");
+                       } else if (!feof(f)) {
                                /* Don't spam the logs if it was just that the connection is closed. */
                                ast_log(LOG_ERROR, "fwrite() returned error: %s\n", strerror(errno));
                        }
@@ -1481,8 +1483,12 @@ int ast_careful_fwrite(FILE *f, int fd, const char *src, size_t len, int timeout
                        continue;
                }
                if (errno && !feof(f)) {
-                       /* Don't spam the logs if it was just that the connection is closed. */
-                       ast_log(LOG_ERROR, "fflush() returned error: %s\n", strerror(errno));
+                       if (errno == EPIPE) {
+                               ast_debug(1, "fflush() failed due to reading end being closed: EPIPE\n");
+                       } else {
+                               /* Don't spam the logs if it was just that the connection is closed. */
+                               ast_log(LOG_ERROR, "fflush() returned error: %s\n", strerror(errno));
+                       }
                }
                n = -1;
                break;