if (pass == 2) {
RUNSCRIPT *script = new_runscript();
+ script->set_job_code_callback(job_code_callback_filesetname);
script->set_command(lc->str);
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));
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;
+ }
+}
/* 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);
/* 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);
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);
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)
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);
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;
+}
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 */
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) */
* 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;
}
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 {
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