Browse code

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)
(cherry picked from commit 1ecade5cbd323e1ab45ec6f83236e1d389739d3b)

Daniel-Constantin Mierla authored on 24/08/2020 08:01:20
Showing 1 changed files
... ...
@@ -139,6 +139,7 @@ void _lc_core_log_udp(int lpriority, const char *format, ...)
139 139
 	va_list arglist;
140 140
 	char obuf[LC_LOG_MSG_MAX_SIZE];
141 141
 	int n;
142
+	int r;
142 143
 
143 144
 	va_start(arglist, format);
144 145
 
... ...
@@ -146,8 +147,11 @@ void _lc_core_log_udp(int lpriority, const char *format, ...)
146 147
 	n += snprintf(obuf + n, LC_LOG_MSG_MAX_SIZE - n, "(%d) ", my_pid());
147 148
 	n += vsnprintf(obuf + n, LC_LOG_MSG_MAX_SIZE - n, format, arglist);
148 149
 	va_end(arglist);
149
-	if(udp_send(&_lc_udp_dst, obuf, n)!=0) {
150
-		udp_send(&_lc_udp_dst, "debug: previous udp send returned non zero\n", 43);
150
+	r = udp_send(&_lc_udp_dst, obuf, n);
151
+	if(r<0) {
152
+		/* sending log message failed - print to stderror to help debugging */
153
+		fprintf(stderr, "error: previous udp send returned failure (%d:%d:%s)\n",
154
+				r, errno, strerror(errno));
151 155
 	}
152 156
 }
153 157
 
... ...
@@ -160,9 +164,9 @@ int ki_log_udp(sip_msg_t *msg, str *txt)
160 164
 
161 165
 	ret=udp_send(&_lc_udp_dst, txt->s, txt->len);
162 166
 
163
-	if(ret==0) return 1;
167
+	if(ret>0) return 1;
164 168
 
165
-	return ret;
169
+	return (ret==0)?-1:ret;
166 170
 
167 171
 }
168 172