]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
properly handle va_list in log_append functions
authorMichel Normand <normand@fr.ibm.com>
Fri, 15 May 2009 08:43:51 +0000 (10:43 +0200)
committerDaniel Lezcano <dlezcano@fr.ibm.com>
Fri, 15 May 2009 08:43:51 +0000 (10:43 +0200)
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 <normand@fr.ibm.com>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
src/lxc/log.c
src/lxc/log.h

index a5a43535df0e7db7bb074f0739622705dce27c8c..af55669339afb5e646785c677ad0c448082bd2e4 100644 (file)
@@ -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;
        }
index a8a82b8ed66ec5cef2a3ecd59a8b84f2f75b283c..1443eb28616a2a444cdeb95bb97ded54601577ae 100644 (file)
@@ -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);                                         \
        }                                                               \
 }