Hi again,

Am Mittwoch, 9. November 2011, 08:53:46 schrieb Kern Sibbald:
> If you want the Director's name, it really needs a new edit variable that
> will be a bit more complicated.

Au contraire :) It was simple as pie. We both seem not to have noticed the 
"director" variable in the jcr structure already being present (at least in fd 
and sd context). This results in the trivial patch 042 as attached, making 
"%D" available for run scripts in the file daemon. As the sd does not execute 
run scripts or otherwise needs any access to the job codes, the sd does not 
need any patching.

I am re-attaching the afforementioned patch that unifies the two callbacks 
"job_code_callback_filesetname" and "job_code_callback_clones" into a single 
one ("job_code_callback_director"). Both have been called from within the 
director, being able to edit different codes in different contexts; however, 
both can be unified to provide access to identical information without any 
problems (we have been using the attached patch in a similar way for quite a 
while now). Compared to the last version I sent (as said, more than 3 years 
ago), it has been adapted for 5.2.1 and modified to check for availability of 
data structures as has been done in the original present callbacks. This patch 
is 040.

Based on that patch 040, I am attaching the trivial patch 041, which makes 
"%D" available in the director as well for compatibility reasons.

As always: it would be great to see the patches upstream. All patches apply to 
bacula 5.2.1.

Thx again for your support,
   Bastian

-- 
Collax GmbH . Basler Str. 115a . 79115 Freiburg . Germany
p: +49 (0) 89-990 157-28        www.collax.com

Geschäftsführer: Bernd Bönte, Boris Nalbach
AG München HRB 173695. Ust.-IdNr: DE270819312
diff -uNr bacula-5.2.1.ori/src/dird/dird_conf.c bacula-5.2.1/src/dird/dird_conf.c
--- bacula-5.2.1.ori/src/dird/dird_conf.c	2011-11-04 13:49:39.000000000 +0100
+++ bacula-5.2.1/src/dird/dird_conf.c	2011-11-04 13:56:55.000000000 +0100
@@ -1879,7 +1879,7 @@
 
    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);
 
@@ -2026,7 +2026,7 @@
        *  - 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();
@@ -2052,14 +2052,18 @@
 }
 
 /* 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;
+   }
    return NULL;
 }
 
diff -uNr bacula-5.2.1.ori/src/dird/job.c bacula-5.2.1/src/dird/job.c
--- bacula-5.2.1.ori/src/dird/job.c	2011-10-30 13:03:42.000000000 +0100
+++ bacula-5.2.1/src/dird/job.c	2011-11-04 13:54:21.000000000 +0100
@@ -1381,14 +1381,6 @@
    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 @@
       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 */
diff -uNr bacula-5.2.1.ori/src/dird/protos.h bacula-5.2.1/src/dird/protos.h
--- bacula-5.2.1.ori/src/dird/protos.h	2011-10-30 13:03:42.000000000 +0100
+++ bacula-5.2.1/src/dird/protos.h	2011-11-04 13:54:21.000000000 +0100
@@ -84,7 +84,7 @@
 
 /* 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);
diff -uNr bacula-5.2.1.ori/src/dird/dird_conf.c bacula-5.2.1/src/dird/dird_conf.c
--- bacula-5.2.1.ori/src/dird/dird_conf.c	2011-11-09 09:27:19.000000000 +0100
+++ bacula-5.2.1/src/dird/dird_conf.c	2011-11-09 09:55:57.000000000 +0100
@@ -2063,6 +2063,7 @@
       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;
 }
diff -uNr bacula-5.2.1.ori/src/filed/job.c bacula-5.2.1/src/filed/job.c
--- bacula-5.2.1.ori/src/filed/job.c	2011-10-30 13:03:42.000000000 +0100
+++ bacula-5.2.1/src/filed/job.c	2011-11-09 09:45:43.000000000 +0100
@@ -550,6 +550,15 @@
 #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 +578,7 @@
 
    /* 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 +627,7 @@
    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 +646,7 @@
    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 */
------------------------------------------------------------------------------
RSA(R) Conference 2012
Save $700 by Nov 18
Register now
http://p.sf.net/sfu/rsa-sfdev2dev1
_______________________________________________
Bacula-devel mailing list
Bacula-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bacula-devel

Reply via email to