From 071454b9392b9c2d64004ef8d97e411b0281099f Mon Sep 17 00:00:00 2001 From: Bastian Friedrich Date: Thu, 10 Nov 2011 09:46:37 +0100 Subject: [PATCH] Add %D option to edit_job_code, simplify callbacks on director side 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 --- bacula/src/dird/dird_conf.c | 43 +++++++++++++++++++++++++++++-------- bacula/src/dird/job.c | 10 +-------- bacula/src/dird/protos.h | 2 +- bacula/src/filed/job.c | 18 +++++++++++++++- 4 files changed, 53 insertions(+), 20 deletions(-) diff --git a/bacula/src/dird/dird_conf.c b/bacula/src/dird/dird_conf.c index 6bd1caa0b3..ca99a85c8e 100644 --- a/bacula/src/dird/dird_conf.c +++ b/bacula/src/dird/dird_conf.c @@ -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; } diff --git a/bacula/src/dird/job.c b/bacula/src/dird/job.c index fa6b1860cb..f850489cac 100644 --- a/bacula/src/dird/job.c +++ b/bacula/src/dird/job.c @@ -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 */ diff --git a/bacula/src/dird/protos.h b/bacula/src/dird/protos.h index f3aade05d3..ee8ddad939 100644 --- a/bacula/src/dird/protos.h +++ b/bacula/src/dird/protos.h @@ -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); diff --git a/bacula/src/filed/job.c b/bacula/src/filed/job.c index 417a3931de..995faa17d2 100644 --- a/bacula/src/filed/job.c +++ b/bacula/src/filed/job.c @@ -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; -- 2.39.5