===================================================================
--- src/dird/fd_cmds.c (révision 6169)
+++ src/dird/fd_cmds.c (copie de travail)
-@@ -537,29 +537,35 @@
+@@ -527,7 +527,8 @@
+ RUNSCRIPT *cmd;
+ bool launch_before_cmd = false;
+ POOLMEM *ehost = get_pool_memory(PM_FNAME);
+- int result;
++ int result, cmd_type;
++ char *c, *command;
+
+ Dmsg0(120, "bdird: sending runscripts to fd\n");
+
+@@ -537,29 +538,33 @@
Dmsg2(200, "bdird: runscript %s -> %s\n", cmd->target, ehost);
if (strcmp(ehost, jcr->client->name()) == 0) {
- pm_strcpy(msg, cmd->command);
- bash_spaces(msg);
-+ char *c;
-+ char *command, cmd_type;
+ foreach_alist(c, cmd->commands) {
+ cmd->get_command(c, &cmd_type, &command);
+ if (cmd_type == SHELL_CMD) {
}
/* TODO : we have to play with other client */
/*
-@@ -567,7 +573,7 @@
+@@ -567,7 +572,7 @@
send command to an other client
}
*/
scan_err2(lc, _("%s item is required in %s resource, but not found.\n"),
"command", "runscript");
}
-@@ -1883,10 +1886,11 @@
- res_runscript.set_target("%c");
- }
-
-- RUNSCRIPT *script = new_runscript();
-- memcpy(script, &res_runscript, sizeof(RUNSCRIPT));
-+ RUNSCRIPT *script = copy_runscript(&res_runscript);
-+ res_runscript.reset_default(true);
-+
+@@ -1886,7 +1889,7 @@
+ RUNSCRIPT *script = new_runscript();
+ memcpy(script, &res_runscript, sizeof(RUNSCRIPT));
script->set_job_code_callback(job_code_callback_filesetname);
-
+
char level; /* Base|Full|Incr...|All (NYI) */
bool on_success; /* execute command on job success (After) */
bool on_failure; /* execute command on job failure (After) */
-@@ -85,8 +84,10 @@
- /* Optional callback function passed to edit_job_code */
+@@ -86,19 +85,22 @@
bool run(JCR *job, const char *name=""); /* name must contain "Before" or "After" keyword */
-+ bool run_command(const char *cmd, JCR *job, const char *name="");
bool can_run_at_level(int JobLevel) { return true;}; /* TODO */
- void set_command(const POOLMEM *cmd, int cmd_type = SHELL_CMD);
+ void add_command(const POOLMEM *cmd, char cmd_type = SHELL_CMD);
-+ void get_command(const char *cmd, char *cmd_type, char **cmd);
++ void get_command(const char *cmd, int *cmd_type, char **cmd);
void set_target(const POOLMEM *client_name);
void reset_default(bool free_string = false);
- bool is_local(); /* true if running on local host */
+- bool is_local(); /* true if running on local host */
++ bool is_local(const char *cmd); /* true if running on local host */
+ void debug();
++ void set_job_code_callback(job_code_callback_t job_code_callback);
+
+- void set_job_code_callback(job_code_callback_t job_code_callback);
++private:
++ bool run_command(const char *cmd, JCR *job, const char *name="");
+ };
+
+ /* create new RUNSCRIPT (set all value to 0) */
+ RUNSCRIPT *new_runscript();
+
+-/* create new RUNSCRIPT from an other */
++/* create new RUNSCRIPT from an other (deep copy) */
+ RUNSCRIPT *copy_runscript(RUNSCRIPT *src);
+
+ /* launch each script from runscripts*/
Index: src/lib/runscript.c
===================================================================
--- src/lib/runscript.c (révision 6169)
+++ src/lib/runscript.c (copie de travail)
-@@ -59,15 +59,20 @@
+@@ -59,15 +59,18 @@
void RUNSCRIPT::reset_default(bool free_strings)
{
+ foreach_alist(c, commands) {
+ free_pool_memory(c);
+ }
++ delete commands;
}
if (free_strings && target) {
free_pool_memory(target);
-
target = NULL;
- command = NULL;
-+ if (commands) {
-+ delete commands;
-+ commands = NULL;
-+ }
++ commands = NULL;
on_success = true;
on_failure = false;
fail_on_error = true;
-@@ -76,17 +81,23 @@
- job_code_callback = NULL;
- }
-
--RUNSCRIPT *copy_runscript(RUNSCRIPT *src)
-+Runscript *copy_runscript(RUNSCRIPT *src)
- {
- Dmsg0(500, "runscript: creating new RUNSCRIPT object from other\n");
-
+@@ -83,10 +86,16 @@
RUNSCRIPT *dst = (RUNSCRIPT *)malloc(sizeof(RUNSCRIPT));
memcpy(dst, src, sizeof(RUNSCRIPT));
dst->set_target(src->target);
return dst;
-@@ -95,9 +106,12 @@
+@@ -95,9 +104,12 @@
void free_runscript(RUNSCRIPT *script)
{
Dmsg0(500, "runscript: freeing RUNSCRIPT object\n");
}
if (script->target) {
free_pool_memory(script->target);
-@@ -108,60 +122,15 @@
+@@ -108,66 +120,25 @@
int run_scripts(JCR *jcr, alist *runscripts, const char *label)
{
Dmsg2(200, "runscript: running all RUNSCRIPT object (%s) JobStatus=%c\n", label, jcr->JobStatus);
}
return 1;
}
-@@ -176,7 +145,7 @@
+
+-bool RUNSCRIPT::is_local()
++bool RUNSCRIPT::is_local(const char *c)
+ {
++ if (c[0] == CONSOLE_CMD) {
++ return true;
++ }
++
+ if (!target || (strcmp(target, "") == 0)) {
+ return true;
+ } else {
+@@ -175,23 +146,31 @@
+ }
}
- /* set this->command to cmd */
+-/* set this->command to cmd */
-void RUNSCRIPT::set_command(const POOLMEM *cmd, int acmd_type)
++/* set add cmd to this->commands alist */
+void RUNSCRIPT::add_command(const POOLMEM *cmd, char acmd_type)
{
- Dmsg1(500, "runscript: setting command = %s\n", NPRT(cmd));
+- Dmsg1(500, "runscript: setting command = %s\n", NPRT(cmd));
++ Dmsg2(500, "runscript: setting command = %s type=%i\n", NPRT(cmd), acmd_type);
-@@ -184,14 +153,21 @@
+ if (!cmd) {
return;
}
+ commands->append(c);
}
-+void RUNSCRIPT::get_command(const char* command, char *acmd_type, char **cmd)
++/* command = ( SHELL_CMD | CONSOLE_CMD ) command */
++void RUNSCRIPT::get_command(const char* command, int *acmd_type, char **cmd)
+{
-+ *acmd_type = command[0];
++ *acmd_type = (int) command[0];
+ *cmd = (char *)command + 1;
+}
+
/* set this->target to client_name */
void RUNSCRIPT::set_target(const POOLMEM *client_name)
{
-@@ -210,14 +186,71 @@
+@@ -210,14 +189,70 @@
bool RUNSCRIPT::run(JCR *jcr, const char *name)
{
+ }
+ }
+
-+ if (!this->is_local()) {
++ if (!this->is_local(c)) {
+ runit = false;
+ }
+
+ return 1;
+}
+
++/* run a command from the list */
+bool RUNSCRIPT::run_command(const char *command, JCR *jcr, const char *name)
+{
POOLMEM *ecmd = get_pool_memory(PM_FNAME);
- int status;
+- int status;
++ int status, cmd_type;
BPIPE *bpipe;
- char line[MAXSTRING];
-+ char cmd_type;
-+ char *cmd;
+- char line[MAXSTRING];
++ char line[MAXSTRING], *cmd;
- 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 %s \"%s\"\n"),
cmd_type==SHELL_CMD?"shell command":"console command", name, ecmd);
-@@ -278,9 +311,12 @@
+@@ -278,9 +313,12 @@
void RUNSCRIPT::debug()
{