]> git.sur5r.net Git - bacula/bacula/commitdiff
kes Apply patch from Bastian Friedrich <bastian.friedrich@collax.com>
authorKern Sibbald <kern@sibbald.com>
Wed, 19 Dec 2007 14:38:08 +0000 (14:38 +0000)
committerKern Sibbald <kern@sibbald.com>
Wed, 19 Dec 2007 14:38:08 +0000 (14:38 +0000)
     that implement %f in RunScripts to pass the FileSet name.

git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/branches/Branch-2.2@6074 91ce42f0-d328-0410-95d8-f526ca767f89

bacula/src/dird/dird_conf.c
bacula/src/dird/protos.h
bacula/src/lib/protos.h
bacula/src/lib/runscript.c
bacula/src/lib/runscript.h
bacula/src/lib/util.c
bacula/technotes-2.1

index 475df3cdf370d4301e8ca43d25412ff263350e2c..aae20e5d917c32d81d186e5abb42b39b4d2699c8 100644 (file)
@@ -1732,6 +1732,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_command(lc->str);
 
@@ -1872,6 +1873,7 @@ static void store_runscript(LEX *lc, RES_ITEM *item, int index, int pass)
 
       RUNSCRIPT *script = new_runscript();
       memcpy(script, &res_runscript, sizeof(RUNSCRIPT));
+      script->set_job_code_callback(job_code_callback_filesetname);
       
       if (*runscripts == NULL) {
         *runscripts = New(alist(10, not_owned_by_alist));
@@ -1884,3 +1886,13 @@ static void store_runscript(LEX *lc, RES_ITEM *item, int index, int pass)
    scan_to_eol(lc);
    set_bit(index, res_all.hdr.item_present);
 }
+
+/* callback function for edit_job_codes */
+char *job_code_callback_filesetname(JCR *jcr, const char* param)
+{
+   if (param[0] == 'f') {
+      return jcr->fileset->name();
+   } else {
+      return NULL;
+   }
+}
index 30e627448d6d562fec11a5bf8e27c10b62765c2c..482ee7f870a5b0d8ffd83da3ed91015cf58cdccd 100644 (file)
@@ -75,6 +75,7 @@ extern void catalog_update(JCR *jcr, BSOCK *bs);
 
 /* dird_conf.c */
 extern const char *level_to_str(int level);
+extern char *job_code_callback_filesetname(JCR *jcr, const char*);
 
 /* expand.c */
 int variable_expansion(JCR *jcr, char *inp, POOLMEM **exp);
index c1ed9ead163e4361ffd3c980ab43afd914d989c5..fbc365629bd2f5214dc2334bdebaed388f205a7b 100644 (file)
@@ -301,6 +301,9 @@ bool             get_tls_enable          (TLS_CONTEXT *ctx);
 
 
 /* util.c */
+
+typedef char *(*job_code_callback_t)(JCR *, const char *);
+
 bool             is_buf_zero             (char *buf, int len);
 void             lcase                   (char *str);
 void             bash_spaces             (char *str);
@@ -317,7 +320,7 @@ const char *     job_type_to_str         (int type);
 const char *     job_status_to_str       (int stat);
 const char *     job_level_to_str        (int level);
 void             make_session_key        (char *key, char *seed, int mode);
-POOLMEM *        edit_job_codes          (JCR *jcr, char *omsg, char *imsg, const char *to);
+POOLMEM *        edit_job_codes          (JCR *jcr, char *omsg, char *imsg, const char *to, job_code_callback_t job_code_callback = NULL);
 void             set_working_directory   (char *wd);
 const char *     last_path_separator     (const char *str);
 
index c36115c3590e84f7106e12dc13c42808370f2a21..0b9db7848d524ca4782eff15a9ad8d304ecad134 100644 (file)
@@ -66,6 +66,7 @@ void RUNSCRIPT::reset_default(bool free_strings)
    fail_on_error = true;
    when = SCRIPT_Never;
    old_proto = false;        /* TODO: drop this with bacula 1.42 */
+   job_code_callback = NULL;
 }
 
 RUNSCRIPT *copy_runscript(RUNSCRIPT *src)
@@ -207,7 +208,7 @@ bool RUNSCRIPT::run(JCR *jcr, const char *name)
    BPIPE *bpipe;
    char line[MAXSTRING];
 
-   ecmd = edit_job_codes(jcr, ecmd, this->command, "");
+   ecmd = edit_job_codes(jcr, ecmd, this->command, "", this->job_code_callback);
    Dmsg1(100, "runscript: running '%s'...\n", ecmd);
    Jmsg(jcr, M_INFO, 0, _("%s: run command \"%s\"\n"), name, ecmd);
 
@@ -266,3 +267,9 @@ void RUNSCRIPT::debug()
    Dmsg1(200,  _("  --> FailJobOnError=%u\n"),  fail_on_error);
    Dmsg1(200,  _("  --> RunWhen=%u\n"),  when);
 }
+
+void RUNSCRIPT::set_job_code_callback(job_code_callback_t arg_job_code_callback) 
+
+{
+   this->job_code_callback = arg_job_code_callback;
+}
index 12710f5612eb8761b16d0c453fcfb001f997d752..27b678b7cc3045439472e088af8904d25d57ce2d 100644 (file)
@@ -73,6 +73,8 @@ public:
    bool fail_on_error;         /* abort job on error (Before) */
    /* TODO : drop this with bacula 1.42 */
    bool old_proto;              /* used by old 1.3X protocol */
+   job_code_callback_t job_code_callback;
+                               /* Optional callback function passed to edit_job_code */
 
    bool run(JCR *job, const char *name=""); /* name must contain "Before" or "After" keyword */
    bool can_run_at_level(int JobLevel) { return true;};        /* TODO */
@@ -81,6 +83,8 @@ public:
    void reset_default(bool free_string = false);
    bool is_local();             /* true if running on local host */
    void debug();
+
+   void set_job_code_callback(job_code_callback_t job_code_callback);
 };
 
 /* create new RUNSCRIPT (set all value to 0) */
index f1560a8cc9a216172f962b022c7f2ea2c46bcb5a..54f96f16fd0e635b6fdc35a1f02b1d25569bc302 100644 (file)
@@ -574,7 +574,7 @@ void make_session_key(char *key, char *seed, int mode)
  *  to = recepients list
  *
  */
-POOLMEM *edit_job_codes(JCR *jcr, char *omsg, char *imsg, const char *to)
+POOLMEM *edit_job_codes(JCR *jcr, char *omsg, char *imsg, const char *to, job_code_callback_t callback)
 {
    char *p, *q;
    const char *str;
@@ -672,10 +672,17 @@ POOLMEM *edit_job_codes(JCR *jcr, char *omsg, char *imsg, const char *to)
             }
             break;
          default:
-            add[0] = '%';
-            add[1] = *p;
-            add[2] = 0;
-            str = add;
+            str = NULL;
+            if (callback != NULL) {
+                str = callback(jcr, p);
+            }
+
+            if (!str) {
+                add[0] = '%';
+                add[1] = *p;
+                add[2] = 0;
+                str = add;
+            }
             break;
          }
       } else {
index c731de8e57ddfe7fb198c4baef1f2594c381455d..dcb5648644a799cd73b77c488c4a1c2eaf656503 100644 (file)
@@ -6,6 +6,8 @@ kes  Apply patch from  Michael Stapelberg <michael@stapelberg.de>
      that implements double quoting include names in conf files,
      and also allows piping input by having the first character 
      be a vertical bar (|). 
+kes  Apply patch from Bastian Friedrich <bastian.friedrich@collax.com>
+     that implement %f in RunScripts to pass the FileSet name.
 kes  Skip leading | when lex input comes from a pipe as suggested
      by Michael Stapelberg <michael@stapelberg.de>.
 13Dec07