From 5276c9218ee038e74a508dccf3d9ab3f7d9ac056 Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Sun, 22 Jul 2007 10:33:41 +0000 Subject: [PATCH] Ensure that RunScript fails job on FD git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@5220 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/lib/runscript.c | 23 ++++++++++++----------- bacula/src/lib/runscript.h | 2 +- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/bacula/src/lib/runscript.c b/bacula/src/lib/runscript.c index 4ce5867550..7d031aeb70 100644 --- a/bacula/src/lib/runscript.c +++ b/bacula/src/lib/runscript.c @@ -103,7 +103,6 @@ int run_scripts(JCR *jcr, alist *runscripts, const char *label) RUNSCRIPT *script; bool runit; - bool ok; int when; @@ -148,17 +147,12 @@ int run_scripts(JCR *jcr, alist *runscripts, const char *label) } if (!script->is_local()) { - runit=false; + runit = false; } /* we execute it */ if (runit) { - ok = script->run(jcr, label); - - /* cancel running job properly */ - if (script->fail_on_error && !ok) { - set_jcr_job_status(jcr, JS_ErrorTerminated); - } + script->run(jcr, label); } } return 1; @@ -205,7 +199,7 @@ void RUNSCRIPT::set_target(const POOLMEM *client_name) pm_strcpy(target, client_name); } -int RUNSCRIPT::run(JCR *jcr, const char *name) +bool RUNSCRIPT::run(JCR *jcr, const char *name) { Dmsg0(200, "runscript: running a RUNSCRIPT object\n"); POOLMEM *ecmd = get_pool_memory(PM_FNAME); @@ -223,7 +217,7 @@ int RUNSCRIPT::run(JCR *jcr, const char *name) berrno be; Jmsg(jcr, M_ERROR, 0, _("Runscript: %s could not execute. ERR=%s\n"), name, be.bstrerror()); - return false; + goto bail_out; } while (fgets(line, sizeof(line), bpipe->rfd)) { int len = strlen(line); @@ -237,9 +231,16 @@ int RUNSCRIPT::run(JCR *jcr, const char *name) berrno be; Jmsg(jcr, M_ERROR, 0, _("Runscript: %s returned non-zero status=%d. ERR=%s\n"), name, be.code(status), be.bstrerror(status)); - return false; + goto bail_out; } return true; + +bail_out: + /* cancel running job properly */ + if (fail_on_error) { + set_jcr_job_status(jcr, JS_ErrorTerminated); + } + return false; } void free_runscripts(alist *runscripts) diff --git a/bacula/src/lib/runscript.h b/bacula/src/lib/runscript.h index ff66d336ba..12710f5612 100644 --- a/bacula/src/lib/runscript.h +++ b/bacula/src/lib/runscript.h @@ -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=""); /* name must contain "Before" or "After" keyword */ + 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); void set_target(const POOLMEM *client_name); -- 2.39.5