]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/dird/ua_status.c
This commit was manufactured by cvs2svn to create tag
[bacula/bacula] / bacula / src / dird / ua_status.c
index a8196d87365c7c0a941fbdbf153cf44bf6d3e923..2d8c59c6e447acea233c6e4230ada45c77f95e5d 100644 (file)
@@ -223,84 +223,86 @@ static void do_director_status(UAContext *ua, char *cmd)
         continue;
       }
       switch (jcr->JobStatus) {
-        case JS_Created:
-            msg = _("is waiting execution");
-           break;
-        case JS_Running:
-            msg = _("is running");
-           break;
-        case JS_Blocked:
-            msg = _("is blocked");
-           break;
-        case JS_Terminated:
-            msg = _("has terminated");
-           break;
-        case JS_ErrorTerminated:
-            msg = _("has erred");
-           break;
-        case JS_Canceled:
-            msg = _("has been canceled");
-           break;
-        case JS_WaitFD:
-           msg = (char *) get_pool_memory(PM_FNAME);
-            Mmsg(&msg, _("is waiting on Client %s"), jcr->client->hdr.name);
-           pool_mem = TRUE;
-           break;
-        case JS_WaitSD:
-           msg = (char *) get_pool_memory(PM_FNAME);
-            Mmsg(&msg, _("is waiting on Storage %s"), jcr->store->hdr.name);
-           pool_mem = TRUE;
-           break;
-        case JS_WaitStoreRes:
-            msg = _("is waiting on max Storage jobs");
-           break;
-        case JS_WaitClientRes:
-            msg = _("is waiting on max Client jobs");
-           break;
-        case JS_WaitJobRes:
-            msg = _("is waiting on max Job jobs");
-           break;
-        case JS_WaitPriority:
-            msg = _("is waiting for higher priority jobs to finish");
-           break;
-        case JS_WaitMaxJobs:
-            msg = _("is waiting on max total jobs");
-           break;
-        case JS_WaitStartTime:
-            msg = _("is waiting for its start time");
-           break;
+      case JS_Created:
+         msg = _("is waiting execution");
+        break;
+      case JS_Running:
+         msg = _("is running");
+        break;
+      case JS_Blocked:
+         msg = _("is blocked");
+        break;
+      case JS_Terminated:
+         msg = _("has terminated");
+        break;
+      case JS_ErrorTerminated:
+         msg = _("has erred");
+        break;
+      case JS_Canceled:
+         msg = _("has been canceled");
+        break;
+      case JS_WaitFD:
+        msg = (char *) get_pool_memory(PM_FNAME);
+         Mmsg(&msg, _("is waiting on Client %s"), jcr->client->hdr.name);
+        pool_mem = TRUE;
+        break;
+      case JS_WaitSD:
+        msg = (char *) get_pool_memory(PM_FNAME);
+         Mmsg(&msg, _("is waiting on Storage %s"), jcr->store->hdr.name);
+        pool_mem = TRUE;
+        break;
+      case JS_WaitStoreRes:
+         msg = _("is waiting on max Storage jobs");
+        break;
+      case JS_WaitClientRes:
+         msg = _("is waiting on max Client jobs");
+        break;
+      case JS_WaitJobRes:
+         msg = _("is waiting on max Job jobs");
+        break;
+      case JS_WaitPriority:
+         msg = _("is waiting for higher priority jobs to finish");
+        break;
+      case JS_WaitMaxJobs:
+         msg = _("is waiting on max total jobs");
+        break;
+      case JS_WaitStartTime:
+         msg = _("is waiting for its start time");
+        break;
 
 
-        default:
-           msg = (char *) get_pool_memory(PM_FNAME);
-            Mmsg(&msg, _("is in unknown state %c"), jcr->JobStatus);
-           pool_mem = TRUE;
-           break;
+      default:
+        msg = (char *) get_pool_memory(PM_FNAME);
+         Mmsg(&msg, _("is in unknown state %c"), jcr->JobStatus);
+        pool_mem = TRUE;
+        break;
       }
+      /* 
+       * Now report Storage daemon status code 
+       */
       switch (jcr->SDJobStatus) {
-        case JS_WaitMount:
-           if (pool_mem) {
-              free_pool_memory(msg);
-              pool_mem = FALSE;
-           }
-            msg = _("is waiting for a mount request");
-           break;
-        case JS_WaitMedia:
-           if (pool_mem) {
-              free_pool_memory(msg);
-              pool_mem = FALSE;
-           }
-            msg = _("is waiting for an appendable Volume");
-           break;
-        case JS_WaitFD:
-           if (!pool_mem) {
-              msg = (char *) get_pool_memory(PM_FNAME);
-              pool_mem = TRUE;
-           }
-            Mmsg(&msg, _("is waiting for Client %s to connect to Storage %s"),
-                jcr->client->hdr.name, jcr->store->hdr.name);
-           break;
-
+      case JS_WaitMount:
+        if (pool_mem) {
+           free_pool_memory(msg);
+           pool_mem = FALSE;
+        }
+         msg = _("is waiting for a mount request");
+        break;
+      case JS_WaitMedia:
+        if (pool_mem) {
+           free_pool_memory(msg);
+           pool_mem = FALSE;
+        }
+         msg = _("is waiting for an appendable Volume");
+        break;
+      case JS_WaitFD:
+        if (!pool_mem) {
+           msg = (char *) get_pool_memory(PM_FNAME);
+           pool_mem = TRUE;
+        }
+         Mmsg(&msg, _("is waiting for Client %s to connect to Storage %s"),
+             jcr->client->hdr.name, jcr->store->hdr.name);
+        break;
       }
       bsendmsg(ua, _("JobId %d Job %s %s.\n"), jcr->JobId, jcr->Job, msg);
       if (pool_mem) {
@@ -397,12 +399,16 @@ static void prt_runtime(UAContext *ua, JOB *job, int level, time_t runtime, POOL
 {
    char dt[MAX_TIME_LENGTH];      
    bool ok = false;
+   bool close_db = false;
    JCR *jcr = ua->jcr;
    MEDIA_DBR mr;
    memset(&mr, 0, sizeof(mr));
    if (job->JobType == JT_BACKUP) {
       jcr->db = NULL;
       ok = complete_jcr_for_job(jcr, job, pool);
+      if (jcr->db) {
+        close_db = true;             /* new db opened, remember to close it */
+      }
       if (ok) {
         ok = find_next_volume_for_append(jcr, &mr, 0);
       }
@@ -414,10 +420,10 @@ static void prt_runtime(UAContext *ua, JOB *job, int level, time_t runtime, POOL
    bsendmsg(ua, _("%-14s %-8s %-18s %-18s %s\n"), 
       level_to_str(level), job_type_to_str(job->JobType), dt, job->hdr.name,
       mr.VolumeName);
-   if (jcr->db) {
+   if (close_db) {
       db_close_database(jcr, jcr->db);
-      jcr->db = ua->db;
    }
+   jcr->db = ua->db;                 /* restore ua db to jcr */
 
 }
 
@@ -427,103 +433,31 @@ static void prt_runtime(UAContext *ua, JOB *job, int level, time_t runtime, POOL
  */
 static void print_jobs_scheduled(UAContext *ua)
 {
-   time_t now, runtime, tomorrow;
+   time_t runtime;
    RUN *run;
    JOB *job;
-   SCHED *sched;
-   struct tm tm;
-   int mday, wday, month, wpos, tmday, twday, tmonth, twpos, i, hour;
-   int tod, tom;
-   int found;
-   int hdr_printed = FALSE;
+   bool hdr_printed = false;
    int level;
 
    Dmsg0(200, "enter find_runs()\n");
 
-   now = time(NULL);
-   localtime_r(&now, &tm);
-   mday = tm.tm_mday - 1;
-   wday = tm.tm_wday;
-   month = tm.tm_mon;
-   wpos = (tm.tm_mday - 1) / 7;
-
-   tomorrow = now + 60 * 60 * 24;
-   localtime_r(&tomorrow, &tm);
-   tmday = tm.tm_mday - 1;
-   twday = tm.tm_wday;
-   tmonth = tm.tm_mon;
-   twpos  = (tm.tm_mday - 1) / 7;
-
    /* Loop through all jobs */
    LockRes();
    for (job=NULL; (job=(JOB *)GetNextRes(R_JOB, (RES *)job)); ) {
       level = job->level;   
-      sched = job->schedule;
-      if (sched == NULL) {           /* scheduled? */
-        continue;                    /* no, skip this job */
+      run = find_next_run(job, runtime);
+      if (!run) {
+        continue;
       }
-      for (run=sched->run; run; run=run->next) {
-        if (run->level) {
-           level = run->level;
-        }
-        /* 
-         * Find runs in next 24 hours
-         */
-        tod = (bit_is_set(mday, run->mday) || bit_is_set(wday, run->wday)) && 
-               bit_is_set(month, run->month) && bit_is_set(wpos, run->wpos);
-
-        tom = (bit_is_set(tmday, run->mday) || bit_is_set(twday, run->wday)) &&
-               bit_is_set(tmonth, run->month) && bit_is_set(wpos, run->wpos);
-
-         Dmsg2(200, "tod=%d tom=%d\n", tod, tom);
-        found = FALSE;
-        if (tod) {                   /* Jobs scheduled today (next 24 hours) */
-           /* find time (time_t) job is to be run */
-           localtime_r(&now, &tm);
-           hour = 0;
-           for (i=tm.tm_hour; i < 24; i++) {
-              if (bit_is_set(i, run->hour)) {
-                 tm.tm_hour = i;
-                 tm.tm_min = run->minute;
-                 tm.tm_sec = 0;
-                 runtime = mktime(&tm);
-                 if (runtime > now) {
-                    if (!hdr_printed) {
-                       hdr_printed = TRUE;
-                       prt_runhdr(ua);
-                    }
-                    prt_runtime(ua, job, level, runtime, run->pool);
-                    found = TRUE;
-                    break;
-                 }
-              }
-           }
-        }
+      if (run->level) {
+        level = run->level;
+      }
+      if (!hdr_printed) {
+        hdr_printed = true;
+        prt_runhdr(ua);
+      }
+      prt_runtime(ua, job, level, runtime, run->pool);
 
-//       Dmsg2(200, "runtime=%d now=%d\n", runtime, now);
-        if (!found && tom) {            /* look at jobs scheduled tomorrow */
-           localtime_r(&tomorrow, &tm);
-           hour = 0;
-           for (i=0; i < 24; i++) {
-              if (bit_is_set(i, run->hour)) {
-                 hour = i;
-                 break;
-              }
-           }
-           tm.tm_hour = hour;
-           tm.tm_min = run->minute;
-           tm.tm_sec = 0;
-           runtime = mktime(&tm);
-            Dmsg2(200, "truntime=%d now=%d\n", runtime, now);
-           if (runtime < tomorrow) {
-              if (!hdr_printed) {
-                 hdr_printed = TRUE;
-                 prt_runhdr(ua);
-              }
-              prt_runtime(ua, job, level, runtime, run->pool);
-           }
-        }
-      } /* end for loop over runs */ 
    } /* end for loop over resources */
    UnlockRes();
    Dmsg0(200, "Leave find_runs()\n");