From dfa5fa385e0cbe9ca7cfd26da75f2d209f56a1af Mon Sep 17 00:00:00 2001 From: Eric Bollengier Date: Tue, 17 May 2011 19:43:09 +0200 Subject: [PATCH] Allow va_arg in Dmsg/Jmsg director plugin functions --- bacula/src/dird/dir_plugins.c | 35 ++++++++++++++++++++++++++--------- bacula/src/dird/dir_plugins.h | 4 ++-- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/bacula/src/dird/dir_plugins.c b/bacula/src/dird/dir_plugins.c index 2c289a3be7..1b579ac0b6 100644 --- a/bacula/src/dird/dir_plugins.c +++ b/bacula/src/dird/dir_plugins.c @@ -34,7 +34,7 @@ #include "bacula.h" #include "dird.h" -const int dbglvl = 0; +const int dbglvl = 100; const char *plugin_type = "-dir.so"; @@ -43,9 +43,9 @@ static bRC baculaGetValue(bpContext *ctx, brVariable var, void *value); static bRC baculaSetValue(bpContext *ctx, bwVariable var, void *value); static bRC baculaRegisterEvents(bpContext *ctx, ...); static bRC baculaJobMsg(bpContext *ctx, const char *file, int line, - int type, utime_t mtime, const char *msg); + int type, utime_t mtime, const char *fmt, ...); static bRC baculaDebugMsg(bpContext *ctx, const char *file, int line, - int level, const char *msg); + int level, const char *fmt, ...); /* Bacula info */ @@ -403,18 +403,35 @@ static bRC baculaRegisterEvents(bpContext *ctx, ...) } static bRC baculaJobMsg(bpContext *ctx, const char *file, int line, - int type, utime_t mtime, const char *msg) + int type, utime_t mtime, const char *fmt, ...) { - Dmsg5(dbglvl, "Job message: %s:%d type=%d time=%lld msg=%s\n", - file, line, type, mtime, msg); + va_list arg_ptr; + char buf[2000]; + JCR *jcr; + + if (ctx) { + jcr = (JCR *)ctx->bContext; + } else { + jcr = NULL; + } + + va_start(arg_ptr, fmt); + bvsnprintf(buf, sizeof(buf), fmt, arg_ptr); + va_end(arg_ptr); + Jmsg(jcr, type, mtime, "%s", buf); return bRC_OK; } static bRC baculaDebugMsg(bpContext *ctx, const char *file, int line, - int level, const char *msg) + int level, const char *fmt, ...) { - Dmsg4(dbglvl, "Debug message: %s:%d level=%d msg=%s\n", - file, line, level, msg); + va_list arg_ptr; + char buf[2000]; + + va_start(arg_ptr, fmt); + bvsnprintf(buf, sizeof(buf), fmt, arg_ptr); + va_end(arg_ptr); + d_msg(file, line, level, "%s", buf); return bRC_OK; } diff --git a/bacula/src/dird/dir_plugins.h b/bacula/src/dird/dir_plugins.h index b1c572489d..1c22cf5b3a 100644 --- a/bacula/src/dird/dir_plugins.h +++ b/bacula/src/dird/dir_plugins.h @@ -134,9 +134,9 @@ typedef struct s_baculaFuncs { bRC (*getBaculaValue)(bpContext *ctx, brVariable var, void *value); bRC (*setBaculaValue)(bpContext *ctx, bwVariable var, void *value); bRC (*JobMessage)(bpContext *ctx, const char *file, int line, - int type, utime_t mtime, const char *msg); + int type, utime_t mtime, const char *fmt, ...); bRC (*DebugMessage)(bpContext *ctx, const char *file, int line, - int level, const char *msg); + int level, const char *fmt, ...); } bFuncs; /* Bacula Core Routines -- not used within a plugin */ -- 2.39.5