From: Eric Bollengier Date: Mon, 27 Jun 2016 12:43:05 +0000 (+0200) Subject: Fix #1902 about a segfault with the "cancel inactive" command X-Git-Tag: Release-7.4.2~6 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=83348794ca958d6264c9e152ee8eea57b0971732;p=bacula%2Fbacula Fix #1902 about a segfault with the "cancel inactive" command --- diff --git a/bacula/src/dird/job.c b/bacula/src/dird/job.c index 9ed9c27083..3193741555 100644 --- a/bacula/src/dird/job.c +++ b/bacula/src/dird/job.c @@ -648,6 +648,8 @@ static int cancel_inactive_job(UAContext *ua, JCR *jcr) cancel_sd_job(ua, "cancel", jcr); bail_out: + jcr->JobId = 0; + free_jcr(jcr); return 1; } diff --git a/bacula/src/dird/ua_cmds.c b/bacula/src/dird/ua_cmds.c index e9cc9296d6..5ba1a68cf2 100644 --- a/bacula/src/dird/ua_cmds.c +++ b/bacula/src/dird/ua_cmds.c @@ -1840,7 +1840,7 @@ int wait_cmd(UAContext *ua, const char *cmd) for (bool running=true; running; ) { running = false; foreach_jcr(jcr) { - if (jcr->JobId != 0) { + if (!jcr->is_internal_job()) { running = true; break; } @@ -1900,7 +1900,7 @@ int wait_cmd(UAContext *ua, const char *cmd) } else if (strcasecmp(ua->argk[i], "mount") == 0) { for (bool waiting=false; !waiting; ) { foreach_jcr(jcr) { - if (jcr->JobId != 0 && + if (!jcr->is_internal_job() && (jcr->JobStatus == JS_WaitMedia || jcr->JobStatus == JS_WaitMount)) { waiting = true; break; diff --git a/bacula/src/dird/ua_select.c b/bacula/src/dird/ua_select.c index d7efcf98f0..3e39ba93a4 100644 --- a/bacula/src/dird/ua_select.c +++ b/bacula/src/dird/ua_select.c @@ -1293,7 +1293,7 @@ static int count_running_jobs(UAContext *ua) JCR *jcr; /* Count Jobs running */ foreach_jcr(jcr) { - if (jcr->JobId == 0) { /* this is us */ + if (jcr->is_internal_job()) { /* this is us */ continue; } tjobs++; /* count of all jobs */ @@ -1363,7 +1363,7 @@ int select_running_jobs(UAContext *ua, alist *jcrs, const char *reason) /* TODO: might want to implement filters (client, status, etc...) */ } else if (strcasecmp(ua->argk[i], NT_("all")) == 0) { foreach_jcr(jcr) { - if (jcr->JobId == 0) { /* Do not cancel consoles */ + if (jcr->is_internal_job()) { /* Do not cancel consoles */ continue; } if (!acl_access_ok(ua, Job_ACL, jcr->job->name())) { @@ -1454,7 +1454,7 @@ int select_running_jobs(UAContext *ua, alist *jcrs, const char *reason) start_prompt(ua, _("Select Job(s):\n")); foreach_jcr(jcr) { char ed1[50]; - if (jcr->JobId == 0) { /* this is us */ + if (jcr->is_internal_job()) { /* this is us */ continue; } bsnprintf(buf, sizeof(buf), _("JobId=%s Job=%s"), edit_int64(jcr->JobId, ed1), jcr->Job); diff --git a/bacula/src/dird/ua_status.c b/bacula/src/dird/ua_status.c index 291de2bf74..395966041d 100644 --- a/bacula/src/dird/ua_status.c +++ b/bacula/src/dird/ua_status.c @@ -68,7 +68,7 @@ bool dot_status_cmd(UAContext *ua, const char *cmd) if (strcasecmp(ua->argk[2], "current") == 0) { ua->send_msg(OKqstatus, ua->argk[2]); foreach_jcr(njcr) { - if (njcr->JobId != 0 && acl_access_ok(ua, Job_ACL, njcr->job->name())) { + if (!njcr->is_internal_job() && acl_access_ok(ua, Job_ACL, njcr->job->name())) { ua->send_msg(DotStatusJob, edit_int64(njcr->JobId, ed1), njcr->JobStatus, njcr->JobErrors); } diff --git a/bacula/src/jcr.h b/bacula/src/jcr.h index 8ac46c2f51..d37a31f0fe 100644 --- a/bacula/src/jcr.h +++ b/bacula/src/jcr.h @@ -192,6 +192,7 @@ public: pthread_mutex_destroy(&mutex_auth); pthread_mutex_destroy(&mutex); }; + bool is_internal_job() {return (JobId == 0 || m_JobType == JT_SYSTEM || m_JobType == JT_CONSOLE); }; bool is_job_canceled() {return job_canceled(this); }; bool is_canceled() {return job_canceled(this); }; bool is_incomplete() { return JobStatus == JS_Incomplete; };