lintian doesn't like orphan packages with uploaders...
[debian/amanda] / server-src / server_util.c
index 24a91ff9625ac2af1a2ea47b9ecdf3422a4eaa23..72462a3668479c7a7bad348f997bb868145be15b 100644 (file)
@@ -1,6 +1,7 @@
 /*
  * Amanda, The Advanced Maryland Automatic Network Disk Archiver
  * Copyright (c) 1991-1999 University of Maryland at College Park
+ * Copyright (c) 2007-2012 Zmanda, Inc.  All Rights Reserved.
  * All Rights Reserved.
  *
  * Permission to use, copy, modify, distribute, and sell this software and its
@@ -50,7 +51,7 @@ const char *cmdstr[] = {
     "PARTDONE", "PORT-WRITE", "DUMPER-STATUS",             /* taper cmds */
     "PORT", "TAPE-ERROR", "TAPER-OK",                   /* taper results */
     "REQUEST-NEW-TAPE", "DIRECTTCP-PORT", "TAKE-SCRIBE-FROM",
-    "START-SCAN", "LAST_TOK",
+    "START-SCAN", "CLOSE-VOLUME", "LAST_TOK",
     NULL
 };
 
@@ -244,6 +245,8 @@ run_server_script(
     char      *line;
     char      *plugin;
     char       level_number[NUM_STR_SIZE];
+    struct stat cmd_stat;
+    int         result;
 
     if ((pp_script_get_execute_on(pp_script) & execute_on) == 0)
        return;
@@ -251,40 +254,78 @@ run_server_script(
        return;
 
     plugin = pp_script_get_plugin(pp_script);
+
     cmd = vstralloc(APPLICATION_DIR, "/", plugin, NULL);
+    result = stat(cmd, &cmd_stat);
+    if (result == -1) {
+       dbprintf("Can't stat script '%s': %s\n", cmd, strerror(errno));
+       amfree(cmd);
+       cmd = vstralloc(get_config_dir(), "/application/", plugin, NULL);
+       result = stat(cmd, &cmd_stat);
+       if (result == -1) {
+           dbprintf("Can't stat script '%s': %s\n", cmd, strerror(errno));
+           amfree(cmd);
+           cmd = vstralloc(CONFIG_DIR, "/application/", plugin, NULL);
+           result = stat(cmd, &cmd_stat);
+           if (result == -1) {
+               dbprintf("Can't stat script '%s': %s\n", cmd, strerror(errno));
+               amfree(cmd);
+               cmd = vstralloc(APPLICATION_DIR, "/", plugin, NULL);
+           }
+       }
+    }
+
     g_ptr_array_add(argv_ptr, stralloc(plugin));
 
     switch (execute_on) {
+    case EXECUTE_ON_PRE_AMCHECK:
+       command = "PRE-AMCHECK";
+       break;
     case EXECUTE_ON_PRE_DLE_AMCHECK:
        command = "PRE-DLE-AMCHECK";
        break;
     case EXECUTE_ON_PRE_HOST_AMCHECK:
        command = "PRE-HOST-AMCHECK";
        break;
+    case EXECUTE_ON_POST_AMCHECK:
+       command = "POST-AMCHECK";
+       break;
     case EXECUTE_ON_POST_DLE_AMCHECK:
        command = "POST-DLE-AMCHECK";
        break;
     case EXECUTE_ON_POST_HOST_AMCHECK:
        command = "POST-HOST-AMCHECK";
        break;
+    case EXECUTE_ON_PRE_ESTIMATE:
+       command = "PRE-ESTIMATE";
+       break;
     case EXECUTE_ON_PRE_DLE_ESTIMATE:
        command = "PRE-DLE-ESTIMATE";
        break;
     case EXECUTE_ON_PRE_HOST_ESTIMATE:
        command = "PRE-HOST-ESTIMATE";
        break;
+    case EXECUTE_ON_POST_ESTIMATE:
+       command = "POST-ESTIMATE";
+       break;
     case EXECUTE_ON_POST_DLE_ESTIMATE:
        command = "POST-DLE-ESTIMATE";
        break;
     case EXECUTE_ON_POST_HOST_ESTIMATE:
        command = "POST-HOST-ESTIMATE";
        break;
+    case EXECUTE_ON_PRE_BACKUP:
+       command = "PRE-BACKUP";
+       break;
     case EXECUTE_ON_PRE_DLE_BACKUP:
        command = "PRE-DLE-BACKUP";
        break;
     case EXECUTE_ON_PRE_HOST_BACKUP:
        command = "PRE-HOST-BACKUP";
        break;
+    case EXECUTE_ON_POST_BACKUP:
+       command = "POST-BACKUP";
+       break;
     case EXECUTE_ON_POST_DLE_BACKUP:
        command = "POST-DLE-BACKUP";
        break;
@@ -352,7 +393,7 @@ run_server_script(
 
 
 void
-run_server_scripts(
+run_server_dle_scripts(
     execute_on_t  execute_on,
     char         *config,
     disk_t      *dp,
@@ -368,6 +409,84 @@ run_server_scripts(
     }
 }
 
+void
+run_server_host_scripts(
+    execute_on_t  execute_on,
+    char         *config,
+    am_host_t   *hostp)
+{
+    identlist_t pp_scriptlist;
+    disk_t *dp;
+
+    GHashTable* executed = g_hash_table_new_full(g_str_hash, g_str_equal,
+                                                NULL, NULL);
+    for (dp = hostp->disks; dp != NULL; dp = dp->hostnext) {
+       if (dp->todo) {
+           for (pp_scriptlist = dp->pp_scriptlist; pp_scriptlist != NULL;
+                pp_scriptlist = pp_scriptlist->next) {
+               int todo = 1;
+               pp_script_t *pp_script = lookup_pp_script((char *)pp_scriptlist->data);
+               g_assert(pp_script != NULL);
+               if (pp_script_get_single_execution(pp_script)) {
+                   todo = g_hash_table_lookup(executed,
+                                              pp_script_get_plugin(pp_script))
+                          == NULL;
+               }
+               if (todo) {
+                   run_server_script(pp_script, execute_on, config, dp, -1);
+                   if (pp_script_get_single_execution(pp_script)) {
+                       g_hash_table_insert(executed,
+                                           pp_script_get_plugin(pp_script),
+                                           GINT_TO_POINTER(1));
+                   }
+               }
+           }
+       }
+    }
+
+    g_hash_table_destroy(executed);
+}
+
+void
+run_server_global_scripts(
+    execute_on_t  execute_on,
+    char         *config)
+{
+    identlist_t  pp_scriptlist;
+    disk_t      *dp;
+    am_host_t   *host;
+
+    GHashTable* executed = g_hash_table_new_full(g_str_hash, g_str_equal,
+                                                NULL, NULL);
+    for (host = get_hostlist(); host != NULL; host = host->next) {
+       for (dp = host->disks; dp != NULL; dp = dp->hostnext) {
+           if (dp->todo) {
+               for (pp_scriptlist = dp->pp_scriptlist; pp_scriptlist != NULL;
+                    pp_scriptlist = pp_scriptlist->next) {
+                   int todo = 1;
+                   pp_script_t *pp_script =
+                                lookup_pp_script((char *)pp_scriptlist->data);
+                   g_assert(pp_script != NULL);
+                   if (pp_script_get_single_execution(pp_script)) {
+                       todo = g_hash_table_lookup(executed,
+                               pp_script_get_plugin(pp_script)) == NULL;
+                   }
+                   if (todo) {
+                       run_server_script(pp_script, execute_on, config,
+                                         dp, -1);
+                       if (pp_script_get_single_execution(pp_script)) {
+                           g_hash_table_insert(executed,
+                                       pp_script_get_plugin(pp_script),
+                                       GINT_TO_POINTER(1));
+                       }
+                   }
+               }
+           }
+       }
+    }
+    g_hash_table_destroy(executed);
+}
+
 void
 run_amcleanup(
     char *config_name)
@@ -573,10 +692,9 @@ server_can_do_estimate(
     info_t *info,
     int     level)
 {
-    gint64  size;
     int     stats;
 
-    size = internal_server_estimate(dp, info, level, &stats);
+    internal_server_estimate(dp, info, level, &stats);
     return stats;
 }