From 414615fb09c45e92fa078c9bed948331ca84875e Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Sun, 22 Jul 2007 12:21:06 +0000 Subject: [PATCH] Correct RunScript to terminate job in FD on failure. git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@5222 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/filed/job.c | 8 ++++++-- bacula/src/lib/jcr.c | 16 ++++++++++++++-- bacula/src/lib/runscript.c | 12 +++++++----- bacula/technotes-2.1 | 1 + 4 files changed, 28 insertions(+), 9 deletions(-) diff --git a/bacula/src/filed/job.c b/bacula/src/filed/job.c index 090a10ea83..b8419ba728 100644 --- a/bacula/src/filed/job.c +++ b/bacula/src/filed/job.c @@ -492,9 +492,13 @@ static int runbeforenow_cmd(JCR *jcr) run_scripts(jcr, jcr->RunScripts, "ClientBeforeJob"); if (job_canceled(jcr)) { - return bnet_fsend(dir, _("2905 Bad RunBeforeNow command.\n")); + bnet_fsend(dir, _("2905 Bad RunBeforeNow command.\n")); + Dmsg0(100, "Back from run_scripts ClientBeforeJob now: FAILED\n"); + return 0; } else { - return bnet_fsend(dir, OKRunBeforeNow); + bnet_fsend(dir, OKRunBeforeNow); + Dmsg0(100, "Back from run_scripts ClientBeforeJob now: OK\n"); + return 1; } } diff --git a/bacula/src/lib/jcr.c b/bacula/src/lib/jcr.c index a93e53346f..0b5e01fdc8 100644 --- a/bacula/src/lib/jcr.c +++ b/bacula/src/lib/jcr.c @@ -599,16 +599,28 @@ void set_jcr_job_status(JCR *jcr, int JobStatus) * For a set of errors, ... keep the current status * so it isn't lost. For all others, set it. */ + Dmsg2(100, "OnEntry JobStatus=%c set=%c\n", jcr->JobStatus, JobStatus); switch (jcr->JobStatus) { case JS_ErrorTerminated: - case JS_Error: case JS_FatalError: - case JS_Differences: case JS_Canceled: break; + case JS_Error: + case JS_Differences: + switch (JobStatus) { + case JS_ErrorTerminated: + case JS_FatalError: + case JS_Canceled: + /* Override more minor status */ + jcr->JobStatus = JobStatus; + break; + default: + break; + } default: jcr->JobStatus = JobStatus; } + Dmsg2(100, "OnExit JobStatus=%c set=%c\n", jcr->JobStatus, JobStatus); } #ifdef TRACE_JCR_CHAIN diff --git a/bacula/src/lib/runscript.c b/bacula/src/lib/runscript.c index 7d031aeb70..c36115c359 100644 --- a/bacula/src/lib/runscript.c +++ b/bacula/src/lib/runscript.c @@ -233,14 +233,16 @@ bool RUNSCRIPT::run(JCR *jcr, const char *name) be.code(status), be.bstrerror(status)); goto bail_out; } + Dmsg0(100, "runscript OK\n"); return true; bail_out: - /* cancel running job properly */ - if (fail_on_error) { - set_jcr_job_status(jcr, JS_ErrorTerminated); - } - return false; + /* cancel running job properly */ + if (fail_on_error) { + set_jcr_job_status(jcr, JS_ErrorTerminated); + } + Dmsg1(100, "runscript failed. fail_on_error=%d\n", fail_on_error); + return false; } void free_runscripts(alist *runscripts) diff --git a/bacula/technotes-2.1 b/bacula/technotes-2.1 index f2405ff22b..62454e357d 100644 --- a/bacula/technotes-2.1 +++ b/bacula/technotes-2.1 @@ -2,6 +2,7 @@ General: 22Jul07 +kes Correct RunScript to terminate job in FD on failure. kes Change abort_on_error and AbortJobOnError to fail_on_error and FailJobOnError in RunScripts. kes Minor tweaks of code formating in RunScripts, principally to -- 2.39.5