]> git.sur5r.net Git - bacula/bacula/commitdiff
Convert all Jmsg on the watchdog thread to Qmsg
authorEric Bollengier <eric@eb.homelinux.org>
Fri, 28 May 2010 11:37:58 +0000 (13:37 +0200)
committerEric Bollengier <eric@eb.homelinux.org>
Fri, 2 Jul 2010 13:37:48 +0000 (15:37 +0200)
bacula/src/lib/message.c
bacula/src/lib/protos.h
bacula/src/lib/watchdog.c

index e403ec9ea70c577e5a6784fd53eac834cb0de41c..ff4c07603027e4d59971606e0baba6ec9e840528 100644 (file)
@@ -1216,11 +1216,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;
     }
index 7e700bdad7d5867c2aee615091bedd82a620e2d6..7a393398caf0d07c972200d9668bbd0cb05dec20 100644 (file)
@@ -339,6 +339,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);
index 770597dbbac3729f98a1c40dc170365a6f896213..3c70ffc783f99232036d191b5c9dc426570601c6 100644 (file)
@@ -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
  *