]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/dird/ua_status.c
Fix typo
[bacula/bacula] / bacula / src / dird / ua_status.c
index 819a2302b34495086af1e380fd9ee8e7c6de6644..7618ec6932f80fa25fcf2e561d55a877e2b9d0ce 100644 (file)
@@ -32,7 +32,7 @@
 
 extern char my_name[];
 extern time_t daemon_start_time;
-extern struct s_last_job last_job;
+extern int num_jobs_run;
 
 static void list_scheduled_jobs(UAContext *ua);
 static void list_running_jobs(UAContext *ua);
@@ -120,26 +120,29 @@ static void do_all_status(UAContext *ua, char *cmd)
 {
    STORE *store, **unique_store;
    CLIENT *client, **unique_client;
-   int i, j, found;
+   int i, j;
+   bool found;
 
    do_director_status(ua, cmd);
 
    /* Count Storage items */
    LockRes();
-   store = NULL;
-   for (i=0; (store = (STORE *)GetNextRes(R_STORAGE, (RES *)store)); i++)
-      { }
+   i = 0;
+   foreach_res(store, R_STORAGE) {
+      i++;
+   }
    unique_store = (STORE **) malloc(i * sizeof(STORE));
    /* Find Unique Storage address/port */        
-   store = (STORE *)GetNextRes(R_STORAGE, NULL);
    i = 0;
-   unique_store[i++] = store;
-   while ((store = (STORE *)GetNextRes(R_STORAGE, (RES *)store))) {
-      found = 0;
+   foreach_res(store, R_STORAGE) {
+      found = false;
+      if (!acl_access_ok(ua, Storage_ACL, store->hdr.name)) {
+        continue;
+      }
       for (j=0; j<i; j++) {
         if (strcmp(unique_store[j]->address, store->address) == 0 &&
             unique_store[j]->SDport == store->SDport) {
-           found = 1;
+           found = true;
            break;
         }
       }
@@ -158,20 +161,22 @@ static void do_all_status(UAContext *ua, char *cmd)
 
    /* Count Client items */
    LockRes();
-   client = NULL;
-   for (i=0; (client = (CLIENT *)GetNextRes(R_CLIENT, (RES *)client)); i++)
-      { }
+   i = 0;
+   foreach_res(client, R_CLIENT) {
+      i++;
+   }
    unique_client = (CLIENT **)malloc(i * sizeof(CLIENT));
    /* Find Unique Client address/port */        
-   client = (CLIENT *)GetNextRes(R_CLIENT, NULL);
    i = 0;
-   unique_client[i++] = client;
-   while ((client = (CLIENT *)GetNextRes(R_CLIENT, (RES *)client))) {
-      found = 0;
+   foreach_res(client, R_CLIENT) {
+      found = false;
+      if (!acl_access_ok(ua, Client_ACL, client->hdr.name)) {
+        continue;
+      }
       for (j=0; j<i; j++) {
         if (strcmp(unique_client[j]->address, client->address) == 0 &&
             unique_client[j]->FDport == client->FDport) {
-           found = 1;
+           found = true;
            break;
         }
       }
@@ -196,10 +201,9 @@ static void do_director_status(UAContext *ua, char *cmd)
 
    bsendmsg(ua, "%s Version: " VERSION " (" BDATE ") %s %s %s\n", my_name,
            HOST_OS, DISTNAME, DISTVER);
-   bstrftime(dt, sizeof(dt), daemon_start_time);
-   strcpy(dt+7, dt+9);    /* cut century */
-   bsendmsg(ua, _("Daemon started %s, %d Job%s run.\n"), dt, last_job.NumJobs,
-        last_job.NumJobs == 1 ? "" : "s");
+   bstrftime_nc(dt, sizeof(dt), daemon_start_time);
+   bsendmsg(ua, _("Daemon started %s, %d Job%s run since started.\n"), 
+        dt, num_jobs_run, num_jobs_run == 1 ? "" : "s");
    /*
     * List scheduled Jobs
     */
@@ -314,8 +318,7 @@ static void prt_runtime(UAContext *ua, JOB *job, int level, time_t runtime, POOL
          bstrncpy(mr.VolumeName, "*unknown*", sizeof(mr.VolumeName));
       }
    }
-   bstrftime(dt, sizeof(dt), runtime);
-   strcpy(dt+7, dt+9);    /* cut century */
+   bstrftime_nc(dt, sizeof(dt), runtime);
    switch (job->JobType) {
    case JT_ADMIN:
    case JT_RESTORE:
@@ -346,11 +349,14 @@ static void list_scheduled_jobs(UAContext *ua)
    int level, num_jobs = 0;
    bool hdr_printed = false;
 
-   Dmsg0(200, "enter find_runs()\n");
+   Dmsg0(200, "enter list_sched_jobs()\n");
 
    /* Loop through all jobs */
    LockRes();
-   for (job=NULL; (job=(JOB *)GetNextRes(R_JOB, (RES *)job)); ) {
+   foreach_res(job, R_JOB) {
+      if (!acl_access_ok(ua, Job_ACL, job->hdr.name)) {
+        continue;
+      }
       for (run=NULL; (run = find_next_run(run, job, runtime)); ) {
         level = job->level;   
         if (run->level) {
@@ -371,7 +377,7 @@ static void list_scheduled_jobs(UAContext *ua)
    } else {
       bsendmsg(ua, "\n");
    }
-   Dmsg0(200, "Leave find_runs()\n");
+   Dmsg0(200, "Leave list_sched_jobs_runs()\n");
 }
 
 static void list_running_jobs(UAContext *ua)
@@ -383,12 +389,18 @@ static void list_running_jobs(UAContext *ua)
    char level[10];
    bool pool_mem = false;
 
+   Dmsg0(200, "enter list_run_jobs()\n");
    lock_jcr_chain();
-   for (jcr=NULL; (jcr=get_next_jcr(jcr)); njobs++) {
+   foreach_jcr(jcr) {
+      njobs++;
       if (jcr->JobId == 0) {     /* this is us */
-        bstrftime(dt, sizeof(dt), jcr->start_time);
-        strcpy(dt+7, dt+9);     /* cut century */
-         bsendmsg(ua, _("Console connected at %s\n"), dt);
+        /* this is a console or other control job. We only show console
+         * jobs in the status output.
+         */
+        if (jcr->JobType == JT_CONSOLE) {
+           bstrftime_nc(dt, sizeof(dt), jcr->start_time);
+            bsendmsg(ua, _("Console connected at %s\n"), dt);
+        }
         njobs--;
       }
       free_locked_jcr(jcr);
@@ -396,18 +408,19 @@ static void list_running_jobs(UAContext *ua)
    if (njobs == 0) {
       unlock_jcr_chain();
       bsendmsg(ua, _("No Running Jobs.\n"));
+      Dmsg0(200, "leave list_run_jobs()\n");
       return;
    }
    njobs = 0;
    bsendmsg(ua, _("\nRunning Jobs:\n"));
-   bsendmsg(ua, _("Level JobId  Job                        Status\n"));
-   bsendmsg(ua, _("====================================================================\n"));
-   for (jcr=NULL; (jcr=get_next_jcr(jcr)); njobs++) {
-      if (jcr->JobId == 0) {     /* this is us */
-        njobs--;
+   bsendmsg(ua, _(" JobId Level   Name                       Status\n"));
+   bsendmsg(ua, _("======================================================================\n"));
+   foreach_jcr(jcr) {
+      if (jcr->JobId == 0 || !acl_access_ok(ua, Job_ACL, jcr->job->hdr.name)) {
         free_locked_jcr(jcr);
         continue;
       }
+      njobs++;
       switch (jcr->JobStatus) {
       case JS_Created:
          msg = _("is waiting execution");
@@ -501,17 +514,17 @@ static void list_running_jobs(UAContext *ua)
       switch (jcr->JobType) {
       case JT_ADMIN:
       case JT_RESTORE:
-         bstrncpy(level, "    ", sizeof(level));
+         bstrncpy(level, "      ", sizeof(level));
         break;
       default:
         bstrncpy(level, level_to_str(jcr->JobLevel), sizeof(level));
-        level[4] = 0;
+        level[7] = 0;
         break;
       }
 
-      bsendmsg(ua, _("%-4s %6d  %-20s %s\n"), 
-        level, 
+      bsendmsg(ua, _("%6d %-6s  %-20s %s\n"), 
         jcr->JobId,
+        level, 
         jcr->Job,
         msg);
 
@@ -522,8 +535,8 @@ static void list_running_jobs(UAContext *ua)
       free_locked_jcr(jcr);
    }
    unlock_jcr_chain();
-
    bsendmsg(ua, "\n");
+   Dmsg0(200, "leave list_run_jobs()\n");
 }
 
 static void list_terminated_jobs(UAContext *ua)
@@ -538,14 +551,13 @@ static void list_terminated_jobs(UAContext *ua)
    lock_last_jobs_list();
    struct s_last_job *je;
    bsendmsg(ua, _("\nTerminated Jobs:\n"));
-   bsendmsg(ua, _(" JobId  Level   Files        Bytes Status   Finished        Name \n"));
-   bsendmsg(ua, _("====================================================================\n"));
-   for (je=NULL; (je=(s_last_job *)last_jobs->next(je)); ) {
+   bsendmsg(ua, _(" JobId  Level     Files      Bytes     Status   Finished        Name \n"));
+   bsendmsg(ua, _("========================================================================\n"));
+   foreach_dlist(je, last_jobs) {
       char JobName[MAX_NAME_LENGTH];
       char *termstat;
 
-      bstrftime(dt, sizeof(dt), je->end_time);
-      strcpy(dt+7, dt+9);     /* cut century */
+      bstrftime_nc(dt, sizeof(dt), je->end_time);
       switch (je->JobType) {
       case JT_ADMIN:
       case JT_RESTORE:
@@ -585,7 +597,7 @@ static void list_terminated_jobs(UAContext *ua)
            *p = 0;
         }
       }
-      bsendmsg(ua, _("%6d  %-4s %8s %12s %-7s  %-8s %s\n"), 
+      bsendmsg(ua, _("%6d  %-6s %8s %14s %-7s  %-8s %s\n"), 
         je->JobId,
         level, 
         edit_uint64_with_commas(je->JobFiles, b1),