From: Kern Sibbald Date: Wed, 29 Aug 2007 09:30:22 +0000 (+0000) Subject: kes Rework bmsg in ua_output to use va_copy() so that bvsnprintf() X-Git-Tag: Release-7.0.0~5781 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=787a808b6efe5d35c8a355daa67905cc1f5f6927;p=bacula%2Fbacula kes Rework bmsg in ua_output to use va_copy() so that bvsnprintf() can be called multiple times. Implement a version for machines without va_copy() that gets a big buffer. git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@5412 91ce42f0-d328-0410-95d8-f526ca767f89 --- diff --git a/bacula/src/baconfig.h b/bacula/src/baconfig.h index ae5bddbf9f..df14b3ce97 100644 --- a/bacula/src/baconfig.h +++ b/bacula/src/baconfig.h @@ -38,6 +38,8 @@ /* Bacula common configuration defines */ +#define HAVE_VA_COPY + #undef TRUE #undef FALSE #define TRUE 1 @@ -627,13 +629,11 @@ extern int thr_setconcurrency(int); #endif #if defined(HAVE_DARWIN_OS) || defined(HAVE_OSF1_OS) +#undef HAVE_VA_COPY /* Apparently someone forgot to wrap getdomainname as a C function */ extern "C" int getdomainname(char *name, int len); #endif -#ifdef HAVE_OSF1_OS -extern "C" int mknod ( const char *path, int mode, dev_t device ); -#endif #if defined(HAVE_WIN32) @@ -661,6 +661,7 @@ inline const char *first_path_separator(const char *path) { return strchr(path, #ifdef HAVE_HPUX_OS # undef h_errno +#undef HAVE_VA_COPY extern int h_errno; /* the {get,set}domainname() functions exist in HPUX's libc. * the configure script detects that correctly. @@ -673,9 +674,10 @@ extern "C" int setdomainname(char *name, int namelen); #ifdef HAVE_OSF1_OS -#undef HAVE_CHFLAGS /* chflags is incorrectly detected */ +#undef HAVE_VA_COPY extern "C" int fchdir(int filedes); extern "C" long gethostid(void); +extern "C" int mknod ( const char *path, int mode, dev_t device ); #endif diff --git a/bacula/src/dird/ua_output.c b/bacula/src/dird/ua_output.c index 8bf7178d22..ab33393a19 100644 --- a/bacula/src/dird/ua_output.c +++ b/bacula/src/dird/ua_output.c @@ -673,7 +673,7 @@ void do_messages(UAContext *ua, const char *cmd) ua->UA_sock->msg = check_pool_memory_size(ua->UA_sock->msg, mlen+1); strcpy(ua->UA_sock->msg, msg); ua->UA_sock->msglen = mlen; - bnet_send(ua->UA_sock); + ua->UA_sock->send(); do_truncate = true; } if (do_truncate) { @@ -699,7 +699,7 @@ int messagescmd(UAContext *ua, const char *cmd) if (console_msg_pending) { do_messages(ua, cmd); } else { - bnet_fsend(ua->UA_sock, _("You have no messages.\n")); + ua->UA_sock->fsend(_("You have no messages.\n")); } return 1; } @@ -711,7 +711,7 @@ void prtit(void *ctx, const char *msg) { UAContext *ua = (UAContext *)ctx; - bnet_fsend(ua->UA_sock, "%s", msg); + ua->UA_sock->fsend("%s", msg); } /* @@ -721,11 +721,13 @@ void prtit(void *ctx, const char *msg) * agent, so we are being called from Bacula core. In * that case direct the messages to the Job. */ +#ifdef HAVE_VA_COPY void bmsg(UAContext *ua, const char *fmt, va_list arg_ptr) { BSOCK *bs = ua->UA_sock; int maxlen, len; POOLMEM *msg = NULL; + va_list ap; if (bs) { msg = bs->msg; @@ -736,7 +738,9 @@ void bmsg(UAContext *ua, const char *fmt, va_list arg_ptr) again: maxlen = sizeof_pool_memory(msg) - 1; - len = bvsnprintf(msg, maxlen, fmt, arg_ptr); + va_copy(ap, arg_ptr); + len = bvsnprintf(msg, maxlen, fmt, ap); + va_end(ap); if (len < 0 || len >= maxlen) { msg = realloc_pool_memory(msg, maxlen + maxlen/2); goto again; @@ -745,13 +749,51 @@ again: if (bs) { bs->msg = msg; bs->msglen = len; - bnet_send(bs); + bs->send(); } else { /* No UA, send to Job */ Jmsg(ua->jcr, M_INFO, 0, "%s", msg); free_pool_memory(msg); } } + +#else /* no va_copy() -- brain damaged version of variable arguments */ + +void bmsg(UAContext *ua, const char *fmt, va_list arg_ptr) +{ + BSOCK *bs = ua->UA_sock; + int maxlen, len; + POOLMEM *msg = NULL; + + if (bs) { + msg = bs->msg; + } + if (!msg) { + msg = get_pool_memory(5000); + } + + maxlen = sizeof_pool_memory(msg) - 1; + if (maxlen < 4999) { + msg = realloc_pool_memory(msg, 5000); + maxlen = 4999; + } + len = bvsnprintf(msg, maxlen, fmt, arg_ptr); + if (len < 0 || len >= maxlen) { + pm_strcpy(msg, _("Message too long to display.\n")); + len = strlen(msg); + } + + if (bs) { + bs->msg = msg; + bs->msglen = len; + bs->send(); + } else { /* No UA, send to Job */ + Jmsg(ua->jcr, M_INFO, 0, "%s", msg); + free_pool_memory(msg); + } + +} +#endif void bsendmsg(void *ctx, const char *fmt, ...) { diff --git a/bacula/src/lib/bsnprintf.c b/bacula/src/lib/bsnprintf.c index b38b353405..f8f88aea6b 100644 --- a/bacula/src/lib/bsnprintf.c +++ b/bacula/src/lib/bsnprintf.c @@ -16,7 +16,7 @@ /* Bacula® - The Network Backup Solution - Copyright (C) 2005-2006 Free Software Foundation Europe e.V. + Copyright (C) 2005-2007 Free Software Foundation Europe e.V. The main author of Bacula is Kern Sibbald, with contributions from many others, a complete list can be found in the file AUTHORS. @@ -45,6 +45,7 @@ #include "bacula.h" #define FP_OUTPUT 1 /* Bacula uses floating point */ + /* Define the following if you want all the features of * normal printf, but with all the security problems. * For Bacula we turn this off, and it silently ignores diff --git a/bacula/src/version.h b/bacula/src/version.h index ce7eaa588a..57e5b5d6a3 100644 --- a/bacula/src/version.h +++ b/bacula/src/version.h @@ -4,8 +4,8 @@ #undef VERSION #define VERSION "2.3.1" -#define BDATE "24 August 2007" -#define LSMDATE "24Aug07" +#define BDATE "29 August 2007" +#define LSMDATE "29Aug07" #define PROG_COPYRIGHT "Copyright (C) %d-2007 Free Software Foundation Europe e.V.\n" #define BYEAR "2007" /* year for copyright messages in progs */