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);
{
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;
}
}
/* 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;
}
}
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
*/
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:
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) {
} 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)
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);
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");
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);
free_locked_jcr(jcr);
}
unlock_jcr_chain();
-
bsendmsg(ua, "\n");
+ Dmsg0(200, "leave list_run_jobs()\n");
}
static void list_terminated_jobs(UAContext *ua)
char dt[MAX_TIME_LENGTH], b1[30], b2[30];
char level[10];
- if (last_jobs->size() == 0) {
+ if (last_jobs->empty()) {
bsendmsg(ua, _("No Terminated Jobs.\n"));
return;
}
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:
*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),