瀏覽代碼

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

(cherry picked from commit f16d046f6330f897b374d9bb7dab3b2ce8eab3a7)
Daniel-Constantin Mierla 5 年之前
父節點
當前提交
b046d03100
共有 1 個文件被更改,包括 8 次插入4 次删除
  1. 8 4
      src/modules/log_custom/log_custom_mod.c

+ 8 - 4
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;
 
 }