From 4bfd0a1b04748cc8e8650abf515af7b34390c734 Mon Sep 17 00:00:00 2001 From: Eric Bollengier Date: Fri, 20 Apr 2007 20:36:47 +0000 Subject: [PATCH] ebl fix #824 bug about runscript use RunsOnSuccess and RunsOnFailure with Before script (like before, but it's more clear) git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@4573 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/lib/runscript.c | 53 ++++++++++++++++++++++++-------------- bacula/src/lib/runscript.h | 4 +-- 2 files changed, 35 insertions(+), 22 deletions(-) diff --git a/bacula/src/lib/runscript.c b/bacula/src/lib/runscript.c index e01c1da5e2..1390af1edf 100644 --- a/bacula/src/lib/runscript.c +++ b/bacula/src/lib/runscript.c @@ -105,6 +105,14 @@ int run_scripts(JCR *jcr, alist *runscripts, const char *label) bool runit; bool status; + int when; + + if (strstr(label, "Before")) { + when = SCRIPT_Before; + } else { + when = SCRIPT_After; + } + if (runscripts == NULL) { Dmsg0(100, "runscript: WARNING RUNSCRIPTS list is NULL\n"); return 0; @@ -114,28 +122,33 @@ int run_scripts(JCR *jcr, alist *runscripts, const char *label) Dmsg2(200, "runscript: try to run %s:%s\n", NPRT(script->target), NPRT(script->command)); runit=false; - if ((script->when & SCRIPT_Before) && (jcr->JobStatus == JS_Created)) { - Dmsg0(200, "runscript: Run it because SCRIPT_Before\n"); - runit = true; + if ((script->when & SCRIPT_Before) && (when & SCRIPT_Before)) { + if ( (script->on_success && (jcr->JobStatus == JS_Running || jcr->JobStatus == JS_Created)) + || + (script->on_failure && job_canceled(jcr)) + ) + { + Dmsg4(200, "runscript: Run it because SCRIPT_Before (%s,%i,%i,%c)\n", script->command, + script->on_success, + script->on_failure, + jcr->JobStatus ); + + runit = true; + } } - if ((script->when & SCRIPT_Before) && (jcr->JobStatus == JS_Running)) { - Dmsg0(200, "runscript: Run it because SCRIPT_Before\n"); - runit = true; - } - - if (script->when & SCRIPT_After) { - if ( (script->on_success && (jcr->JobStatus == JS_Terminated)) - || - (script->on_failure && job_canceled(jcr)) - ) - { - Dmsg4(200, "runscript: Run it because SCRIPT_After (%s,%i,%i,%c)\n", script->command, - script->on_success, - script->on_failure, - jcr->JobStatus ); - runit = true; - } + if ((script->when & SCRIPT_After) && (when & SCRIPT_After)) { + if ( (script->on_success && (jcr->JobStatus == JS_Terminated)) + || + (script->on_failure && job_canceled(jcr)) + ) + { + Dmsg4(200, "runscript: Run it because SCRIPT_After (%s,%i,%i,%c)\n", script->command, + script->on_success, + script->on_failure, + jcr->JobStatus ); + runit = true; + } } if (!script->is_local()) { diff --git a/bacula/src/lib/runscript.h b/bacula/src/lib/runscript.h index d75a7b4b47..42b1c898d9 100644 --- a/bacula/src/lib/runscript.h +++ b/bacula/src/lib/runscript.h @@ -45,7 +45,7 @@ * script->on_failure = true; * script->when = SCRIPT_After; * - * script->run("Label"); + * script->run("LabelBefore"); // the label must contain "Before" or "After" special keyword * free_runscript(script); */ @@ -74,7 +74,7 @@ public: /* TODO : drop this with bacula 1.42 */ bool old_proto; /* used by old 1.3X protocol */ - int run(JCR *job, const char *name=""); + int 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); void set_target(const POOLMEM *client_name); -- 2.39.5