]> git.sur5r.net Git - bacula/bacula/commitdiff
Fix #1902 about a segfault with the "cancel inactive" command
authorEric Bollengier <eric@baculasystems.com>
Mon, 27 Jun 2016 12:43:05 +0000 (14:43 +0200)
committerKern Sibbald <kern@sibbald.com>
Sun, 3 Jul 2016 10:37:27 +0000 (12:37 +0200)
bacula/src/dird/job.c
bacula/src/dird/ua_cmds.c
bacula/src/dird/ua_select.c
bacula/src/dird/ua_status.c
bacula/src/jcr.h

index 9ed9c27083800a0e2bb744e0382249e03939c9eb..3193741555f91d386d2fff95dd2822c66e5cbeda 100644 (file)
@@ -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;
 }
 
index e9cc9296d6c63b65a8d8d5754c814d8747cf0436..5ba1a68cf2ac413fec8625b723f9a9aee79ea889 100644 (file)
@@ -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;
index d7efcf98f0bc2a432ffeac939411044cce9332c9..3e39ba93a4524947098504e8dd4b63e487078949 100644 (file)
@@ -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);
index 291de2bf746a28b82dc383d4a25ea6cde8da30b0..395966041dff58ea217d8de708faf47a51ea96a7 100644 (file)
@@ -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);
             }
index 8ac46c2f5168045a87a02a15cfa5b1381bf0afa2..d37a31f0fe6b523bf4d756bdb9867797bf3d2205 100644 (file)
@@ -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; };