From: Kern Sibbald Date: Fri, 26 Dec 2003 17:37:54 +0000 (+0000) Subject: Define foreach_res() + work on jobdefs + bstrftime_nc X-Git-Tag: Release-7.0.0~9780 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=7f9caa4ed605a622ab1b7e3cf2d8cbd215270743;p=bacula%2Fbacula Define foreach_res() + work on jobdefs + bstrftime_nc git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@956 91ce42f0-d328-0410-95d8-f526ca767f89 --- diff --git a/bacula/src/dird/dird.c b/bacula/src/dird/dird.c index f839831a5d..8a0c47ed52 100644 --- a/bacula/src/dird/dird.c +++ b/bacula/src/dird/dird.c @@ -315,7 +315,7 @@ static int check_resources() LockRes(); - job = (JOB *)GetNextRes(R_JOB, NULL); + job = (JOB *)GetNextRes(R_JOB, NULL); director = (DIRRES *)GetNextRes(R_DIRECTOR, NULL); if (!director) { Jmsg(NULL, M_FATAL, 0, _("No Director resource defined in %s\n\ @@ -341,7 +341,7 @@ Without that I don't know who I am :-(\n"), configfile); Jmsg(NULL, M_FATAL, 0, _("No Job records defined in %s\n"), configfile); OK = FALSE; } - for (job=NULL; (job = (JOB *)GetNextRes(R_JOB, (RES *)job)); ) { + foreach_res(job, R_JOB) { if (!job->client) { Jmsg(NULL, M_FATAL, 0, _("No Client record defined for job %s\n"), job->hdr.name); OK = FALSE; @@ -384,7 +384,8 @@ Without that I don't know who I am :-(\n"), configfile); create_pool(NULL, db, job->pool, POOL_OP_UPDATE); /* update request */ } /* Set default value in all counters */ - for (COUNTER *counter=NULL; (counter = (COUNTER *)GetNextRes(R_COUNTER, (RES *)counter)); ) { + COUNTER *counter; + foreach_res(counter, R_COUNTER) { /* Write to catalog? */ if (!counter->created && counter->Catalog == catalog) { COUNTER_DBR cr; diff --git a/bacula/src/dird/dird_conf.c b/bacula/src/dird/dird_conf.c index e1fa607ab3..b6738d5f83 100644 --- a/bacula/src/dird/dird_conf.c +++ b/bacula/src/dird/dird_conf.c @@ -61,8 +61,6 @@ extern void store_inc(LEX *lc, struct res_items *item, int index, int pass); /* Forward referenced subroutines */ -static void store_backup(LEX *lc, struct res_items *item, int index, int pass); -static void store_restore(LEX *lc, struct res_items *item, int index, int pass); static void store_jobtype(LEX *lc, struct res_items *item, int index, int pass); static void store_level(LEX *lc, struct res_items *item, int index, int pass); static void store_replace(LEX *lc, struct res_items *item, int index, int pass); @@ -190,44 +188,41 @@ static struct res_items cat_items[] = { * name handler value code flags default_value */ static struct res_items job_items[] = { - {"name", store_name, ITEM(res_job.hdr.name), 0, ITEM_REQUIRED, 0}, - {"description", store_str, ITEM(res_job.hdr.desc), 0, 0, 0}, - {"backup", store_backup, ITEM(res_job), JT_BACKUP, 0, 0}, - {"verify", store_backup, ITEM(res_job), JT_VERIFY, 0, 0}, - {"restore", store_restore, ITEM(res_job), JT_RESTORE, 0, 0}, - {"schedule", store_res, ITEM(res_job.schedule), R_SCHEDULE, 0, 0}, - {"type", store_jobtype, ITEM(res_job), 0, 0, 0}, - {"level", store_level, ITEM(res_job), 0, 0, 0}, - {"messages", store_res, ITEM(res_job.messages), R_MSGS, 0, 0}, - {"storage", store_res, ITEM(res_job.storage), R_STORAGE, 0, 0}, - {"pool", store_res, ITEM(res_job.pool), R_POOL, 0, 0}, - {"client", store_res, ITEM(res_job.client), R_CLIENT, 0, 0}, - {"fileset", store_res, ITEM(res_job.fileset), R_FILESET, 0, 0}, - {"jobdefs", store_defs, ITEM(res_job), R_JOB, 0, 0}, - {"verifyjob", store_res, ITEM(res_job.verify_job), R_JOB, 0, 0}, - {"where", store_dir, ITEM(res_job.RestoreWhere), 0, 0, 0}, - {"replace", store_replace, ITEM(res_job.replace), 0, ITEM_DEFAULT, REPLACE_ALWAYS}, - {"bootstrap",store_dir, ITEM(res_job.RestoreBootstrap), 0, 0, 0}, - {"maxruntime", store_time, ITEM(res_job.MaxRunTime), 0, 0, 0}, - {"maxwaittime", store_time, ITEM(res_job.MaxWaitTime), 0, 0, 0}, - {"maxstartdelay", store_time,ITEM(res_job.MaxStartDelay), 0, 0, 0}, + {"name", store_name, ITEM(res_job.hdr.name), 0, ITEM_REQUIRED, 0}, + {"description", store_str, ITEM(res_job.hdr.desc), 0, 0, 0}, + {"type", store_jobtype, ITEM(res_job), 0, 0, 0}, + {"level", store_level, ITEM(res_job), 0, 0, 0}, + {"messages", store_res, ITEM(res_job.messages), R_MSGS, 0, 0}, + {"storage", store_res, ITEM(res_job.storage), R_STORAGE, 0, 0}, + {"pool", store_res, ITEM(res_job.pool), R_POOL, 0, 0}, + {"client", store_res, ITEM(res_job.client), R_CLIENT, 0, 0}, + {"fileset", store_res, ITEM(res_job.fileset), R_FILESET, 0, 0}, + {"schedule", store_res, ITEM(res_job.schedule), R_SCHEDULE, 0, 0}, + {"verifyjob", store_res, ITEM(res_job.verify_job), R_JOB, 0, 0}, + {"jobdefs", store_res, ITEM(res_job.jobdefs), R_JOBDEFS, 0, 0}, + {"where", store_dir, ITEM(res_job.RestoreWhere), 0, 0, 0}, + {"bootstrap",store_dir, ITEM(res_job.RestoreBootstrap), 0, 0, 0}, + {"writebootstrap",store_dir, ITEM(res_job.WriteBootstrap), 0, 0, 0}, + {"replace", store_replace, ITEM(res_job.replace), 0, ITEM_DEFAULT, REPLACE_ALWAYS}, + {"maxruntime", store_time, ITEM(res_job.MaxRunTime), 0, 0, 0}, + {"maxwaittime", store_time, ITEM(res_job.MaxWaitTime), 0, 0, 0}, + {"maxstartdelay",store_time, ITEM(res_job.MaxStartDelay), 0, 0, 0}, + {"jobretention", store_time, ITEM(res_job.JobRetention), 0, 0, 0}, {"prefixlinks", store_yesno, ITEM(res_job.PrefixLinks), 1, ITEM_DEFAULT, 0}, {"prunejobs", store_yesno, ITEM(res_job.PruneJobs), 1, ITEM_DEFAULT, 0}, {"prunefiles", store_yesno, ITEM(res_job.PruneFiles), 1, ITEM_DEFAULT, 0}, - {"prunevolumes", store_yesno, ITEM(res_job.PruneVolumes), 1, ITEM_DEFAULT, 0}, + {"prunevolumes",store_yesno, ITEM(res_job.PruneVolumes), 1, ITEM_DEFAULT, 0}, + {"spoolattributes",store_yesno, ITEM(res_job.SpoolAttributes), 1, ITEM_DEFAULT, 0}, {"runbeforejob", store_str, ITEM(res_job.RunBeforeJob), 0, 0, 0}, {"runafterjob", store_str, ITEM(res_job.RunAfterJob), 0, 0, 0}, {"runafterfailedjob", store_str, ITEM(res_job.RunAfterFailedJob), 0, 0, 0}, {"clientrunbeforejob", store_str, ITEM(res_job.ClientRunBeforeJob), 0, 0, 0}, {"clientrunafterjob", store_str, ITEM(res_job.ClientRunAfterJob), 0, 0, 0}, - {"spoolattributes", store_yesno, ITEM(res_job.SpoolAttributes), 1, ITEM_DEFAULT, 0}, - {"writebootstrap", store_dir, ITEM(res_job.WriteBootstrap), 0, 0, 0}, {"maximumconcurrentjobs", store_pint, ITEM(res_job.MaxConcurrentJobs), 0, ITEM_DEFAULT, 1}, {"rescheduleonerror", store_yesno, ITEM(res_job.RescheduleOnError), 1, ITEM_DEFAULT, 0}, {"rescheduleinterval", store_time, ITEM(res_job.RescheduleInterval), 0, ITEM_DEFAULT, 60 * 30}, {"rescheduletimes", store_pint, ITEM(res_job.RescheduleTimes), 0, 0, 0}, {"priority", store_pint, ITEM(res_job.Priority), 0, ITEM_DEFAULT, 10}, - {"jobretention", store_time, ITEM(res_job.JobRetention), 0, 0, 0}, {NULL, NULL, NULL, 0, 0, 0} }; @@ -324,7 +319,6 @@ struct s_res resources[] = { {"director", dir_items, R_DIRECTOR, NULL}, {"client", cli_items, R_CLIENT, NULL}, {"job", job_items, R_JOB, NULL}, - {"jobdefs", job_items, R_JOBDEFS, NULL}, {"storage", store_items, R_STORAGE, NULL}, {"catalog", cat_items, R_CATALOG, NULL}, {"schedule", sch_items, R_SCHEDULE, NULL}, @@ -334,6 +328,7 @@ struct s_res resources[] = { {"messages", msgs_items, R_MSGS, NULL}, {"counter", counter_items, R_COUNTER, NULL}, {"console", con_items, R_CONSOLE, NULL}, + {"jobdefs", job_items, R_JOBDEFS, NULL}, {NULL, NULL, 0, NULL} }; @@ -370,6 +365,7 @@ struct s_jt jobtypes[] = { {NULL, 0} }; +#ifdef old_deprecated_code /* Keywords (RHS) permitted in Backup and Verify records */ static struct s_kw BakVerFields[] = { @@ -389,6 +385,7 @@ static struct s_kw RestoreFields[] = { {"bootstrap", 'B'}, /* bootstrap file */ {NULL, 0} }; +#endif /* Options permitted in Restore replace= */ struct s_kw ReplaceOptions[] = { @@ -710,7 +707,7 @@ static void free_incexe(INCEXE *incexe) } /* - * Free memory of resource. + * Free memory of resource -- called when daemon terminates. * NB, we don't need to worry about freeing any references * to other resources as they will be freed when that * resource chain is traversed. Mainly we worry about freeing @@ -907,6 +904,9 @@ void save_resource(int type, struct res_items *items, int pass) int i, size; int error = 0; + if (type == R_JOBDEFS) { + return; /* nothing required */ + } /* * Ensure that all required items are present */ @@ -923,7 +923,8 @@ void save_resource(int type, struct res_items *items, int pass) } } - /* During pass 2 in each "store" routine, we looked up pointers + /* + * During pass 2 in each "store" routine, we looked up pointers * to all the resources referrenced in the current resource, now we * must copy their addresses from the static record to the allocated * record. @@ -948,6 +949,7 @@ void save_resource(int type, struct res_items *items, int pass) res->res_dir.messages = res_all.res_dir.messages; break; case R_JOB: + case R_JOBDEFS: if ((res = (URES *)GetResWithName(type, res_all.res_dir.hdr.name)) == NULL) { Emsg1(M_ERROR_TERM, 0, "Cannot find Job resource %s\n", res_all.res_dir.hdr.name); @@ -959,21 +961,24 @@ void save_resource(int type, struct res_items *items, int pass) res->res_job.storage = res_all.res_job.storage; res->res_job.pool = res_all.res_job.pool; res->res_job.verify_job = res_all.res_job.verify_job; - if (res->res_job.JobType == 0) { - Emsg1(M_ERROR_TERM, 0, "Job Type not defined for Job resource %s\n", res_all.res_dir.hdr.name); - } - if (res->res_job.level != 0) { - int i; - for (i=0; joblevels[i].level_name; i++) { - if (joblevels[i].level == res->res_job.level && - joblevels[i].job_type == res->res_job.JobType) { - i = 0; - break; - } + res->res_job.jobdefs = res_all.res_job.jobdefs; + if (type == R_JOB) { + if (res->res_job.JobType == 0) { + Emsg1(M_ERROR_TERM, 0, "Job Type not defined for Job resource %s\n", res_all.res_dir.hdr.name); } - if (i != 0) { - Emsg1(M_ERROR_TERM, 0, "Inappropriate level specified in Job resource %s\n", - res_all.res_dir.hdr.name); + if (res->res_job.level != 0) { + int i; + for (i=0; joblevels[i].level_name; i++) { + if (joblevels[i].level == res->res_job.level && + joblevels[i].job_type == res->res_job.JobType) { + i = 0; + break; + } + } + if (i != 0) { + Emsg1(M_ERROR_TERM, 0, "Inappropriate level specified in Job resource %s\n", + res_all.res_dir.hdr.name); + } } } break; @@ -992,7 +997,8 @@ void save_resource(int type, struct res_items *items, int pass) res->res_client.catalog = res_all.res_client.catalog; break; case R_SCHEDULE: - /* Schedule is a bit different in that it contains a RUN record + /* + * Schedule is a bit different in that it contains a RUN record * chain which isn't a "named" resource. This chain was linked * in by run_conf.c during pass 2, so here we jam the pointer * into the Schedule resource. @@ -1070,6 +1076,9 @@ void save_resource(int type, struct res_items *items, int pass) } /* Common */ if (!error) { + if (type == R_JOBDEFS) { + Dmsg0(200, "Storing JobDefs definition.\n"); + } res = (URES *)malloc(size); memcpy(res, &res_all, size); if (!resources[rindex].res_head) { @@ -1160,6 +1169,7 @@ static void store_replace(LEX *lc, struct res_items *item, int index, int pass) set_bit(index, res_all.hdr.item_present); } +#ifdef old_deprecated_code /* * Store backup/verify info for Job record * @@ -1356,3 +1366,4 @@ static void store_restore(LEX *lc, struct res_items *item, int index, int pass) lc->options = options; /* reset original options */ set_bit(index, res_all.hdr.item_present); } +#endif diff --git a/bacula/src/dird/dird_conf.h b/bacula/src/dird/dird_conf.h index ef375599cc..604c879983 100644 --- a/bacula/src/dird/dird_conf.h +++ b/bacula/src/dird/dird_conf.h @@ -211,6 +211,7 @@ struct JOB { STORE *storage; /* Where is device -- Storage daemon */ POOL *pool; /* Where is media -- Media Pool */ JOB *verify_job; /* Job name to verify */ + JOB *jobdefs; /* Job defaults */ uint32_t NumConcurrentJobs; /* number of concurrent jobs running */ }; diff --git a/bacula/src/dird/scheduler.c b/bacula/src/dird/scheduler.c index 3aec031f38..977d6199b0 100644 --- a/bacula/src/dird/scheduler.c +++ b/bacula/src/dird/scheduler.c @@ -101,7 +101,8 @@ JCR *wait_for_next_job(char *one_shot_job_to_run) #define list_chain #ifdef list_chain - for (job_item *je=NULL; (je=(job_item *)jobs_to_run->next(je)); ) { + job_item *je; + foreach_dlist(je, jobs_to_run) { dump_job(je, "Walk queue"); } #endif @@ -164,11 +165,14 @@ JCR *wait_for_next_job(char *one_shot_job_to_run) */ void term_scheduler() { - /* Release all queued job entries to be run */ - for (void *je=NULL; (je=jobs_to_run->next(je)); ) { - free(je); + if (jobs_to_run) { + job_item *je; + /* Release all queued job entries to be run */ + foreach_dlist(je, jobs_to_run) { + free(je); + } + delete jobs_to_run; } - delete jobs_to_run; } /* @@ -217,7 +221,7 @@ static void find_runs() /* Loop through all jobs */ LockRes(); - for (job=NULL; (job=(JOB *)GetNextRes(R_JOB, (RES *)job)); ) { + foreach_res(job, R_JOB) { sched = job->schedule; if (sched == NULL) { /* scheduled? */ continue; /* no, skip this job */ @@ -291,7 +295,7 @@ static void find_runs() static void add_job(JOB *job, RUN *run, time_t now, time_t runtime) { - job_item *ji = NULL; + job_item *ji; bool inserted = false; /* * Don't run any job that ran less than a minute ago, but @@ -320,7 +324,7 @@ static void add_job(JOB *job, RUN *run, time_t now, time_t runtime) } /* Add this job to the wait queue in runtime, priority sorted order */ - while ( (ji=(job_item *)jobs_to_run->next(ji)) ) { + foreach_dlist(ji, jobs_to_run) { if (ji->runtime > je->runtime || (ji->runtime == je->runtime && ji->Priority > je->Priority)) { jobs_to_run->insert_before(je, ji); diff --git a/bacula/src/dird/ua_select.c b/bacula/src/dird/ua_select.c index 98d2528c4a..531039f8d8 100644 --- a/bacula/src/dird/ua_select.c +++ b/bacula/src/dird/ua_select.c @@ -820,7 +820,7 @@ int get_media_type(UAContext *ua, char *MediaType, int max_media) start_prompt(ua, _("Media Types defined in conf file:\n")); LockRes(); - for (store = NULL; (store = (STORE *)GetNextRes(R_STORAGE, (RES *)store)); ) { + foreach_res(store, R_STORAGE) { add_prompt(ua, store->media_type); } UnlockRes(); diff --git a/bacula/src/dird/ua_status.c b/bacula/src/dird/ua_status.c index f780810106..766c6cda63 100644 --- a/bacula/src/dird/ua_status.c +++ b/bacula/src/dird/ua_status.c @@ -120,26 +120,26 @@ 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; for (j=0; jaddress, store->address) == 0 && unique_store[j]->SDport == store->SDport) { - found = 1; + found = true; break; } } @@ -158,20 +158,19 @@ 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; for (j=0; jaddress, client->address) == 0 && unique_client[j]->FDport == client->FDport) { - found = 1; + found = true; break; } } @@ -196,8 +195,7 @@ 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 */ + bstrftime_nc(dt, sizeof(dt), daemon_start_time); bsendmsg(ua, _("Daemon started %s, %d Job%s run.\n"), dt, last_job.NumJobs, last_job.NumJobs == 1 ? "" : "s"); /* @@ -314,8 +312,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: @@ -350,7 +347,7 @@ static void list_scheduled_jobs(UAContext *ua) /* Loop through all jobs */ LockRes(); - for (job=NULL; (job=(JOB *)GetNextRes(R_JOB, (RES *)job)); ) { + foreach_res(job, R_JOB) { for (run=NULL; (run = find_next_run(run, job, runtime)); ) { level = job->level; if (run->level) { @@ -390,8 +387,7 @@ static void list_running_jobs(UAContext *ua) * jobs in the status output. */ if (jcr->JobType == JT_CONSOLE) { - bstrftime(dt, sizeof(dt), jcr->start_time); - strcpy(dt+7, dt+9); /* cut century */ + bstrftime_nc(dt, sizeof(dt), jcr->start_time); bsendmsg(ua, _("Console connected at %s\n"), dt); } njobs--; @@ -549,8 +545,7 @@ static void list_terminated_jobs(UAContext *ua) 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: diff --git a/bacula/src/filed/status.c b/bacula/src/filed/status.c index ff6f835354..4207bb1157 100755 --- a/bacula/src/filed/status.c +++ b/bacula/src/filed/status.c @@ -59,8 +59,7 @@ static void do_status(void sendit(char *msg, int len, void *sarg), void *arg) len = Mmsg(&msg, "%s Version: " VERSION " (" BDATE ") %s %s %s\n", my_name, HOST_OS, DISTNAME, DISTVER); sendit(msg, len, arg); - bstrftime(dt, sizeof(dt), daemon_start_time); - strcpy(dt+7, dt+9); /* cut century */ + bstrftime_nc(dt, sizeof(dt), daemon_start_time); len = Mmsg(&msg, _("Daemon started %s, %d Job%s run.\n"), dt, last_job.NumJobs, last_job.NumJobs == 1 ? "" : "s"); sendit(msg, len, arg); @@ -89,8 +88,7 @@ static void do_status(void sendit(char *msg, int len, void *sarg), void *arg) struct s_last_job *je; lock_last_jobs_list(); for (je=NULL; (je=(s_last_job *)last_jobs->next(je)); ) { - bstrftime(dt, sizeof(dt), je->end_time); - strcpy(dt+7, dt+9); /* cut century */ + bstrftime_nc(dt, sizeof(dt), je->end_time); len = Mmsg(&msg, _("Last Job %s finished at %s\n"), je->Job, dt); sendit(msg, len, arg); @@ -110,8 +108,7 @@ static void do_status(void sendit(char *msg, int len, void *sarg), void *arg) Dmsg0(200, "Begin status jcr loop.\n"); lock_jcr_chain(); for (njcr=NULL; (njcr=get_next_jcr(njcr)); ) { - bstrftime(dt, sizeof(dt), njcr->start_time); - strcpy(dt+7, dt+9); /* cut century */ + bstrftime_nc(dt, sizeof(dt), njcr->start_time); if (njcr->JobId == 0) { len = Mmsg(&msg, _("Director connected at: %s\n"), dt); } else { @@ -190,8 +187,7 @@ static void list_terminated_jobs(void *arg) char *termstat; char buf[1000]; - 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: diff --git a/bacula/src/lib/btime.c b/bacula/src/lib/btime.c index 8cd302f472..825573e2cf 100644 --- a/bacula/src/lib/btime.c +++ b/bacula/src/lib/btime.c @@ -53,6 +53,21 @@ char *bstrftime(char *dt, int maxlen, utime_t tim) return dt; } +/* Formatted time for user display: dd-Mon-yy hh:mm (no century) */ +char *bstrftime_nc(char *dt, int maxlen, utime_t tim) +{ + time_t ttime = tim; + struct tm tm; + + /* ***FIXME**** the format and localtime_r() should be user configurable */ + localtime_r(&ttime, &tm); + /* NOTE! since the compiler complains about %y, I use %y and cut the century */ + strftime(dt, maxlen, "%d-%b-%Y %H:%M", &tm); + strcpy(dt+7, dt+9); + return dt; +} + + /* Unix time to standard time string yyyy-mm-dd hh:mm:ss */ char *bstrutime(char *dt, int maxlen, utime_t tim) { diff --git a/bacula/src/lib/btime.h b/bacula/src/lib/btime.h index 9dfc88b8b2..9f5b5d1986 100644 --- a/bacula/src/lib/btime.h +++ b/bacula/src/lib/btime.h @@ -32,16 +32,17 @@ #define __btime_INCLUDED /* New btime definition -- use this */ -extern btime_t get_current_btime(void); -extern time_t btime_to_unix(btime_t bt); /* bacula time to epoch time */ -extern utime_t btime_to_utime(btime_t bt); /* bacula time to utime_t */ +btime_t get_current_btime(void); +time_t btime_to_unix(btime_t bt); /* bacula time to epoch time */ +utime_t btime_to_utime(btime_t bt); /* bacula time to utime_t */ -extern int tm_wom(int mday, int wday); -extern int tm_woy(time_t stime); +int tm_wom(int mday, int wday); +int tm_woy(time_t stime); -extern char *bstrftime(char *dt, int maxlen, utime_t tim); -extern char *bstrutime(char *dt, int maxlen, utime_t tim); -extern utime_t str_to_utime(char *str); +char *bstrutime(char *dt, int maxlen, utime_t tim); +char *bstrftime(char *dt, int maxlen, utime_t tim); +char *bstrftime_nc(char *dt, int maxlen, utime_t tim); +utime_t str_to_utime(char *str); /* =========================================================== */ diff --git a/bacula/src/lib/dlist.h b/bacula/src/lib/dlist.h index d50178a186..11d2f76d75 100644 --- a/bacula/src/lib/dlist.h +++ b/bacula/src/lib/dlist.h @@ -35,7 +35,7 @@ * Loop var through each member of list */ #define foreach_dlist(var, list) \ - for((var)=NULL; ((void *)(var))=(list)->next((var)); ) + for((var)=NULL; (((void *)(var))=(list)->next(var)); ) struct dlink { void *next; diff --git a/bacula/src/lib/parse_conf.c b/bacula/src/lib/parse_conf.c index 927deb90c1..aa908f9b8a 100755 --- a/bacula/src/lib/parse_conf.c +++ b/bacula/src/lib/parse_conf.c @@ -426,7 +426,8 @@ void store_res(LEX *lc, struct res_items *item, int index, int pass) set_bit(index, res_all.hdr.item_present); } -/* Store default values for Resource from xxxDefs +/* + * Store default values for Resource from xxxDefs * If we are in pass 2, do a lookup of the * resource and store everything not explicitly set * in main resource. @@ -440,13 +441,23 @@ void store_defs(LEX *lc, struct res_items *item, int index, int pass) lex_get_token(lc, T_NAME); if (pass == 2) { + Dmsg2(200, "Code=%d name=%s\n", item->code, lc->str); res = GetResWithName(item->code, lc->str); if (res == NULL) { - scan_err3(lc, _("Could not find config Resource %s referenced on line %d : %s\n"), + scan_err3(lc, _("Missing config Resource \"%s\" referenced on line %d : %s\n"), lc->str, lc->line_no, lc->line); } - /* for each item not set, we copy the field from item */ + /* for each item not set, we copy the field from res */ +#ifdef xxx + for (int i=0; item->name;; i++, item++) { + if (bit_is_set(i, res->item_present)) { + Dmsg2(000, "Item %d is present in %s\n", i, res->name); + } else { + Dmsg2(000, "Item %d is not present in %s\n", i, res->name); + } + } /* ***FIXME **** add code */ +#endif } scan_to_eol(lc); } diff --git a/bacula/src/lib/parse_conf.h b/bacula/src/lib/parse_conf.h index 6b07b0afa6..5d63dfc0dc 100644 --- a/bacula/src/lib/parse_conf.h +++ b/bacula/src/lib/parse_conf.h @@ -110,6 +110,11 @@ void free_resource(int type); void init_resource(int type, struct res_items *item); void save_resource(int type, struct res_items *item, int pass); char *res_to_str(int rcode); +/* Loop through each resource of type, returning in var */ +#define foreach_res(var, type) \ + for((var)=NULL; (((void *)(var))=GetNextRes((type), (RES *)var));) + + void store_str(LEX *lc, struct res_items *item, int index, int pass); void store_dir(LEX *lc, struct res_items *item, int index, int pass); diff --git a/bacula/src/stored/status.c b/bacula/src/stored/status.c index 161628ea4f..b9dbce14b6 100644 --- a/bacula/src/stored/status.c +++ b/bacula/src/stored/status.c @@ -63,8 +63,7 @@ int status_cmd(JCR *jcr) bnet_fsend(user, "\n%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 */ + bstrftime_nc(dt, sizeof(dt), daemon_start_time); bnet_fsend(user, _("Daemon started %s, %d Job%s run.\n"), dt, last_job.NumJobs, last_job.NumJobs == 1 ? "" : "s"); @@ -266,8 +265,7 @@ static void list_terminated_jobs(void *arg) char *termstat; char buf[1000]; - 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: