]> git.sur5r.net Git - bacula/bacula/commitdiff
Add %D option to edit_job_code, simplify callbacks on director side
authorBastian Friedrich <bastian.friedrich@collax.com>
Thu, 10 Nov 2011 08:46:37 +0000 (09:46 +0100)
committerKern Sibbald <kern@sibbald.com>
Sat, 20 Apr 2013 12:50:12 +0000 (14:50 +0200)
Unifies the two callbacks "job_code_callback_filesetname" and
"job_code_callback_clones" into a single one ("job_code_callback_director").

Signed-off-by: Eric Bollengier <eric@baculasystems.com>
bacula/src/dird/dird_conf.c
bacula/src/dird/job.c
bacula/src/dird/protos.h
bacula/src/filed/job.c

index 6bd1caa0b33ffe1532467885bad9091297c34e35..ca99a85c8ebd12d19204e66a05e6616ed86ac921 100644 (file)
@@ -1878,7 +1878,7 @@ static void store_short_runscript(LEX *lc, RES_ITEM *item, int index, int pass)
 
    if (pass == 2) {
       RUNSCRIPT *script = new_runscript();
-      script->set_job_code_callback(job_code_callback_filesetname);
+      script->set_job_code_callback(job_code_callback_director);
 
       script->set_command(lc->str);
 
@@ -2025,7 +2025,7 @@ static void store_runscript(LEX *lc, RES_ITEM *item, int index, int pass)
        *  - POOLMEM command string (ex: /bin/true) 
        *  - int command type (ex: SHELL_CMD)
        */
-      res_runscript.set_job_code_callback(job_code_callback_filesetname);
+      res_runscript.set_job_code_callback(job_code_callback_director);
       while ((c=(char*)res_runscript.commands->pop()) != NULL) {
          t = (intptr_t)res_runscript.commands->pop();
          RUNSCRIPT *script = new_runscript();
@@ -2051,14 +2051,39 @@ static void store_runscript(LEX *lc, RES_ITEM *item, int index, int pass)
 }
 
 /* callback function for edit_job_codes */
-extern "C" char *job_code_callback_filesetname(JCR *jcr, const char* param)
+/* See ../lib/util.c, function edit_job_codes, for more remaining codes */
+extern "C" char *job_code_callback_director(JCR *jcr, const char* param)
 {
-   if (param[0] == 'f' && jcr->fileset) {
-      return jcr->fileset->name();
-
-   } else if (param[0] == 'h' && jcr->client) {
-      return jcr->client->address;
-   } 
+   static char yes[] = "yes";
+   static char no[] = "no";
+   switch (param[0]) {
+      case 'f':
+         if (jcr->fileset) {
+            return jcr->fileset->name();
+         }
+         break;
+      case 'h':
+         if (jcr->client) {
+            return jcr->client->address;
+         }
+         break;
+      case 'p':
+         if (jcr->pool) {
+            return jcr->pool->name();
+         }
+         break;
+      case 'w':
+         if (jcr->wstore) {
+            return jcr->wstore->name();
+         }
+         break;
+      case 'x':
+         return jcr->spool_data ? yes : no;
+         break;
+      case 'D':
+         return my_name;
+         break;
+   }
    return NULL;
 }
 
index fa6b1860cbfc663274646587bfa3a432994f211e..f850489cac6dee540a15353475cdefc755332e21 100644 (file)
@@ -1381,14 +1381,6 @@ void free_wstorage(JCR *jcr)
    jcr->wstore = NULL;
 }
 
-char *job_code_callback_clones(JCR *jcr, const char* param) 
-{
-   if (param[0] == 'p') {
-      return jcr->pool->name();
-   }
-   return NULL;
-}
-
 void create_clones(JCR *jcr)
 {
    /*
@@ -1402,7 +1394,7 @@ void create_clones(JCR *jcr)
       UAContext *ua = new_ua_context(jcr);
       ua->batch = true;
       foreach_alist(runcmd, job->run_cmds) {
-         cmd = edit_job_codes(jcr, cmd, runcmd, "", job_code_callback_clones);
+         cmd = edit_job_codes(jcr, cmd, runcmd, "", job_code_callback_director);
          Mmsg(ua->cmd, "run %s cloned=yes", cmd);
          Dmsg1(900, "=============== Clone cmd=%s\n", ua->cmd);
          parse_ua_args(ua);                 /* parse command */
index f3aade05d3713131ec4c90076fa98c7804ea5086..ee8ddad9390feb4925eefe94e482bd4976043c13 100644 (file)
@@ -84,7 +84,7 @@ extern bool despool_attributes_from_file(JCR *jcr, const char *file);
 
 /* dird_conf.c */
 extern const char *level_to_str(int level);
-extern "C" char *job_code_callback_filesetname(JCR *jcr, const char*);
+extern "C" char *job_code_callback_director(JCR *jcr, const char*);
 
 /* expand.c */
 int variable_expansion(JCR *jcr, char *inp, POOLMEM **exp);
index 417a3931de57c7114bd1a41137c190e6412ee84f..995faa17d263e43b31c1b0f65c54ce37ebe1043e 100644 (file)
@@ -550,6 +550,19 @@ static int job_cmd(JCR *jcr)
 #endif
 }
 
+extern "C" char *job_code_callback_filed(JCR *jcr, const char* param)
+{
+   switch (param[0]) {
+      case 'D':
+         if (jcr->director) { 
+            return jcr->director->hdr.name;
+         }
+         break;
+   }
+   return NULL;
+
+}
+
 static int runbefore_cmd(JCR *jcr)
 {
    bool ok;
@@ -569,6 +582,7 @@ static int runbefore_cmd(JCR *jcr)
 
    /* Run the command now */
    script = new_runscript();
+   script->set_job_code_callback(job_code_callback_filed);
    script->set_command(cmd);
    script->when = SCRIPT_Before;
    ok = script->run(jcr, "ClientRunBeforeJob");
@@ -617,6 +631,7 @@ static int runafter_cmd(JCR *jcr)
    unbash_spaces(msg);
 
    cmd = new_runscript();
+   cmd->set_job_code_callback(job_code_callback_filed);
    cmd->set_command(msg);
    cmd->on_success = true;
    cmd->on_failure = false;
@@ -635,6 +650,7 @@ static int runscript_cmd(JCR *jcr)
    int on_success, on_failure, fail_on_error;
 
    RUNSCRIPT *cmd = new_runscript() ;
+   cmd->set_job_code_callback(job_code_callback_filed);
 
    Dmsg1(100, "runscript_cmd: '%s'\n", dir->msg);
    /* Note, we cannot sscanf into bools */
@@ -815,7 +831,7 @@ void add_file_to_fileset(JCR *jcr, const char *fname, bool is_file)
    case '|':
       p++;                            /* skip over | */
       fn = get_pool_memory(PM_FNAME);
-      fn = edit_job_codes(jcr, fn, p, "");
+      fn = edit_job_codes(jcr, fn, p, "", job_code_callback_filed);
       bpipe = open_bpipe(fn, 0, "r");
       if (!bpipe) {
          berrno be;