diff options
author | Pau Espin Pedrol <pespin@sysmocom.de> | 2018-11-12 17:00:22 +0100 |
---|---|---|
committer | Pau Espin Pedrol <pespin@sysmocom.de> | 2018-11-12 17:16:32 +0100 |
commit | de5758d307f6794b4126c6cf5251a5c5a8b9f193 (patch) | |
tree | 1ef2241e4a3f3b4cab54c22b725cc7edb915feb4 | |
parent | 4179207e0ec2833c649174aef5b32b54431f23a8 (diff) |
osmo_ortp: Log domain and fix strings without endl char
Change-Id: Ib6df0df04cd6ba342753c84398274d04917ace40
-rw-r--r-- | src/trau/osmo_ortp.c | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/src/trau/osmo_ortp.c b/src/trau/osmo_ortp.c index d8f4abf..0eb1661 100644 --- a/src/trau/osmo_ortp.c +++ b/src/trau/osmo_ortp.c @@ -102,8 +102,35 @@ static void my_ortp_logfn( #endif OrtpLogLevel lev, const char *fmt, va_list args) { + /* Some strings coming from ortp are not endline terminated and mangle + * the output. Make sure all strings are endl terminated before + * printing. + */ + int needs_endl; + const char *domain_str; + char *str; + size_t fmt_len = strlen(fmt); +#if HAVE_ORTP_LOG_DOMAIN + /* domain can be NULL, found experimentally */ + domain_str = domain ? : ""; +#else + domain_str = ""; +#endif + size_t domain_len = strlen(domain_str); + + if (fmt_len == 0) + return; + + needs_endl = fmt[fmt_len - 1] != '\n' ? 1 : 0; + + str = osmo_ortp_malloc(domain_len + 2 /*": "*/ + fmt_len + needs_endl + 1); + sprintf(str, "%s%s%s%s", domain_str, domain_len ? ": " : "", fmt, needs_endl ? "\n" : ""); + osmo_vlogp(DLMIB, ortp_to_osmo_lvl(lev), __FILE__, 0, - 0, fmt, args); + 0, str, args); + + osmo_ortp_free(str); + } /* ORTP signal callbacks */ |