From ded0b77316c959178ab98cbab7c8637d36715d01 Mon Sep 17 00:00:00 2001 From: Marius Vlad Date: Fri, 1 Nov 2019 14:28:22 +0200 Subject: [PATCH] compositor: Pass the entire string in one-shot when writting logger data This fixes the situation where the same logger scope is passed multiple times and the timestamp is being sent before the log mesasge. Signed-off-by: Marius Vlad Reported-by: Pekka Paalanen --- compositor/main.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/compositor/main.c b/compositor/main.c index f9b7a631..29a427b9 100644 --- a/compositor/main.c +++ b/compositor/main.c @@ -199,14 +199,24 @@ weston_log_file_close(void) static int vlog(const char *fmt, va_list ap) { + const char *oom = "Out of memory"; char timestr[128]; int len = 0; + char *str; if (weston_log_scope_is_enabled(log_scope)) { - len = weston_log_scope_printf(log_scope, "%s ", - weston_log_timestamp(timestr, - sizeof timestr)); - len += weston_log_scope_vprintf(log_scope, fmt, ap); + int len_va; + char *log_timestamp = weston_log_timestamp(timestr, + sizeof(timestr)); + len_va = vasprintf(&str, fmt, ap); + if (len_va >= 0) { + len = weston_log_scope_printf(log_scope, "%s %s", + log_timestamp, str); + free(str); + } else { + len = weston_log_scope_printf(log_scope, "%s %s", + log_timestamp, oom); + } } return len;