- if (jcr->job->ClientRunBeforeJob) {
- pm_strcpy(msg, jcr->job->ClientRunBeforeJob);
- bash_spaces(msg);
- bnet_fsend(fd, runbefore, msg);
- if (!response(jcr, fd, OKRunBefore, "ClientRunBeforeJob", DISPLAY_ERROR)) {
- set_jcr_job_status(jcr, JS_ErrorTerminated);
- free_pool_memory(msg);
- return 0;
- }
- }
- if (jcr->job->ClientRunAfterJob) {
- fd->msglen = pm_strcpy(msg, jcr->job->ClientRunAfterJob);
- bash_spaces(msg);
- bnet_fsend(fd, runafter, msg);
- if (!response(jcr, fd, OKRunAfter, "ClientRunAfterJob", DISPLAY_ERROR)) {
- set_jcr_job_status(jcr, JS_ErrorTerminated);
- free_pool_memory(msg);
- return 0;
+ RUNSCRIPT *cmd;
+ bool launch_before_cmd = false;
+ POOLMEM *ehost = get_pool_memory(PM_FNAME);
+ int result;
+
+ Dmsg0(120, "bdird: sending runscripts to fd\n");
+
+ foreach_alist(cmd, jcr->job->RunScripts) {
+
+ if (cmd->can_run_at_level(jcr->JobLevel) && cmd->target) {
+
+ ehost = edit_job_codes(jcr, ehost, cmd->target, "");
+ Dmsg2(200, "bdird: runscript %s -> %s\n", cmd->target, ehost);
+
+ if (strcmp(ehost, jcr->client->hdr.name) == 0) {
+ pm_strcpy(msg, cmd->command);
+ bash_spaces(msg);
+
+ Dmsg1(120, "bdird: sending runscripts to fd '%s'\n", cmd->command);
+
+ /* TODO: remove this with bacula 1.42 */
+ if (cmd->old_proto) {
+ result = send_runscript_with_old_proto(jcr, cmd->when, msg);
+
+ } else {
+ bnet_fsend(fd, runscript, cmd->on_success,
+ cmd->on_failure,
+ cmd->abort_on_error,
+ cmd->when,
+ msg);
+
+ result = response(jcr, fd, OKRunScript, "RunScript", DISPLAY_ERROR);
+ launch_before_cmd=true;
+ }
+
+ if (!result) {
+ set_jcr_job_status(jcr, JS_ErrorTerminated);
+ free_pool_memory(msg);
+ free_pool_memory(ehost);
+ return 0;
+ }
+ }
+ /* TODO : we have to play with other client */
+ /*
+ else {
+ send command to an other client
+ }
+ */
+ }
+ }
+
+ /* We tell to the FD that i can execute commands (ie ClientRunBeforeJob) */
+ if (launch_before_cmd) {
+ bnet_fsend(fd, runbeforenow);
+ if (!response(jcr, fd, OKRunBeforeNow, "RunBeforeNow", DISPLAY_ERROR)) {
+ set_jcr_job_status(jcr, JS_ErrorTerminated);
+ free_pool_memory(msg);
+ free_pool_memory(ehost);
+ return 0;