From 5e7cc309a14f2f21fea3cfecfb14e76e7c66e7c5 Mon Sep 17 00:00:00 2001 From: Eric Bollengier Date: Fri, 28 May 2010 13:37:58 +0200 Subject: [PATCH] Convert all Jmsg on the watchdog thread to Qmsg --- bacula/src/lib/message.c | 13 +++++++++++++ bacula/src/lib/protos.h | 1 + bacula/src/lib/watchdog.c | 13 +++++++++++++ 3 files changed, 27 insertions(+) diff --git a/bacula/src/lib/message.c b/bacula/src/lib/message.c index 638c4c259a..def39b8d85 100644 --- a/bacula/src/lib/message.c +++ b/bacula/src/lib/message.c @@ -1218,11 +1218,24 @@ Jmsg(JCR *jcr, int type, utime_t mtime, const char *fmt,...) return; } + /* The watchdog thread can't use Jmsg directly, we always queued it */ + if (is_watchdog()) { + va_start(arg_ptr, fmt); + bvsnprintf(rbuf+len, sizeof(rbuf)-len, fmt, arg_ptr); + va_end(arg_ptr); + Qmsg(jcr, type, mtime, "%s", rbuf); + return; + } + msgs = NULL; if (!jcr) { jcr = get_jcr_from_tsd(); } if (jcr) { + if (!jcr->dequeuing_msgs) { /* Avoid recursion */ + /* Dequeue messages to keep the original order */ + dequeue_messages(jcr); + } msgs = jcr->jcr_msgs; JobId = jcr->JobId; } diff --git a/bacula/src/lib/protos.h b/bacula/src/lib/protos.h index 701d98e2c0..450a70ad8b 100644 --- a/bacula/src/lib/protos.h +++ b/bacula/src/lib/protos.h @@ -341,6 +341,7 @@ int stop_watchdog(void); watchdog_t *new_watchdog(void); bool register_watchdog(watchdog_t *wd); bool unregister_watchdog(watchdog_t *wd); +bool is_watchdog(); /* timers.c */ btimer_t *start_child_timer(JCR *jcr, pid_t pid, uint32_t wait); diff --git a/bacula/src/lib/watchdog.c b/bacula/src/lib/watchdog.c index 770597dbba..3c70ffc783 100644 --- a/bacula/src/lib/watchdog.c +++ b/bacula/src/lib/watchdog.c @@ -60,6 +60,19 @@ static pthread_t wd_tid; static dlist *wd_queue; static dlist *wd_inactive; +/* + * Returns: 0 if the current thread is NOT the watchdog + * 1 if the current thread is the watchdog + */ +bool is_watchdog() +{ + if (wd_is_init && pthread_equal(pthread_self(), wd_tid)) { + return true; + } else { + return false; + } +} + /* * Start watchdog thread * -- 2.39.5