[Asterisk-code-review] http.c: Reduce log spam (asterisk[14])

Jenkins2 asteriskteam at digium.com
Tue Jul 11 19:46:13 CDT 2017


Jenkins2 has submitted this change and it was merged. ( https://gerrit.asterisk.org/5963 )

Change subject: http.c:  Reduce log spam
......................................................................

http.c:  Reduce log spam

Messages like "fwrite() failed: Connection reset by peer" are no
help whatsoever, especially since they can be caused simply by a
client disconnecting.

* Make those WARNINGs DEBUGs.
* Check the return of the headers fprintf.

Change-Id: I17bd5f3621514152a7b2b263c801324c5e96568b
---
M main/http.c
1 file changed, 8 insertions(+), 5 deletions(-)

Approvals:
  Richard Mudgett: Looks good to me, but someone else must approve
  Joshua Colp: Looks good to me, approved
  Jenkins2: Approved for Submit



diff --git a/main/http.c b/main/http.c
index 907f102..32eb418 100644
--- a/main/http.c
+++ b/main/http.c
@@ -505,7 +505,7 @@
 	}
 
 	/* send http header */
-	fprintf(ser->f,
+	if (fprintf(ser->f,
 		"HTTP/1.1 %d %s\r\n"
 		"%s"
 		"Date: %s\r\n"
@@ -521,17 +521,20 @@
 		static_content ? "" : "Cache-Control: no-cache, no-store\r\n",
 		http_header ? ast_str_buffer(http_header) : "",
 		content_length
-		);
+		) <= 0) {
+		ast_debug(1, "fprintf() failed: %s\n", strerror(errno));
+		close_connection = 1;
+	}
 
 	/* send content */
-	if (method != AST_HTTP_HEAD || status_code >= 400) {
+	if (!close_connection && (method != AST_HTTP_HEAD || status_code >= 400)) {
 		if (out && ast_str_strlen(out)) {
 			/*
 			 * NOTE: Because ser->f is a non-standard FILE *, fwrite() will probably not
 			 * behave exactly as documented.
 			 */
 			if (fwrite(ast_str_buffer(out), ast_str_strlen(out), 1, ser->f) != 1) {
-				ast_log(LOG_ERROR, "fwrite() failed: %s\n", strerror(errno));
+				ast_debug(1, "fwrite() failed: %s\n", strerror(errno));
 				close_connection = 1;
 			}
 		}
@@ -546,7 +549,7 @@
 				 * behave exactly as documented.
 				 */
 				if (fwrite(buf, len, 1, ser->f) != 1) {
-					ast_log(LOG_WARNING, "fwrite() failed: %s\n", strerror(errno));
+					ast_debug(1, "fwrite() failed: %s\n", strerror(errno));
 					close_connection = 1;
 					break;
 				}

-- 
To view, visit https://gerrit.asterisk.org/5963
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 14
Gerrit-MessageType: merged
Gerrit-Change-Id: I17bd5f3621514152a7b2b263c801324c5e96568b
Gerrit-Change-Number: 5963
Gerrit-PatchSet: 3
Gerrit-Owner: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Jenkins2
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Richard Mudgett <rmudgett at digium.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20170711/518b03bc/attachment.html>


More information about the asterisk-code-review mailing list