From: Michel Normand Date: Fri, 15 May 2009 08:43:51 +0000 (+0200) Subject: properly handle va_list in log_append functions X-Git-Tag: lxc_0_6_3~95 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5fd8380be601c9f82708096a90a554d37f07b949;p=thirdparty%2Flxc.git properly handle va_list in log_append functions the support of multiple appenders need to associate one va_list per appender. This is the purpose of this patch to copy the va_list before to call the appender. Signed-off-by: Michel Normand Signed-off-by: Daniel Lezcano --- diff --git a/src/lxc/log.c b/src/lxc/log.c index a5a43535d..af5566933 100644 --- a/src/lxc/log.c +++ b/src/lxc/log.c @@ -45,7 +45,7 @@ lxc_log_define(lxc_log, lxc); /*---------------------------------------------------------------------------*/ static int log_append_logfile(const struct lxc_log_appender *appender, - const struct lxc_log_event *event) + struct lxc_log_event *event) { char buffer[LXC_LOG_BUFFER_SIZE]; int n; @@ -62,10 +62,10 @@ static int log_append_logfile(const struct lxc_log_appender *appender, event->category); n += vsnprintf(buffer + n, sizeof(buffer) - n, event->fmt, - event->va); + *event->vap); if (n >= sizeof(buffer) - 1) { - WARN("truncated next event from %d to %d bytes", n, + WARN("truncated next event from %d to %zd bytes", n, sizeof(buffer)); n = sizeof(buffer) - 1; } diff --git a/src/lxc/log.h b/src/lxc/log.h index a8a82b8ed..1443eb286 100644 --- a/src/lxc/log.h +++ b/src/lxc/log.h @@ -71,14 +71,13 @@ struct lxc_log_event { struct timeval timestamp; struct lxc_log_locinfo *locinfo; const char *fmt; - va_list va; + va_list *vap; }; /* log appender object */ struct lxc_log_appender { const char* name; - int (*append)(const struct lxc_log_appender *, - const struct lxc_log_event *); + int (*append)(const struct lxc_log_appender *, struct lxc_log_event *); /* * appenders can be stacked @@ -148,17 +147,23 @@ static inline int lxc_log_priority_to_int(const char* name) static inline void __lxc_log_append(const struct lxc_log_appender *appender, - const struct lxc_log_event* event) + struct lxc_log_event* event) { + va_list va, *va_keep; + va_keep = event->vap; + while (appender) { + va_copy(va, *va_keep); + event->vap = &va; appender->append(appender, event); appender = appender->next; + va_end(va); } } static inline void __lxc_log(const struct lxc_log_category* category, - const struct lxc_log_event* event) + struct lxc_log_event* event) { while (category) { __lxc_log_append(category->appender, event); @@ -185,12 +190,14 @@ static inline void LXC_##PRIORITY(struct lxc_log_locinfo* locinfo, \ .fmt = format, \ .locinfo = locinfo \ }; \ + va_list va_ref; \ \ gettimeofday(&evt.timestamp, NULL); \ \ - va_start(evt.va, format); \ + va_start(va_ref, format); \ + evt.vap = &va_ref; \ __lxc_log(acategory, &evt); \ - va_end(evt.va); \ + va_end(va_ref); \ } \ }