}
/*
- * 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);
}
*/
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);
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;
}
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);
}
/* 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));
}
/* 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));
};
enum {
- SHELL_CMD = 1,
- CONSOLE_CMD = 2
+ SHELL_CMD = '|',
+ CONSOLE_CMD = '@'
};
/*
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();