From 5f86c4c8ad1f008b50e6aa3f224bdc9e7565e526 Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Mon, 29 Mar 2004 22:04:03 +0000 Subject: [PATCH] Implement Qmsg() + conio linking git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@1162 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/autoconf/configure.in | 12 +++- bacula/configure | 72 ++++++++++++++++++- bacula/kernstodo | 9 +-- bacula/src/console/conio.c | 6 ++ bacula/src/console/console.c | 3 + bacula/src/filed/win32/winabout.cpp | 25 +++---- bacula/src/filed/win32/winabout.h | 8 +-- bacula/src/lib/bnet.c | 48 ++++++------- bacula/src/lib/dlist.c | 1 + bacula/src/lib/jcr.c | 3 +- bacula/src/lib/message.c | 107 ++++++++++++++++------------ bacula/src/version.h | 4 +- 12 files changed, 204 insertions(+), 94 deletions(-) diff --git a/bacula/autoconf/configure.in b/bacula/autoconf/configure.in index 908b592f26..0641dbb08e 100644 --- a/bacula/autoconf/configure.in +++ b/bacula/autoconf/configure.in @@ -321,7 +321,17 @@ if test x$support_conio = xyes; then got_conio="yes" support_readline=no AC_DEFINE(HAVE_CONIO, 1, [Set if Bacula conio support enabled]) - ], [ echo " "; echo "termcap library not found. CONIO turned off ..."; echo " "]) + ], + [ AC_CHECK_LIB(ncurses, tgetent, + [ CONS_LIBS="-lncurses" + CONS_OBJ="conio.o" + CONS_SRC="conio.c" + got_conio="yes" + support_readline=no + AC_DEFINE(HAVE_CONIO, 1, [Set if Bacula conio support enabled]) + ], + [ echo " "; echo "Neither termcap nor ncurses library found. CONIO turned off ..."; echo " "]) + ]) ],[echo " "; echo "termcap.h not found. CONIO turned off ..."; echo " "]) fi diff --git a/bacula/configure b/bacula/configure index dda4b004ae..b84fbf035e 100755 --- a/bacula/configure +++ b/bacula/configure @@ -5264,7 +5264,77 @@ _ACEOF else - echo " "; echo "termcap library not found. CONIO turned off ..."; echo " " + echo "$as_me:$LINENO: checking for tgetent in -lncurses" >&5 +echo $ECHO_N "checking for tgetent in -lncurses... $ECHO_C" >&6 +if test "${ac_cv_lib_ncurses_tgetent+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-lncurses $LIBS" +cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +/* Override any gcc2 internal prototype to avoid an error. */ +#ifdef __cplusplus +extern "C" +#endif +/* We use char because int might match the return type of a gcc2 + builtin and then its argument prototype would still apply. */ +char tgetent (); +int +main () +{ +tgetent (); + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest$ac_exeext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_lib_ncurses_tgetent=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_cv_lib_ncurses_tgetent=no +fi +rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +echo "$as_me:$LINENO: result: $ac_cv_lib_ncurses_tgetent" >&5 +echo "${ECHO_T}$ac_cv_lib_ncurses_tgetent" >&6 +if test $ac_cv_lib_ncurses_tgetent = yes; then + CONS_LIBS="-lncurses" + CONS_OBJ="conio.o" + CONS_SRC="conio.c" + got_conio="yes" + support_readline=no + +cat >>confdefs.h <<\_ACEOF +#define HAVE_CONIO 1 +_ACEOF + + +else + echo " "; echo "Neither termcap nor ncurses library found. CONIO turned off ..."; echo " " +fi + + fi diff --git a/bacula/kernstodo b/bacula/kernstodo index b4cf9a08f8..7e9fb02a88 100644 --- a/bacula/kernstodo +++ b/bacula/kernstodo @@ -1,5 +1,5 @@ Kern's ToDo List - 25 March 2004 + 28 March 2004 Documentation to do: (any release a little bit at a time) - DB upgrade to version 5 in bacula-1.27b, DB upgrade to @@ -72,6 +72,7 @@ For 1.33 Testing/Documentation: Overland Neo2000 (LVD) For 1.33 +- Null dlist head and tail pointers if all items are removed. - Complete Win32 installer - Finish work on Gnome restore GUI. - On unknown client in restore "client=xxx" @@ -79,9 +80,6 @@ For 1.33 ERR=no such table: temp1 - Fix "llist jobid=xx" where no fileset or client exists. - Build console in client-only build. -- Test Qmsg() code to be used in bnet.c to prevent recursion. Queue the - message. If dequeueing toss the messages. Lock while dequeuing so that - it cannot be called recursively and set dequeuing flag. - Test work on conio.c -- particularly linking. - Phil says that Windows file sizes mismatch in Verify when they should, and that either the file size or the catalog size was zero. @@ -1428,3 +1426,6 @@ Block Position: 0 - Allow "delete job jobid=xx jobid=xxx". - Update volume FromPool (or FromPool=xxx) refreshes the Volume defaults from Pool. - Implement multiple Volume in "purge jobs volume=". +- Test Qmsg() code to be used in bnet.c to prevent recursion. Queue the + message. If dequeueing toss the messages. Lock while dequeuing so that + it cannot be called recursively and set dequeuing flag. diff --git a/bacula/src/console/conio.c b/bacula/src/console/conio.c index 7447ead95e..5b5cc57514 100755 --- a/bacula/src/console/conio.c +++ b/bacula/src/console/conio.c @@ -224,6 +224,8 @@ static void asdell(); int input_line(char *string, int length); void con_term(); void trapctlc(); +int usrbrk(); +void clrbrk(); void con_init(FILE *input) { @@ -432,6 +434,10 @@ input_line(char *string, int length) } noline = 1; /* no line fetched yet */ for (cl=cp=0; clmsg); sock->msglen = strlen(sock->msg); return 1; diff --git a/bacula/src/filed/win32/winabout.cpp b/bacula/src/filed/win32/winabout.cpp index 6f941c0cc4..69ace2286a 100755 --- a/bacula/src/filed/win32/winabout.cpp +++ b/bacula/src/filed/win32/winabout.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2000-2003 Kern Sibbald and John Walker + Copyright (C) 2000-2004 Kern Sibbald and John Walker This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as @@ -18,7 +18,7 @@ This file is patterned after the VNC Win32 code by ATT - Copyright (2000) Kern E. Sibbald + Kern E. Sibbald, 2000 */ #include "winbacula.h" @@ -26,12 +26,10 @@ bacAbout::bacAbout() { - visible = FALSE; + visible = false; } -bacAbout::~bacAbout() -{ -} +bacAbout::~bacAbout() { }; void bacAbout::Show(BOOL show) { @@ -41,21 +39,22 @@ void bacAbout::Show(BOOL show) } } + BOOL CALLBACK bacAbout::DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) { - /* The dialog-box this pointer is in USERDATA */ - bacAbout *_this = (bacAbout *)GetWindowLong(hwnd, GWL_USERDATA); + /* Get the dialog class pointer from USERDATA */ + bacAbout *_this; switch (uMsg) { case WM_INITDIALOG: - /* Retrieve the Dialog box parameter */ + /* save the dialog class pointer */ SetWindowLong(hwnd, GWL_USERDATA, lParam); _this = (bacAbout *)lParam; /* Show the dialog */ SetForegroundWindow(hwnd); - _this->visible = TRUE; + _this->visible = true; return TRUE; case WM_COMMAND: @@ -63,14 +62,16 @@ bacAbout::DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) case IDCANCEL: case IDOK: EndDialog(hwnd, TRUE); - _this->visible = FALSE; + _this = (bacAbout *)GetWindowLong(hwnd, GWL_USERDATA); + _this->visible = false; return TRUE; } break; case WM_DESTROY: EndDialog(hwnd, FALSE); - _this->visible = FALSE; + _this = (bacAbout *)GetWindowLong(hwnd, GWL_USERDATA); + _this->visible = false; return TRUE; } return 0; diff --git a/bacula/src/filed/win32/winabout.h b/bacula/src/filed/win32/winabout.h index 9d4d086c04..5408a75283 100755 --- a/bacula/src/filed/win32/winabout.h +++ b/bacula/src/filed/win32/winabout.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2000, 2001, 2002 Kern Sibbald and John Walker + Copyright (C) 2000-2004 Kern Sibbald and John Walker This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as @@ -18,7 +18,7 @@ This file was inspired by the VNC Win32 code by ATT - Copyright (2000) Kern E. Sibbald + Kern E. Sibbald, 2000 */ @@ -34,7 +34,7 @@ class bacAbout { public: bacAbout(); - ~bacAbout(); + ~bacAbout(); /* The dialog box window proc */ static BOOL CALLBACK DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam); @@ -42,7 +42,7 @@ public: void Show(BOOL show); /* Object local storage */ - BOOL visible; + bool visible; }; #endif diff --git a/bacula/src/lib/bnet.c b/bacula/src/lib/bnet.c index 0cc4ccbd47..bef757e231 100644 --- a/bacula/src/lib/bnet.c +++ b/bacula/src/lib/bnet.c @@ -92,7 +92,7 @@ static int32_t write_nbytes(BSOCK *bsock, char *ptr, int32_t nbytes) if (bsock->spool) { nwritten = fwrite(ptr, 1, nbytes, bsock->spool_fd); if (nwritten != nbytes) { - Jmsg1(bsock->jcr, M_FATAL, 0, _("Attr spool write error. ERR=%s\n"), strerror(errno)); + Qmsg1(bsock->jcr, M_FATAL, 0, _("Attr spool write error. ERR=%s\n"), strerror(errno)); Dmsg2(400, "nwritten=%d nbytes=%d.\n", nwritten, nbytes); return -1; } @@ -179,8 +179,8 @@ int32_t bnet_recv(BSOCK *bsock) if (nbytes != sizeof(int32_t)) { bsock->errors++; bsock->b_errno = EIO; - Jmsg5(bsock->jcr, M_ERROR, 0, _("Read expected %d got %d from %s:%s:%d\n"), pktsiz, nbytes, - bsock->who, bsock->host, bsock->port); + Qmsg5(bsock->jcr, M_ERROR, 0, _("Read expected %d got %d from %s:%s:%d\n"), + sizeof(int32_t), nbytes, bsock->who, bsock->host, bsock->port); return BNET_ERROR; } @@ -196,7 +196,7 @@ int32_t bnet_recv(BSOCK *bsock) /* If signal or packet size too big */ if (pktsiz < 0 || pktsiz > 1000000) { if (pktsiz > 0) { /* if packet too big */ - Jmsg3(bsock->jcr, M_FATAL, 0, + Qmsg3(bsock->jcr, M_FATAL, 0, _("Packet size too big from \"%s:%s:%d. Terminating connection.\n"), bsock->who, bsock->host, bsock->port); pktsiz = BNET_TERMINATE; /* hang up */ @@ -226,7 +226,7 @@ int32_t bnet_recv(BSOCK *bsock) bsock->b_errno = errno; } bsock->errors++; - Jmsg4(bsock->jcr, M_ERROR, 0, _("Read error from %s:%s:%d: ERR=%s\n"), + Qmsg4(bsock->jcr, M_ERROR, 0, _("Read error from %s:%s:%d: ERR=%s\n"), bsock->who, bsock->host, bsock->port, bnet_strerror(bsock)); return BNET_ERROR; } @@ -236,7 +236,7 @@ int32_t bnet_recv(BSOCK *bsock) if (nbytes != pktsiz) { bsock->b_errno = EIO; bsock->errors++; - Jmsg5(bsock->jcr, M_ERROR, 0, _("Read expected %d got %d from %s:%s:%d\n"), pktsiz, nbytes, + Qmsg5(bsock->jcr, M_ERROR, 0, _("Read expected %d got %d from %s:%s:%d\n"), pktsiz, nbytes, bsock->who, bsock->host, bsock->port); return BNET_ERROR; } @@ -296,14 +296,14 @@ int bnet_despool_to_bsock(BSOCK *bsock) nbytes = fread(bsock->msg, 1, bsock->msglen, bsock->spool_fd); if (nbytes != (size_t)bsock->msglen) { Dmsg2(400, "nbytes=%d msglen=%d\n", nbytes, bsock->msglen); - Jmsg1(bsock->jcr, M_FATAL, 0, _("fread attr spool error. ERR=%s\n"), strerror(errno)); + Qmsg1(bsock->jcr, M_FATAL, 0, _("fread attr spool error. ERR=%s\n"), strerror(errno)); return 0; } } bnet_send(bsock); } if (ferror(bsock->spool_fd)) { - Jmsg1(bsock->jcr, M_FATAL, 0, _("fread attr spool error. ERR=%s\n"), strerror(errno)); + Qmsg1(bsock->jcr, M_FATAL, 0, _("fread attr spool error. ERR=%s\n"), strerror(errno)); return 0; } return 1; @@ -348,11 +348,11 @@ bnet_send(BSOCK *bsock) } if (rc < 0) { if (!bsock->suppress_error_msgs && !bsock->timed_out) { - Jmsg4(bsock->jcr, M_ERROR, 0, _("Write error sending to %s:%s:%d: ERR=%s\n"), + Qmsg4(bsock->jcr, M_ERROR, 0, _("Write error sending to %s:%s:%d: ERR=%s\n"), bsock->who, bsock->host, bsock->port, bnet_strerror(bsock)); } } else { - Jmsg5(bsock->jcr, M_ERROR, 0, _("Wrote %d bytes to %s:%s:%d, but only %d accepted.\n"), + Qmsg5(bsock->jcr, M_ERROR, 0, _("Wrote %d bytes to %s:%s:%d, but only %d accepted.\n"), bsock->who, bsock->host, bsock->port, bsock->msglen, rc); } return 0; @@ -377,11 +377,11 @@ bnet_send(BSOCK *bsock) } if (rc < 0) { if (!bsock->suppress_error_msgs) { - Jmsg4(bsock->jcr, M_ERROR, 0, _("Write error sending to %s:%s:%d: ERR=%s\n"), + Qmsg4(bsock->jcr, M_ERROR, 0, _("Write error sending to %s:%s:%d: ERR=%s\n"), bsock->who, bsock->host, bsock->port, bnet_strerror(bsock)); } } else { - Jmsg5(bsock->jcr, M_ERROR, 0, _("Wrote %d bytes to %s:%s:%d, but only %d accepted.\n"), + Qmsg5(bsock->jcr, M_ERROR, 0, _("Wrote %d bytes to %s:%s:%d, but only %d accepted.\n"), bsock->msglen, bsock->who, bsock->host, bsock->port, rc); } return 0; @@ -542,13 +542,13 @@ static uint32_t *bget_host_ip(JCR *jcr, char *host) } else { P(ip_mutex); if ((hp = gethostbyname(host)) == NULL) { - Jmsg2(jcr, M_ERROR, 0, "gethostbyname() for host \"%s\" failed: ERR=%s\n", + Qmsg2(jcr, M_ERROR, 0, "gethostbyname() for host \"%s\" failed: ERR=%s\n", host, gethost_strerror()); V(ip_mutex); return NULL; } if (hp->h_length != sizeof(inaddr.s_addr) || hp->h_addrtype != AF_INET) { - Jmsg2(jcr, M_ERROR, 0, _("gethostbyname() network address length error.\n\ + Qmsg2(jcr, M_ERROR, 0, _("gethostbyname() network address length error.\n\ Wanted %d got %d bytes for s_addr.\n"), sizeof(inaddr.s_addr), hp->h_length); V(ip_mutex); return NULL; @@ -609,7 +609,7 @@ bnet_open(JCR *jcr, const char *name, char *host, char *service, int port, int * * Receive notification when connection dies. */ if (setsockopt(sockfd, SOL_SOCKET, SO_KEEPALIVE, (sockopt_val_t)&turnon, sizeof(turnon)) < 0) { - Jmsg(jcr, M_WARNING, 0, _("Cannot set SO_KEEPALIVE on socket: %s\n"), strerror(errno)); + Qmsg1(jcr, M_WARNING, 0, _("Cannot set SO_KEEPALIVE on socket: %s\n"), strerror(errno)); } for (i = 0; addr_list[i] != ((uint32_t) -1); i++) { @@ -650,13 +650,13 @@ bnet_connect(JCR *jcr, int retry_interval, int max_retry_time, const char *name, if (i < 0) { i = 60 * 5; /* complain again in 5 minutes */ if (verbose) - Jmsg(jcr, M_WARNING, 0, "Could not connect to %s on %s:%d. ERR=%s\n\ + Qmsg4(jcr, M_WARNING, 0, "Could not connect to %s on %s:%d. ERR=%s\n\ Retrying ...\n", name, host, port, strerror(errno)); } bmicrosleep(retry_interval, 0); max_retry_time -= retry_interval; if (max_retry_time <= 0) { - Jmsg(jcr, M_FATAL, 0, _("Unable to connect to %s on %s:%d. ERR=%s\n"), + Qmsg4(jcr, M_FATAL, 0, _("Unable to connect to %s on %s:%d. ERR=%s\n"), name, host, port, strerror(errno)); return NULL; } @@ -729,21 +729,21 @@ int bnet_set_buffer_size(BSOCK *bs, uint32_t size, int rw) } start_size = dbuf_size; if ((bs->msg = realloc_pool_memory(bs->msg, dbuf_size+100)) == NULL) { - Jmsg0(bs->jcr, M_FATAL, 0, _("Could not malloc BSOCK data buffer\n")); + Qmsg0(bs->jcr, M_FATAL, 0, _("Could not malloc BSOCK data buffer\n")); return 0; } if (rw & BNET_SETBUF_READ) { while ((dbuf_size > TAPE_BSIZE) && (setsockopt(bs->fd, SOL_SOCKET, SO_RCVBUF, (sockopt_val_t)&dbuf_size, sizeof(dbuf_size)) < 0)) { - Jmsg1(bs->jcr, M_ERROR, 0, _("sockopt error: %s\n"), strerror(errno)); + Qmsg1(bs->jcr, M_ERROR, 0, _("sockopt error: %s\n"), strerror(errno)); dbuf_size -= TAPE_BSIZE; } Dmsg1(200, "set network buffer size=%d\n", dbuf_size); if (dbuf_size != start_size) { - Jmsg1(bs->jcr, M_WARNING, 0, _("Warning network buffer = %d bytes not max size.\n"), dbuf_size); + Qmsg1(bs->jcr, M_WARNING, 0, _("Warning network buffer = %d bytes not max size.\n"), dbuf_size); } if (dbuf_size % TAPE_BSIZE != 0) { - Jmsg1(bs->jcr, M_ABORT, 0, _("Network buffer size %d not multiple of tape block size.\n"), + Qmsg1(bs->jcr, M_ABORT, 0, _("Network buffer size %d not multiple of tape block size.\n"), dbuf_size); } } @@ -756,15 +756,15 @@ int bnet_set_buffer_size(BSOCK *bs, uint32_t size, int rw) if (rw & BNET_SETBUF_WRITE) { while ((dbuf_size > TAPE_BSIZE) && (setsockopt(bs->fd, SOL_SOCKET, SO_SNDBUF, (sockopt_val_t)&dbuf_size, sizeof(dbuf_size)) < 0)) { - Jmsg1(bs->jcr, M_ERROR, 0, _("sockopt error: %s\n"), strerror(errno)); + Qmsg1(bs->jcr, M_ERROR, 0, _("sockopt error: %s\n"), strerror(errno)); dbuf_size -= TAPE_BSIZE; } Dmsg1(200, "set network buffer size=%d\n", dbuf_size); if (dbuf_size != start_size) { - Jmsg1(bs->jcr, M_WARNING, 0, _("Warning network buffer = %d bytes not max size.\n"), dbuf_size); + Qmsg1(bs->jcr, M_WARNING, 0, _("Warning network buffer = %d bytes not max size.\n"), dbuf_size); } if (dbuf_size % TAPE_BSIZE != 0) { - Jmsg1(bs->jcr, M_ABORT, 0, _("Network buffer size %d not multiple of tape block size.\n"), + Qmsg1(bs->jcr, M_ABORT, 0, _("Network buffer size %d not multiple of tape block size.\n"), dbuf_size); } } diff --git a/bacula/src/lib/dlist.c b/bacula/src/lib/dlist.c index 9dd304e2f2..c0d1242638 100644 --- a/bacula/src/lib/dlist.c +++ b/bacula/src/lib/dlist.c @@ -155,6 +155,7 @@ void dlist::destroy() n = ni; } num_items = 0; + head = tail = NULL; } diff --git a/bacula/src/lib/jcr.c b/bacula/src/lib/jcr.c index 3b97f59341..8f7d60bd1b 100755 --- a/bacula/src/lib/jcr.c +++ b/bacula/src/lib/jcr.c @@ -286,8 +286,8 @@ static void free_common_jcr(JCR *jcr) } pthread_mutex_destroy(&jcr->mutex); - close_msg(jcr); /* close messages for this job */ delete jcr->msg_queue; + close_msg(jcr); /* close messages for this job */ /* do this after closing messages */ if (jcr->client_name) { @@ -355,6 +355,7 @@ void free_jcr(JCR *jcr) Dmsg2(400, "free_jcr 0x%x use_count=%d\n", jcr, jcr->use_count); return; } + dequeue_messages(jcr); remove_jcr(jcr); job_end_pop(jcr); /* pop and call hooked routines */ diff --git a/bacula/src/lib/message.c b/bacula/src/lib/message.c index b8b4b004d0..e6cb8f010b 100755 --- a/bacula/src/lib/message.c +++ b/bacula/src/lib/message.c @@ -1033,14 +1033,16 @@ void j_msg(const char *file, int line, JCR *jcr, int type, int level, const char pool_buf = get_pool_memory(PM_EMSG); i = Mmsg(&pool_buf, "%s:%d ", file, line); -again: - maxlen = sizeof_pool_memory(pool_buf) - i - 1; - va_start(arg_ptr, fmt); - len = bvsnprintf(pool_buf+i, maxlen, fmt, arg_ptr); - va_end(arg_ptr); - if (len < 0 || len >= maxlen) { - pool_buf = realloc_pool_memory(pool_buf, maxlen + i + maxlen/2); - goto again; + for (;;) { + maxlen = sizeof_pool_memory(pool_buf) - i - 1; + va_start(arg_ptr, fmt); + len = bvsnprintf(pool_buf+i, maxlen, fmt, arg_ptr); + va_end(arg_ptr); + if (len < 0 || len >= maxlen) { + pool_buf = realloc_pool_memory(pool_buf, maxlen + i + maxlen/2); + continue; + } + break; } Jmsg(jcr, type, level, "%s", pool_buf); @@ -1058,14 +1060,16 @@ int m_msg(const char *file, int line, POOLMEM **pool_buf, const char *fmt, ...) i = sprintf(mp_chr(*pool_buf), "%s:%d ", file, line); -again: - maxlen = sizeof_pool_memory(*pool_buf) - i - 1; - va_start(arg_ptr, fmt); - len = bvsnprintf(*pool_buf+i, maxlen, fmt, arg_ptr); - va_end(arg_ptr); - if (len < 0 || len >= maxlen) { - *pool_buf = realloc_pool_memory(*pool_buf, maxlen + i + maxlen/2); - goto again; + for (;;) { + maxlen = sizeof_pool_memory(*pool_buf) - i - 1; + va_start(arg_ptr, fmt); + len = bvsnprintf(*pool_buf+i, maxlen, fmt, arg_ptr); + va_end(arg_ptr); + if (len < 0 || len >= maxlen) { + *pool_buf = realloc_pool_memory(*pool_buf, maxlen + i + maxlen/2); + continue; + } + break; } return len; } @@ -1079,14 +1083,16 @@ int Mmsg(POOLMEM **pool_buf, const char *fmt, ...) va_list arg_ptr; int len, maxlen; -again: - maxlen = sizeof_pool_memory(*pool_buf) - 1; - va_start(arg_ptr, fmt); - len = bvsnprintf(*pool_buf, maxlen, fmt, arg_ptr); - va_end(arg_ptr); - if (len < 0 || len >= maxlen) { - *pool_buf = realloc_pool_memory(*pool_buf, maxlen + maxlen/2); - goto again; + for (;;) { + maxlen = sizeof_pool_memory(*pool_buf) - 1; + va_start(arg_ptr, fmt); + len = bvsnprintf(*pool_buf, maxlen, fmt, arg_ptr); + va_end(arg_ptr); + if (len < 0 || len >= maxlen) { + *pool_buf = realloc_pool_memory(*pool_buf, maxlen + maxlen/2); + continue; + } + break; } return len; } @@ -1096,7 +1102,9 @@ static pthread_mutex_t msg_queue_mutex = PTHREAD_MUTEX_INITIALIZER; /* * We queue messages rather than print them directly. This * is generally used in low level routines (msg handler, bnet) - * to prevent recursion. + * to prevent recursion (i.e. if you are in the middle of + * sending a message, it is a bit messy to recursively call + * yourself when the bnet packet is not reentrant). */ void Qmsg(JCR *jcr, int type, int level, const char *fmt,...) { @@ -1105,26 +1113,33 @@ void Qmsg(JCR *jcr, int type, int level, const char *fmt,...) POOLMEM *pool_buf; MQUEUE_ITEM *item; - if (jcr->dequeuing) { /* do not allow recursion */ - return; - } pool_buf = get_pool_memory(PM_EMSG); -again: - maxlen = sizeof_pool_memory(pool_buf) - 1; - va_start(arg_ptr, fmt); - len = bvsnprintf(pool_buf, maxlen, fmt, arg_ptr); - va_end(arg_ptr); - if (len < 0 || len >= maxlen) { - pool_buf = realloc_pool_memory(pool_buf, maxlen + maxlen/2); - goto again; + for (;;) { + maxlen = sizeof_pool_memory(pool_buf) - 1; + va_start(arg_ptr, fmt); + len = bvsnprintf(pool_buf, maxlen, fmt, arg_ptr); + va_end(arg_ptr); + if (len < 0 || len >= maxlen) { + pool_buf = realloc_pool_memory(pool_buf, maxlen + maxlen/2); + continue; + } + break; } item = (MQUEUE_ITEM *)malloc(sizeof(MQUEUE_ITEM) + strlen(pool_buf) + 1); item->type = type; item->level = level; strcpy(item->msg, pool_buf); P(msg_queue_mutex); - jcr->msg_queue->append(item); + /* If no jcr or dequeuing send to daemon to avoid recursion */ + if (!jcr || jcr->dequeuing) { + /* jcr==NULL => daemon message, safe to send now */ + Jmsg(NULL, item->type, item->level, "%s", item->msg); + free(item); + } else { + /* Queue message for later sending */ + jcr->msg_queue->append(item); + } V(msg_queue_mutex); free_memory(pool_buf); } @@ -1159,14 +1174,16 @@ void q_msg(const char *file, int line, JCR *jcr, int type, int level, const char pool_buf = get_pool_memory(PM_EMSG); i = Mmsg(&pool_buf, "%s:%d ", file, line); -again: - maxlen = sizeof_pool_memory(pool_buf) - i - 1; - va_start(arg_ptr, fmt); - len = bvsnprintf(pool_buf+i, maxlen, fmt, arg_ptr); - va_end(arg_ptr); - if (len < 0 || len >= maxlen) { - pool_buf = realloc_pool_memory(pool_buf, maxlen + i + maxlen/2); - goto again; + for (;;) { + maxlen = sizeof_pool_memory(pool_buf) - i - 1; + va_start(arg_ptr, fmt); + len = bvsnprintf(pool_buf+i, maxlen, fmt, arg_ptr); + va_end(arg_ptr); + if (len < 0 || len >= maxlen) { + pool_buf = realloc_pool_memory(pool_buf, maxlen + i + maxlen/2); + continue; + } + break; } Qmsg(jcr, type, level, "%s", pool_buf); diff --git a/bacula/src/version.h b/bacula/src/version.h index 3015c23ed2..45169f0c1d 100644 --- a/bacula/src/version.h +++ b/bacula/src/version.h @@ -2,8 +2,8 @@ #undef VERSION #define VERSION "1.33.6" #define VSTRING "1" -#define BDATE "27 Mar 2004" -#define LSMDATE "27Mar04" +#define BDATE "28 Mar 2004" +#define LSMDATE "28Mar04" /* Debug flags */ #undef DEBUG -- 2.39.5