From fb818de24fea89fdaff0f68550e9606b4af75050 Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Wed, 19 Dec 2007 14:38:08 +0000 Subject: [PATCH] kes Apply patch from Bastian Friedrich 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 | 12 ++++++++++++ bacula/src/dird/protos.h | 1 + bacula/src/lib/protos.h | 5 ++++- bacula/src/lib/runscript.c | 9 ++++++++- bacula/src/lib/runscript.h | 4 ++++ bacula/src/lib/util.c | 17 ++++++++++++----- bacula/technotes-2.1 | 2 ++ 7 files changed, 43 insertions(+), 7 deletions(-) diff --git a/bacula/src/dird/dird_conf.c b/bacula/src/dird/dird_conf.c index 475df3cdf3..aae20e5d91 100644 --- a/bacula/src/dird/dird_conf.c +++ b/bacula/src/dird/dird_conf.c @@ -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; + } +} diff --git a/bacula/src/dird/protos.h b/bacula/src/dird/protos.h index 30e627448d..482ee7f870 100644 --- a/bacula/src/dird/protos.h +++ b/bacula/src/dird/protos.h @@ -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); diff --git a/bacula/src/lib/protos.h b/bacula/src/lib/protos.h index c1ed9ead16..fbc365629b 100644 --- a/bacula/src/lib/protos.h +++ b/bacula/src/lib/protos.h @@ -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); diff --git a/bacula/src/lib/runscript.c b/bacula/src/lib/runscript.c index c36115c359..0b9db7848d 100644 --- a/bacula/src/lib/runscript.c +++ b/bacula/src/lib/runscript.c @@ -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; +} diff --git a/bacula/src/lib/runscript.h b/bacula/src/lib/runscript.h index 12710f5612..27b678b7cc 100644 --- a/bacula/src/lib/runscript.h +++ b/bacula/src/lib/runscript.h @@ -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) */ diff --git a/bacula/src/lib/util.c b/bacula/src/lib/util.c index f1560a8cc9..54f96f16fd 100644 --- a/bacula/src/lib/util.c +++ b/bacula/src/lib/util.c @@ -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 { diff --git a/bacula/technotes-2.1 b/bacula/technotes-2.1 index c731de8e57..dcb5648644 100644 --- a/bacula/technotes-2.1 +++ b/bacula/technotes-2.1 @@ -6,6 +6,8 @@ kes Apply patch from Michael Stapelberg 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 + 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 . 13Dec07 -- 2.39.5