[sr-dev] git:master:f16d046f: log_custom: print to stderror if sending log message fails

Daniel-Constantin Mierla miconda at gmail.com
Mon Aug 24 10:06:09 CEST 2020


Module: kamailio
Branch: master
Commit: f16d046f6330f897b374d9bb7dab3b2ce8eab3a7
URL: https://github.com/kamailio/kamailio/commit/f16d046f6330f897b374d9bb7dab3b2ce8eab3a7

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2020-08-24T10:01:20+02:00

log_custom: print to stderror if sending log message fails

- help troubleshooting while avoiding looping to same function in case
the log engine is set to log custom module

---

Modified: src/modules/log_custom/log_custom_mod.c

---

Diff:  https://github.com/kamailio/kamailio/commit/f16d046f6330f897b374d9bb7dab3b2ce8eab3a7.diff
Patch: https://github.com/kamailio/kamailio/commit/f16d046f6330f897b374d9bb7dab3b2ce8eab3a7.patch

---

diff --git a/src/modules/log_custom/log_custom_mod.c b/src/modules/log_custom/log_custom_mod.c
index 5253dad37e..a0f2e7542e 100644
--- a/src/modules/log_custom/log_custom_mod.c
+++ b/src/modules/log_custom/log_custom_mod.c
@@ -139,6 +139,7 @@ void _lc_core_log_udp(int lpriority, const char *format, ...)
 	va_list arglist;
 	char obuf[LC_LOG_MSG_MAX_SIZE];
 	int n;
+	int r;
 
 	va_start(arglist, format);
 
@@ -146,8 +147,11 @@ void _lc_core_log_udp(int lpriority, const char *format, ...)
 	n += snprintf(obuf + n, LC_LOG_MSG_MAX_SIZE - n, "(%d) ", my_pid());
 	n += vsnprintf(obuf + n, LC_LOG_MSG_MAX_SIZE - n, format, arglist);
 	va_end(arglist);
-	if(udp_send(&_lc_udp_dst, obuf, n)!=0) {
-		udp_send(&_lc_udp_dst, "debug: previous udp send returned non zero\n", 43);
+	r = udp_send(&_lc_udp_dst, obuf, n);
+	if(r<0) {
+		/* sending log message failed - print to stderror to help debugging */
+		fprintf(stderr, "error: previous udp send returned failure (%d:%d:%s)\n",
+				r, errno, strerror(errno));
 	}
 }
 
@@ -160,9 +164,9 @@ int ki_log_udp(sip_msg_t *msg, str *txt)
 
 	ret=udp_send(&_lc_udp_dst, txt->s, txt->len);
 
-	if(ret==0) return 1;
+	if(ret>0) return 1;
 
-	return ret;
+	return (ret==0)?-1:ret;
 
 }
 




More information about the sr-dev mailing list