diff options
author | Neels Hofmeyr <neels@hofmeyr.de> | 2019-11-18 15:41:28 +0100 |
---|---|---|
committer | laforge <laforge@osmocom.org> | 2019-12-17 13:52:21 +0000 |
commit | 037c6c1ba8b9cc637d94155b103de6107f688117 (patch) | |
tree | 1884131a2ca1c1f11e5da447d97f2d4cd3df694c | |
parent | 18cf9f39c560aaf7aa3952910a3a9f776c353fed (diff) |
logging from sofia: add missing newline
Sometimes, logging from sofia lacks the final newline character, messing up log
output. First snprintf() to a buffer, add '\n' if necessary and then log.
Change-Id: Ia26c0b57a0166cf7de87c49471ce6f528a366dd5
-rw-r--r-- | src/sip.c | 14 |
1 files changed, 13 insertions, 1 deletions
@@ -666,7 +666,19 @@ static void sip_logger(void *stream, char const *fmt, va_list ap) * the log handler call-back function, so we have no clue what log level the * currently logged message was sent for :( As a result, we can only use one * hard-coded LOGL_NOTICE here */ - osmo_vlogp(DSIP, LOGL_NOTICE, "", 0, 0, fmt, ap); + if (!log_check_level(DSIP, LOGL_NOTICE)) + return; + /* The sofia-sip log line *sometimes* lacks a terminating '\n'. Add it. */ + char log_line[256]; + int rc = vsnprintf(log_line, sizeof(log_line), fmt, ap); + if (rc > 0) { + /* since we're explicitly checking for sizeof(log_line), we can use vsnprintf()'s return value (which, + * alone, would possibly cause writing past the buffer's end). */ + char *end = log_line + OSMO_MIN(rc, sizeof(log_line) - 2); + osmo_strlcpy(end, "\n", 2); + LOGP(DSIP, LOGL_NOTICE, "%s", log_line); + } else + LOGP(DSIP, LOGL_NOTICE, "unknown logging from sip\n"); } void sip_agent_init(struct sip_agent *agent, struct app_config *app) |