]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/dird/dird.c
Fix bug #2346 Dir blocks when max reloads reached
[bacula/bacula] / bacula / src / dird / dird.c
index 9bde2ebb8422cca99103e09310b147151ed5b33a..c1c1b151a0bb08dbe73d8972033ce08d840f4ed1 100644 (file)
@@ -64,6 +64,7 @@ void init_device_resources();
 
 static char *runjob = NULL;
 static bool foreground = false;
+static bool make_pid_file = true;     /* create pid file */
 static void init_reload(void);
 static CONFIG *config;
 static bool test_config = false;
@@ -82,8 +83,6 @@ extern dlist client_globals;
 extern dlist store_globals;
 extern dlist job_globals;
 extern dlist sched_globals;
-extern dlist *daemon_msg_queue;
-extern pthread_mutex_t daemon_msg_queue_mutex;
 extern RES_ITEM job_items[];
 #if defined(_MSC_VER)
 extern "C" { // work around visual compiler mangling variables
@@ -133,6 +132,7 @@ static void usage()
       "     -g               groupid\n"
       "     -m               print kaboom output (for debugging)\n"
       "     -r <job>         run <job> now\n"
+      "     -P               do not create pid file\n"
       "     -s               no signals\n"
       "     -t               test - read configuration and exit\n"
       "     -u               userid\n"
@@ -175,7 +175,6 @@ int main (int argc, char *argv[])
    bool no_signals = false;
    char *uid = NULL;
    char *gid = NULL;
-   MQUEUE_ITEM *item = NULL;
 
    /* DELETE ME when bugs in MA1512, MA1632 MA1639 are fixed */
    MA1512_reload_job_end_cb = reload_job_end_cb;
@@ -190,11 +189,10 @@ int main (int argc, char *argv[])
    init_msg(NULL, NULL);              /* initialize message handler */
    init_reload();
    daemon_start_time = time(NULL);
-   /* Setup daemon message queue */
-   daemon_msg_queue = New(dlist(item, &item->link));
+   setup_daemon_message_queue();
    console_command = run_console_command;
 
-   while ((ch = getopt(argc, argv, "c:d:fg:mr:stu:v?T")) != -1) {
+   while ((ch = getopt(argc, argv, "c:d:fg:mPr:stu:v?T")) != -1) {
       switch (ch) {
       case 'c':                    /* specify config file */
          if (configfile != NULL) {
@@ -239,6 +237,10 @@ int main (int argc, char *argv[])
          prt_kaboom = true;
          break;
 
+      case 'P':                    /* no pid file */
+         make_pid_file = false;
+         break;
+
       case 'r':                    /* run job */
          if (runjob != NULL) {
             free(runjob);
@@ -311,8 +313,10 @@ int main (int argc, char *argv[])
 
    if (!test_config) {
       /* Create pid must come after we are a daemon -- so we have our final pid */
-      create_pid_file(director->pid_directory, "bacula-dir",
-                      get_first_port_host_order(director->DIRaddrs));
+      if (make_pid_file) {
+         create_pid_file(director->pid_directory, "bacula-dir",
+                          get_first_port_host_order(director->DIRaddrs));
+      }
       read_state_file(director->working_directory, "bacula-dir",
                       get_first_port_host_order(director->DIRaddrs));
    }
@@ -522,7 +526,7 @@ void reload_config(int sig)
       if (already_here) {
          V(reload_mutex);
          if (tries++ > 10) {
-            Jmsg(NULL, M_INFO, 0, _("Already doing a reload request, "
+            Qmsg(NULL, M_INFO, 0, _("Already doing a reload request, "
                                     "request ignored.\n"));
             return;
          }
@@ -546,8 +550,8 @@ void reload_config(int sig)
 
    table = find_free_reload_table_entry();
    if (table < 0) {
-      Jmsg(NULL, M_ERROR, 0, _("Too many open reload requests. "
-                               "Request ignored.\n"));
+      Qmsg(NULL, M_ERROR, 0, _("Too many (%d) open reload requests. "
+                               "Request ignored.\n"), max_reloads);
       goto bail_out;
    }
 
@@ -567,11 +571,11 @@ void reload_config(int sig)
        */
       rtable = find_free_reload_table_entry();    /* save new, bad table */
       if (rtable < 0) {
-         Jmsg(NULL, M_ERROR, 0, _("Please correct configuration file: %s\n"), configfile);
-         Jmsg(NULL, M_ERROR_TERM, 0, _("Out of reload table entries. Giving up.\n"));
+         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"));
       } else {
-         Jmsg(NULL, M_ERROR, 0, _("Please correct configuration file: %s\n"), configfile);
-         Jmsg(NULL, M_ERROR, 0, _("Resetting previous configuration.\n"));
+         Qmsg(NULL, M_ERROR, 0, _("Please correct configuration file: %s\n"), configfile);
+         Qmsg(NULL, M_ERROR, 0, _("Resetting previous configuration.\n"));
       }
       /* Save broken res_head pointer */
       reload_table[rtable].res_head = res_head;
@@ -601,7 +605,7 @@ void reload_config(int sig)
          CLIENT *client;
          client = GetClientResWithName(cg->name);
          if (!client) {
-            Jmsg(NULL, M_INFO, 0, _("Client=%s not found. Assuming it was removed!!!\n"), cg->name);
+            Qmsg(NULL, M_INFO, 0, _("Client=%s not found. Assuming it was removed!!!\n"), cg->name);
          } else {
             client->globals = cg;      /* Set globals pointer */
          }
@@ -611,7 +615,7 @@ void reload_config(int sig)
          STORE *store;
          store = GetStoreResWithName(sg->name);
          if (!store) {
-            Jmsg(NULL, M_INFO, 0, _("Storage=%s not found. Assuming it was removed!!!\n"), sg->name);
+            Qmsg(NULL, M_INFO, 0, _("Storage=%s not found. Assuming it was removed!!!\n"), sg->name);
          } else {
             store->globals = sg;       /* set globals pointer */
             Dmsg2(200, "Reload found numConcurrent=%ld for Store %s\n",
@@ -623,7 +627,7 @@ void reload_config(int sig)
          JOB *job;
          job = GetJobResWithName(jg->name);
          if (!job) {
-            Jmsg(NULL, M_INFO, 0, _("Job=%s not found. Assuming it was removed!!!\n"), jg->name);
+            Qmsg(NULL, M_INFO, 0, _("Job=%s not found. Assuming it was removed!!!\n"), jg->name);
          } else {
             job->globals = jg;         /* Set globals pointer */
          }
@@ -633,7 +637,7 @@ void reload_config(int sig)
          SCHED *sched;
          sched = GetSchedResWithName(schg->name);
          if (!sched) {
-            Jmsg(NULL, M_INFO, 0, _("Schedule=%s not found. Assuming it was removed!!!\n"), schg->name);
+            Qmsg(NULL, M_INFO, 0, _("Schedule=%s not found. Assuming it was removed!!!\n"), schg->name);
          } else {
             sched->globals = schg;     /* Set globals pointer */
          }
@@ -677,7 +681,9 @@ void terminate_dird(int sig)
    unload_plugins();
    if (!test_config) {
       write_state_file(director->working_directory, "bacula-dir", get_first_port_host_order(director->DIRaddrs));
-      delete_pid_file(director->pid_directory, "bacula-dir", get_first_port_host_order(director->DIRaddrs));
+      if (make_pid_file) {
+         delete_pid_file(director->pid_directory, "bacula-dir", get_first_port_host_order(director->DIRaddrs));
+      }
    }
    term_scheduler();
    term_job_server();
@@ -698,10 +704,7 @@ void terminate_dird(int sig)
    term_msg();                        /* terminate message handler */
    cleanup_crypto();
 
-   P(daemon_msg_queue_mutex);
-   daemon_msg_queue->destroy();
-   free(daemon_msg_queue);
-   V(daemon_msg_queue_mutex);
+   free_daemon_message_queue();
 
    if (reload_table) {
       free(reload_table);