]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/dird/dird.c
ebl Modify disk-changer to check if slot contains something before
[bacula/bacula] / bacula / src / dird / dird.c
index bccd480be136f8ee857d1a28fcbac718befbe500..cba298e56cb624b7b21dc3b9cc4d8671cb6b4619 100644 (file)
@@ -1,7 +1,7 @@
 /*
    Bacula® - The Network Backup Solution
 
-   Copyright (C) 2000-2007 Free Software Foundation Europe e.V.
+   Copyright (C) 2000-2008 Free Software Foundation Europe e.V.
 
    The main author of Bacula is Kern Sibbald, with contributions from
    many others, a complete list can be found in the file AUTHORS.
@@ -58,12 +58,14 @@ void term_job_server();
 void store_jobtype(LEX *lc, RES_ITEM *item, int index, int pass);
 void store_level(LEX *lc, RES_ITEM *item, int index, int pass);
 void store_replace(LEX *lc, RES_ITEM *item, int index, int pass);
+void store_migtype(LEX *lc, RES_ITEM *item, int index, int pass);
 void init_device_resources();
 
 static char *runjob = NULL;
 static int background = 1;
 static void init_reload(void);
-
+static CONFIG *config;
 /* Globals Exported */
 DIRRES *director;                     /* Director resource */
 int FDConnectTimeout;
@@ -76,6 +78,7 @@ extern int r_first, r_last;           /* first and last resources */
 extern RES_TABLE resources[];
 extern RES **res_head;
 extern RES_ITEM job_items[];
+extern int  res_all_size;
 
 #if defined(_MSC_VER)
 extern "C" { // work around visual compiler mangling variables
@@ -140,6 +143,8 @@ int main (int argc, char *argv[])
    init_reload();
    daemon_start_time = time(NULL);
 
+   console_command = run_console_command;
+
    while ((ch = getopt(argc, argv, "c:d:fg:r:stu:v?")) != -1) {
       switch (ch) {
       case 'c':                    /* specify config file */
@@ -223,7 +228,10 @@ int main (int argc, char *argv[])
       configfile = bstrdup(CONFIG_FILE);
    }
 
-   parse_config(configfile);
+   config = new_config_parser();
+   config->init(configfile, NULL, M_ERROR_TERM, (void *)&res_all, res_all_size,
+                r_first, r_last, resources, res_head);
+   config->parse_config();
 
    if (init_crypto() != 0) {
       Jmsg((JCR *)NULL, M_ERROR_TERM, 0, _("Cryptography library initialization failed.\n"));
@@ -244,6 +252,8 @@ int main (int argc, char *argv[])
       read_state_file(director->working_directory, "bacula-dir", get_first_port_host_order(director->DIRaddrs));
    }
 
+   load_dir_plugins(director->plugin_directory);
+
    drop(uid, gid);                    /* reduce privileges if requested */
 
    if (!check_catalog()) {
@@ -328,8 +338,10 @@ void terminate_dird(int sig)
       exit(1);
    }
    already_here = true;
+   debug_level = 0;                   /* turn off debug */
    stop_watchdog();
    generate_daemon_event(NULL, "Exit");
+   unload_plugins();
    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));
    term_scheduler();
@@ -343,7 +355,9 @@ void terminate_dird(int sig)
    if (debug_level > 5) {
       print_memory_pool_stats();
    }
-   free_config_resources();
+   config->free_resources();
+   free(config);
+   config = NULL;
    term_ua_server();
    term_msg();                        /* terminate message handler */
    cleanup_crypto();
@@ -469,7 +483,7 @@ void reload_config(int sig)
    }
 
    Dmsg1(100, "Reload_config njobs=%d\n", njobs);
-   reload_table[table].res_table = save_config_resources();
+   reload_table[table].res_table = config->save_resources();
    Dmsg1(100, "Saved old config in table %d\n", table);
 
    ok = parse_config(configfile, 0, M_ERROR);  /* no exit on error */
@@ -484,7 +498,7 @@ void reload_config(int sig)
          Jmsg(NULL, M_ERROR, 0, _("Please correct configuration file: %s\n"), configfile);
          Jmsg(NULL, M_ERROR, 0, _("Resetting previous configuration.\n"));
       }
-      reload_table[rtable].res_table = save_config_resources();
+      reload_table[rtable].res_table = config->save_resources();
       /* Now restore old resoure values */
       int num = r_last - r_first + 1;
       RES **res_tab = reload_table[table].res_table;
@@ -707,6 +721,7 @@ static bool check_resources()
                           job_items[i].handler == store_jobtype ||
                           job_items[i].handler == store_level   ||
                           job_items[i].handler == store_pint    ||
+                          job_items[i].handler == store_migtype ||
                           job_items[i].handler == store_replace) {
                   def_ivalue = (int *)((char *)(job->jobdefs) + offset);
                   Dmsg5(400, "Job \"%s\", field \"%s\" def_ivalue=%d item %d offset=%u\n",
@@ -879,7 +894,7 @@ static bool check_catalog()
        * Make sure we can open catalog, otherwise print a warning
        * message because the server is probably not running.
        */
-      db = db_init_database(NULL, catalog->db_name, catalog->db_user,
+      db = db_init(NULL, catalog->db_driver, catalog->db_name, catalog->db_user,
                          catalog->db_password, catalog->db_address,
                          catalog->db_port, catalog->db_socket,
                          catalog->mult_db_connections);
@@ -900,12 +915,14 @@ static bool check_catalog()
       /* Loop over all pools, defining/updating them in each database */
       POOL *pool;
       foreach_res(pool, R_POOL) {
-         create_pool(NULL, db, pool, POOL_OP_UPDATE);  /* update request */
-      }
-
-      /* Loop over all pools for updating RecyclePool */
-      foreach_res(pool, R_POOL) {
-         update_pool_recyclepool(NULL, db, pool);
+         /*
+          * If the Pool has a catalog resource create the pool only
+          *   in that catalog.
+          */
+         if (!pool->catalog || pool->catalog == catalog) {
+            create_pool(NULL, db, pool, POOL_OP_UPDATE);  /* update request */
+            update_pool_recyclepool(NULL, db, pool);
+         }
       }
 
       STORE *store;