]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
Send reload messages directly to the UA Console rather than via a Job message
authorEric Bollengier <eric@baculasystems.com>
Mon, 11 Apr 2022 07:23:36 +0000 (09:23 +0200)
committerEric Bollengier <eric@baculasystems.com>
Thu, 14 Sep 2023 11:56:59 +0000 (13:56 +0200)
When the Job messages are not send to the console (when using a
web interface to manage bacula for example), the reload messages
are not visible within bconsole after a reload command.

bacula/src/dird/dird.c
bacula/src/dird/protos.h
bacula/src/dird/ua_cmds.c

index 348b7d7338d28f9d39bafaaf3706c001ceb6de6c..fb6fc78a6ddd3fbd732d446d83693cbc42e41acf 100644 (file)
@@ -659,6 +659,27 @@ static void connect_and_init_globals()
    }
 }
 
+/* We store messages into a alist for the reload command,
+ * the first message is the error level, then we have the
+ * message itself
+ */
+#define reload_append_msg0(lst, pm, level, format) do { \
+  char code[2];    \
+  code[0] = level; \
+  code[1] = 0;     \
+  lst->append(bstrdup(code));   \
+  lst->append(bstrdup(format)); \
+ } while(0)
+
+#define reload_append_msg1(lst, pm, level, format, arg1) do { \
+  char code[2];    \
+  code[0] = level; \
+  code[1] = 0;     \
+  lst->append(bstrdup(code));       \
+  Mmsg(pm, format, arg1);           \
+  lst->append(bstrdup(pm.c_str())); \
+  } while(0)
+
 /*
  * If we get here, we have received a SIGHUP, which means to
  *    reread our configuration file.
@@ -678,8 +699,7 @@ static void connect_and_init_globals()
  *   resources, but a SYSTEM job is not since it *should* not have any
  *   permanent pointers to jobs.
  */
-extern "C"
-void reload_config(int sig)
+bool reload_config(int sig, alist *msglist)
 {
    static bool already_here = false;
 #if !defined(HAVE_WIN32)
@@ -687,9 +707,11 @@ void reload_config(int sig)
 #endif
    JCR *jcr;
    int njobs = 0;                     /* number of running jobs */
+   bool ret = false;
    int table, rtable;
    bool ok=false;
    int tries=0;
+   POOL_MEM msg;
 
    /* Wait to do the reload */
    do {
@@ -697,9 +719,10 @@ void reload_config(int sig)
       if (already_here) {
          V(reload_mutex);
          if (tries++ > 10) {
-            Qmsg(NULL, M_INFO, 0, _("Already doing a reload request, "
-                                    "request ignored.\n"));
-            return;
+            reload_append_msg0(msglist, msg, M_INFO,
+                               _("Already doing a reload request, "
+                                 "request ignored.\n"));
+            return false;
          }
          Dmsg0(10, "Already doing a reload request, waiting a bit\n");
          bmicrosleep(1, 0);
@@ -724,8 +747,9 @@ void reload_config(int sig)
 
    table = find_free_reload_table_entry();
    if (table < 0) {
-      Qmsg(NULL, M_ERROR, 0, _("Too many (%d) open reload requests. "
-                               "Request ignored.\n"), max_reloads);
+      reload_append_msg1(msglist, msg, M_ERROR,
+                         _("Too many (%d) open reload requests. "
+                           "Request ignored.\n"), max_reloads);
       goto bail_out;
    }
 
@@ -745,11 +769,12 @@ void reload_config(int sig)
        */
       rtable = find_free_reload_table_entry();    /* save new, bad table */
       if (rtable < 0) {
-         Qmsg(NULL, M_ERROR, 0, _("Please correct configuration file: %s\n"), configfile);
-         Qmsg(NULL, M_ERROR_TERM, 0, _("Out of reload table entries. Giving up.\n"));
+         reload_append_msg1(msglist, msg, M_ERROR, _("Please correct configuration file: %s\n"), configfile);
+         reload_append_msg0(msglist, msg, M_ERROR_TERM, _("Out of reload table entries. Giving up.\n"));
+
       } else {
-         Qmsg(NULL, M_ERROR, 0, _("Please correct configuration file: %s\n"), configfile);
-         Qmsg(NULL, M_ERROR, 0, _("Resetting previous configuration.\n"));
+         reload_append_msg1(msglist, msg, M_ERROR, _("Please correct configuration file: %s\n"), configfile);
+         reload_append_msg0(msglist, msg, M_ERROR, _("Resetting previous configuration.\n"));
       }
       /* Save broken res_head pointer */
       reload_table[rtable].res_head = res_head;
@@ -784,6 +809,7 @@ void reload_config(int sig)
       events_send_msg(NULL, "DD0005",
                       EVENTS_TYPE_DAEMON, "*Director*",
                       (intptr_t)get_first_port_host_order(director->DIRaddrs), "Director configuration reloaded");
+      ret = true;               // reload ok
    }
 
    /* Reset other globals */
@@ -813,6 +839,7 @@ bail_out:
    signal(SIGHUP, reload_config);
 #endif
    already_here = false;
+   return ret;
 }
 
 /* Cleanup and then exit */
@@ -905,6 +932,25 @@ void terminate_dird(int sig)
    exit(sig);
 }
 
+extern "C"
+void reload_config(int sig)
+{
+   alist msg(owned_by_alist, 5);
+   // list of strings M_LEVEL, message
+   if (!reload_config(sig, &msg)) {
+      char *m, *code;
+      while (!msg.empty()) {
+         code = (char *)msg.remove(0);
+         m = (char *)msg.remove(0);
+
+         Qmsg(NULL, code[0], 0, "%s", m);
+
+         free(code);
+         free(m);
+      }
+   }
+}
+
 /*
  * Make a quick check to see that we have all the
  * resources needed.
index f92d901029aec1df9250ed5cba1d4b1bdf5819ef..4e334345ba315460f2c8273fcbdcd5aeb4038646 100644 (file)
@@ -371,6 +371,9 @@ bool update_snapshot(UAContext *ua);
 int prune_snapshot(UAContext *ua);
 bool send_snapshot_retention(JCR *jcr, utime_t val);
 
+/* dird.c */
+bool reload_config(int sig, alist *msglist);
+
 /* ua_collect.c */
 bool update_permanent_stats(void *data);
 void initialize_statcollector();
index fd545a466610f7167e5e7bf6734bb0236934aacc..8d7c31f48f501b2ae2d289860bc0e4b452d5ab14 100644 (file)
@@ -1832,12 +1832,32 @@ static int time_cmd(UAContext *ua, const char *cmd)
 /*
  * reload the conf file
  */
-extern "C" void reload_config(int sig);
 
 static int reload_cmd(UAContext *ua, const char *cmd)
 {
+   alist msg(owned_by_alist, 5);
    ua->send_events("DC0019", EVENTS_TYPE_COMMAND, "reload");
-   reload_config(1);
+
+   /* msgs is a list of message_level + message 
+    * We display through the UAContext the messages
+    * properly
+    */
+   if (!reload_config(1, &msg)) {
+      char *m, *code;
+      while (!msg.empty()) {
+         code = (char *)msg.remove(0);
+         m = (char *)msg.remove(0);
+
+         if (code[0] == M_INFO) {
+            ua->send_msg("%s", m);
+
+         } else {
+            ua->error_msg("%s", m);
+         }
+         free(code);
+         free(m);
+      }
+   }
    return 1;
 }