- if (jcr->job->RunAfterJob) {
- POOLMEM *after = get_pool_memory(PM_FNAME);
- int status;
-
- after = edit_run_codes(jcr, after, jcr->job->RunAfterJob);
- status = run_program(after, 0, NULL);
- free_pool_memory(after);
+ if ((jcr->job->RunAfterJob && jcr->JobStatus == JS_Terminated) ||
+ (jcr->job->RunAfterFailedJob && jcr->JobStatus != JS_Terminated)) {
+ POOLMEM *after = get_pool_memory(PM_FNAME);
+ int status;
+ BPIPE *bpipe;
+ char line[MAXSTRING];
+
+ if (jcr->JobStatus == JS_Terminated) {
+ after = edit_job_codes(jcr, after, jcr->job->RunAfterJob, "");
+ } else {
+ after = edit_job_codes(jcr, after, jcr->job->RunAfterFailedJob, "");
+ }
+ bpipe = open_bpipe(after, 0, "r");
+ free_pool_memory(after);
+ while (fgets(line, sizeof(line), bpipe->rfd)) {
+ Jmsg(jcr, M_INFO, 0, _("RunAfter: %s"), line);
+ }
+ status = close_bpipe(bpipe);
+ /*
+ * Note, if we get an error here, do not mark the
+ * job in error, simply report the error condition.
+ */
+ if (status != 0) {
+ if (jcr->JobStatus == JS_Terminated) {
+ Jmsg(jcr, M_WARNING, 0, _("RunAfterJob returned non-zero status=%d\n"),
+ status);
+ } else {
+ Jmsg(jcr, M_FATAL, 0, _("RunAfterFailedJob returned non-zero status=%d\n"),
+ status);
+ }
+ }
+ }
+ /* Send off any queued messages */
+ if (jcr->msg_queue->size() > 0) {
+ dequeue_messages(jcr);
+ }