mirror of
https://git.proxmox.com/git/mirror_lxc
synced 2025-08-14 12:56:46 +00:00
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 <normand@fr.ibm.com> Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
This commit is contained in:
parent
31c53c2e1a
commit
5fd8380be6
@ -45,7 +45,7 @@ lxc_log_define(lxc_log, lxc);
|
|||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static int log_append_logfile(const struct lxc_log_appender *appender,
|
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];
|
char buffer[LXC_LOG_BUFFER_SIZE];
|
||||||
int n;
|
int n;
|
||||||
@ -62,10 +62,10 @@ static int log_append_logfile(const struct lxc_log_appender *appender,
|
|||||||
event->category);
|
event->category);
|
||||||
|
|
||||||
n += vsnprintf(buffer + n, sizeof(buffer) - n, event->fmt,
|
n += vsnprintf(buffer + n, sizeof(buffer) - n, event->fmt,
|
||||||
event->va);
|
*event->vap);
|
||||||
|
|
||||||
if (n >= sizeof(buffer) - 1) {
|
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));
|
sizeof(buffer));
|
||||||
n = sizeof(buffer) - 1;
|
n = sizeof(buffer) - 1;
|
||||||
}
|
}
|
||||||
|
@ -71,14 +71,13 @@ struct lxc_log_event {
|
|||||||
struct timeval timestamp;
|
struct timeval timestamp;
|
||||||
struct lxc_log_locinfo *locinfo;
|
struct lxc_log_locinfo *locinfo;
|
||||||
const char *fmt;
|
const char *fmt;
|
||||||
va_list va;
|
va_list *vap;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* log appender object */
|
/* log appender object */
|
||||||
struct lxc_log_appender {
|
struct lxc_log_appender {
|
||||||
const char* name;
|
const char* name;
|
||||||
int (*append)(const struct lxc_log_appender *,
|
int (*append)(const struct lxc_log_appender *, struct lxc_log_event *);
|
||||||
const struct lxc_log_event *);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* appenders can be stacked
|
* appenders can be stacked
|
||||||
@ -148,17 +147,23 @@ static inline int lxc_log_priority_to_int(const char* name)
|
|||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
__lxc_log_append(const struct lxc_log_appender *appender,
|
__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) {
|
while (appender) {
|
||||||
|
va_copy(va, *va_keep);
|
||||||
|
event->vap = &va;
|
||||||
appender->append(appender, event);
|
appender->append(appender, event);
|
||||||
appender = appender->next;
|
appender = appender->next;
|
||||||
|
va_end(va);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
__lxc_log(const struct lxc_log_category* category,
|
__lxc_log(const struct lxc_log_category* category,
|
||||||
const struct lxc_log_event* event)
|
struct lxc_log_event* event)
|
||||||
{
|
{
|
||||||
while (category) {
|
while (category) {
|
||||||
__lxc_log_append(category->appender, event);
|
__lxc_log_append(category->appender, event);
|
||||||
@ -185,12 +190,14 @@ static inline void LXC_##PRIORITY(struct lxc_log_locinfo* locinfo, \
|
|||||||
.fmt = format, \
|
.fmt = format, \
|
||||||
.locinfo = locinfo \
|
.locinfo = locinfo \
|
||||||
}; \
|
}; \
|
||||||
|
va_list va_ref; \
|
||||||
\
|
\
|
||||||
gettimeofday(&evt.timestamp, NULL); \
|
gettimeofday(&evt.timestamp, NULL); \
|
||||||
\
|
\
|
||||||
va_start(evt.va, format); \
|
va_start(va_ref, format); \
|
||||||
|
evt.vap = &va_ref; \
|
||||||
__lxc_log(acategory, &evt); \
|
__lxc_log(acategory, &evt); \
|
||||||
va_end(evt.va); \
|
va_end(va_ref); \
|
||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user