From 67585d571acd117bd94f8eeb0d579f0e0772137f Mon Sep 17 00:00:00 2001 From: Eric Bollengier Date: Thu, 13 Mar 2008 14:18:15 +0000 Subject: [PATCH] ebl Permit multiple command/console per runscript definition. git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@6600 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/dird/dird_conf.c | 53 +++++++++++++++++++++++++------------ bacula/src/lib/runscript.c | 4 +-- bacula/src/lib/runscript.h | 10 +++---- bacula/technotes-2.3 | 2 ++ 4 files changed, 45 insertions(+), 24 deletions(-) diff --git a/bacula/src/dird/dird_conf.c b/bacula/src/dird/dird_conf.c index f5ff79e367..1c5fd5ab02 100644 --- a/bacula/src/dird/dird_conf.c +++ b/bacula/src/dird/dird_conf.c @@ -1767,14 +1767,19 @@ static void store_runscript_target(LEX *lc, RES_ITEM *item, int index, int pass) } /* - * Store a runscript->command as a string + * Store a runscript->command as a string and runscript->cmd_type as a pointer */ static void store_runscript_cmd(LEX *lc, RES_ITEM *item, int index, int pass) { lex_get_token(lc, T_STRING); if (pass == 2) { - ((RUNSCRIPT*)item->value)->set_command(lc->str, item->code); + Dmsg2(1, "runscript cmd=%s type=%c\n", lc->str, item->code); + POOLMEM *c = get_pool_memory(PM_FNAME); + /* Each runscript command takes 2 entries in commands list */ + pm_strcpy(c, lc->str); + ((RUNSCRIPT*) item->value)->commands->prepend(c); /* command line */ + ((RUNSCRIPT*) item->value)->commands->prepend((void *)item->code); /* command type */ } scan_to_eol(lc); } @@ -1876,7 +1881,8 @@ static RES_ITEM runscript_items[] = { */ static void store_runscript(LEX *lc, RES_ITEM *item, int index, int pass) { - int token, i; + char *c; + int token, i, t; alist **runscripts = (alist **)(item->value) ; Dmsg1(200, "store_runscript: begin store_runscript pass=%i\n", pass); @@ -1889,6 +1895,10 @@ static void store_runscript(LEX *lc, RES_ITEM *item, int index, int pass) scan_err1(lc, _("Expecting open brace. Got %s"), lc->str); } + if (pass == 2) { + res_runscript.commands = New(alist(10, not_owned_by_alist)); + } + while ((token = lex_get_token(lc, T_SKIP_EOL)) != T_EOF) { if (token == T_EOB) { break; @@ -1916,26 +1926,35 @@ static void store_runscript(LEX *lc, RES_ITEM *item, int index, int pass) } if (pass == 2) { - if (res_runscript.command == NULL) { - scan_err2(lc, _("%s item is required in %s resource, but not found.\n"), - "command", "runscript"); - } - /* run on client by default */ if (res_runscript.target == NULL) { res_runscript.set_target("%c"); } - - 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)); + *runscripts = New(alist(10, not_owned_by_alist)); } - - (*runscripts)->append(script); - script->debug(); + /* + * commands list contains 2 values per command + * - POOLMEM command string (ex: /bin/true) + * - int command type (ex: SHELL_CMD) + */ + res_runscript.set_job_code_callback(job_code_callback_filesetname); + while ((c=(char*)res_runscript.commands->pop()) != NULL) { + t = (int) res_runscript.commands->pop(); + res_runscript.command = c; + res_runscript.cmd_type = t; + RUNSCRIPT *script = new_runscript(); + memcpy(script, &res_runscript, sizeof(RUNSCRIPT)); + /* target is taken from res_runscript, each runscript object have + * a copy + */ + script->target = NULL; + script->set_target(res_runscript.target); + + (*runscripts)->append(script); + script->debug(); + } + delete res_runscript.commands; } scan_to_eol(lc); diff --git a/bacula/src/lib/runscript.c b/bacula/src/lib/runscript.c index bac10eb985..39e10a0117 100644 --- a/bacula/src/lib/runscript.c +++ b/bacula/src/lib/runscript.c @@ -190,7 +190,7 @@ bool RUNSCRIPT::is_local() } /* set this->command to cmd */ -void RUNSCRIPT::set_command(const POOLMEM *cmd, int acmd_type) +void RUNSCRIPT::set_command(const char *cmd, int acmd_type) { Dmsg1(500, "runscript: setting command = %s\n", NPRT(cmd)); @@ -207,7 +207,7 @@ void RUNSCRIPT::set_command(const POOLMEM *cmd, int acmd_type) } /* set this->target to client_name */ -void RUNSCRIPT::set_target(const POOLMEM *client_name) +void RUNSCRIPT::set_target(const char *client_name) { Dmsg1(500, "runscript: setting target = %s\n", NPRT(client_name)); diff --git a/bacula/src/lib/runscript.h b/bacula/src/lib/runscript.h index 3659246c7c..5d98260987 100644 --- a/bacula/src/lib/runscript.h +++ b/bacula/src/lib/runscript.h @@ -63,8 +63,8 @@ enum { }; enum { - SHELL_CMD = 1, - CONSOLE_CMD = 2 + SHELL_CMD = '|', + CONSOLE_CMD = '@' }; /* @@ -84,11 +84,11 @@ public: bool old_proto; /* used by old 1.3X protocol */ job_code_callback_t job_code_callback; /* Optional callback function passed to edit_job_code */ - + alist *commands; /* Use during parsing */ 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 set_command(const POOLMEM *cmd, int cmd_type = SHELL_CMD); - void set_target(const POOLMEM *client_name); + void set_command(const char *cmd, int cmd_type = SHELL_CMD); + void set_target(const char *client_name); void reset_default(bool free_string = false); bool is_local(); /* true if running on local host */ void debug(); diff --git a/bacula/technotes-2.3 b/bacula/technotes-2.3 index 8b1916c299..e3e4af05a4 100644 --- a/bacula/technotes-2.3 +++ b/bacula/technotes-2.3 @@ -2,6 +2,8 @@ General: 13Mar08 +ebl Permit multiple command/console per runscript definition. + RunScript { command = /bin/true ; command = /bin/false ... } ebl Add RunsWhen = AfterVSS to runscript. You can execute a command (restart an application) just after the VSS snapshot on windows. kes Don't zap dcr values during release_volume() as they might -- 2.39.5