]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
Fix #8895 A Jmsg deadlock the PGSQL timezone mismatch handling code
authorAlain Spineux <alain@baculasystems.com>
Mon, 7 Mar 2022 13:27:41 +0000 (14:27 +0100)
committerEric Bollengier <eric@baculasystems.com>
Thu, 14 Sep 2023 11:56:58 +0000 (13:56 +0200)
- A Jmsg() should not be called when the Catalog is not yet up and running
- Instead use Qmsg() and tweak dequeue_daemon_messages() to handle jcr==NULL

bacula/src/cats/postgresql.c
bacula/src/lib/message.c

index 1725f8091303a1c9fb4c437399e64695e0690537..74b15f01ea2e1d068a6a4d35afefc2d790126690 100644 (file)
@@ -453,14 +453,14 @@ bool BDB_POSTGRESQL::bdb_open_database(JCR *jcr)
       int sys_offset = get_system_utc_offset();
       int ret = pgsql_get_utc_offset(this, &pgsql_offset);
       if (ret != 0) {
-         Jmsg(jcr, ret, 0, "%s", errmsg);
+         Qmsg(jcr, ret, 0, "%s", errmsg);
       } else {
          if (sys_offset != pgsql_offset) {
             /* try again in case we would be just on Daylight Saving Time switch */
             sys_offset = get_system_utc_offset();
          }
          if (sys_offset != pgsql_offset) {
-            Jmsg(jcr, M_WARNING, 0, _("Postgresql and sytem timezone mismatch detected\n"));
+            Qmsg(jcr, M_WARNING, 0, _("Postgresql and system timezone mismatch detected\n"));
          }
       }
    }
@@ -483,6 +483,7 @@ get_out:
    if (print_msg) {
       Jmsg(jcr, print_msg, 0, "%s", errmsg);
    }
+   dequeue_daemon_messages(jcr);
    return retval; 
 } 
 
index abc22bd908e528edfa23fc05c70f6dcb23b632f4..f00fff45fad689d8be3afc81b33ef9f19ddbb05f 100644 (file)
@@ -1915,10 +1915,12 @@ void dequeue_daemon_messages(JCR *jcr)
    if (daemon_msg_queue && !dequeuing_daemon_msgs) {
       P(daemon_msg_queue_mutex);
       dequeuing_daemon_msgs = true;
-      jcr->dequeuing_msgs = true;
-      JobId = jcr->JobId;
-      jcr->JobId = 0;       /* set daemon JobId == 0 */
-      if (jcr->dir_bsock) jcr->dir_bsock->suppress_error_messages(true);
+      if (jcr != NULL) {
+         jcr->dequeuing_msgs = true;
+         JobId = jcr->JobId;
+         jcr->JobId = 0;       /* set daemon JobId == 0 */
+         if (jcr->dir_bsock) jcr->dir_bsock->suppress_error_messages(true);
+      }
       foreach_dlist(item, daemon_msg_queue) {
          if (item->type == M_FATAL || item->type == M_ERROR) {
             item->type = M_SECURITY;
@@ -1932,11 +1934,13 @@ void dequeue_daemon_messages(JCR *jcr)
                  item->repeat+1, item->msg);
          }
       }
-      if (jcr->dir_bsock) jcr->dir_bsock->suppress_error_messages(false);
       /* Remove messages just sent */
       daemon_msg_queue->destroy();
-      jcr->JobId = JobId;   /* restore JobId */
-      jcr->dequeuing_msgs = false;
+      if (jcr != NULL) {
+         if (jcr->dir_bsock) jcr->dir_bsock->suppress_error_messages(false);
+         jcr->JobId = JobId;   /* restore JobId */
+         jcr->dequeuing_msgs = false;
+      }
       dequeuing_daemon_msgs = false;
       V(daemon_msg_queue_mutex);
    }