1 Index: patches/testing/runscript_with_multiple_command.patch
2 ===================================================================
3 --- patches/testing/runscript_with_multiple_command.patch (révision 6171)
4 +++ patches/testing/runscript_with_multiple_command.patch (copie de travail)
6 -Index: patches/testing/runscript_with_multiple_command.patch
7 -===================================================================
8 ---- patches/testing/runscript_with_multiple_command.patch (révision 6170)
9 -+++ patches/testing/runscript_with_multiple_command.patch (copie de travail)
11 --Index: src/dird/fd_cmds.c
12 --===================================================================
13 ----- src/dird/fd_cmds.c (révision 6169)
14 --+++ src/dird/fd_cmds.c (copie de travail)
15 --@@ -537,29 +537,35 @@
16 -- Dmsg2(200, "bdird: runscript %s -> %s\n", cmd->target, ehost);
18 -- if (strcmp(ehost, jcr->client->name()) == 0) {
19 --- pm_strcpy(msg, cmd->command);
22 --+ char *command, cmd_type;
23 --+ foreach_alist(c, cmd->commands) {
24 --+ cmd->get_command(c, &cmd_type, &command);
25 --+ if (cmd_type == SHELL_CMD) {
26 --+ pm_strcpy(msg, command);
29 --- Dmsg1(120, "bdird: sending runscripts to fd '%s'\n", cmd->command);
30 --+ Dmsg1(120, "bdird: sending runscripts to fd '%s'\n", command);
32 --- /* TODO: remove this with bacula 1.42 */
33 --- if (cmd->old_proto) {
34 --- result = send_runscript_with_old_proto(jcr, cmd->when, msg);
35 --+ /* TODO: remove this with bacula 1.42 */
36 --+ if (cmd->old_proto) {
37 --+ result = send_runscript_with_old_proto(jcr, cmd->when, msg);
40 --+ fd->fsend(runscript, cmd->on_success,
42 --+ cmd->fail_on_error,
47 --- fd->fsend(runscript, cmd->on_success,
49 --- cmd->fail_on_error,
53 --- result = response(jcr, fd, OKRunScript, "RunScript", DISPLAY_ERROR);
54 --- launch_before_cmd = true;
55 --+ result = response(jcr, fd, OKRunScript, "RunScript", DISPLAY_ERROR);
56 --+ launch_before_cmd = true;
68 -- /* TODO : we have to play with other client */
71 -- send command to an other client
78 -- /* Tell the FD to execute the ClientRunBeforeJob */
79 --Index: src/dird/dird_conf.c
80 --===================================================================
81 ----- src/dird/dird_conf.c (révision 6169)
82 --+++ src/dird/dird_conf.c (copie de travail)
83 --@@ -651,16 +651,19 @@
86 -- if (res->res_job.RunScripts) {
87 --- RUNSCRIPT *script;
88 --- foreach_alist(script, res->res_job.RunScripts) {
89 --- sendit(sock, _(" --> RunScript\n"));
90 --- sendit(sock, _(" --> Command=%s\n"), NPRT(script->command));
91 --- sendit(sock, _(" --> Target=%s\n"), NPRT(script->target));
92 --- sendit(sock, _(" --> RunOnSuccess=%u\n"), script->on_success);
93 --- sendit(sock, _(" --> RunOnFailure=%u\n"), script->on_failure);
94 --- sendit(sock, _(" --> FailJobOnError=%u\n"), script->fail_on_error);
95 --- sendit(sock, _(" --> RunWhen=%u\n"), script->when);
98 --+ RUNSCRIPT *script;
99 --+ foreach_alist(script, res->res_job.RunScripts) {
100 --+ sendit(sock, _(" --> RunScript\n"));
101 --+ foreach_alist(c, script->commands) {
102 --+ sendit(sock, _(" --> Command=%s\n"), NPRT(c));
104 --+ sendit(sock, _(" --> Target=%s\n"), NPRT(script->target));
105 --+ sendit(sock, _(" --> RunOnSuccess=%u\n"), script->on_success);
106 --+ sendit(sock, _(" --> RunOnFailure=%u\n"), script->on_failure);
107 --+ sendit(sock, _(" --> FailJobOnError=%u\n"), script->fail_on_error);
108 --+ sendit(sock, _(" --> RunWhen=%u\n"), script->when);
111 -- if (res->res_job.pool) {
112 -- sendit(sock, _(" --> "));
113 --@@ -1724,14 +1727,14 @@
117 --- * Store a runscript->command as a string
118 --+ * Store a runscript->commands as a alist(char + string)
120 -- static void store_runscript_cmd(LEX *lc, RES_ITEM *item, int index, int pass)
122 -- lex_get_token(lc, T_STRING);
125 --- ((RUNSCRIPT*)item->value)->set_command(lc->str, item->code);
126 --+ ((RUNSCRIPT*)item->value)->add_command(lc->str, item->code);
130 --@@ -1745,7 +1748,7 @@
131 -- RUNSCRIPT *script = new_runscript();
132 -- script->set_job_code_callback(job_code_callback_filesetname);
134 --- script->set_command(lc->str);
135 --+ script->add_command(lc->str);
137 -- /* TODO: remove all script->old_proto with bacula 1.42 */
139 --@@ -1873,7 +1876,7 @@
143 --- if (res_runscript.command == NULL) {
144 --+ if (res_runscript.commands == NULL) {
145 -- scan_err2(lc, _("%s item is required in %s resource, but not found.\n"),
146 -- "command", "runscript");
148 --@@ -1883,10 +1886,11 @@
149 -- res_runscript.set_target("%c");
152 --- RUNSCRIPT *script = new_runscript();
153 --- memcpy(script, &res_runscript, sizeof(RUNSCRIPT));
154 --+ RUNSCRIPT *script = copy_runscript(&res_runscript);
155 --+ res_runscript.reset_default(true);
157 -- script->set_job_code_callback(job_code_callback_filesetname);
160 -- if (*runscripts == NULL) {
161 -- *runscripts = New(alist(10, not_owned_by_alist));
163 --Index: src/filed/job.c
164 --===================================================================
165 ----- src/filed/job.c (révision 6169)
166 --+++ src/filed/job.c (copie de travail)
167 --@@ -481,7 +481,7 @@
169 -- /* Run the command now */
170 -- script = new_runscript();
171 --- script->set_command(cmd);
172 --+ script->add_command(cmd);
173 -- script->when = SCRIPT_Before;
174 -- ok = script->run(jcr, "ClientRunBeforeJob");
175 -- free_runscript(script);
176 --@@ -529,7 +529,7 @@
177 -- unbash_spaces(msg);
179 -- cmd = new_runscript();
180 --- cmd->set_command(msg);
181 --+ cmd->add_command(msg);
182 -- cmd->on_success = true;
183 -- cmd->on_failure = false;
184 -- cmd->when = SCRIPT_After;
185 --@@ -567,7 +567,7 @@
186 -- cmd->fail_on_error = fail_on_error;
187 -- unbash_spaces(msg);
189 --- cmd->set_command(msg);
190 --+ cmd->add_command(msg);
192 -- jcr->RunScripts->append(cmd);
194 --Index: src/lib/runscript.h
195 --===================================================================
196 ----- src/lib/runscript.h (révision 6169)
197 --+++ src/lib/runscript.h (copie de travail)
205 --+ CONSOLE_CMD = '@'
213 --- POOLMEM *command; /* command string */
214 --+ alist *commands; /* list of command/console string */
215 -- POOLMEM *target; /* host target */
216 -- int when; /* SCRIPT_Before|Script_After BEFORE/AFTER JOB*/
217 --- int cmd_type; /* Command type -- Shell, Console */
218 -- char level; /* Base|Full|Incr...|All (NYI) */
219 -- bool on_success; /* execute command on job success (After) */
220 -- bool on_failure; /* execute command on job failure (After) */
222 -- /* Optional callback function passed to edit_job_code */
224 -- bool run(JCR *job, const char *name=""); /* name must contain "Before" or "After" keyword */
225 --+ bool run_command(const char *cmd, JCR *job, const char *name="");
226 -- bool can_run_at_level(int JobLevel) { return true;}; /* TODO */
227 --- void set_command(const POOLMEM *cmd, int cmd_type = SHELL_CMD);
228 --+ void add_command(const POOLMEM *cmd, char cmd_type = SHELL_CMD);
229 --+ void get_command(const char *cmd, char *cmd_type, char **cmd);
230 -- void set_target(const POOLMEM *client_name);
231 -- void reset_default(bool free_string = false);
232 -- bool is_local(); /* true if running on local host */
233 --Index: src/lib/runscript.c
234 --===================================================================
235 ----- src/lib/runscript.c (révision 6169)
236 --+++ src/lib/runscript.c (copie de travail)
237 --@@ -59,15 +59,20 @@
239 -- void RUNSCRIPT::reset_default(bool free_strings)
241 --- if (free_strings && command) {
242 --- free_pool_memory(command);
244 --+ if (free_strings && commands) {
245 --+ foreach_alist(c, commands) {
246 --+ free_pool_memory(c);
249 -- if (free_strings && target) {
250 -- free_pool_memory(target);
259 -- on_success = true;
260 -- on_failure = false;
261 -- fail_on_error = true;
262 --@@ -76,17 +81,23 @@
263 -- job_code_callback = NULL;
266 ---RUNSCRIPT *copy_runscript(RUNSCRIPT *src)
267 --+Runscript *copy_runscript(RUNSCRIPT *src)
269 -- Dmsg0(500, "runscript: creating new RUNSCRIPT object from other\n");
271 -- RUNSCRIPT *dst = (RUNSCRIPT *)malloc(sizeof(RUNSCRIPT));
272 -- memcpy(dst, src, sizeof(RUNSCRIPT));
274 --- dst->command = NULL;
275 --+ dst->commands = New(alist(5, not_owned_by_alist));
278 --+ foreach_alist(c, src->commands) {
279 --+ m = get_pool_memory(PM_FNAME);
281 --+ dst->commands->append(m);
284 -- dst->target = NULL;
286 --- dst->set_command(src->command, src->cmd_type);
287 -- dst->set_target(src->target);
290 --@@ -95,9 +106,12 @@
291 -- void free_runscript(RUNSCRIPT *script)
293 -- Dmsg0(500, "runscript: freeing RUNSCRIPT object\n");
295 --- if (script->command) {
296 --- free_pool_memory(script->command);
298 --+ if (script->commands) {
299 --+ foreach_alist(c, script->commands) {
300 --+ free_pool_memory(c);
302 --+ delete script->commands;
304 -- if (script->target) {
305 -- free_pool_memory(script->target);
306 --@@ -108,60 +122,15 @@
307 -- int run_scripts(JCR *jcr, alist *runscripts, const char *label)
309 -- Dmsg2(200, "runscript: running all RUNSCRIPT object (%s) JobStatus=%c\n", label, jcr->JobStatus);
311 --- RUNSCRIPT *script;
316 --- if (strstr(label, NT_("Before"))) {
317 --- when = SCRIPT_Before;
319 --- when = SCRIPT_After;
322 -- if (runscripts == NULL) {
323 -- Dmsg0(100, "runscript: WARNING RUNSCRIPTS list is NULL\n");
328 --+ RUNSCRIPT *script;
329 -- foreach_alist(script, runscripts) {
330 --- Dmsg2(200, "runscript: try to run %s:%s\n", NPRT(script->target), NPRT(script->command));
333 --- if ((script->when & SCRIPT_Before) && (when & SCRIPT_Before)) {
334 --- if ((script->on_success
335 --- && (jcr->JobStatus == JS_Running || jcr->JobStatus == JS_Created))
336 --- || (script->on_failure && job_canceled(jcr))
339 --- Dmsg4(200, "runscript: Run it because SCRIPT_Before (%s,%i,%i,%c)\n",
340 --- script->command, script->on_success, script->on_failure,
341 --- jcr->JobStatus );
346 --- if ((script->when & SCRIPT_After) && (when & SCRIPT_After)) {
347 --- if ((script->on_success && (jcr->JobStatus == JS_Terminated))
348 --- || (script->on_failure && job_canceled(jcr))
351 --- Dmsg4(200, "runscript: Run it because SCRIPT_After (%s,%i,%i,%c)\n",
352 --- script->command, script->on_success, script->on_failure,
353 --- jcr->JobStatus );
358 --- if (!script->is_local()) {
362 --- /* we execute it */
364 --- script->run(jcr, label);
366 --+ script->run(jcr, label);
370 --@@ -176,7 +145,7 @@
373 -- /* set this->command to cmd */
374 ---void RUNSCRIPT::set_command(const POOLMEM *cmd, int acmd_type)
375 --+void RUNSCRIPT::add_command(const POOLMEM *cmd, char acmd_type)
377 -- Dmsg1(500, "runscript: setting command = %s\n", NPRT(cmd));
379 --@@ -184,14 +153,21 @@
384 --- command = get_pool_memory(PM_FNAME);
386 --+ commands = New(alist(5, not_owned_by_alist));
389 --- pm_strcpy(command, cmd);
390 --- cmd_type = acmd_type;
391 --+ POOLMEM *c = get_pool_memory(PM_FNAME);
392 --+ Mmsg(c, "%c%s", acmd_type, cmd);
393 --+ commands->append(c);
396 --+void RUNSCRIPT::get_command(const char* command, char *acmd_type, char **cmd)
398 --+ *acmd_type = command[0];
399 --+ *cmd = (char *)command + 1;
402 -- /* set this->target to client_name */
403 -- void RUNSCRIPT::set_target(const POOLMEM *client_name)
405 --@@ -210,14 +186,71 @@
407 -- bool RUNSCRIPT::run(JCR *jcr, const char *name)
409 --- Dmsg1(100, "runscript: running a RUNSCRIPT object type=%d\n", cmd_type);
415 --+ if (strstr(name, NT_("Before"))) {
416 --+ when = SCRIPT_Before;
418 --+ when = SCRIPT_After;
421 --+ foreach_alist(c, this->commands) {
422 --+ Dmsg2(200, "runscript: try to run %s:%s\n", NPRT(this->target), NPRT(c));
425 --+ if ((this->when & SCRIPT_Before) && (when & SCRIPT_Before)) {
426 --+ if ((this->on_success
427 --+ && (jcr->JobStatus == JS_Running || jcr->JobStatus == JS_Created))
428 --+ || (this->on_failure && job_canceled(jcr))
431 --+ Dmsg4(200, "runscript: Run it because SCRIPT_Before (%s,%i,%i,%c)\n",
432 --+ c, this->on_success, this->on_failure,
433 --+ jcr->JobStatus );
438 --+ if ((this->when & SCRIPT_After) && (when & SCRIPT_After)) {
439 --+ if ((this->on_success && (jcr->JobStatus == JS_Terminated))
440 --+ || (this->on_failure && job_canceled(jcr))
443 --+ Dmsg4(200, "runscript: Run it because SCRIPT_After (%s,%i,%i,%c)\n",
444 --+ c, this->on_success, this->on_failure,
445 --+ jcr->JobStatus );
450 --+ if (!this->is_local()) {
454 --+ /* we execute it */
456 --+ this->run_command(c, jcr, name);
462 --+bool RUNSCRIPT::run_command(const char *command, JCR *jcr, const char *name)
464 -- POOLMEM *ecmd = get_pool_memory(PM_FNAME);
467 -- char line[MAXSTRING];
471 --- ecmd = edit_job_codes(jcr, ecmd, this->command, "", this->job_code_callback);
472 --- Dmsg1(100, "runscript: running '%s'...\n", ecmd);
473 --+ this->get_command(command, &cmd_type, &cmd);
474 --+ ecmd = edit_job_codes(jcr, ecmd, cmd, "", this->job_code_callback);
476 --+ Dmsg2(100, "runscript: running '%s' object type=%c...\n", ecmd, cmd_type);
477 -- Jmsg(jcr, M_INFO, 0, _("%s: run %s \"%s\"\n"),
478 -- cmd_type==SHELL_CMD?"shell command":"console command", name, ecmd);
480 --@@ -278,9 +311,12 @@
482 -- void RUNSCRIPT::debug()
485 -- Dmsg0(200, "runscript: debug\n");
486 -- Dmsg0(200, _(" --> RunScript\n"));
487 --- Dmsg1(200, _(" --> Command=%s\n"), NPRT(command));
488 --+ foreach_alist(c, commands) {
489 --+ Dmsg1(200, _(" --> Command=%s\n"), NPRT(c));
491 -- Dmsg1(200, _(" --> Target=%s\n"), NPRT(target));
492 -- Dmsg1(200, _(" --> RunOnSuccess=%u\n"), on_success);
493 -- Dmsg1(200, _(" --> RunOnFailure=%u\n"), on_failure);
494 -Index: src/dird/fd_cmds.c
495 -===================================================================
496 ---- src/dird/fd_cmds.c (révision 6169)
497 -+++ src/dird/fd_cmds.c (copie de travail)
500 - bool launch_before_cmd = false;
501 - POOLMEM *ehost = get_pool_memory(PM_FNAME);
503 -+ int result, cmd_type;
504 -+ char *c, *command;
506 - Dmsg0(120, "bdird: sending runscripts to fd\n");
508 -@@ -537,29 +538,33 @@
509 - Dmsg2(200, "bdird: runscript %s -> %s\n", cmd->target, ehost);
511 - if (strcmp(ehost, jcr->client->name()) == 0) {
512 -- pm_strcpy(msg, cmd->command);
514 -+ foreach_alist(c, cmd->commands) {
515 -+ cmd->get_command(c, &cmd_type, &command);
516 -+ if (cmd_type == SHELL_CMD) {
517 -+ pm_strcpy(msg, command);
520 -- Dmsg1(120, "bdird: sending runscripts to fd '%s'\n", cmd->command);
521 -+ Dmsg1(120, "bdird: sending runscripts to fd '%s'\n", command);
523 -- /* TODO: remove this with bacula 1.42 */
524 -- if (cmd->old_proto) {
525 -- result = send_runscript_with_old_proto(jcr, cmd->when, msg);
526 -+ /* TODO: remove this with bacula 1.42 */
527 -+ if (cmd->old_proto) {
528 -+ result = send_runscript_with_old_proto(jcr, cmd->when, msg);
531 -+ fd->fsend(runscript, cmd->on_success,
533 -+ cmd->fail_on_error,
538 -- fd->fsend(runscript, cmd->on_success,
540 -- cmd->fail_on_error,
544 -- result = response(jcr, fd, OKRunScript, "RunScript", DISPLAY_ERROR);
545 -- launch_before_cmd = true;
546 -+ result = response(jcr, fd, OKRunScript, "RunScript", DISPLAY_ERROR);
547 -+ launch_before_cmd = true;
559 - /* TODO : we have to play with other client */
562 - send command to an other client
569 - /* Tell the FD to execute the ClientRunBeforeJob */
570 -Index: src/dird/dird_conf.c
571 -===================================================================
572 ---- src/dird/dird_conf.c (révision 6169)
573 -+++ src/dird/dird_conf.c (copie de travail)
574 -@@ -651,16 +651,19 @@
577 - if (res->res_job.RunScripts) {
578 -- RUNSCRIPT *script;
579 -- foreach_alist(script, res->res_job.RunScripts) {
580 -- sendit(sock, _(" --> RunScript\n"));
581 -- sendit(sock, _(" --> Command=%s\n"), NPRT(script->command));
582 -- sendit(sock, _(" --> Target=%s\n"), NPRT(script->target));
583 -- sendit(sock, _(" --> RunOnSuccess=%u\n"), script->on_success);
584 -- sendit(sock, _(" --> RunOnFailure=%u\n"), script->on_failure);
585 -- sendit(sock, _(" --> FailJobOnError=%u\n"), script->fail_on_error);
586 -- sendit(sock, _(" --> RunWhen=%u\n"), script->when);
589 -+ RUNSCRIPT *script;
590 -+ foreach_alist(script, res->res_job.RunScripts) {
591 -+ sendit(sock, _(" --> RunScript\n"));
592 -+ foreach_alist(c, script->commands) {
593 -+ sendit(sock, _(" --> Command=%s\n"), NPRT(c));
595 -+ sendit(sock, _(" --> Target=%s\n"), NPRT(script->target));
596 -+ sendit(sock, _(" --> RunOnSuccess=%u\n"), script->on_success);
597 -+ sendit(sock, _(" --> RunOnFailure=%u\n"), script->on_failure);
598 -+ sendit(sock, _(" --> FailJobOnError=%u\n"), script->fail_on_error);
599 -+ sendit(sock, _(" --> RunWhen=%u\n"), script->when);
602 - if (res->res_job.pool) {
603 - sendit(sock, _(" --> "));
604 -@@ -1724,14 +1727,14 @@
608 -- * Store a runscript->command as a string
609 -+ * Store a runscript->commands as a alist(char + string)
611 - static void store_runscript_cmd(LEX *lc, RES_ITEM *item, int index, int pass)
613 - lex_get_token(lc, T_STRING);
616 -- ((RUNSCRIPT*)item->value)->set_command(lc->str, item->code);
617 -+ ((RUNSCRIPT*)item->value)->add_command(lc->str, item->code);
621 -@@ -1745,7 +1748,7 @@
622 - RUNSCRIPT *script = new_runscript();
623 - script->set_job_code_callback(job_code_callback_filesetname);
625 -- script->set_command(lc->str);
626 -+ script->add_command(lc->str);
628 - /* TODO: remove all script->old_proto with bacula 1.42 */
630 -@@ -1873,7 +1876,7 @@
634 -- if (res_runscript.command == NULL) {
635 -+ if (res_runscript.commands == NULL) {
636 - scan_err2(lc, _("%s item is required in %s resource, but not found.\n"),
637 - "command", "runscript");
639 -@@ -1886,7 +1889,7 @@
640 - RUNSCRIPT *script = new_runscript();
641 - memcpy(script, &res_runscript, sizeof(RUNSCRIPT));
642 - script->set_job_code_callback(job_code_callback_filesetname);
645 - if (*runscripts == NULL) {
646 - *runscripts = New(alist(10, not_owned_by_alist));
648 -Index: src/filed/job.c
649 -===================================================================
650 ---- src/filed/job.c (révision 6169)
651 -+++ src/filed/job.c (copie de travail)
654 - /* Run the command now */
655 - script = new_runscript();
656 -- script->set_command(cmd);
657 -+ script->add_command(cmd);
658 - script->when = SCRIPT_Before;
659 - ok = script->run(jcr, "ClientRunBeforeJob");
660 - free_runscript(script);
662 - unbash_spaces(msg);
664 - cmd = new_runscript();
665 -- cmd->set_command(msg);
666 -+ cmd->add_command(msg);
667 - cmd->on_success = true;
668 - cmd->on_failure = false;
669 - cmd->when = SCRIPT_After;
671 - cmd->fail_on_error = fail_on_error;
672 - unbash_spaces(msg);
674 -- cmd->set_command(msg);
675 -+ cmd->add_command(msg);
677 - jcr->RunScripts->append(cmd);
679 -Index: src/lib/runscript.h
680 -===================================================================
681 ---- src/lib/runscript.h (révision 6169)
682 -+++ src/lib/runscript.h (copie de travail)
698 -- POOLMEM *command; /* command string */
699 -+ alist *commands; /* list of command/console string */
700 - POOLMEM *target; /* host target */
701 - int when; /* SCRIPT_Before|Script_After BEFORE/AFTER JOB*/
702 -- int cmd_type; /* Command type -- Shell, Console */
703 - char level; /* Base|Full|Incr...|All (NYI) */
704 - bool on_success; /* execute command on job success (After) */
705 - bool on_failure; /* execute command on job failure (After) */
708 - bool run(JCR *job, const char *name=""); /* name must contain "Before" or "After" keyword */
709 - bool can_run_at_level(int JobLevel) { return true;}; /* TODO */
710 -- void set_command(const POOLMEM *cmd, int cmd_type = SHELL_CMD);
711 -+ void add_command(const POOLMEM *cmd, char cmd_type = SHELL_CMD);
712 -+ void get_command(const char *cmd, int *cmd_type, char **cmd);
713 - void set_target(const POOLMEM *client_name);
714 - void reset_default(bool free_string = false);
715 - bool is_local(); /* true if running on local host */
717 -+ void set_job_code_callback(job_code_callback_t job_code_callback);
719 -- void set_job_code_callback(job_code_callback_t job_code_callback);
721 -+ bool run_command(const char *cmd, JCR *job, const char *name="");
724 - /* create new RUNSCRIPT (set all value to 0) */
725 - RUNSCRIPT *new_runscript();
727 --/* create new RUNSCRIPT from an other */
728 -+/* create new RUNSCRIPT from an other (deep copy) */
729 - RUNSCRIPT *copy_runscript(RUNSCRIPT *src);
731 - /* launch each script from runscripts*/
732 -Index: src/lib/runscript.c
733 -===================================================================
734 ---- src/lib/runscript.c (révision 6169)
735 -+++ src/lib/runscript.c (copie de travail)
738 - void RUNSCRIPT::reset_default(bool free_strings)
740 -- if (free_strings && command) {
741 -- free_pool_memory(command);
743 -+ if (free_strings && commands) {
744 -+ foreach_alist(c, commands) {
745 -+ free_pool_memory(c);
749 - if (free_strings && target) {
750 - free_pool_memory(target);
757 - on_failure = false;
758 - fail_on_error = true;
760 - RUNSCRIPT *dst = (RUNSCRIPT *)malloc(sizeof(RUNSCRIPT));
761 - memcpy(dst, src, sizeof(RUNSCRIPT));
763 -- dst->command = NULL;
764 -+ dst->commands = New(alist(5, not_owned_by_alist));
767 -+ foreach_alist(c, src->commands) {
768 -+ m = get_pool_memory(PM_FNAME);
770 -+ dst->commands->append(m);
773 - dst->target = NULL;
775 -- dst->set_command(src->command, src->cmd_type);
776 - dst->set_target(src->target);
780 - void free_runscript(RUNSCRIPT *script)
782 - Dmsg0(500, "runscript: freeing RUNSCRIPT object\n");
784 -- if (script->command) {
785 -- free_pool_memory(script->command);
787 -+ if (script->commands) {
788 -+ foreach_alist(c, script->commands) {
789 -+ free_pool_memory(c);
791 -+ delete script->commands;
793 - if (script->target) {
794 - free_pool_memory(script->target);
795 -@@ -108,60 +120,15 @@
796 - int run_scripts(JCR *jcr, alist *runscripts, const char *label)
798 - Dmsg2(200, "runscript: running all RUNSCRIPT object (%s) JobStatus=%c\n", label, jcr->JobStatus);
800 -- RUNSCRIPT *script;
805 -- if (strstr(label, NT_("Before"))) {
806 -- when = SCRIPT_Before;
808 -- when = SCRIPT_After;
811 - if (runscripts == NULL) {
812 - Dmsg0(100, "runscript: WARNING RUNSCRIPTS list is NULL\n");
817 -+ RUNSCRIPT *script;
818 - foreach_alist(script, runscripts) {
819 -- Dmsg2(200, "runscript: try to run %s:%s\n", NPRT(script->target), NPRT(script->command));
822 -- if ((script->when & SCRIPT_Before) && (when & SCRIPT_Before)) {
823 -- if ((script->on_success
824 -- && (jcr->JobStatus == JS_Running || jcr->JobStatus == JS_Created))
825 -- || (script->on_failure && job_canceled(jcr))
828 -- Dmsg4(200, "runscript: Run it because SCRIPT_Before (%s,%i,%i,%c)\n",
829 -- script->command, script->on_success, script->on_failure,
835 -- if ((script->when & SCRIPT_After) && (when & SCRIPT_After)) {
836 -- if ((script->on_success && (jcr->JobStatus == JS_Terminated))
837 -- || (script->on_failure && job_canceled(jcr))
840 -- Dmsg4(200, "runscript: Run it because SCRIPT_After (%s,%i,%i,%c)\n",
841 -- script->command, script->on_success, script->on_failure,
847 -- if (!script->is_local()) {
851 -- /* we execute it */
853 -- script->run(jcr, label);
855 -+ script->run(jcr, label);
859 -@@ -175,23 +142,31 @@
863 --/* set this->command to cmd */
864 --void RUNSCRIPT::set_command(const POOLMEM *cmd, int acmd_type)
865 -+/* set add cmd to this->commands alist */
866 -+void RUNSCRIPT::add_command(const POOLMEM *cmd, char acmd_type)
868 -- Dmsg1(500, "runscript: setting command = %s\n", NPRT(cmd));
869 -+ Dmsg2(500, "runscript: setting command = %s type=%i\n", NPRT(cmd), acmd_type);
876 -- command = get_pool_memory(PM_FNAME);
878 -+ commands = New(alist(5, not_owned_by_alist));
881 -- pm_strcpy(command, cmd);
882 -- cmd_type = acmd_type;
883 -+ POOLMEM *c = get_pool_memory(PM_FNAME);
884 -+ Mmsg(c, "%c%s", acmd_type, cmd);
885 -+ commands->append(c);
888 -+/* command = ( SHELL_CMD | CONSOLE_CMD ) command */
889 -+void RUNSCRIPT::get_command(const char* command, int *acmd_type, char **cmd)
891 -+ *acmd_type = (int) command[0];
892 -+ *cmd = (char *)command + 1;
895 - /* set this->target to client_name */
896 - void RUNSCRIPT::set_target(const POOLMEM *client_name)
898 -@@ -210,14 +185,70 @@
900 - bool RUNSCRIPT::run(JCR *jcr, const char *name)
902 -- Dmsg1(100, "runscript: running a RUNSCRIPT object type=%d\n", cmd_type);
908 -+ if (strstr(name, NT_("Before"))) {
909 -+ when = SCRIPT_Before;
911 -+ when = SCRIPT_After;
914 -+ foreach_alist(c, this->commands) {
915 -+ Dmsg2(200, "runscript: try to run %s:%s\n", NPRT(this->target), NPRT(c));
918 -+ if ((this->when & SCRIPT_Before) && (when & SCRIPT_Before)) {
919 -+ if ((this->on_success
920 -+ && (jcr->JobStatus == JS_Running || jcr->JobStatus == JS_Created))
921 -+ || (this->on_failure && job_canceled(jcr))
924 -+ Dmsg4(200, "runscript: Run it because SCRIPT_Before (%s,%i,%i,%c)\n",
925 -+ c, this->on_success, this->on_failure,
931 -+ if ((this->when & SCRIPT_After) && (when & SCRIPT_After)) {
932 -+ if ((this->on_success && (jcr->JobStatus == JS_Terminated))
933 -+ || (this->on_failure && job_canceled(jcr))
936 -+ Dmsg4(200, "runscript: Run it because SCRIPT_After (%s,%i,%i,%c)\n",
937 -+ c, this->on_success, this->on_failure,
943 -+ if (!this->is_local()) {
947 -+ /* we execute it */
949 -+ this->run_command(c, jcr, name);
955 -+/* run a command from the list */
956 -+bool RUNSCRIPT::run_command(const char *command, JCR *jcr, const char *name)
958 - POOLMEM *ecmd = get_pool_memory(PM_FNAME);
960 -+ int status, cmd_type;
962 -- char line[MAXSTRING];
963 -+ char line[MAXSTRING], *cmd;
965 -- ecmd = edit_job_codes(jcr, ecmd, this->command, "", this->job_code_callback);
966 -- Dmsg1(100, "runscript: running '%s'...\n", ecmd);
967 -+ this->get_command(command, &cmd_type, &cmd);
968 -+ ecmd = edit_job_codes(jcr, ecmd, cmd, "", this->job_code_callback);
970 -+ Dmsg2(100, "runscript: running '%s' object type=%c...\n", ecmd, cmd_type);
971 - Jmsg(jcr, M_INFO, 0, _("%s: run %s \"%s\"\n"),
972 - cmd_type==SHELL_CMD?"shell command":"console command", name, ecmd);
974 -@@ -278,9 +309,12 @@
976 - void RUNSCRIPT::debug()
979 - Dmsg0(200, "runscript: debug\n");
980 - Dmsg0(200, _(" --> RunScript\n"));
981 -- Dmsg1(200, _(" --> Command=%s\n"), NPRT(command));
982 -+ foreach_alist(c, commands) {
983 -+ Dmsg1(200, _(" --> Command=%s\n"), NPRT(c));
985 - Dmsg1(200, _(" --> Target=%s\n"), NPRT(target));
986 - Dmsg1(200, _(" --> RunOnSuccess=%u\n"), on_success);
987 - Dmsg1(200, _(" --> RunOnFailure=%u\n"), on_failure);
988 Index: src/dird/fd_cmds.c
989 ===================================================================
990 --- src/dird/fd_cmds.c (révision 6169)
991 +++ src/dird/fd_cmds.c (copie de travail)
994 bool launch_before_cmd = false;
995 POOLMEM *ehost = get_pool_memory(PM_FNAME);
997 + int result, cmd_type;
1000 Dmsg0(120, "bdird: sending runscripts to fd\n");
1002 @@ -537,29 +538,33 @@
1003 Dmsg2(200, "bdird: runscript %s -> %s\n", cmd->target, ehost);
1005 if (strcmp(ehost, jcr->client->name()) == 0) {
1006 - pm_strcpy(msg, cmd->command);
1008 + foreach_alist(c, cmd->commands) {
1009 + cmd->get_command(c, &cmd_type, &command);
1010 + if (cmd_type == SHELL_CMD) {
1011 + pm_strcpy(msg, command);
1014 - Dmsg1(120, "bdird: sending runscripts to fd '%s'\n", cmd->command);
1015 + Dmsg1(120, "bdird: sending runscripts to fd '%s'\n", command);
1017 - /* TODO: remove this with bacula 1.42 */
1018 - if (cmd->old_proto) {
1019 - result = send_runscript_with_old_proto(jcr, cmd->when, msg);
1020 + /* TODO: remove this with bacula 1.42 */
1021 + if (cmd->old_proto) {
1022 + result = send_runscript_with_old_proto(jcr, cmd->when, msg);
1025 + fd->fsend(runscript, cmd->on_success,
1027 + cmd->fail_on_error,
1032 - fd->fsend(runscript, cmd->on_success,
1034 - cmd->fail_on_error,
1038 - result = response(jcr, fd, OKRunScript, "RunScript", DISPLAY_ERROR);
1039 - launch_before_cmd = true;
1040 + result = response(jcr, fd, OKRunScript, "RunScript", DISPLAY_ERROR);
1041 + launch_before_cmd = true;
1053 /* TODO : we have to play with other client */
1056 send command to an other client
1063 /* Tell the FD to execute the ClientRunBeforeJob */
1064 Index: src/dird/dird_conf.c
1065 ===================================================================
1066 --- src/dird/dird_conf.c (révision 6169)
1067 +++ src/dird/dird_conf.c (copie de travail)
1068 @@ -651,16 +651,19 @@
1071 if (res->res_job.RunScripts) {
1072 - RUNSCRIPT *script;
1073 - foreach_alist(script, res->res_job.RunScripts) {
1074 - sendit(sock, _(" --> RunScript\n"));
1075 - sendit(sock, _(" --> Command=%s\n"), NPRT(script->command));
1076 - sendit(sock, _(" --> Target=%s\n"), NPRT(script->target));
1077 - sendit(sock, _(" --> RunOnSuccess=%u\n"), script->on_success);
1078 - sendit(sock, _(" --> RunOnFailure=%u\n"), script->on_failure);
1079 - sendit(sock, _(" --> FailJobOnError=%u\n"), script->fail_on_error);
1080 - sendit(sock, _(" --> RunWhen=%u\n"), script->when);
1083 + RUNSCRIPT *script;
1084 + foreach_alist(script, res->res_job.RunScripts) {
1085 + sendit(sock, _(" --> RunScript\n"));
1086 + foreach_alist(c, script->commands) {
1087 + sendit(sock, _(" --> Command=%s\n"), NPRT(c));
1089 + sendit(sock, _(" --> Target=%s\n"), NPRT(script->target));
1090 + sendit(sock, _(" --> RunOnSuccess=%u\n"), script->on_success);
1091 + sendit(sock, _(" --> RunOnFailure=%u\n"), script->on_failure);
1092 + sendit(sock, _(" --> FailJobOnError=%u\n"), script->fail_on_error);
1093 + sendit(sock, _(" --> RunWhen=%u\n"), script->when);
1096 if (res->res_job.pool) {
1097 sendit(sock, _(" --> "));
1098 @@ -1724,14 +1727,14 @@
1102 - * Store a runscript->command as a string
1103 + * Store a runscript->commands as a alist(char + string)
1105 static void store_runscript_cmd(LEX *lc, RES_ITEM *item, int index, int pass)
1107 lex_get_token(lc, T_STRING);
1110 - ((RUNSCRIPT*)item->value)->set_command(lc->str, item->code);
1111 + ((RUNSCRIPT*)item->value)->add_command(lc->str, item->code);
1115 @@ -1745,7 +1748,7 @@
1116 RUNSCRIPT *script = new_runscript();
1117 script->set_job_code_callback(job_code_callback_filesetname);
1119 - script->set_command(lc->str);
1120 + script->add_command(lc->str);
1122 /* TODO: remove all script->old_proto with bacula 1.42 */
1124 @@ -1873,7 +1876,7 @@
1128 - if (res_runscript.command == NULL) {
1129 + if (res_runscript.commands == NULL) {
1130 scan_err2(lc, _("%s item is required in %s resource, but not found.\n"),
1131 "command", "runscript");
1133 @@ -1886,7 +1889,7 @@
1134 RUNSCRIPT *script = new_runscript();
1135 memcpy(script, &res_runscript, sizeof(RUNSCRIPT));
1136 script->set_job_code_callback(job_code_callback_filesetname);
1139 if (*runscripts == NULL) {
1140 *runscripts = New(alist(10, not_owned_by_alist));
1142 Index: src/filed/job.c
1143 ===================================================================
1144 --- src/filed/job.c (révision 6169)
1145 +++ src/filed/job.c (copie de travail)
1148 /* Run the command now */
1149 script = new_runscript();
1150 - script->set_command(cmd);
1151 + script->add_command(cmd);
1152 script->when = SCRIPT_Before;
1153 ok = script->run(jcr, "ClientRunBeforeJob");
1154 free_runscript(script);
1158 cmd = new_runscript();
1159 - cmd->set_command(msg);
1160 + cmd->add_command(msg);
1161 cmd->on_success = true;
1162 cmd->on_failure = false;
1163 cmd->when = SCRIPT_After;
1165 cmd->fail_on_error = fail_on_error;
1168 - cmd->set_command(msg);
1169 + cmd->add_command(msg);
1171 jcr->RunScripts->append(cmd);
1173 Index: src/lib/runscript.h
1174 ===================================================================
1175 --- src/lib/runscript.h (révision 6169)
1176 +++ src/lib/runscript.h (copie de travail)
1192 - POOLMEM *command; /* command string */
1193 + alist *commands; /* list of command/console string */
1194 POOLMEM *target; /* host target */
1195 int when; /* SCRIPT_Before|Script_After BEFORE/AFTER JOB*/
1196 - int cmd_type; /* Command type -- Shell, Console */
1197 char level; /* Base|Full|Incr...|All (NYI) */
1198 bool on_success; /* execute command on job success (After) */
1199 bool on_failure; /* execute command on job failure (After) */
1202 bool run(JCR *job, const char *name=""); /* name must contain "Before" or "After" keyword */
1203 bool can_run_at_level(int JobLevel) { return true;}; /* TODO */
1204 - void set_command(const POOLMEM *cmd, int cmd_type = SHELL_CMD);
1205 + void add_command(const POOLMEM *cmd, char cmd_type = SHELL_CMD);
1206 + void get_command(const char *cmd, int *cmd_type, char **cmd);
1207 void set_target(const POOLMEM *client_name);
1208 void reset_default(bool free_string = false);
1209 - bool is_local(); /* true if running on local host */
1210 + bool is_local(const char *cmd); /* true if running on local host */
1212 + void set_job_code_callback(job_code_callback_t job_code_callback);
1214 - void set_job_code_callback(job_code_callback_t job_code_callback);
1216 + bool run_command(const char *cmd, JCR *job, const char *name="");
1219 /* create new RUNSCRIPT (set all value to 0) */
1220 RUNSCRIPT *new_runscript();
1222 -/* create new RUNSCRIPT from an other */
1223 +/* create new RUNSCRIPT from an other (deep copy) */
1224 RUNSCRIPT *copy_runscript(RUNSCRIPT *src);
1226 /* launch each script from runscripts*/
1227 Index: src/lib/runscript.c
1228 ===================================================================
1229 --- src/lib/runscript.c (révision 6169)
1230 +++ src/lib/runscript.c (copie de travail)
1233 void RUNSCRIPT::reset_default(bool free_strings)
1235 - if (free_strings && command) {
1236 - free_pool_memory(command);
1238 + if (free_strings && commands) {
1239 + foreach_alist(c, commands) {
1240 + free_pool_memory(c);
1244 if (free_strings && target) {
1245 free_pool_memory(target);
1253 fail_on_error = true;
1255 RUNSCRIPT *dst = (RUNSCRIPT *)malloc(sizeof(RUNSCRIPT));
1256 memcpy(dst, src, sizeof(RUNSCRIPT));
1258 - dst->command = NULL;
1259 + dst->commands = New(alist(5, not_owned_by_alist));
1262 + foreach_alist(c, src->commands) {
1263 + m = get_pool_memory(PM_FNAME);
1265 + dst->commands->append(m);
1270 - dst->set_command(src->command, src->cmd_type);
1271 dst->set_target(src->target);
1275 void free_runscript(RUNSCRIPT *script)
1277 Dmsg0(500, "runscript: freeing RUNSCRIPT object\n");
1279 - if (script->command) {
1280 - free_pool_memory(script->command);
1282 + if (script->commands) {
1283 + foreach_alist(c, script->commands) {
1284 + free_pool_memory(c);
1286 + delete script->commands;
1288 if (script->target) {
1289 free_pool_memory(script->target);
1290 @@ -108,66 +120,25 @@
1291 int run_scripts(JCR *jcr, alist *runscripts, const char *label)
1293 Dmsg2(200, "runscript: running all RUNSCRIPT object (%s) JobStatus=%c\n", label, jcr->JobStatus);
1295 - RUNSCRIPT *script;
1300 - if (strstr(label, NT_("Before"))) {
1301 - when = SCRIPT_Before;
1303 - when = SCRIPT_After;
1306 if (runscripts == NULL) {
1307 Dmsg0(100, "runscript: WARNING RUNSCRIPTS list is NULL\n");
1312 + RUNSCRIPT *script;
1313 foreach_alist(script, runscripts) {
1314 - Dmsg2(200, "runscript: try to run %s:%s\n", NPRT(script->target), NPRT(script->command));
1317 - if ((script->when & SCRIPT_Before) && (when & SCRIPT_Before)) {
1318 - if ((script->on_success
1319 - && (jcr->JobStatus == JS_Running || jcr->JobStatus == JS_Created))
1320 - || (script->on_failure && job_canceled(jcr))
1323 - Dmsg4(200, "runscript: Run it because SCRIPT_Before (%s,%i,%i,%c)\n",
1324 - script->command, script->on_success, script->on_failure,
1330 - if ((script->when & SCRIPT_After) && (when & SCRIPT_After)) {
1331 - if ((script->on_success && (jcr->JobStatus == JS_Terminated))
1332 - || (script->on_failure && job_canceled(jcr))
1335 - Dmsg4(200, "runscript: Run it because SCRIPT_After (%s,%i,%i,%c)\n",
1336 - script->command, script->on_success, script->on_failure,
1342 - if (!script->is_local()) {
1346 - /* we execute it */
1348 - script->run(jcr, label);
1350 + script->run(jcr, label);
1355 -bool RUNSCRIPT::is_local()
1356 +bool RUNSCRIPT::is_local(const char *c)
1358 + if (c[0] == CONSOLE_CMD) {
1362 if (!target || (strcmp(target, "") == 0)) {
1365 @@ -175,23 +146,31 @@
1369 -/* set this->command to cmd */
1370 -void RUNSCRIPT::set_command(const POOLMEM *cmd, int acmd_type)
1371 +/* set add cmd to this->commands alist */
1372 +void RUNSCRIPT::add_command(const POOLMEM *cmd, char acmd_type)
1374 - Dmsg1(500, "runscript: setting command = %s\n", NPRT(cmd));
1375 + Dmsg2(500, "runscript: setting command = %s type=%i\n", NPRT(cmd), acmd_type);
1382 - command = get_pool_memory(PM_FNAME);
1384 + commands = New(alist(5, not_owned_by_alist));
1387 - pm_strcpy(command, cmd);
1388 - cmd_type = acmd_type;
1389 + POOLMEM *c = get_pool_memory(PM_FNAME);
1390 + Mmsg(c, "%c%s", acmd_type, cmd);
1391 + commands->append(c);
1394 +/* command = ( SHELL_CMD | CONSOLE_CMD ) command */
1395 +void RUNSCRIPT::get_command(const char* command, int *acmd_type, char **cmd)
1397 + *acmd_type = (int) command[0];
1398 + *cmd = (char *)command + 1;
1401 /* set this->target to client_name */
1402 void RUNSCRIPT::set_target(const POOLMEM *client_name)
1404 @@ -210,14 +189,70 @@
1406 bool RUNSCRIPT::run(JCR *jcr, const char *name)
1408 - Dmsg1(100, "runscript: running a RUNSCRIPT object type=%d\n", cmd_type);
1414 + if (strstr(name, NT_("Before"))) {
1415 + when = SCRIPT_Before;
1417 + when = SCRIPT_After;
1420 + foreach_alist(c, this->commands) {
1421 + Dmsg2(200, "runscript: try to run %s:%s\n", NPRT(this->target), NPRT(c));
1424 + if ((this->when & SCRIPT_Before) && (when & SCRIPT_Before)) {
1425 + if ((this->on_success
1426 + && (jcr->JobStatus == JS_Running || jcr->JobStatus == JS_Created))
1427 + || (this->on_failure && job_canceled(jcr))
1430 + Dmsg4(200, "runscript: Run it because SCRIPT_Before (%s,%i,%i,%c)\n",
1431 + c, this->on_success, this->on_failure,
1437 + if ((this->when & SCRIPT_After) && (when & SCRIPT_After)) {
1438 + if ((this->on_success && (jcr->JobStatus == JS_Terminated))
1439 + || (this->on_failure && job_canceled(jcr))
1442 + Dmsg4(200, "runscript: Run it because SCRIPT_After (%s,%i,%i,%c)\n",
1443 + c, this->on_success, this->on_failure,
1449 + if (!this->is_local(c)) {
1453 + /* we execute it */
1455 + this->run_command(c, jcr, name);
1461 +/* run a command from the list */
1462 +bool RUNSCRIPT::run_command(const char *command, JCR *jcr, const char *name)
1464 POOLMEM *ecmd = get_pool_memory(PM_FNAME);
1466 + int status, cmd_type;
1468 - char line[MAXSTRING];
1469 + char line[MAXSTRING], *cmd;
1471 - ecmd = edit_job_codes(jcr, ecmd, this->command, "", this->job_code_callback);
1472 - Dmsg1(100, "runscript: running '%s'...\n", ecmd);
1473 + this->get_command(command, &cmd_type, &cmd);
1474 + ecmd = edit_job_codes(jcr, ecmd, cmd, "", this->job_code_callback);
1476 + Dmsg2(100, "runscript: running '%s' object type=%c...\n", ecmd, cmd_type);
1477 Jmsg(jcr, M_INFO, 0, _("%s: run %s \"%s\"\n"),
1478 cmd_type==SHELL_CMD?"shell command":"console command", name, ecmd);
1480 @@ -278,9 +313,12 @@
1482 void RUNSCRIPT::debug()
1485 Dmsg0(200, "runscript: debug\n");
1486 Dmsg0(200, _(" --> RunScript\n"));
1487 - Dmsg1(200, _(" --> Command=%s\n"), NPRT(command));
1488 + foreach_alist(c, commands) {
1489 + Dmsg1(200, _(" --> Command=%s\n"), NPRT(c));
1491 Dmsg1(200, _(" --> Target=%s\n"), NPRT(target));
1492 Dmsg1(200, _(" --> RunOnSuccess=%u\n"), on_success);
1493 Dmsg1(200, _(" --> RunOnFailure=%u\n"), on_failure);