From 3f0b185aef8b461ff51388ddd162a58416c0fc9f Mon Sep 17 00:00:00 2001 From: Alain Spineux Date: Mon, 7 Mar 2022 14:27:41 +0100 Subject: [PATCH] Fix #8895 A Jmsg deadlock the PGSQL timezone mismatch handling code - 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 | 5 +++-- bacula/src/lib/message.c | 18 +++++++++++------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/bacula/src/cats/postgresql.c b/bacula/src/cats/postgresql.c index 1725f8091..74b15f01e 100644 --- a/bacula/src/cats/postgresql.c +++ b/bacula/src/cats/postgresql.c @@ -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; } diff --git a/bacula/src/lib/message.c b/bacula/src/lib/message.c index abc22bd90..f00fff45f 100644 --- a/bacula/src/lib/message.c +++ b/bacula/src/lib/message.c @@ -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); } -- 2.47.3