--- /dev/null
+ This patch fixes a problem with overriding storage daemon
+ specifications. Previously they were not always honored.
+ This implements more uniform handling. It also eliminates
+ an orphaned buffer situation using JobDefs.
+ Apply to version 1.36.1 with:
+
+ cd <bacula-source>
+ patch -p0 <1.36.1-store.patch
+ make
+ make install
+ ...
+
+Index: src/dird/job.c
+===================================================================
+RCS file: /cvsroot/bacula/bacula/src/dird/job.c,v
+retrieving revision 1.92
+diff -u -r1.92 job.c
+--- src/dird/job.c 21 Nov 2004 13:10:15 -0000 1.92
++++ src/dird/job.c 21 Dec 2004 13:04:08 -0000
+@@ -4,10 +4,10 @@
+ *
+ * Kern Sibbald, October MM
+ *
+- * Version $Id$
++ * Version $Id$
+ */
+ /*
+- Copyright (C) 2000-2004 Kern Sibbald and John Walker
++ Copyright (C) 2000-2004 Kern Sibbald
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+@@ -344,7 +344,7 @@
+ if (!ua->jcr->storage[0]) {
+ copy_storage(ua->jcr, jcr);
+ } else {
+- ua->jcr->store = jcr->store;
++ set_storage(ua->jcr, jcr->store);
+ }
+ if (!connect_to_storage_daemon(ua->jcr, 10, SDConnectTimeout, 1)) {
+ bsendmsg(ua, _("Failed to connect to Storage daemon.\n"));
+@@ -724,6 +724,12 @@
+ if (jcr->term_wait_inited) {
+ pthread_cond_destroy(&jcr->term_wait);
+ }
++ /* Delete lists setup to hold storage pointers */
++ for (int i=0; i<MAX_STORE; i++) {
++ if (jcr->storage[i]) {
++ delete jcr->storage[i];
++ }
++ }
+ jcr->job_end_push.destroy();
+ Dmsg0(200, "End dird free_jcr\n");
+ }
+@@ -749,10 +755,17 @@
+ break;
+ }
+ jcr->JobPriority = job->Priority;
++ /* Copy storage definitions -- deleted in dir_free_jcr above */
+ for (int i=0; i<MAX_STORE; i++) {
+- jcr->storage[i] = job->storage[i];
++ STORE *st;
++ if (job->storage[i]) {
++ jcr->storage[i] = New(alist(10, not_owned_by_alist));
++ foreach_alist(st, job->storage[i]) {
++ jcr->storage[i]->append(st);
++ }
++ }
+ }
+- if (!jcr->store && jcr->storage[0]) {
++ if (jcr->storage[0]) {
+ jcr->store = (STORE *)jcr->storage[0]->first();
+ }
+ jcr->client = job->client;
+@@ -805,6 +818,9 @@
+ for (int i=0; i < MAX_STORE; i++) {
+ if (old_jcr->storage[i]) {
+ STORE *st;
++ if (old_jcr->storage[i]) {
++ delete old_jcr->storage[i];
++ }
+ new_jcr->storage[i] = New(alist(10, not_owned_by_alist));
+ foreach_alist(st, old_jcr->storage[i]) {
+ new_jcr->storage[i]->append(st);
+@@ -817,3 +833,10 @@
+ }
+ }
+ }
++
++/* Set storage override */
++void set_storage(JCR *jcr, STORE *store)
++{
++ jcr->store = store;
++ jcr->storage[0]->prepend(store);
++}
+Index: src/dird/msgchan.c
+===================================================================
+RCS file: /cvsroot/bacula/bacula/src/dird/msgchan.c,v
+retrieving revision 1.32
+diff -u -r1.32 msgchan.c
+--- src/dird/msgchan.c 29 Sep 2004 19:58:17 -0000 1.32
++++ src/dird/msgchan.c 21 Dec 2004 13:04:08 -0000
+@@ -13,10 +13,10 @@
+ * Create a thread to interact with the Storage daemon
+ * who returns a job status and requests Catalog services, etc.
+ *
+- * Version $Id$
++ * Version $Id$
+ */
+ /*
+- Copyright (C) 2000-2004 Kern Sibbald and John Walker
++ Copyright (C) 2000-2004 Kern Sibbald
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+@@ -64,10 +64,9 @@
+ int max_retry_time, int verbose)
+ {
+ BSOCK *sd;
+- STORE *store = jcr->store;
+- if (!store) {
+- jcr->store = store = (STORE *)jcr->storage[0]->first();
+- }
++ STORE *store;
++
++ store = (STORE *)jcr->storage[0]->first();
+
+ /*
+ * Open message channel with the Storage daemon
+@@ -94,13 +93,13 @@
+ */
+ int start_storage_daemon_job(JCR *jcr)
+ {
+- int status;
++ int status = 0;
+ STORE *storage;
+ BSOCK *sd;
+ char auth_key[100];
+ POOL_MEM device_name, pool_name, pool_type, media_type;
++ int i;
+
+- storage = jcr->store;
+ sd = jcr->store_bsock;
+ /*
+ * Now send JobId and permissions, and get back the authorization key.
+@@ -139,23 +138,29 @@
+ /*
+ * Send use device = xxx media = yyy pool = zzz
+ */
+- pm_strcpy(device_name, storage->dev_name);
+- pm_strcpy(media_type, storage->media_type);
+- pm_strcpy(pool_type, jcr->pool->pool_type);
+- pm_strcpy(pool_name, jcr->pool->hdr.name);
+- bash_spaces(device_name);
+- bash_spaces(media_type);
+- bash_spaces(pool_type);
+- bash_spaces(pool_name);
+- bnet_fsend(sd, use_device, device_name.c_str(),
+- media_type.c_str(), pool_name.c_str(), pool_type.c_str());
+- Dmsg1(110, ">stored: %s", sd->msg);
+- status = response(jcr, sd, OK_device, "Use Device", NO_DISPLAY);
+- if (!status) {
+- pm_strcpy(pool_type, sd->msg); /* save message */
+- Jmsg(jcr, M_FATAL, 0, _("\n"
+- " Storage daemon didn't accept Device \"%s\" because:\n %s"),
+- device_name.c_str(), pool_type.c_str()/* sd->msg */);
++
++ for (i=0; i < MAX_STORE; i++) {
++ if (jcr->storage[i]) {
++ storage = (STORE *)jcr->storage[i]->first();
++ pm_strcpy(device_name, storage->dev_name);
++ pm_strcpy(media_type, storage->media_type);
++ pm_strcpy(pool_type, jcr->pool->pool_type);
++ pm_strcpy(pool_name, jcr->pool->hdr.name);
++ bash_spaces(device_name);
++ bash_spaces(media_type);
++ bash_spaces(pool_type);
++ bash_spaces(pool_name);
++ bnet_fsend(sd, use_device, device_name.c_str(),
++ media_type.c_str(), pool_name.c_str(), pool_type.c_str());
++ Dmsg1(110, ">stored: %s", sd->msg);
++ status = response(jcr, sd, OK_device, "Use Device", NO_DISPLAY);
++ if (!status) {
++ pm_strcpy(pool_type, sd->msg); /* save message */
++ Jmsg(jcr, M_FATAL, 0, _("\n"
++ " Storage daemon didn't accept Device \"%s\" because:\n %s"),
++ device_name.c_str(), pool_type.c_str()/* sd->msg */);
++ }
++ }
+ }
+ return status;
+ }
+Index: src/dird/protos.h
+===================================================================
+RCS file: /cvsroot/bacula/bacula/src/dird/protos.h,v
+retrieving revision 1.56
+diff -u -r1.56 protos.h
+--- src/dird/protos.h 17 Nov 2004 22:48:22 -0000 1.56
++++ src/dird/protos.h 21 Dec 2004 13:04:08 -0000
+@@ -1,7 +1,7 @@
+ /*
+ * Director external function prototypes
+ *
+- * Version $Id$
++ * Version $Id$
+ */
+ /*
+ Copyright (C) 2000-2004 Kern Sibbald and John Walker
+@@ -62,7 +62,7 @@
+
+ /* fd_cmds.c */
+ extern int connect_to_file_daemon(JCR *jcr, int retry_interval,
+- int max_retry_time, int verbose);
++ int max_retry_time, int verbose);
+ extern int send_include_list(JCR *jcr);
+ extern int send_exclude_list(JCR *jcr);
+ extern int send_bootstrap_file(JCR *jcr);
+@@ -70,7 +70,7 @@
+ extern int get_attributes_and_put_in_catalog(JCR *jcr);
+ extern int get_attributes_and_compare_to_catalog(JCR *jcr, JobId_t JobId);
+ extern int put_file_into_catalog(JCR *jcr, long file_index, char *fname,
+- char *link, char *attr, int stream);
++ char *link, char *attr, int stream);
+ extern void get_level_since_time(JCR *jcr, char *since, int since_len);
+ extern int send_run_before_and_after_commands(JCR *jcr);
+
+@@ -91,13 +91,14 @@
+ extern int cancel_job(UAContext *ua, JCR *jcr);
+ extern void init_jcr_job_record(JCR *jcr);
+ extern void copy_storage(JCR *new_jcr, JCR *old_jcr);
++extern void set_storage(JCR *jcr, STORE *store);
+
+ /* mountreq.c */
+ extern void mount_request(JCR *jcr, BSOCK *bs, char *buf);
+
+ /* msgchan.c */
+ extern bool connect_to_storage_daemon(JCR *jcr, int retry_interval,
+- int max_retry_time, int verbose);
++ int max_retry_time, int verbose);
+ extern int start_storage_daemon_job(JCR *jcr);
+ extern int start_storage_daemon_message_thread(JCR *jcr);
+ extern int bget_dirmsg(BSOCK *bs);
+@@ -149,28 +150,28 @@
+ void free_ua_context(UAContext *ua);
+
+ /* ua_select.c */
+-STORE *select_storage_resource(UAContext *ua);
+-JOB *select_job_resource(UAContext *ua);
+-JOB *select_restore_job_resource(UAContext *ua);
+-CLIENT *select_client_resource(UAContext *ua);
++STORE *select_storage_resource(UAContext *ua);
++JOB *select_job_resource(UAContext *ua);
++JOB *select_restore_job_resource(UAContext *ua);
++CLIENT *select_client_resource(UAContext *ua);
+ FILESET *select_fileset_resource(UAContext *ua);
+-int select_pool_and_media_dbr(UAContext *ua, POOL_DBR *pr, MEDIA_DBR *mr);
+-int select_media_dbr(UAContext *ua, MEDIA_DBR *mr);
+-bool select_pool_dbr(UAContext *ua, POOL_DBR *pr);
+-int select_client_dbr(UAContext *ua, CLIENT_DBR *cr);
+-
+-void start_prompt(UAContext *ua, const char *msg);
+-void add_prompt(UAContext *ua, const char *prompt);
+-int do_prompt(UAContext *ua, const char *automsg, const char *msg, char *prompt, int max_prompt);
+-CAT *get_catalog_resource(UAContext *ua);
++int select_pool_and_media_dbr(UAContext *ua, POOL_DBR *pr, MEDIA_DBR *mr);
++int select_media_dbr(UAContext *ua, MEDIA_DBR *mr);
++bool select_pool_dbr(UAContext *ua, POOL_DBR *pr);
++int select_client_dbr(UAContext *ua, CLIENT_DBR *cr);
++
++void start_prompt(UAContext *ua, const char *msg);
++void add_prompt(UAContext *ua, const char *prompt);
++int do_prompt(UAContext *ua, const char *automsg, const char *msg, char *prompt, int max_prompt);
++CAT *get_catalog_resource(UAContext *ua);
+ STORE *get_storage_resource(UAContext *ua, int use_default);
+-int get_media_type(UAContext *ua, char *MediaType, int max_media);
+-bool get_pool_dbr(UAContext *ua, POOL_DBR *pr);
+-int get_client_dbr(UAContext *ua, CLIENT_DBR *cr);
++int get_media_type(UAContext *ua, char *MediaType, int max_media);
++bool get_pool_dbr(UAContext *ua, POOL_DBR *pr);
++int get_client_dbr(UAContext *ua, CLIENT_DBR *cr);
+ POOL *get_pool_resource(UAContext *ua);
+ POOL *select_pool_resource(UAContext *ua);
+ CLIENT *get_client_resource(UAContext *ua);
+-int get_job_dbr(UAContext *ua, JOB_DBR *jr);
++int get_job_dbr(UAContext *ua, JOB_DBR *jr);
+
+ int find_arg_keyword(UAContext *ua, const char **list);
+ int find_arg(UAContext *ua, const char *keyword);
+@@ -190,3 +191,6 @@
+
+ /* ua_purge.c */
+ int purge_jobs_from_volume(UAContext *ua, MEDIA_DBR *mr);
++
++/* ua_run.c */
++extern int run_cmd(UAContext *ua, const char *cmd);
+Index: src/dird/scheduler.c
+===================================================================
+RCS file: /cvsroot/bacula/bacula/src/dird/scheduler.c,v
+retrieving revision 1.27
+diff -u -r1.27 scheduler.c
+--- src/dird/scheduler.c 3 Oct 2004 19:47:34 -0000 1.27
++++ src/dird/scheduler.c 21 Dec 2004 13:04:08 -0000
+@@ -10,7 +10,7 @@
+ * Version $Id$
+ */
+ /*
+- Copyright (C) 2000-2004 Kern Sibbald and John Walker
++ Copyright (C) 2000-2004 Kern Sibbald
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+@@ -157,7 +157,7 @@
+ jcr->dif_pool = run->dif_pool; /* override dif pool */
+ }
+ if (run->storage) {
+- jcr->store = run->storage; /* override storage */
++ set_storage(jcr, run->storage); /* override storage */
+ }
+ if (run->msgs) {
+ jcr->messages = run->msgs; /* override messages */
+Index: src/dird/ua.h
+===================================================================
+RCS file: /cvsroot/bacula/bacula/src/dird/ua.h,v
+retrieving revision 1.23
+diff -u -r1.23 ua.h
+--- src/dird/ua.h 18 Jun 2004 10:07:41 -0000 1.23
++++ src/dird/ua.h 21 Dec 2004 13:04:08 -0000
+@@ -3,7 +3,7 @@
+ *
+ * Kern Sibbald, August MMI
+ *
+- * Version $Id$
++ * Version $Id$
+ */
+ /*
+ Copyright (C) 2000-2004 Kern Sibbald and John Walker
+@@ -48,6 +48,7 @@
+ bool automount; /* if set, mount after label */
+ bool quit; /* if set, quit */
+ bool verbose; /* set for normal UA verbosity */
++ bool batch; /* set for non-interactive mode */
+ uint32_t pint32_val; /* positive integer */
+ int32_t int32_val; /* positive/negative */
+ };
+Index: src/dird/ua_cmds.c
+===================================================================
+RCS file: /cvsroot/bacula/bacula/src/dird/ua_cmds.c,v
+retrieving revision 1.127
+diff -u -r1.127 ua_cmds.c
+--- src/dird/ua_cmds.c 4 Oct 2004 20:34:01 -0000 1.127
++++ src/dird/ua_cmds.c 21 Dec 2004 13:04:10 -0000
+@@ -4,7 +4,7 @@
+ *
+ * Kern Sibbald, September MM
+ *
+- * Version $Id$
++ * Version $Id$
+ */
+
+ /*
+@@ -52,7 +52,6 @@
+ extern int gui_cmd(UAContext *ua, const char *cmd);
+ extern int sqlquerycmd(UAContext *ua, const char *cmd);
+ extern int querycmd(UAContext *ua, const char *cmd);
+-extern int run_cmd(UAContext *ua, const char *cmd);
+ extern int retentioncmd(UAContext *ua, const char *cmd);
+ extern int prunecmd(UAContext *ua, const char *cmd);
+ extern int purgecmd(UAContext *ua, const char *cmd);
+@@ -1195,7 +1194,7 @@
+ BSOCK *sd;
+ JCR *jcr = ua->jcr;
+
+- jcr->store = store;
++ set_storage(jcr, store);
+ /* Try connecting for up to 15 seconds */
+ bsendmsg(ua, _("Connecting to Storage daemon %s at %s:%d\n"),
+ store->hdr.name, store->address, store->SDport);
+@@ -1254,8 +1253,10 @@
+ /* 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);
+@@ -1286,8 +1287,10 @@
+ /* 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);
+@@ -1841,7 +1844,7 @@
+ Dmsg2(120, "Found storage, MediaType=%s DevName=%s\n",
+ store->media_type, store->dev_name);
+
+- jcr->store = store;
++ set_storage(jcr, store);
+ if (!connect_to_storage_daemon(jcr, 10, SDConnectTimeout, 1)) {
+ bsendmsg(ua, _("Failed to connect to Storage daemon.\n"));
+ return;
+Index: src/dird/ua_label.c
+===================================================================
+RCS file: /cvsroot/bacula/bacula/src/dird/ua_label.c,v
+retrieving revision 1.38
+diff -u -r1.38 ua_label.c
+--- src/dird/ua_label.c 17 Aug 2004 14:40:09 -0000 1.38
++++ src/dird/ua_label.c 21 Dec 2004 13:04:10 -0000
+@@ -8,7 +8,7 @@
+ */
+
+ /*
+- Copyright (C) 2000-2004 Kern Sibbald and John Walker
++ Copyright (C) 2000-2004 Kern Sibbald
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+@@ -170,7 +170,7 @@
+ if (!store) {
+ return 1;
+ }
+- ua->jcr->store = store;
++ set_storage(ua->jcr, store);
+
+ scan = find_arg(ua, _("scan")) >= 0;
+
+@@ -296,7 +296,7 @@
+ if (!store) {
+ return 1;
+ }
+- ua->jcr->store = store;
++ set_storage(ua->jcr, store);
+
+ if (!relabel && find_arg_keyword(ua, barcode_keyword) >= 0) {
+ label_from_barcodes(ua);
+Index: src/dird/ua_run.c
+===================================================================
+RCS file: /cvsroot/bacula/bacula/src/dird/ua_run.c,v
+retrieving revision 1.58
+diff -u -r1.58 ua_run.c
+--- src/dird/ua_run.c 8 Nov 2004 21:12:12 -0000 1.58
++++ src/dird/ua_run.c 21 Dec 2004 13:04:11 -0000
+@@ -4,11 +4,11 @@
+ *
+ * Kern Sibbald, December MMI
+ *
+- * Version $Id$
++ * Version $Id$
+ */
+
+ /*
+- Copyright (C) 2001-2004 Kern Sibbald and John Walker
++ Copyright (C) 2001-2004 Kern Sibbald
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+@@ -42,6 +42,9 @@
+ * For Restore Jobs
+ * run <job-name> jobid=nn
+ *
++ * Returns: 0 on error
++ * JobId if OK
++ *
+ */
+ int run_cmd(UAContext *ua, const char *cmd)
+ {
+@@ -101,7 +104,7 @@
+ catalog_name = NULL;
+
+ for (i=1; i<ua->argc; i++) {
+- Dmsg2(200, "Doing arg %d = %s\n", i, ua->argk[i]);
++ Dmsg2(800, "Doing arg %d = %s\n", i, ua->argk[i]);
+ kw_ok = false;
+ /* Keep looking until we find a good keyword */
+ for (j=0; !kw_ok && kw[j]; j++) {
+@@ -111,12 +114,12 @@
+ bsendmsg(ua, _("Value missing for keyword %s\n"), ua->argk[i]);
+ return 1;
+ }
+- Dmsg1(200, "Got keyword=%s\n", kw[j]);
++ Dmsg1(800, "Got keyword=%s\n", kw[j]);
+ switch (j) {
+ case 0: /* job */
+ if (job_name) {
+ bsendmsg(ua, _("Job name specified twice.\n"));
+- return 1;
++ return 0;
+ }
+ job_name = ua->argv[i];
+ kw_ok = true;
+@@ -124,7 +127,7 @@
+ case 1: /* JobId */
+ if (jid) {
+ bsendmsg(ua, _("JobId specified twice.\n"));
+- return 1;
++ return 0;
+ }
+ jid = ua->argv[i];
+ kw_ok = true;
+@@ -133,7 +136,7 @@
+ case 3: /* fd */
+ if (client_name) {
+ bsendmsg(ua, _("Client specified twice.\n"));
+- return 1;
++ return 0;
+ }
+ client_name = ua->argv[i];
+ kw_ok = true;
+@@ -141,7 +144,7 @@
+ case 4: /* fileset */
+ if (fileset_name) {
+ bsendmsg(ua, _("FileSet specified twice.\n"));
+- return 1;
++ return 0;
+ }
+ fileset_name = ua->argv[i];
+ kw_ok = true;
+@@ -149,7 +152,7 @@
+ case 5: /* level */
+ if (level_name) {
+ bsendmsg(ua, _("Level specified twice.\n"));
+- return 1;
++ return 0;
+ }
+ level_name = ua->argv[i];
+ kw_ok = true;
+@@ -158,7 +161,7 @@
+ case 7: /* sd */
+ if (store_name) {
+ bsendmsg(ua, _("Storage specified twice.\n"));
+- return 1;
++ return 0;
+ }
+ store_name = ua->argv[i];
+ kw_ok = true;
+@@ -166,7 +169,7 @@
+ case 8: /* pool */
+ if (pool_name) {
+ bsendmsg(ua, _("Pool specified twice.\n"));
+- return 1;
++ return 0;
+ }
+ pool_name = ua->argv[i];
+ kw_ok = true;
+@@ -174,7 +177,7 @@
+ case 9: /* where */
+ if (where) {
+ bsendmsg(ua, _("Where specified twice.\n"));
+- return 1;
++ return 0;
+ }
+ where = ua->argv[i];
+ kw_ok = true;
+@@ -182,7 +185,7 @@
+ case 10: /* bootstrap */
+ if (bootstrap) {
+ bsendmsg(ua, _("Bootstrap specified twice.\n"));
+- return 1;
++ return 0;
+ }
+ bootstrap = ua->argv[i];
+ kw_ok = true;
+@@ -190,7 +193,7 @@
+ case 11: /* replace */
+ if (replace) {
+ bsendmsg(ua, _("Replace specified twice.\n"));
+- return 1;
++ return 0;
+ }
+ replace = ua->argv[i];
+ kw_ok = true;
+@@ -198,7 +201,7 @@
+ case 12: /* When */
+ if (when) {
+ bsendmsg(ua, _("When specified twice.\n"));
+- return 1;
++ return 0;
+ }
+ when = ua->argv[i];
+ kw_ok = true;
+@@ -206,7 +209,7 @@
+ case 13: /* Priority */
+ if (Priority) {
+ bsendmsg(ua, _("Priority specified twice.\n"));
+- return 1;
++ return 0;
+ }
+ Priority = atoi(ua->argv[i]);
+ if (Priority <= 0) {
+@@ -221,7 +224,7 @@
+ case 15: /* Verify Job */
+ if (verify_job_name) {
+ bsendmsg(ua, _("Verify Job specified twice.\n"));
+- return 1;
++ return 0;
+ }
+ verify_job_name = ua->argv[i];
+ kw_ok = true;
+@@ -255,21 +258,22 @@
+ Dmsg1(200, "Set jobname=%s\n", job_name);
+ } else {
+ bsendmsg(ua, _("Invalid keyword: %s\n"), ua->argk[i]);
+- return 1;
++ return 0;
+ }
+ }
+ } /* end argc loop */
+
+- Dmsg0(200, "Done scan.\n");
++ Dmsg0(800, "Done scan.\n");
+
+ CAT *catalog = NULL;
+ if (catalog_name != NULL) {
+ catalog = (CAT *)GetResWithName(R_CATALOG, catalog_name);
+ if (catalog == NULL) {
+ bsendmsg(ua, _("Catalog \"%s\" not found\n"), catalog_name);
+- return 1;
++ return 0;
+ }
+ }
++ Dmsg1(200, "Using catalog=%s\n", catalog_name);
+
+ if (job_name) {
+ /* Find Job */
+@@ -287,11 +291,11 @@
+ job = select_job_resource(ua);
+ }
+ if (!job) {
+- return 1;
++ return 0;
+ } else if (!acl_access_ok(ua, Job_ACL, job->hdr.name)) {
+ bsendmsg(ua, _("No authorization. Job \"%s\".\n"),
+ job->hdr.name);
+- return 1;
++ return 0;
+ }
+
+ if (store_name) {
+@@ -310,8 +314,9 @@
+ } else if (!acl_access_ok(ua, Storage_ACL, store->hdr.name)) {
+ bsendmsg(ua, _("No authorization. Storage \"%s\".\n"),
+ store->hdr.name);
+- return 1;
++ return 0;
+ }
++ Dmsg1(200, "Using storage=%s\n", store->hdr.name);
+
+ if (pool_name) {
+ pool = (POOL *)GetResWithName(R_POOL, pool_name);
+@@ -325,12 +330,13 @@
+ pool = job->pool; /* use default */
+ }
+ if (!pool) {
+- return 1;
++ return 0;
+ } else if (!acl_access_ok(ua, Pool_ACL, store->hdr.name)) {
+ bsendmsg(ua, _("No authorization. Pool \"%s\".\n"),
+ pool->hdr.name);
+- return 1;
++ return 0;
+ }
++ Dmsg1(200, "Using pool\n", pool->hdr.name);
+
+ if (client_name) {
+ client = (CLIENT *)GetResWithName(R_CLIENT, client_name);
+@@ -344,12 +350,13 @@
+ client = job->client; /* use default */
+ }
+ if (!client) {
+- return 1;
++ return 0;
+ } else if (!acl_access_ok(ua, Client_ACL, store->hdr.name)) {
+ bsendmsg(ua, _("No authorization. Client \"%s\".\n"),
+ client->hdr.name);
+- return 1;
++ return 0;
+ }
++ Dmsg1(200, "Using client=%s\n", client->hdr.name);
+
+ if (fileset_name) {
+ fileset = (FILESET *)GetResWithName(R_FILESET, fileset_name);
+@@ -361,11 +368,11 @@
+ fileset = job->fileset; /* use default */
+ }
+ if (!fileset) {
+- return 1;
++ return 0;
+ } else if (!acl_access_ok(ua, FileSet_ACL, store->hdr.name)) {
+ bsendmsg(ua, _("No authorization. FileSet \"%s\".\n"),
+ fileset->hdr.name);
+- return 1;
++ return 0;
+ }
+
+ if (verify_job_name) {
+@@ -386,7 +393,7 @@
+ set_jcr_defaults(jcr, job);
+
+ jcr->verify_job = verify_job;
+- jcr->store = store;
++ set_storage(jcr, store);
+ jcr->client = client;
+ jcr->fileset = fileset;
+ jcr->pool = pool;
+@@ -460,7 +467,7 @@
+ }
+
+ /* Run without prompting? */
+- if (find_arg(ua, _("yes")) > 0) {
++ if (ua->batch || find_arg(ua, _("yes")) > 0) {
+ goto start_job;
+ }
+
+@@ -701,7 +708,7 @@
+ /* Storage */
+ store = select_storage_resource(ua);
+ if (store) {
+- jcr->store = store;
++ set_storage(jcr, store);
+ goto try_again;
+ }
+ break;
+@@ -847,7 +854,7 @@
+ } else {
+ bsendmsg(ua, _("Job started. JobId=%u\n"), JobId);
+ }
+- return 1;
++ return JobId;
+ }
+
+ bail_out:
+Index: src/dird/ua_server.c
+===================================================================
+RCS file: /cvsroot/bacula/bacula/src/dird/ua_server.c,v
+retrieving revision 1.35
+diff -u -r1.35 ua_server.c
+--- src/dird/ua_server.c 19 Sep 2004 18:56:24 -0000 1.35
++++ src/dird/ua_server.c 21 Dec 2004 13:04:11 -0000
+@@ -99,6 +99,15 @@
+ {
+ JCR *jcr;
+ jcr = new_jcr(sizeof(JCR), dird_free_jcr);
++ /*
++ * The job and defaults are not really used, but
++ * we set them up to ensure that everything is correctly
++ * initialized.
++ */
++ LockRes();
++ jcr->job = (JOB *)GetNextRes(R_JOB, NULL);
++ set_jcr_defaults(jcr, jcr->job);
++ UnlockRes();
+ jcr->sd_auth_key = bstrdup("dummy"); /* dummy Storage daemon key */
+ create_unique_job_name(jcr, base_name);
+ jcr->sched_time = jcr->start_time;
+@@ -106,20 +115,6 @@
+ jcr->JobLevel = L_NONE;
+ jcr->JobStatus = JS_Running;
+ jcr->JobId = 0;
+- /*
+- * None of these are really defined for control JCRs, so we
+- * simply take the first of each one. This ensures that there
+- * will be no null pointer references.
+- */
+- LockRes();
+- jcr->job = (JOB *)GetNextRes(R_JOB, NULL);
+- jcr->messages = (MSGS *)GetNextRes(R_MSGS, NULL);
+- jcr->client = (CLIENT *)GetNextRes(R_CLIENT, NULL);
+- jcr->pool = (POOL *)GetNextRes(R_POOL, NULL);
+- jcr->catalog = (CAT *)GetNextRes(R_CATALOG, NULL);
+- jcr->store = (STORE *)GetNextRes(R_STORAGE, NULL);
+- jcr->fileset = (FILESET *)GetNextRes(R_FILESET, NULL);
+- UnlockRes();
+ return jcr;
+ }
+
+Index: src/dird/ua_status.c
+===================================================================
+RCS file: /cvsroot/bacula/bacula/src/dird/ua_status.c,v
+retrieving revision 1.61
+diff -u -r1.61 ua_status.c
+--- src/dird/ua_status.c 19 Sep 2004 18:56:25 -0000 1.61
++++ src/dird/ua_status.c 21 Dec 2004 13:04:12 -0000
+@@ -282,7 +282,7 @@
+ {
+ BSOCK *sd;
+
+- ua->jcr->store = store;
++ set_storage(ua->jcr, store);
+ /* Try connecting for up to 15 seconds */
+ bsendmsg(ua, _("Connecting to Storage daemon %s at %s:%d\n"),
+ store->hdr.name, store->address, store->SDport);
This patch fixes the despooling size printed in the Job
report. Previously, it reported the total size for the
device. This patch makes it report the size for the job.
+
+21Dec04
+ This patch fixes a problem with overriding storage daemon
+ specifications. Previously they were not always honored.
+ This implements more uniform handling. It also eliminates
+ an orphaned buffer situation using JobDefs.
#endif
/* Allow printing of NULL pointers */
-#define NPRT(x) (x)?(x):"*None*"
+#define NPRT(x) (x)?(x):"*None*"
#ifdef ENABLE_NLS
#include <libintl.h>
#define MAXSTRING 500
/* Maximum length to edit time/date */
-#define MAX_TIME_LENGTH 50
+#define MAX_TIME_LENGTH 50
/* Maximum Name length including EOS */
#define MAX_NAME_LENGTH 128
/*** FIXME ***/
-/*
- * File type (Bacula defined).
+/*
+ * File type (Bacula defined).
* NOTE!!! These are saved in the Attributes record on the tape, so
* do not change them. If need be, add to them.
*
* additional optional fields in the attribute record.
*/
#define FT_MASK 0xFFFF /* Bits used by FT (type) */
-#define FT_LNKSAVED 1 /* hard link to file already saved */
+#define FT_LNKSAVED 1 /* hard link to file already saved */
#define FT_REGE 2 /* Regular file but empty */
#define FT_REG 3 /* Regular file */
#define FT_LNK 4 /* Soft Link */
#define P(x) \
do { int errstat; if ((errstat=pthread_mutex_lock(&(x)))) \
e_msg(__FILE__, __LINE__, M_ABORT, 0, "Mutex lock failure. ERR=%s\n",\
- strerror(errstat)); \
+ strerror(errstat)); \
} while(0)
#define V(x) \
do { int errstat; if ((errstat=pthread_mutex_unlock(&(x)))) \
- e_msg(__FILE__, __LINE__, M_ABORT, 0, "Mutex unlock failure. ERR=%s\n",\
- strerror(errstat)); \
+ e_msg(__FILE__, __LINE__, M_ABORT, 0, "Mutex unlock failure. ERR=%s\n",\
+ strerror(errstat)); \
} while(0)
#endif /* DEBUG_MUTEX */
#define Pw(x) \
do { int errstat; if ((errstat=rwl_writelock(&(x)))) \
e_msg(__FILE__, __LINE__, M_ABORT, 0, "Write lock lock failure. ERR=%s\n",\
- strerror(errstat)); \
+ strerror(errstat)); \
} while(0)
#define Vw(x) \
do { int errstat; if ((errstat=rwl_writeunlock(&(x)))) \
- e_msg(__FILE__, __LINE__, M_ABORT, 0, "Write lock unlock failure. ERR=%s\n",\
- strerror(errstat)); \
+ e_msg(__FILE__, __LINE__, M_ABORT, 0, "Write lock unlock failure. ERR=%s\n",\
+ strerror(errstat)); \
} while(0)
#define LockRes() b_LockRes(__FILE__, __LINE__)
#define Pmsg13(lvl,msg,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13) p_msg(__FILE__,__LINE__,lvl,msg,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13)
#define Pmsg14(lvl,msg,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14) p_msg(__FILE__,__LINE__,lvl,msg,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14)
-
+
/* Daemon Error Messages that are delivered according to the message resource */
#define Emsg0(typ, lvl, msg) e_msg(__FILE__, __LINE__, typ, lvl, msg)
#define Emsg1(typ, lvl, msg, a1) e_msg(__FILE__, __LINE__, typ, lvl, msg, a1)
#endif
#ifdef HAVE_SUN_OS
- /*
+ /*
* On Solaris 2.5, threads are not timesliced by default, so we need to
* explictly increase the conncurrency level.
*/
extern "C" int fchdir(int filedes);
extern "C" long gethostid(void);
#endif
-
+
/* This probably should be done on a machine by machine basic, but it works */
#define ALIGN_SIZE (sizeof(double))
#define BALIGN(x) (((x) + ALIGN_SIZE - 1) & ~(ALIGN_SIZE -1))
/*
* Replace codes needed in both file routines and non-file routines
- * Job replace codes -- in "replace"
+ * Job replace codes -- in "replace"
*/
#define REPLACE_ALWAYS 'a'
#define REPLACE_IFNEWER 'w'
#endif
#ifdef HAVE_NL_LANGINFO
#include <langinfo.h>
-#else
+#else
#define nl_langinfo(x) ("ANSI_X3.4-1968")
#endif
#else
#include "lib/getopt.h"
#endif
-#endif
+#endif
#include <string.h>
#include <strings.h>
#include <pthread.h>
/* Local Bacula includes. Be sure to put all the system
- * includes before these.
+ * includes before these.
*/
#include "version.h"
#include "bc_types.h"
#ifndef __bc_types_INCLUDED
#define __bc_types_INCLUDED
-typedef char POOLMEM;
+typedef char POOLMEM;
/* Types */
/* Limits for the above types. */
-#undef INT8_MIN
-#undef INT8_MAX
-#undef UINT8_MAX
-#undef INT16_MIN
-#undef INT16_MAX
+#undef INT8_MIN
+#undef INT8_MAX
+#undef UINT8_MAX
+#undef INT16_MIN
+#undef INT16_MAX
#undef UINT16_MAX
-#undef INT32_MIN
-#undef INT32_MAX
+#undef INT32_MIN
+#undef INT32_MAX
#undef UINT32_MAX
#define INT8_MIN (-127-1)
* The purpose of these routines is to ensure that Bacula
* can limp along if no real database is loaded on the
* system.
- *
- * Kern Sibbald, January MMI
+ *
+ * Kern Sibbald, January MMI
*
* Version $Id$
*
if (working_directory[strlen(working_directory)-1] == '/') {
sep = 0;
} else {
- sep = '/';
+ sep = '/';
}
Mmsg(dbf, "%s%c%s-%s", working_directory, sep, mdb->db_name, name);
return dbf;
*/
B_DB *
db_init_database(JCR *jcr, char const *db_name, char const *db_user, char const *db_password,
- char const *db_address, int db_port, char const *db_socket,
+ char const *db_address, int db_port, char const *db_socket,
int mult_db_connections)
{
B_DB *mdb;
/* Look to see if DB already open */
for (mdb=NULL; (mdb=(B_DB *)qnext(&db_list, &mdb->bq)); ) {
if (strcmp(mdb->db_name, db_name) == 0) {
- Dmsg2(200, "DB REopen %d %s\n", mdb->ref_count, db_name);
+ Dmsg2(200, "DB REopen %d %s\n", mdb->ref_count, db_name);
mdb->ref_count++;
V(mutex);
return mdb; /* already open */
Dmsg0(200, "make_filename\n");
dbf = make_filename(mdb, DB_CONTROL_FILENAME);
- mdb->cfd = open(dbf, O_CREAT|O_RDWR, 0600);
+ mdb->cfd = open(dbf, O_CREAT|O_RDWR, 0600);
free_memory(dbf);
if (mdb->cfd < 0) {
- Mmsg2(&mdb->errmsg, _("Unable to open Catalog DB control file %s: ERR=%s\n"),
+ Mmsg2(&mdb->errmsg, _("Unable to open Catalog DB control file %s: ERR=%s\n"),
dbf, strerror(errno));
V(mutex);
return 0;
Mmsg1(&mdb->errmsg, _("Error reading catalog DB control file. ERR=%s\n"), strerror(errno));
badctl = 1;
} else if (mdb->control.bdb_version != BDB_VERSION) {
- Mmsg2(&mdb->errmsg, _("Error, catalog DB control file wrong version. \
-Wanted %d, got %d\n\
-Please reinitialize the working directory.\n"),
+ Mmsg2(&mdb->errmsg, _("Error, catalog DB control file wrong version. "
+"Wanted %d, got %d\n"
+"Please reinitialize the working directory.\n"),
BDB_VERSION, mdb->control.bdb_version);
badctl = 1;
}
return 1;
}
-void db_close_database(JCR *jcr, B_DB *mdb)
+void db_close_database(JCR *jcr, B_DB *mdb)
{
P(mutex);
mdb->ref_count--;
if (mdb->filesetfd) {
fclose(mdb->filesetfd);
}
- rwl_destroy(&mdb->lock);
+ rwl_destroy(&mdb->lock);
free_pool_memory(mdb->errmsg);
free_pool_memory(mdb->cmd);
free_pool_memory(mdb->cached_path);
{
char *dbf;
- if (!mdb->jobfd) {
+ if (!mdb->jobfd) {
dbf = make_filename(mdb, DB_JOBS_FILENAME);
mdb->jobfd = fopen(dbf, "r+");
if (!mdb->jobfd) {
- Mmsg2(&mdb->errmsg, "Error opening DB Jobs file %s: ERR=%s\n",
+ Mmsg2(&mdb->errmsg, "Error opening DB Jobs file %s: ERR=%s\n",
dbf, strerror(errno));
Emsg0(M_FATAL, 0, mdb->errmsg);
free_memory(dbf);
{
char *dbf;
- if (!mdb->jobmediafd) {
+ if (!mdb->jobmediafd) {
dbf = make_filename(mdb, DB_JOBMEDIA_FILENAME);
mdb->jobmediafd = fopen(dbf, "r+");
if (!mdb->jobmediafd) {
- Mmsg2(&mdb->errmsg, "Error opening DB JobMedia file %s: ERR=%s\n",
+ Mmsg2(&mdb->errmsg, "Error opening DB JobMedia file %s: ERR=%s\n",
dbf, strerror(errno));
Emsg0(M_FATAL, 0, mdb->errmsg);
free_memory(dbf);
{
char *dbf;
- if (!mdb->poolfd) {
+ if (!mdb->poolfd) {
dbf = make_filename(mdb, DB_POOLS_FILENAME);
mdb->poolfd = fopen(dbf, "r+");
if (!mdb->poolfd) {
- Mmsg2(&mdb->errmsg, "Error opening DB Pools file %s: ERR=%s\n",
+ Mmsg2(&mdb->errmsg, "Error opening DB Pools file %s: ERR=%s\n",
dbf, strerror(errno));
Emsg0(M_FATAL, 0, mdb->errmsg);
free_memory(dbf);
{
char *dbf;
- if (!mdb->clientfd) {
+ if (!mdb->clientfd) {
dbf = make_filename(mdb, DB_CLIENT_FILENAME);
mdb->clientfd = fopen(dbf, "r+");
if (!mdb->clientfd) {
- Mmsg2(&mdb->errmsg, "Error opening DB Clients file %s: ERR=%s\n",
+ Mmsg2(&mdb->errmsg, "Error opening DB Clients file %s: ERR=%s\n",
dbf, strerror(errno));
Emsg0(M_FATAL, 0, mdb->errmsg);
free_memory(dbf);
{
char *dbf;
- if (!mdb->filesetfd) {
+ if (!mdb->filesetfd) {
dbf = make_filename(mdb, DB_CLIENT_FILENAME);
mdb->filesetfd = fopen(dbf, "r+");
if (!mdb->filesetfd) {
- Mmsg2(&mdb->errmsg, "Error opening DB FileSet file %s: ERR=%s\n",
+ Mmsg2(&mdb->errmsg, "Error opening DB FileSet file %s: ERR=%s\n",
dbf, strerror(errno));
Emsg0(M_FATAL, 0, mdb->errmsg);
free_memory(dbf);
{
char *dbf;
- if (!mdb->mediafd) {
+ if (!mdb->mediafd) {
dbf = make_filename(mdb, DB_MEDIA_FILENAME);
mdb->mediafd = fopen(dbf, "r+");
if (!mdb->mediafd) {
- Mmsg2(&mdb->errmsg, "Error opening DB Media file %s: ERR=%s\n",
+ Mmsg2(&mdb->errmsg, "Error opening DB Media file %s: ERR=%s\n",
dbf, strerror(errno));
free_memory(dbf);
return 0;
e_msg(file, line, M_ABORT, 0, "rwl_writelock failure. ERR=%s\n",
strerror(errstat));
}
-}
+}
void _db_unlock(const char *file, int line, B_DB *mdb)
{
e_msg(file, line, M_ABORT, 0, "rwl_writeunlock failure. ERR=%s\n",
strerror(errstat));
}
-}
+}
/*
* Start a transaction. This groups inserts and makes things
- * much more efficient. Usually started when inserting
+ * much more efficient. Usually started when inserting
* file attributes.
*/
void db_start_transaction(JCR *jcr, B_DB *mdb)
* The purpose of these routines is to ensure that Bacula
* can limp along if no real database is loaded on the
* system.
- *
- * Kern Sibbald, January MMI
+ *
+ * Kern Sibbald, January MMI
*
* Version $Id$
*/
}
int db_create_file_item(JCR *jcr, B_DB *mdb, ATTR_DBR *ar)
-{
+{
/****FIXME***** not implemented */
return 1;
}
-/*
- * Create a new record for the Job
+/*
+ * Create a new record for the Job
* This record is created at the start of the Job,
* it is updated in bdb_update.c when the Job terminates.
*
return 1;
}
-/* Create a JobMedia record for Volume used this job
+/* Create a JobMedia record for Volume used this job
* Returns: 0 on failure
* record-id on success
*/
}
-/*
+/*
* Create Unique Media record. This record
* contains all the data pertaining to a specific
* Volume.
*
* Returns: 0 on failure
* 1 on success
- */
+ */
int db_create_media_record(JCR *jcr, B_DB *mdb, MEDIA_DBR *mr)
{
int len;
/*
* Create a unique FileSet record or return existing record
*
- * Note, here we write the FILESET_DBR structure
+ * Note, here we write the FILESET_DBR structure
*
* Returns: 0 on failure
* 1 on success
* The purpose of these routines is to ensure that Bacula
* can limp along if no real database is loaded on the
* system.
- *
- * Kern Sibbald, January MMI
+ *
+ * Kern Sibbald, January MMI
*
* Version $Id$
*/
* Delete a Pool record given the Name
*
* Returns: 0 on error
- * the number of records deleted on success
+ * the number of records deleted on success
*/
int db_delete_pool_record(JCR *jcr, B_DB *mdb, POOL_DBR *pr)
{
memset(&opr, 0, sizeof(opr));
stat = fwrite(&opr, sizeof(opr), 1, mdb->poolfd);
db_unlock(mdb);
- return stat;
+ return stat;
}
-int db_delete_media_record(JCR *jcr, B_DB *mdb, MEDIA_DBR *mr)
-{
+int db_delete_media_record(JCR *jcr, B_DB *mdb, MEDIA_DBR *mr)
+{
int stat;
MEDIA_DBR omr;
memset(&omr, 0, sizeof(omr));
stat = fwrite(&omr, sizeof(omr), 1, mdb->mediafd);
db_unlock(mdb);
- return stat;
+ return stat;
}
#endif /* HAVE_BACULA_DB */
* The purpose of these routines is to ensure that Bacula
* can limp along if no real database is loaded on the
* system.
- *
- * Kern Sibbald, January MMI
+ *
+ * Kern Sibbald, January MMI
*
* Version $Id$
*/
*/
-/*
+/*
* Find job start time. Used to find last full save that terminated normally
* so we can do Incremental and Differential saves.
*
*/
while (fgets(cmd, sizeof(cmd), mdb->jobfd)) {
- if (sscanf(cmd, "JobStart JobId=%d Name=%127s Type=%1s Level=%1s \
-StartTime=%100s", &JobId, Name, cType, cLevel, StartTime) == 5) {
+ if (sscanf(cmd, "JobStart JobId=%d Name=%127s Type=%1s Level=%1s "
+"StartTime=%100s", &JobId, Name, cType, cLevel, StartTime) == 5) {
if (JobId < jr->JobId) {
continue; /* older not a candidate */
}
Level = cLevel[0];
unbash_spaces(Name);
unbash_spaces(StartTime);
- Dmsg4(200, "Got Type=%c Level=%c Name=%s StartTime=%s\n",
+ Dmsg4(200, "Got Type=%c Level=%c Name=%s StartTime=%s\n",
Type, Level, Name, StartTime);
- Dmsg3(200, "Want Type=%c Level=%c Name=%s\n", jr->JobType, jr->JobLevel,
+ Dmsg3(200, "Want Type=%c Level=%c Name=%s\n", jr->JobType, jr->JobLevel,
jr->Name);
/* Differential is since last Full backup */
/* Incremental is since last FULL or Incremental or Differential */
- if (((jr->JobLevel == L_DIFFERENTIAL) && (Type == jr->JobType &&
+ if (((jr->JobLevel == L_DIFFERENTIAL) && (Type == jr->JobType &&
Level == L_FULL && strcmp(Name, jr->Name) == 0)) ||
- ((jr->JobLevel == L_INCREMENTAL) && (Type == jr->JobType &&
+ ((jr->JobLevel == L_INCREMENTAL) && (Type == jr->JobType &&
(Level == L_FULL || Level == L_INCREMENTAL ||
Level == L_DIFFERENTIAL) && strcmp(Name, jr->Name) == 0))) {
addr = ftell(mdb->jobfd); /* save current location */
found = 0;
/* Search for matching JobEnd record */
while (!found && fgets(cmd, sizeof(cmd), mdb->jobfd)) {
- if (sscanf(cmd, "JobEnd JobId=%d JobStatus=%1s ClientId=%d",
+ if (sscanf(cmd, "JobEnd JobId=%d JobStatus=%1s ClientId=%d",
&EndId, JobStatus, &ClientId) == 3) {
- if (EndId == JobId && *JobStatus == 'T' && ClientId == jr->ClientId) {
- Dmsg0(200, "====found EndJob matching Job\n");
+ if (EndId == JobId && *JobStatus == 'T' && ClientId == jr->ClientId) {
+ Dmsg0(200, "====found EndJob matching Job\n");
found = 1;
break;
}
if (found) {
pm_strcpy(stime, StartTime);
stat = 1; /* Got a candidate */
- Dmsg5(200, "Got candidate JobId=%d Type=%c Level=%c Name=%s StartTime=%s\n",
+ Dmsg5(200, "Got candidate JobId=%d Type=%c Level=%c Name=%s StartTime=%s\n",
JobId, Type, Level, Name, StartTime);
}
}
}
-/*
+/*
* Find Available Media (Volume) for Pool
*
* Find a Volume for a given PoolId, MediaType, and VolStatus
*
- * Note! this does not correctly implement InChanger.
+ * Note! this does not correctly implement InChanger.
*
* Returns: 0 on failure
* numrows on success
- */
+ */
int
-db_find_next_volume(JCR *jcr, B_DB *mdb, int item, bool InChanger, MEDIA_DBR *mr)
+db_find_next_volume(JCR *jcr, B_DB *mdb, int item, bool InChanger, MEDIA_DBR *mr)
{
MEDIA_DBR omr;
int stat = 0;
while (fread(&omr, len, 1, mdb->mediafd) > 0) {
if (mr->PoolId == omr.PoolId && strcmp(mr->VolStatus, omr.VolStatus) == 0 &&
strcmp(mr->MediaType, omr.MediaType) == 0) {
- if (!(++index == item)) { /* looking for item'th entry */
- Dmsg0(200, "Media record matches, but not index\n");
+ if (!(++index == item)) { /* looking for item'th entry */
+ Dmsg0(200, "Media record matches, but not index\n");
continue;
}
- Dmsg0(200, "Media record matches\n");
+ Dmsg0(200, "Media record matches\n");
memcpy(mr, &omr, len);
- Dmsg1(200, "Findnextvol MediaId=%d\n", mr->MediaId);
+ Dmsg1(200, "Findnextvol MediaId=%d\n", mr->MediaId);
stat = 1;
break; /* found it */
}
}
db_unlock(mdb);
- return stat;
+ return stat;
}
int
* Bacula Catalog Database Get record interface routines
* Note, these routines generally get a record by id or
* by name. If more logic is involved, the routine
- * should be in find.c
+ * should be in find.c
*
* Bacula Catalog Database routines written specifically
* for Bacula. Note, these routines are VERY dumb and
* The purpose of these routines is to ensure that Bacula
* can limp along if no real database is loaded on the
* system.
- *
- * Kern Sibbald, January MMI
+ *
+ * Kern Sibbald, January MMI
*
* Version $Id$
*/
*/
-/*
+/*
* Get Job record for given JobId
* Returns: 0 on failure
* 1 on success
*/
int db_get_job_record(JCR *jcr, B_DB *mdb, JOB_DBR *jr)
-{
+{
JOB_DBR ojr;
faddr_t rec_addr;
int found = 0;
/* Search by Job */
} else if (strcmp(jr->Job, ojr.Job) == 0) {
found = 1;
- Dmsg1(200, "Found Job: %s\n", ojr.Job);
+ Dmsg1(200, "Found Job: %s\n", ojr.Job);
}
if (!found) {
rec_addr = ftell(mdb->jobfd); /* save start next record */
}
-/*
+/*
* Get the number of pool records
*
* Returns: -1 on failure
}
-/*
- * Get Pool Record
+/*
+ * Get Pool Record
* If the PoolId is non-zero, we get its record,
* otherwise, we search on the PoolName
*
* Returns: 0 on failure
- * id on success
+ * id on success
*/
int db_get_pool_record(JCR *jcr, B_DB *mdb, POOL_DBR *pr)
{
/* Search by Name */
} else if (strcmp(pr->Name, opr.Name) == 0) {
found = 1;
- Dmsg1(200, "Found pool: %s\n", opr.Name);
+ Dmsg1(200, "Found pool: %s\n", opr.Name);
}
if (!found) {
rec_addr = ftell(mdb->poolfd); /* save start next record */
return stat;
}
-/*
+/*
* Get the number of Media records
*
* Returns: -1 on failure
}
/*
- * This function returns a list of all the Media record ids
+ * This function returns a list of all the Media record ids
* for a specified PoolId
* The caller must free ids if non-NULL.
*
return 1;
}
-/*
- * Get Media Record
+/*
+ * Get Media Record
* If the MediaId is non-zero, we get its record,
* otherwise, we search on the MediaName
*
* Returns: 0 on failure
- * id on success
+ * id on success
*/
int db_get_media_record(JCR *jcr, B_DB *mdb, MEDIA_DBR *mr)
{
Dmsg1(200, "VolName=%s\n", omr.VolumeName);
/* If id not zero, search by Id */
if (mr->MediaId != 0) {
- Dmsg1(200, "MediaId=%d\n", mr->MediaId);
+ Dmsg1(200, "MediaId=%d\n", mr->MediaId);
if (mr->MediaId == omr.MediaId) {
found = 1;
}
while (fread(&mr, mrlen, 1, mdb->mediafd) > 0) {
if (jm.MediaId == mr.MediaId) {
if (*VolumeNames[0] != 0) { /* if not first name, */
- pm_strcat(VolumeNames, "|"); /* add separator */
+ pm_strcat(VolumeNames, "|"); /* add separator */
}
pm_strcat(VolumeNames, mr.VolumeName); /* add Volume Name */
found++;
strcpy(mdb->errmsg, "No Volumes found.\n");
}
db_unlock(mdb);
- return found;
+ return found;
}
-/*
- * Get Client Record
+/*
+ * Get Client Record
* If the ClientId is non-zero, we get its record,
* otherwise, we search on the Name
*
* Returns: 0 on failure
- * id on success
+ * id on success
*/
int db_get_client_record(JCR *jcr, B_DB *mdb, CLIENT_DBR *cr)
{
}
memcpy(cr, &lcr, len);
stat = lcr.ClientId;
- Dmsg2(200, "Found Client record: ClientId=%d Name=%s\n",
+ Dmsg2(200, "Found Client record: ClientId=%d Name=%s\n",
lcr.ClientId, lcr.Name);
break;
}
return stat;
}
-/*
+/*
* Get FileSet Record (We read the FILESET_DBR structure)
* If the FileSetId is non-zero, we get its record,
* otherwise, we search on the FileSet (its name).
*
* Returns: 0 on failure
- * id on success
+ * id on success
*/
int db_get_fileset_record(JCR *jcr, B_DB *mdb, FILESET_DBR *fsr)
{
/* Found desired record, now return it */
memcpy(fsr, &lfsr, sizeof(lfsr));
stat = fsr->FileSetId;
- Dmsg2(200, "Found FileSet record: FileSetId=%d FileSet=%s\n",
+ Dmsg2(200, "Found FileSet record: FileSetId=%d FileSet=%s\n",
lfsr.FileSetId, lfsr.FileSet);
break;
}
* The purpose of these routines is to ensure that Bacula
* can limp along if no real database is loaded on the
* system.
- *
- * Kern Sibbald, January MMI
+ *
+ * Kern Sibbald, January MMI
*
* Version $Id$
*/
* -----------------------------------------------------------------------
*/
-/*
+/*
* Submit general SQL query
*/
-int db_list_sql_query(JCR *jcr, B_DB *mdb, char *query, DB_LIST_HANDLER *sendit,
+int db_list_sql_query(JCR *jcr, B_DB *mdb, char *query, DB_LIST_HANDLER *sendit,
void *ctx, int verbose)
{
sendit(ctx, "SQL Queries not implemented with internal database.\n");
fseek(mdb->poolfd, 0L, SEEK_SET); /* rewind file */
len = sizeof(pr);
while (fread(&pr, len, 1, mdb->poolfd) > 0) {
- Mmsg(mdb->cmd, " %7d %6d %6d %-10s %s\n",
+ Mmsg(mdb->cmd, " %7d %6d %6d %-10s %s\n",
pr.PoolId, pr.NumVols, pr.MaxVols, pr.PoolType, pr.Name);
sendit(ctx, mdb->cmd);
}
/*
* List Media records
*/
-void db_list_media_records(JCR *jcr, B_DB *mdb, MEDIA_DBR *mdbr,
+void db_list_media_records(JCR *jcr, B_DB *mdb, MEDIA_DBR *mdbr,
DB_LIST_HANDLER *sendit, void *ctx)
{
char ewc[30];
fseek(mdb->mediafd, 0L, SEEK_SET); /* rewind file */
len = sizeof(mr);
while (fread(&mr, len, 1, mdb->mediafd) > 0) {
- Mmsg(mdb->cmd, " %-10s %17s %-15s %s\n",
+ Mmsg(mdb->cmd, " %-10s %17s %-15s %s\n",
mr.VolStatus, edit_uint64_with_commas(mr.VolBytes, ewc),
mr.MediaType, mr.VolumeName);
sendit(ctx, mdb->cmd);
return;
}
-void db_list_jobmedia_records(JCR *jcr, B_DB *mdb, uint32_t JobId,
+void db_list_jobmedia_records(JCR *jcr, B_DB *mdb, uint32_t JobId,
DB_LIST_HANDLER *sendit, void *ctx)
{
JOBMEDIA_DBR jm;
fseek(mdb->mediafd, 0L, SEEK_SET);
while (fread(&mr, mrlen, 1, mdb->mediafd) > 0) {
if (mr.MediaId == jm.MediaId) {
- Mmsg(mdb->cmd, " %7d %-10s %10d %10d\n",
+ Mmsg(mdb->cmd, " %7d %-10s %10d %10d\n",
jm.JobId, mr.VolumeName, jm.FirstIndex, jm.LastIndex);
sendit(ctx, mdb->cmd);
break;
fseek(mdb->mediafd, 0L, SEEK_SET);
while (fread(&mr, mrlen, 1, mdb->mediafd) > 0) {
if (mr.MediaId == jm.MediaId) {
- Mmsg(mdb->cmd, " %7d %-10s %10d %10d\n",
+ Mmsg(mdb->cmd, " %7d %-10s %10d %10d\n",
jm.JobId, mr.VolumeName, jm.FirstIndex, jm.LastIndex);
sendit(ctx, mdb->cmd);
break;
/*
* List Job records
*/
-void db_list_job_records(JCR *jcr, B_DB *mdb, JOB_DBR *jr,
+void db_list_job_records(JCR *jcr, B_DB *mdb, JOB_DBR *jr,
DB_LIST_HANDLER *sendit, void *ctx)
{
int jrlen;
return;
}
fseek(mdb->jobfd, 0L, SEEK_SET); /* rewind file */
- /*
+ /*
* Linear search through Job records
*/
sendit(ctx, " JobId StartTime Type Level Bytes Files Stat JobName\n");
}
localtime_r(&ojr.StartTime, &tm);
strftime(dt, sizeof(dt), "%m-%d %H:%M", &tm);
- Mmsg(mdb->cmd, " %7d %-10s %c %c %14s %10s %c %s\n",
- ojr.JobId, dt, (char)ojr.JobType, (char)ojr.JobLevel,
- edit_uint64_with_commas(ojr.JobBytes, ewc1),
+ Mmsg(mdb->cmd, " %7d %-10s %c %c %14s %10s %c %s\n",
+ ojr.JobId, dt, (char)ojr.JobType, (char)ojr.JobLevel,
+ edit_uint64_with_commas(ojr.JobBytes, ewc1),
edit_uint64_with_commas(ojr.JobFiles, ewc2),
(char)ojr.JobStatus, ojr.Name);
sendit(ctx, mdb->cmd);
/*
* List Job Totals
*/
-void db_list_job_totals(JCR *jcr, B_DB *mdb, JOB_DBR *jr,
+void db_list_job_totals(JCR *jcr, B_DB *mdb, JOB_DBR *jr,
DB_LIST_HANDLER *sendit, void *ctx)
{
char ewc1[30], ewc2[30], ewc3[30];
return;
}
fseek(mdb->jobfd, 0L, SEEK_SET); /* rewind file */
- /*
+ /*
* Linear search through JobStart records
*/
sendit(ctx, " NumJobs NumFiles NumBytes\n");
total_bytes += ojr.JobBytes;
total_jobs++;
}
- Mmsg(mdb->cmd, " %7s %10s %15s\n",
+ Mmsg(mdb->cmd, " %7s %10s %15s\n",
edit_uint64_with_commas(total_jobs, ewc1),
- edit_uint64_with_commas(total_files, ewc2),
+ edit_uint64_with_commas(total_files, ewc2),
edit_uint64_with_commas(total_bytes, ewc3));
sendit(ctx, mdb->cmd);
sendit(ctx, "=======================================\n");
void db_list_client_records(JCR *jcr, B_DB *mdb, DB_LIST_HANDLER *sendit, void *ctx)
{ }
-int db_list_sql_query(JCR *jcr, B_DB *mdb, char *query, DB_LIST_HANDLER *sendit,
+int db_list_sql_query(JCR *jcr, B_DB *mdb, char *query, DB_LIST_HANDLER *sendit,
void *ctx, int verbose, e_list_type type)
{
return 0;
}
void
-db_list_pool_records(JCR *jcr, B_DB *mdb, DB_LIST_HANDLER *sendit, void *ctx, e_list_type type)
+db_list_pool_records(JCR *jcr, B_DB *mdb, DB_LIST_HANDLER *sendit, void *ctx, e_list_type type)
{ }
void
-db_list_media_records(JCR *jcr, B_DB *mdb, MEDIA_DBR *mdbr,
+db_list_media_records(JCR *jcr, B_DB *mdb, MEDIA_DBR *mdbr,
DB_LIST_HANDLER *sendit, void *ctx, e_list_type type)
{ }
-void db_list_jobmedia_records(JCR *jcr, B_DB *mdb, uint32_t JobId,
+void db_list_jobmedia_records(JCR *jcr, B_DB *mdb, uint32_t JobId,
DB_LIST_HANDLER *sendit, void *ctx, e_list_type type)
{ }
void
-db_list_job_records(JCR *jcr, B_DB *mdb, JOB_DBR *jr, DB_LIST_HANDLER *sendit,
+db_list_job_records(JCR *jcr, B_DB *mdb, JOB_DBR *jr, DB_LIST_HANDLER *sendit,
void *ctx, e_list_type type)
{ }
* The purpose of these routines is to ensure that Bacula
* can limp along if no real database is loaded on the
* system.
- *
- * Kern Sibbald, January MMI
+ *
+ * Kern Sibbald, January MMI
*
*
* Version $Id$
* most current start fields to the job record.
* It is assumed that you did a db_create_job_record() already.
*/
-bool db_update_job_start_record(JCR *jcr, B_DB *mdb, JOB_DBR *jr)
+bool db_update_job_start_record(JCR *jcr, B_DB *mdb, JOB_DBR *jr)
{
int len, stat = 1;
JOB_DBR ojr;
* This is called at Job termination time to add all the
* other fields to the job record.
*/
-int db_update_job_end_record(JCR *jcr, B_DB *mdb, JOB_DBR *jr)
+int db_update_job_end_record(JCR *jcr, B_DB *mdb, JOB_DBR *jr)
{
int len, stat = 1;
JOB_DBR ojr;
}
-int db_update_media_record(JCR *jcr, B_DB *mdb, MEDIA_DBR *mr)
-{
+int db_update_media_record(JCR *jcr, B_DB *mdb, MEDIA_DBR *mr)
+{
int stat = 1;
MEDIA_DBR omr;
int len;
-
+
db_lock(mdb);
Dmsg0(200, "In db_update_media_record\n");
mr->MediaId = 0;
return stat;
}
-int db_update_pool_record(JCR *jcr, B_DB *mdb, POOL_DBR *pr)
-{
+int db_update_pool_record(JCR *jcr, B_DB *mdb, POOL_DBR *pr)
+{
int stat = 1;
POOL_DBR opr;
int len;
-
+
db_lock(mdb);
Dmsg0(200, "In db_update_pool_record\n");
len = sizeof(opr);
/* Update specific fields */
opr.NumVols = pr->NumVols;
- opr.MaxVols = pr->MaxVols;
+ opr.MaxVols = pr->MaxVols;
opr.UseOnce = pr->UseOnce;
opr.UseCatalog = pr->UseCatalog;
opr.AcceptAnyVolume = pr->AcceptAnyVolume;
}
int db_mark_file_record(JCR *jcr, B_DB *mdb, FileId_t FileId, JobId_t JobId)
-{
+{
return 1;
}
return 0;
}
-int db_update_media_defaults(JCR *jcr, B_DB *mdb, MEDIA_DBR *mr)
+int db_update_media_defaults(JCR *jcr, B_DB *mdb, MEDIA_DBR *mr)
{
return 1;
}
} B_DB;
-/*
- * "Generic" names for easier conversion
+/*
+ * "Generic" names for easier conversion
*
* S Q L I T E
*/
#define sql_free_result(x) my_sqlite_free_table(x)
#define sql_fetch_row(x) my_sqlite_fetch_row(x)
#define sql_query(x, y) my_sqlite_query((x), (y))
-#define sql_close(x) sqlite_close((x)->db)
+#define sql_close(x) sqlite_close((x)->db)
#define sql_strerror(x) (x)->sqlite_errmsg?(x)->sqlite_errmsg:"unknown"
#define sql_num_rows(x) (x)->nrow
#define sql_data_seek(x, i) (x)->row = (i)
#define sql_field_seek(x, y) my_sqlite_field_seek((x), (y))
#define sql_fetch_field(x) my_sqlite_fetch_field(x)
#define sql_num_fields(x) ((x)->ncolumn)
-#define SQL_ROW char**
+#define SQL_ROW char**
#define sql_free_result(x) mysql_free_result((x)->result)
#define sql_fetch_row(x) mysql_fetch_row((x)->result)
#define sql_query(x, y) mysql_query((x)->db, (y))
-#define sql_close(x) mysql_close((x)->db)
+#define sql_close(x) mysql_close((x)->db)
#define sql_strerror(x) mysql_error((x)->db)
#define sql_num_rows(x) mysql_num_rows((x)->result)
#define sql_data_seek(x, i) mysql_data_seek((x)->result, (i))
typedef char **POSTGRESQL_ROW;
typedef struct pg_field {
- char *name;
- int max_length;
- unsigned int type;
- unsigned int flags; // 1 == not null
+ char *name;
+ int max_length;
+ unsigned int type;
+ unsigned int flags; // 1 == not null
} POSTGRESQL_FIELD;
#define sql_free_result(x) my_postgresql_free_result(x)
#define sql_fetch_row(x) my_postgresql_fetch_row(x)
#define sql_query(x, y) my_postgresql_query((x), (y))
-#define sql_close(x) PQfinish((x)->db)
+#define sql_close(x) PQfinish((x)->db)
#define sql_strerror(x) PQresultErrorMessage((x)->result)
#define sql_num_rows(x) ((unsigned) PQntuples((x)->result))
#define sql_data_seek(x, i) my_postgresql_data_seek((x), (i))
/* This is a "dummy" definition for use outside of sql.c
*/
-typedef struct s_db {
+typedef struct s_db {
int dummy; /* for SunOS compiler */
-} B_DB;
+} B_DB;
#endif /* __SQL_C */
typedef uint32_t FileId_t;
typedef uint32_t DBId_t; /* general DB id type */
typedef uint32_t JobId_t;
-
+
#define faddr_t long
/* Volume Parameter structure */
struct VOL_PARAMS {
char VolumeName[MAX_NAME_LENGTH]; /* Volume name */
- uint32_t VolIndex; /* Volume seqence no. */
+ uint32_t VolIndex; /* Volume seqence no. */
uint32_t FirstIndex; /* First index this Volume */
uint32_t LastIndex; /* Last index this Volume */
uint32_t StartFile; /* File for start of data */
uint32_t MaxVolJobs; /* Max Jobs on Volume */
uint32_t MaxVolFiles; /* Max files on Volume */
uint64_t MaxVolBytes; /* Max bytes on Volume */
- char PoolType[MAX_NAME_LENGTH];
+ char PoolType[MAX_NAME_LENGTH];
char LabelFormat[MAX_NAME_LENGTH];
/* Extra stuff not in DB */
faddr_t rec_addr;
#include "jcr.h"
/*
- * Some functions exported by sql.c for use withing the
+ * Some functions exported by sql.c for use withing the
* cats directory.
*/
void list_result(B_DB *mdb, DB_LIST_HANDLER *send, void *ctx, e_list_type type);
int check_tables_version(JCR *jcr, B_DB *mdb);
void _db_unlock(const char *file, int line, B_DB *mdb);
void _db_lock(const char *file, int line, B_DB *mdb);
-
+
#endif /* __SQL_H_ */
* never have errors, or it is really fatal.
*/
B_DB *
-db_init_database(JCR *jcr, const char *db_name, const char *db_user, const char *db_password,
+db_init_database(JCR *jcr, const char *db_name, const char *db_user, const char *db_password,
const char *db_address, int db_port, const char *db_socket,
int mult_db_connections)
{
B_DB *mdb;
- if (!db_user) {
+ if (!db_user) {
Jmsg(jcr, M_FATAL, 0, _("A user name for MySQL must be supplied.\n"));
return NULL;
}
if (!mult_db_connections) {
for (mdb=NULL; (mdb=(B_DB *)qnext(&db_list, &mdb->bq)); ) {
if (strcmp(mdb->db_name, db_name) == 0) {
- Dmsg2(100, "DB REopen %d %s\n", mdb->ref_count, db_name);
+ Dmsg2(100, "DB REopen %d %s\n", mdb->ref_count, db_name);
mdb->ref_count++;
V(mutex);
return mdb; /* already open */
mdb->connected = FALSE;
if ((errstat=rwl_init(&mdb->lock)) != 0) {
- Mmsg1(&mdb->errmsg, _("Unable to initialize DB lock. ERR=%s\n"),
+ Mmsg1(&mdb->errmsg, _("Unable to initialize DB lock. ERR=%s\n"),
strerror(errstat));
V(mutex);
return 0;
}
bmicrosleep(5,0);
}
-
+
Dmsg0(50, "mysql_real_connect done\n");
- Dmsg3(50, "db_user=%s db_name=%s db_password=%s\n", mdb->db_user, mdb->db_name,
- mdb->db_password==NULL?"(NULL)":mdb->db_password);
-
+ Dmsg3(50, "db_user=%s db_name=%s db_password=%s\n", mdb->db_user, mdb->db_name,
+ mdb->db_password==NULL?"(NULL)":mdb->db_password);
+
if (mdb->db == NULL) {
- Mmsg2(&mdb->errmsg, _("Unable to connect to MySQL server. \n\
-Database=%s User=%s\n\
-It is probably not running or your password is incorrect.\n"),
+ Mmsg2(&mdb->errmsg, _("Unable to connect to MySQL server. \n"
+"Database=%s User=%s\n"
+"It is probably not running or your password is incorrect.\n"),
mdb->db_name, mdb->db_user);
V(mutex);
return 0;
mysql_server_end();
#endif
}
- rwl_destroy(&mdb->lock);
+ rwl_destroy(&mdb->lock);
free_pool_memory(mdb->errmsg);
free_pool_memory(mdb->cmd);
free_pool_memory(mdb->cached_path);
/*
* Return the next unique index (auto-increment) for
* the given table. Return NULL on error.
- *
+ *
* For MySQL, NULL causes the auto-increment value
* to be updated.
*/
{
strcpy(index, "NULL");
return 1;
-}
+}
/*
while (len--) {
switch (*o) {
case 0:
- *n++= '\\';
- *n++= '0';
+ *n++= '\\';
+ *n++= '0';
o++;
break;
case '\n':
- *n++= '\\';
- *n++= 'n';
+ *n++= '\\';
+ *n++= 'n';
o++;
break;
case '\r':
- *n++= '\\';
- *n++= 'r';
+ *n++= '\\';
+ *n++= 'r';
o++;
break;
case '\\':
- *n++= '\\';
- *n++= '\\';
+ *n++= '\\';
+ *n++= '\\';
o++;
break;
case '\'':
- *n++= '\\';
- *n++= '\'';
+ *n++= '\\';
+ *n++= '\'';
o++;
break;
case '"':
- *n++= '\\';
- *n++= '"';
+ *n++= '\\';
+ *n++= '"';
o++;
break;
case '\032':
- *n++= '\\';
- *n++= 'Z';
+ *n++= '\\';
+ *n++= 'Z';
o++;
break;
default:
int db_sql_query(B_DB *mdb, const char *query, DB_RESULT_HANDLER *result_handler, void *ctx)
{
SQL_ROW row;
-
+
db_lock(mdb);
if (sql_query(mdb, query) != 0) {
Mmsg(mdb->errmsg, _("Query failed: %s: ERR=%s\n"), query, sql_strerror(mdb));
* never have errors, or it is really fatal.
*/
B_DB *
-db_init_database(JCR *jcr, const char *db_name, const char *db_user, const char *db_password,
- const char *db_address, int db_port, const char *db_socket,
+db_init_database(JCR *jcr, const char *db_name, const char *db_user, const char *db_password,
+ const char *db_address, int db_port, const char *db_socket,
int mult_db_connections)
{
B_DB *mdb;
- if (!db_user) {
+ if (!db_user) {
Jmsg(jcr, M_FATAL, 0, _("A user name for PostgreSQL must be supplied.\n"));
return NULL;
}
/* Look to see if DB already open */
for (mdb=NULL; (mdb=(B_DB *)qnext(&db_list, &mdb->bq)); ) {
if (strcmp(mdb->db_name, db_name) == 0) {
- Dmsg2(100, "DB REopen %d %s\n", mdb->ref_count, db_name);
+ Dmsg2(100, "DB REopen %d %s\n", mdb->ref_count, db_name);
mdb->ref_count++;
V(mutex);
return mdb; /* already open */
mdb->connected = false;
if ((errstat=rwl_init(&mdb->lock)) != 0) {
- Mmsg1(&mdb->errmsg, _("Unable to initialize DB lock. ERR=%s\n"),
+ Mmsg1(&mdb->errmsg, _("Unable to initialize DB lock. ERR=%s\n"),
strerror(errstat));
V(mutex);
return 0;
/* If no connect, try once more in case it is a timing problem */
if (PQstatus(mdb->db) == CONNECTION_OK) {
- break;
+ break;
}
bmicrosleep(5, 0);
}
Dmsg0(50, "pg_real_connect done\n");
- Dmsg3(50, "db_user=%s db_name=%s db_password=%s\n", mdb->db_user, mdb->db_name,
- mdb->db_password==NULL?"(NULL)":mdb->db_password);
-
+ Dmsg3(50, "db_user=%s db_name=%s db_password=%s\n", mdb->db_user, mdb->db_name,
+ mdb->db_password==NULL?"(NULL)":mdb->db_password);
+
if (PQstatus(mdb->db) != CONNECTION_OK) {
Mmsg2(&mdb->errmsg, _("Unable to connect to PostgreSQL server.\n"
- "Database=%s User=%s\n"
- "It is probably not running or your password is incorrect.\n"),
+ "Database=%s User=%s\n"
+ "It is probably not running or your password is incorrect.\n"),
mdb->db_name, mdb->db_user);
V(mutex);
return 0;
if (mdb->connected && mdb->db) {
sql_close(mdb);
}
- rwl_destroy(&mdb->lock);
+ rwl_destroy(&mdb->lock);
free_pool_memory(mdb->errmsg);
free_pool_memory(mdb->cmd);
free_pool_memory(mdb->cached_path);
if (mdb->db_socket) {
free(mdb->db_socket);
}
- my_postgresql_free_result(mdb);
+ my_postgresql_free_result(mdb);
free(mdb);
}
V(mutex);
/*
* Return the next unique index (auto-increment) for
* the given table. Return NULL on error.
- *
+ *
* For PostgreSQL, NULL causes the auto-increment value
* to be updated.
*/
{
strcpy(index, "NULL");
return 1;
-}
+}
/*
SQL_ROW row;
Dmsg0(500, "db_sql_query started\n");
-
+
db_lock(mdb);
if (sql_query(mdb, query) != 0) {
Mmsg(mdb->errmsg, _("Query failed: %s: ERR=%s\n"), query, sql_strerror(mdb));
if ((mdb->result = sql_store_result(mdb)) != NULL) {
int num_fields = sql_num_fields(mdb);
- Dmsg0(500, "db_sql_query sql_store_result suceeded\n");
+ Dmsg0(500, "db_sql_query sql_store_result suceeded\n");
while ((row = sql_fetch_row(mdb)) != NULL) {
- Dmsg0(500, "db_sql_query sql_fetch_row worked\n");
+ Dmsg0(500, "db_sql_query sql_fetch_row worked\n");
if (result_handler(ctx, num_fields, row))
break;
}
-POSTGRESQL_ROW my_postgresql_fetch_row(B_DB *mdb)
+POSTGRESQL_ROW my_postgresql_fetch_row(B_DB *mdb)
{
int j;
POSTGRESQL_ROW row = NULL; // by default, return NULL
Dmsg1(500, "we have need space of %d bytes\n", sizeof(char *) * mdb->num_fields);
if (mdb->row != NULL) {
- Dmsg0(500, "my_postgresql_fetch_row freeing space\n");
+ Dmsg0(500, "my_postgresql_fetch_row freeing space\n");
free(mdb->row);
mdb->row = NULL;
}
// get each value from this row
for (j = 0; j < mdb->num_fields; j++) {
mdb->row[j] = PQgetvalue(mdb->result, mdb->row_number, j);
- Dmsg2(500, "my_postgresql_fetch_row field '%d' has value '%s'\n", j, mdb->row[j]);
+ Dmsg2(500, "my_postgresql_fetch_row field '%d' has value '%s'\n", j, mdb->row[j]);
}
// increment the row number for the next call
mdb->row_number++;
max_length = 0;
for (i = 0; i < mdb->num_rows; i++) {
if (PQgetisnull(mdb->result, i, field_num)) {
- this_length = 4; // "NULL"
+ this_length = 4; // "NULL"
} else {
this_length = strlen(PQgetvalue(mdb->result, i, field_num));
}
-
+
if (max_length < this_length) {
max_length = this_length;
}
return max_length;
}
-POSTGRESQL_FIELD * my_postgresql_fetch_field(B_DB *mdb)
+POSTGRESQL_FIELD * my_postgresql_fetch_field(B_DB *mdb)
{
int i;
mdb->fields = (POSTGRESQL_FIELD *)malloc(sizeof(POSTGRESQL_FIELD) * mdb->num_fields);
for (i = 0; i < mdb->num_fields; i++) {
- Dmsg1(500, "filling field %d\n", i);
+ Dmsg1(500, "filling field %d\n", i);
mdb->fields[i].name = PQfname(mdb->result, i);
mdb->fields[i].max_length = my_postgresql_max_length(mdb, i);
mdb->fields[i].type = PQftype(mdb->result, i);
mdb->fields[i].flags = 0;
- Dmsg4(500, "my_postgresql_fetch_field finds field '%s' has length='%d' type='%d' and IsNull=%d\n",
+ Dmsg4(500, "my_postgresql_fetch_field finds field '%s' has length='%d' type='%d' and IsNull=%d\n",
mdb->fields[i].name, mdb->fields[i].max_length, mdb->fields[i].type,
mdb->fields[i].flags);
} // end for
return &mdb->fields[mdb->field_number++];
}
-void my_postgresql_data_seek(B_DB *mdb, int row)
+void my_postgresql_data_seek(B_DB *mdb, int row)
{
// set the row number to be returned on the next call
// to my_postgresql_fetch_row
return mdb->status;
}
-void my_postgresql_free_result (B_DB *mdb)
+void my_postgresql_free_result (B_DB *mdb)
{
if (mdb->result) {
PQclear(mdb->result);
}
}
-int my_postgresql_currval(B_DB *mdb, char *table_name)
+int my_postgresql_currval(B_DB *mdb, char *table_name)
{
// Obtain the current value of the sequence that
// provides the serial value for primary key of the table.
/* Database prototypes */
/* sql.c */
-B_DB *db_init_database(JCR *jcr, const char *db_name, const char *db_user, const char *db_password,
- const char *db_address, int db_port, const char *db_socket,
+B_DB *db_init_database(JCR *jcr, const char *db_name, const char *db_user, const char *db_password,
+ const char *db_address, int db_port, const char *db_socket,
int mult_db_connections);
int db_open_database(JCR *jcr, B_DB *db);
void db_close_database(JCR *jcr, B_DB *db);
int db_create_media_record(JCR *jcr, B_DB *db, MEDIA_DBR *media_dbr);
int db_create_client_record(JCR *jcr, B_DB *db, CLIENT_DBR *cr);
int db_create_fileset_record(JCR *jcr, B_DB *db, FILESET_DBR *fsr);
-int db_create_pool_record(JCR *jcr, B_DB *db, POOL_DBR *pool_dbr);
+int db_create_pool_record(JCR *jcr, B_DB *db, POOL_DBR *pool_dbr);
bool db_create_jobmedia_record(JCR *jcr, B_DB *mdb, JOBMEDIA_DBR *jr);
int db_create_counter_record(JCR *jcr, B_DB *mdb, COUNTER_DBR *cr);
int db_update_media_record(JCR *jcr, B_DB *db, MEDIA_DBR *mr);
int db_update_media_defaults(JCR *jcr, B_DB *mdb, MEDIA_DBR *mr);
int db_update_counter_record(JCR *jcr, B_DB *mdb, COUNTER_DBR *cr);
-int db_add_SIG_to_file_record(JCR *jcr, B_DB *mdb, FileId_t FileId, char *SIG, int type);
+int db_add_SIG_to_file_record(JCR *jcr, B_DB *mdb, FileId_t FileId, char *SIG, int type);
int db_mark_file_record(JCR *jcr, B_DB *mdb, FileId_t FileId, JobId_t JobId);
void db_make_inchanger_unique(JCR *jcr, B_DB *mdb, MEDIA_DBR *mr);
/*
* Bacula Catalog Database interface routines
- *
+ *
* Almost generic set of SQL database interface routines
* (with a little more work)
*
Dmsg0(800, "int_handler finishes\n");
return 0;
}
-
+
/* NOTE!!! The following routines expect that the
int check_tables_version(JCR *jcr, B_DB *mdb)
{
const char *query = "SELECT VersionId FROM Version";
-
+
bacula_db_version = 0;
db_sql_query(mdb, query, int_handler, (void *)&bacula_db_version);
if (bacula_db_version != BDB_VERSION) {
m_msg(file, line, &mdb->errmsg, _("query %s failed:\n%s\n"), cmd, sql_strerror(mdb));
j_msg(file, line, jcr, M_FATAL, 0, "%s", mdb->errmsg);
if (verbose) {
- j_msg(file, line, jcr, M_INFO, 0, "%s\n", cmd);
+ j_msg(file, line, jcr, M_INFO, 0, "%s\n", cmd);
}
return 0;
}
return mdb->result != NULL;
}
-/*
- * Utility routine to do inserts
- * Returns: 0 on failure
+/*
+ * Utility routine to do inserts
+ * Returns: 0 on failure
* 1 on success
*/
int
m_msg(file, line, &mdb->errmsg, _("insert %s failed:\n%s\n"), cmd, sql_strerror(mdb));
j_msg(file, line, jcr, M_FATAL, 0, "%s", mdb->errmsg);
if (verbose) {
- j_msg(file, line, jcr, M_INFO, 0, "%s\n", cmd);
+ j_msg(file, line, jcr, M_INFO, 0, "%s\n", cmd);
}
return 0;
}
}
if (mdb->num_rows != 1) {
char ed1[30];
- m_msg(file, line, &mdb->errmsg, _("Insertion problem: affected_rows=%s\n"),
+ m_msg(file, line, &mdb->errmsg, _("Insertion problem: affected_rows=%s\n"),
edit_uint64(mdb->num_rows, ed1));
if (verbose) {
- j_msg(file, line, jcr, M_INFO, 0, "%s\n", cmd);
+ j_msg(file, line, jcr, M_INFO, 0, "%s\n", cmd);
}
return 0;
}
/* Utility routine for updates.
* Returns: 0 on failure
- * 1 on success
+ * 1 on success
*/
int
UpdateDB(const char *file, int line, JCR *jcr, B_DB *mdb, char *cmd)
m_msg(file, line, &mdb->errmsg, _("update %s failed:\n%s\n"), cmd, sql_strerror(mdb));
j_msg(file, line, jcr, M_ERROR, 0, "%s", mdb->errmsg);
if (verbose) {
- j_msg(file, line, jcr, M_INFO, 0, "%s\n", cmd);
+ j_msg(file, line, jcr, M_INFO, 0, "%s\n", cmd);
}
return 0;
}
mdb->num_rows = sql_affected_rows(mdb);
if (mdb->num_rows < 1) {
char ed1[30];
- m_msg(file, line, &mdb->errmsg, _("Update problem: affected_rows=%s\n"),
+ m_msg(file, line, &mdb->errmsg, _("Update problem: affected_rows=%s\n"),
edit_uint64(mdb->num_rows, ed1));
if (verbose) {
// j_msg(file, line, jcr, M_INFO, 0, "%s\n", cmd);
return 1;
}
-/* Utility routine for deletes
+/* Utility routine for deletes
*
* Returns: -1 on error
* n number of rows affected
m_msg(file, line, &mdb->errmsg, _("delete %s failed:\n%s\n"), cmd, sql_strerror(mdb));
j_msg(file, line, jcr, M_ERROR, 0, "%s", mdb->errmsg);
if (verbose) {
- j_msg(file, line, jcr, M_INFO, 0, "%s\n", cmd);
+ j_msg(file, line, jcr, M_INFO, 0, "%s\n", cmd);
}
return -1;
}
if (QUERY_DB(jcr, mdb, mdb->cmd)) {
if ((row = sql_fetch_row(mdb)) == NULL) {
- Mmsg1(&mdb->errmsg, _("error fetching row: %s\n"), sql_strerror(mdb));
+ Mmsg1(&mdb->errmsg, _("error fetching row: %s\n"), sql_strerror(mdb));
stat = -1;
} else {
stat = atoi(row[0]);
e_msg(file, line, M_ABORT, 0, "rwl_writelock failure. ERR=%s\n",
be.strerror(errstat));
}
-}
+}
/*
* Unlock the database. This can be called multiple times by the
e_msg(file, line, M_ABORT, 0, "rwl_writeunlock failure. ERR=%s\n",
be.strerror(errstat));
}
-}
+}
/*
* Start a transaction. This groups inserts and makes things
- * much more efficient. Usually started when inserting
+ * much more efficient. Usually started when inserting
* file attributes.
*/
void db_start_transaction(JCR *jcr, B_DB *mdb)
if (mdb->transaction && mdb->changes > 10000) {
db_end_transaction(jcr, mdb);
}
- if (!mdb->transaction) {
+ if (!mdb->transaction) {
my_sqlite_query(mdb, "BEGIN"); /* begin transaction */
Dmsg0(400, "Start SQLite transaction\n");
mdb->transaction = 1;
/*
* This is turned off because transactions break
- * if multiple simultaneous jobs are run.
+ * if multiple simultaneous jobs are run.
*/
#ifdef HAVE_POSTGRESQL
if (!mdb->allow_transactions) {
if (mdb->transaction && mdb->changes > 25000) {
db_end_transaction(jcr, mdb);
}
- if (!mdb->transaction) {
+ if (!mdb->transaction) {
db_sql_query(mdb, "BEGIN", NULL, NULL); /* begin transaction */
Dmsg0(400, "Start PosgreSQL transaction\n");
mdb->transaction = 1;
void db_end_transaction(JCR *jcr, B_DB *mdb)
{
/*
- * This can be called during thread cleanup and
+ * This can be called during thread cleanup and
* the db may already be closed. So simply return.
*/
if (!mdb) {
{
const char *p, *f;
- /* Find path without the filename.
+ /* Find path without the filename.
* I.e. everything after the last / is a "filename".
* OK, maybe it is a directory name, but we treat it like
* a filename. If we don't find a / then the whole name
}
/* If filename doesn't exist (i.e. root directory), we
- * simply create a blank name consisting of a single
+ * simply create a blank name consisting of a single
* space. This makes handling zero length filenames
* easier.
*/
mdb->fnl = 0;
}
- mdb->pnl = f - fname;
+ mdb->pnl = f - fname;
if (mdb->pnl > 0) {
mdb->path = check_pool_memory_size(mdb->path, mdb->pnl+1);
memcpy(mdb->path, fname, mdb->pnl);
for (i = 0; i < sql_num_fields(mdb); i++) {
field = sql_fetch_field(mdb);
for (j = 0; j < (int)field->max_length + 2; j++) {
- send(ctx, "-");
+ send(ctx, "-");
}
send(ctx, "+");
}
}
/*
- * If full_list is set, we list vertically, otherwise, we
- * list on one line horizontally.
+ * If full_list is set, we list vertically, otherwise, we
+ * list on one line horizontally.
*/
void
list_result(JCR *jcr, B_DB *mdb, DB_LIST_HANDLER *send, void *ctx, e_list_type type)
col_len = field->max_length;
}
if (col_len < 4 && !IS_NOT_NULL(field->flags)) {
- col_len = 4; /* 4 = length of the word "NULL" */
+ col_len = 4; /* 4 = length of the word "NULL" */
}
field->max_length = col_len; /* reset column info */
}
for (i = 0; i < sql_num_fields(mdb); i++) {
field = sql_fetch_field(mdb);
if (row[i] == NULL) {
- bsnprintf(buf, sizeof(buf), " %-*s |", (int)field->max_length, "NULL");
+ bsnprintf(buf, sizeof(buf), " %-*s |", (int)field->max_length, "NULL");
} else if (IS_NUM(field->type) && !jcr->gui && is_an_integer(row[i])) {
- bsnprintf(buf, sizeof(buf), " %*s |", (int)field->max_length,
+ bsnprintf(buf, sizeof(buf), " %*s |", (int)field->max_length,
add_commas(row[i], ewc));
} else {
- bsnprintf(buf, sizeof(buf), " %-*s |", (int)field->max_length, row[i]);
+ bsnprintf(buf, sizeof(buf), " %-*s |", (int)field->max_length, row[i]);
}
send(ctx, buf);
}
return;
vertical_list:
-
+
Dmsg1(800, "list_result starts vertical list at %d fields\n", sql_num_fields(mdb));
while ((row = sql_fetch_row(mdb)) != NULL) {
sql_field_seek(mdb, 0);
for (i = 0; i < sql_num_fields(mdb); i++) {
field = sql_fetch_field(mdb);
if (row[i] == NULL) {
- bsnprintf(buf, sizeof(buf), " %*s: %s\n", max_len, field->name, "NULL");
+ bsnprintf(buf, sizeof(buf), " %*s: %s\n", max_len, field->name, "NULL");
} else if (IS_NUM(field->type) && !jcr->gui && is_an_integer(row[i])) {
- bsnprintf(buf, sizeof(buf), " %*s: %s\n", max_len, field->name,
+ bsnprintf(buf, sizeof(buf), " %*s: %s\n", max_len, field->name,
add_commas(row[i], ewc));
} else {
- bsnprintf(buf, sizeof(buf), " %*s: %s\n", max_len, field->name, row[i]);
+ bsnprintf(buf, sizeof(buf), " %*s: %s\n", max_len, field->name, row[i]);
}
send(ctx, buf);
}
/*
* Bacula Catalog Database Create record interface routines
- *
+ *
* Kern Sibbald, March 2000
*
* Version $Id$
stime = jr->SchedTime;
ASSERT(stime != 0);
- localtime_r(&stime, &tm);
+ localtime_r(&stime, &tm);
strftime(dt, sizeof(dt), "%Y-%m-%d %T", &tm);
JobTDate = (utime_t)stime;
/* Must create it */
Mmsg(mdb->cmd,
-"INSERT INTO Job (Job,Name,Type,Level,JobStatus,SchedTime,JobTDate) VALUES \
-('%s','%s','%c','%c','%c','%s',%s)",
- jr->Job, jr->Name, (char)(jr->JobType), (char)(jr->JobLevel),
+"INSERT INTO Job (Job,Name,Type,Level,JobStatus,SchedTime,JobTDate) VALUES "
+"('%s','%s','%c','%c','%c','%s',%s)",
+ jr->Job, jr->Name, (char)(jr->JobType), (char)(jr->JobLevel),
(char)(jr->JobStatus), dt, edit_uint64(JobTDate, ed1));
if (!INSERT_DB(jcr, mdb, mdb->cmd)) {
- Mmsg2(&mdb->errmsg, _("Create DB Job record %s failed. ERR=%s\n"),
+ Mmsg2(&mdb->errmsg, _("Create DB Job record %s failed. ERR=%s\n"),
mdb->cmd, sql_strerror(mdb));
jr->JobId = 0;
stat = 0;
return stat;
}
-/* Create a JobMedia record for medium used this job
+/* Create a JobMedia record for medium used this job
* Returns: false on failure
* true on success
*/
}
count++;
- Mmsg(mdb->cmd,
- "INSERT INTO JobMedia (JobId,MediaId,FirstIndex,LastIndex,"
- "StartFile,EndFile,StartBlock,EndBlock,VolIndex) "
- "VALUES (%u,%u,%u,%u,%u,%u,%u,%u,%u)",
+ Mmsg(mdb->cmd,
+ "INSERT INTO JobMedia (JobId,MediaId,FirstIndex,LastIndex,"
+ "StartFile,EndFile,StartBlock,EndBlock,VolIndex) "
+ "VALUES (%u,%u,%u,%u,%u,%u,%u,%u,%u)",
jm->JobId, jm->MediaId, jm->FirstIndex, jm->LastIndex,
jm->StartFile, jm->EndFile, jm->StartBlock, jm->EndBlock,count);
Dmsg0(300, mdb->cmd);
if (!INSERT_DB(jcr, mdb, mdb->cmd)) {
- Mmsg2(&mdb->errmsg, _("Create JobMedia record %s failed: ERR=%s\n"), mdb->cmd,
+ Mmsg2(&mdb->errmsg, _("Create JobMedia record %s failed: ERR=%s\n"), mdb->cmd,
sql_strerror(mdb));
ok = false;
} else {
/* Worked, now update the Media record with the EndFile and EndBlock */
- Mmsg(mdb->cmd,
- "UPDATE Media SET EndFile=%u, EndBlock=%u WHERE MediaId=%u",
+ Mmsg(mdb->cmd,
+ "UPDATE Media SET EndFile=%u, EndBlock=%u WHERE MediaId=%u",
jm->EndFile, jm->EndBlock, jm->MediaId);
if (!UPDATE_DB(jcr, mdb, mdb->cmd)) {
- Mmsg2(&mdb->errmsg, _("Update Media record %s failed: ERR=%s\n"), mdb->cmd,
+ Mmsg2(&mdb->errmsg, _("Update Media record %s failed: ERR=%s\n"), mdb->cmd,
sql_strerror(mdb));
ok = false;
}
if (QUERY_DB(jcr, mdb, mdb->cmd)) {
mdb->num_rows = sql_num_rows(mdb);
if (mdb->num_rows > 0) {
- Mmsg1(&mdb->errmsg, _("pool record %s already exists\n"), pr->Name);
+ Mmsg1(&mdb->errmsg, _("pool record %s already exists\n"), pr->Name);
sql_free_result(mdb);
db_unlock(mdb);
return 0;
}
/* Must create it */
- Mmsg(mdb->cmd,
-"INSERT INTO Pool (Name,NumVols,MaxVols,UseOnce,UseCatalog,\
-AcceptAnyVolume,AutoPrune,Recycle,VolRetention,VolUseDuration,\
-MaxVolJobs,MaxVolFiles,MaxVolBytes,PoolType,LabelFormat) \
-VALUES ('%s',%u,%u,%d,%d,%d,%d,%d,%s,%s,%u,%u,%s,'%s','%s')",
+ Mmsg(mdb->cmd,
+"INSERT INTO Pool (Name,NumVols,MaxVols,UseOnce,UseCatalog,"
+"AcceptAnyVolume,AutoPrune,Recycle,VolRetention,VolUseDuration,"
+"MaxVolJobs,MaxVolFiles,MaxVolBytes,PoolType,LabelFormat) "
+"VALUES ('%s',%u,%u,%d,%d,%d,%d,%d,%s,%s,%u,%u,%s,'%s','%s')",
pr->Name,
pr->NumVols, pr->MaxVols,
pr->UseOnce, pr->UseCatalog,
pr->PoolType, pr->LabelFormat);
Dmsg1(200, "Create Pool: %s\n", mdb->cmd);
if (!INSERT_DB(jcr, mdb, mdb->cmd)) {
- Mmsg2(&mdb->errmsg, _("Create db Pool record %s failed: ERR=%s\n"),
+ Mmsg2(&mdb->errmsg, _("Create db Pool record %s failed: ERR=%s\n"),
mdb->cmd, sql_strerror(mdb));
pr->PoolId = 0;
stat = 0;
stat = 1;
}
db_unlock(mdb);
-
+
return stat;
}
-/*
+/*
* Create Media record. VolumeName and non-zero Slot must be unique
*
* Returns: 0 on failure
* 1 on success
- */
+ */
int
db_create_media_record(JCR *jcr, B_DB *mdb, MEDIA_DBR *mr)
{
struct tm tm;
db_lock(mdb);
- Mmsg(mdb->cmd, "SELECT MediaId FROM Media WHERE VolumeName='%s'",
+ Mmsg(mdb->cmd, "SELECT MediaId FROM Media WHERE VolumeName='%s'",
mr->VolumeName);
Dmsg1(300, "selectpool: %s\n", mdb->cmd);
if (QUERY_DB(jcr, mdb, mdb->cmd)) {
mdb->num_rows = sql_num_rows(mdb);
if (mdb->num_rows > 0) {
- Mmsg1(&mdb->errmsg, _("Volume \"%s\" already exists.\n"), mr->VolumeName);
+ Mmsg1(&mdb->errmsg, _("Volume \"%s\" already exists.\n"), mr->VolumeName);
sql_free_result(mdb);
db_unlock(mdb);
return 0;
}
/* Must create it */
- Mmsg(mdb->cmd,
-"INSERT INTO Media (VolumeName,MediaType,PoolId,MaxVolBytes,VolCapacityBytes,"
+ Mmsg(mdb->cmd,
+"INSERT INTO Media (VolumeName,MediaType,PoolId,MaxVolBytes,VolCapacityBytes,"
"Recycle,VolRetention,VolUseDuration,MaxVolJobs,MaxVolFiles,"
-"VolStatus,Slot,VolBytes,InChanger,VolReadTime,VolWriteTime,"
+"VolStatus,Slot,VolBytes,InChanger,VolReadTime,VolWriteTime,"
"EndFile,EndBlock) "
-"VALUES ('%s','%s',%u,%s,%s,%d,%s,%s,%u,%u,'%s',%d,%s,%d,%s,%s,0,0)",
+"VALUES ('%s','%s',%u,%s,%s,%d,%s,%s,%u,%u,'%s',%d,%s,%d,%s,%s,0,0)",
mr->VolumeName,
- mr->MediaType, mr->PoolId,
+ mr->MediaType, mr->PoolId,
edit_uint64(mr->MaxVolBytes,ed1),
edit_uint64(mr->VolCapacityBytes, ed2),
mr->Recycle,
if (mr->LabelDate) {
char dt[MAX_TIME_LENGTH];
localtime_r(&mr->LabelDate, &tm);
- strftime(dt, sizeof(dt), "%Y-%m-%d %T", &tm);
- Mmsg(mdb->cmd, "UPDATE Media SET LabelDate='%s' "
- "WHERE MediaId=%d", dt, mr->MediaId);
+ strftime(dt, sizeof(dt), "%Y-%m-%d %T", &tm);
+ Mmsg(mdb->cmd, "UPDATE Media SET LabelDate='%s' "
+ "WHERE MediaId=%d", dt, mr->MediaId);
stat = UPDATE_DB(jcr, mdb, mdb->cmd);
}
}
-/*
- * Create a Unique record for the client -- no duplicates
+/*
+ * Create a Unique record for the client -- no duplicates
* Returns: 0 on failure
* 1 on success with id in cr->ClientId
*/
mdb->num_rows = sql_num_rows(mdb);
/* If more than one, report error, but return first row */
if (mdb->num_rows > 1) {
- Mmsg1(&mdb->errmsg, _("More than one Client!: %d\n"), (int)(mdb->num_rows));
- Jmsg(jcr, M_ERROR, 0, "%s", mdb->errmsg);
+ Mmsg1(&mdb->errmsg, _("More than one Client!: %d\n"), (int)(mdb->num_rows));
+ Jmsg(jcr, M_ERROR, 0, "%s", mdb->errmsg);
}
if (mdb->num_rows >= 1) {
if ((row = sql_fetch_row(mdb)) == NULL) {
- Mmsg1(&mdb->errmsg, _("error fetching Client row: %s\n"), sql_strerror(mdb));
- Jmsg(jcr, M_ERROR, 0, "%s", mdb->errmsg);
+ Mmsg1(&mdb->errmsg, _("error fetching Client row: %s\n"), sql_strerror(mdb));
+ Jmsg(jcr, M_ERROR, 0, "%s", mdb->errmsg);
sql_free_result(mdb);
db_unlock(mdb);
return 0;
}
/* Must create it */
- Mmsg(mdb->cmd, "INSERT INTO Client (Name, Uname, AutoPrune, \
-FileRetention, JobRetention) VALUES \
-('%s', '%s', %d, %s, %s)", cr->Name, cr->Uname, cr->AutoPrune,
+ Mmsg(mdb->cmd, "INSERT INTO Client (Name, Uname, AutoPrune, "
+"FileRetention, JobRetention) VALUES "
+"('%s', '%s', %d, %s, %s)", cr->Name, cr->Uname, cr->AutoPrune,
edit_uint64(cr->FileRetention, ed1),
edit_uint64(cr->JobRetention, ed2));
}
-/*
- * Create a Unique record for the counter -- no duplicates
+/*
+ * Create a Unique record for the counter -- no duplicates
* Returns: 0 on failure
* 1 on success with counter filled in
*/
}
-/*
+/*
* Create a FileSet record. This record is unique in the
* name and the MD5 signature of the include/exclude sets.
* Returns: 0 on failure
if (QUERY_DB(jcr, mdb, mdb->cmd)) {
mdb->num_rows = sql_num_rows(mdb);
if (mdb->num_rows > 1) {
- Mmsg1(&mdb->errmsg, _("More than one FileSet!: %d\n"), (int)(mdb->num_rows));
- Jmsg(jcr, M_ERROR, 0, "%s", mdb->errmsg);
+ Mmsg1(&mdb->errmsg, _("More than one FileSet!: %d\n"), (int)(mdb->num_rows));
+ Jmsg(jcr, M_ERROR, 0, "%s", mdb->errmsg);
}
if (mdb->num_rows >= 1) {
if ((row = sql_fetch_row(mdb)) == NULL) {
- Mmsg1(&mdb->errmsg, _("error fetching FileSet row: ERR=%s\n"), sql_strerror(mdb));
- Jmsg(jcr, M_ERROR, 0, "%s", mdb->errmsg);
+ Mmsg1(&mdb->errmsg, _("error fetching FileSet row: ERR=%s\n"), sql_strerror(mdb));
+ Jmsg(jcr, M_ERROR, 0, "%s", mdb->errmsg);
sql_free_result(mdb);
db_unlock(mdb);
return 0;
* unsigned long st_blocks; * number of blocks allocated *
* time_t st_atime; * time of last access *
* time_t st_mtime; * time of last modification *
- * time_t st_ctime; * time of last inode change *
+ * time_t st_ctime; * time of last inode change *
* };
*/
-/*
- * Create File record in B_DB
+/*
+ * Create File record in B_DB
*
* In order to reduce database size, we store the File attributes,
- * the FileName, and the Path separately. In principle, there
+ * the FileName, and the Path separately. In principle, there
* is a single FileName record and a single Path record, no matter
* how many times it occurs. This is this subroutine, we separate
* the file and the path and create three database records.
/*
* Make sure we have an acceptable attributes record.
*/
- if (!(ar->Stream == STREAM_UNIX_ATTRIBUTES ||
+ if (!(ar->Stream == STREAM_UNIX_ATTRIBUTES ||
ar->Stream == STREAM_UNIX_ATTRIBUTES_EX)) {
Mmsg0(&mdb->errmsg, _("Attempt to put non-attributes into catalog\n"));
Jmsg(jcr, M_ERROR, 0, "%s", mdb->errmsg);
/* Must create it */
Mmsg(mdb->cmd,
- "INSERT INTO File (FileIndex,JobId,PathId,FilenameId,"
- "LStat,MD5) VALUES (%u,%u,%u,%u,'%s','0')",
- ar->FileIndex, ar->JobId, ar->PathId, ar->FilenameId,
+ "INSERT INTO File (FileIndex,JobId,PathId,FilenameId,"
+ "LStat,MD5) VALUES (%u,%u,%u,%u,'%s','0')",
+ ar->FileIndex, ar->JobId, ar->PathId, ar->FilenameId,
ar->attr);
if (!INSERT_DB(jcr, mdb, mdb->cmd)) {
- Mmsg2(&mdb->errmsg, _("Create db File record %s failed. ERR=%s"),
+ Mmsg2(&mdb->errmsg, _("Create db File record %s failed. ERR=%s"),
mdb->cmd, sql_strerror(mdb));
Jmsg(jcr, M_FATAL, 0, "%s", mdb->errmsg);
ar->FileId = 0;
strcmp(mdb->cached_path, mdb->path) == 0) {
ar->PathId = mdb->cached_path_id;
return 1;
- }
+ }
Mmsg(mdb->cmd, "SELECT PathId FROM Path WHERE Path='%s'", mdb->esc_name);
mdb->num_rows = sql_num_rows(mdb);
if (mdb->num_rows > 1) {
char ed1[30];
- Mmsg2(&mdb->errmsg, _("More than one Path!: %s for path: %s\n"),
+ Mmsg2(&mdb->errmsg, _("More than one Path!: %s for path: %s\n"),
edit_uint64(mdb->num_rows, ed1), mdb->path);
- Jmsg(jcr, M_WARNING, 0, "%s", mdb->errmsg);
+ Jmsg(jcr, M_WARNING, 0, "%s", mdb->errmsg);
}
/* Even if there are multiple paths, take the first one */
if (mdb->num_rows >= 1) {
if ((row = sql_fetch_row(mdb)) == NULL) {
- Mmsg1(&mdb->errmsg, _("error fetching row: %s\n"), sql_strerror(mdb));
- Jmsg(jcr, M_ERROR, 0, "%s", mdb->errmsg);
+ Mmsg1(&mdb->errmsg, _("error fetching row: %s\n"), sql_strerror(mdb));
+ Jmsg(jcr, M_ERROR, 0, "%s", mdb->errmsg);
sql_free_result(mdb);
ar->PathId = 0;
ASSERT(ar->PathId);
Mmsg(mdb->cmd, "INSERT INTO Path (Path) VALUES ('%s')", mdb->esc_name);
if (!INSERT_DB(jcr, mdb, mdb->cmd)) {
- Mmsg2(&mdb->errmsg, _("Create db Path record %s failed. ERR=%s\n"),
+ Mmsg2(&mdb->errmsg, _("Create db Path record %s failed. ERR=%s\n"),
mdb->cmd, sql_strerror(mdb));
Jmsg(jcr, M_FATAL, 0, "%s", mdb->errmsg);
ar->PathId = 0;
}
/* Create a Unique record for the filename -- no duplicates */
-static int db_create_filename_record(JCR *jcr, B_DB *mdb, ATTR_DBR *ar)
+static int db_create_filename_record(JCR *jcr, B_DB *mdb, ATTR_DBR *ar)
{
SQL_ROW row;
mdb->num_rows = sql_num_rows(mdb);
if (mdb->num_rows > 1) {
char ed1[30];
- Mmsg2(&mdb->errmsg, _("More than one Filename! %s for file: %s\n"),
+ Mmsg2(&mdb->errmsg, _("More than one Filename! %s for file: %s\n"),
edit_uint64(mdb->num_rows, ed1), mdb->fname);
- Jmsg(jcr, M_WARNING, 0, "%s", mdb->errmsg);
+ Jmsg(jcr, M_WARNING, 0, "%s", mdb->errmsg);
}
if (mdb->num_rows >= 1) {
if ((row = sql_fetch_row(mdb)) == NULL) {
- Mmsg2(&mdb->errmsg, _("Error fetching row for file=%s: ERR=%s\n"),
+ Mmsg2(&mdb->errmsg, _("Error fetching row for file=%s: ERR=%s\n"),
mdb->fname, sql_strerror(mdb));
- Jmsg(jcr, M_ERROR, 0, "%s", mdb->errmsg);
+ Jmsg(jcr, M_ERROR, 0, "%s", mdb->errmsg);
ar->FilenameId = 0;
} else {
ar->FilenameId = atoi(row[0]);
Mmsg(mdb->cmd, "INSERT INTO Filename (Name) VALUES ('%s')", mdb->esc_name);
if (!INSERT_DB(jcr, mdb, mdb->cmd)) {
- Mmsg2(&mdb->errmsg, _("Create db Filename record %s failed. ERR=%s\n"),
+ Mmsg2(&mdb->errmsg, _("Create db Filename record %s failed. ERR=%s\n"),
mdb->cmd, sql_strerror(mdb));
Jmsg(jcr, M_FATAL, 0, "%s", mdb->errmsg);
ar->FilenameId = 0;
/*
* Bacula Catalog Database Delete record interface routines
- *
+ *
* Kern Sibbald, December 2000
*
* Version $Id$
extern void print_result(B_DB *mdb);
extern int QueryDB(const char *file, int line, JCR *jcr, B_DB *db, char *select_cmd);
extern int DeleteDB(const char *file, int line, JCR *jcr, B_DB *db, char *delete_cmd);
-
+
/*
* Delete Pool record, must also delete all associated
* Media records.
if (QUERY_DB(jcr, mdb, mdb->cmd)) {
mdb->num_rows = sql_num_rows(mdb);
-
+
if (mdb->num_rows == 0) {
- Mmsg(mdb->errmsg, _("No pool record %s exists\n"), pr->Name);
+ Mmsg(mdb->errmsg, _("No pool record %s exists\n"), pr->Name);
sql_free_result(mdb);
db_unlock(mdb);
return 0;
} else if (mdb->num_rows != 1) {
- Mmsg(mdb->errmsg, _("Expecting one pool record, got %d\n"), mdb->num_rows);
+ Mmsg(mdb->errmsg, _("Expecting one pool record, got %d\n"), mdb->num_rows);
sql_free_result(mdb);
db_unlock(mdb);
return 0;
}
if ((row = sql_fetch_row(mdb)) == NULL) {
- Mmsg1(&mdb->errmsg, _("Error fetching row %s\n"), sql_strerror(mdb));
+ Mmsg1(&mdb->errmsg, _("Error fetching row %s\n"), sql_strerror(mdb));
db_unlock(mdb);
return 0;
}
#define MAX_DEL_LIST_LEN 1000000
struct s_del_ctx {
- JobId_t *JobId;
+ JobId_t *JobId;
int num_ids; /* ids stored */
int max_ids; /* size of array */
int num_del; /* number deleted */
{
struct s_del_ctx *del = (struct s_del_ctx *)ctx;
- if (del->num_ids == MAX_DEL_LIST_LEN) {
+ if (del->num_ids == MAX_DEL_LIST_LEN) {
return 1;
}
if (del->num_ids == del->max_ids) {
}
-/*
- * This routine will purge (delete) all records
+/*
+ * This routine will purge (delete) all records
* associated with a particular Volume. It will
* not delete the media record itself.
*/
if (mr->MediaId == 0 && !db_get_media_record(jcr, mdb, mr)) {
db_unlock(mdb);
return 0;
- }
+ }
/* Do purge if not already purged */
if (strcmp(mr->VolStatus, "Purged") != 0) {
/* Delete associated records */
}
/*
- * Purge all records associated with a
+ * Purge all records associated with a
* media record. This does not delete the
* media record itself. But the media status
* is changed to "Purged".
if (mr->MediaId == 0 && !db_get_media_record(jcr, mdb, mr)) {
db_unlock(mdb);
return 0;
- }
+ }
/* Delete associated records */
do_media_purge(mdb, mr); /* Note, always purge */
* Note, generally, these routines are more complicated
* that a simple search by name or id. Such simple
* request are in get.c
- *
+ *
* Kern Sibbald, December 2000
*
* Version $Id$
* find last full save for Incremental and Differential saves.
*
* StartTime is returned in stime
- *
+ *
* Returns: 0 on failure
* 1 on success, jr is unchanged, but stime is set
*/
/* If no Id given, we must find corresponding job */
if (jr->JobId == 0) {
/* Differential is since last Full backup */
- Mmsg(mdb->cmd,
+ Mmsg(mdb->cmd,
"SELECT StartTime FROM Job WHERE JobStatus='T' AND Type='%c' AND "
"Level='%c' AND Name='%s' AND ClientId=%u AND FileSetId=%u "
"ORDER BY StartTime DESC LIMIT 1",
/* Incremental is since last Full, Incremental, or Differential */
} else if (jr->JobLevel == L_INCREMENTAL) {
- /*
+ /*
* For an Incremental job, we must first ensure
* that a Full backup was done (cmd edited above)
* then we do a second look to find the most recent
* backup
*/
if (!QUERY_DB(jcr, mdb, mdb->cmd)) {
- Mmsg2(&mdb->errmsg, _("Query error for start time request: ERR=%s\nCMD=%s\n"),
+ Mmsg2(&mdb->errmsg, _("Query error for start time request: ERR=%s\nCMD=%s\n"),
sql_strerror(mdb), mdb->cmd);
db_unlock(mdb);
return 0;
}
if ((row = sql_fetch_row(mdb)) == NULL) {
sql_free_result(mdb);
- Mmsg(mdb->errmsg, _("No prior Full backup Job record found.\n"));
+ Mmsg(mdb->errmsg, _("No prior Full backup Job record found.\n"));
db_unlock(mdb);
return 0;
}
sql_free_result(mdb);
/* Now edit SQL command for Incremental Job */
- Mmsg(mdb->cmd,
+ Mmsg(mdb->cmd,
"SELECT StartTime FROM Job WHERE JobStatus='T' AND Type='%c' AND "
"Level IN ('%c','%c','%c') AND Name='%s' AND ClientId=%u "
"AND FileSetId=%u ORDER BY StartTime DESC LIMIT 1",
jr->JobType, L_INCREMENTAL, L_DIFFERENTIAL, L_FULL, jr->Name,
jr->ClientId, jr->FileSetId);
} else {
- Mmsg1(&mdb->errmsg, _("Unknown level=%d\n"), jr->JobLevel);
+ Mmsg1(&mdb->errmsg, _("Unknown level=%d\n"), jr->JobLevel);
db_unlock(mdb);
return 0;
}
}
/*
- * Find last failed job since given start-time
+ * Find last failed job since given start-time
* it must be either Full or Diff.
*
* Returns: false on failure
db_lock(mdb);
/* Differential is since last Full backup */
- Mmsg(mdb->cmd,
+ Mmsg(mdb->cmd,
"SELECT Level FROM Job WHERE JobStatus!='T' AND Type='%c' AND "
"Level IN ('%c','%c') AND Name='%s' AND ClientId=%u "
"AND FileSetId=%u AND StartTime>'%s' "
}
-/*
+/*
* Find JobId of last job that ran. E.g. for
* VERIFY_CATALOG we want the JobId of the last INIT.
* For VERIFY_VOLUME_TO_CATALOG, we want the JobId of the last Job.
/* Find last full */
db_lock(mdb);
if (jr->JobLevel == L_VERIFY_CATALOG) {
- Mmsg(mdb->cmd,
+ Mmsg(mdb->cmd,
"SELECT JobId FROM Job WHERE Type='V' AND Level='%c' AND "
" JobStatus='T' AND Name='%s' AND "
"ClientId=%u ORDER BY StartTime DESC LIMIT 1",
"SELECT JobId FROM Job WHERE Type='B' AND JobStatus='T' AND "
"Name='%s' ORDER BY StartTime DESC LIMIT 1", Name);
} else {
- Mmsg(mdb->cmd,
+ Mmsg(mdb->cmd,
"SELECT JobId FROM Job WHERE Type='B' AND JobStatus='T' AND "
"ClientId=%u ORDER BY StartTime DESC LIMIT 1", jr->ClientId);
}
return 1;
}
-/*
+/*
* Find Available Media (Volume) for Pool
*
* Find a Volume for a given PoolId, MediaType, and Status.
* numrows on success
*/
int
-db_find_next_volume(JCR *jcr, B_DB *mdb, int item, bool InChanger, MEDIA_DBR *mr)
+db_find_next_volume(JCR *jcr, B_DB *mdb, int item, bool InChanger, MEDIA_DBR *mr)
{
SQL_ROW row;
int numrows;
if (item == -1) { /* find oldest volume */
/* Find oldest volume */
Mmsg(mdb->cmd, "SELECT MediaId,VolumeName,VolJobs,VolFiles,VolBlocks,"
- "VolBytes,VolMounts,VolErrors,VolWrites,MaxVolBytes,VolCapacityBytes,"
- "VolRetention,VolUseDuration,MaxVolJobs,MaxVolFiles,Recycle,Slot,"
- "FirstWritten,LastWritten,VolStatus,InChanger "
- "FROM Media WHERE PoolId=%u AND MediaType='%s' AND VolStatus IN ('Full',"
- "'Recycle','Purged','Used','Append') "
- "ORDER BY LastWritten LIMIT 1", mr->PoolId, mr->MediaType);
+ "VolBytes,VolMounts,VolErrors,VolWrites,MaxVolBytes,VolCapacityBytes,"
+ "VolRetention,VolUseDuration,MaxVolJobs,MaxVolFiles,Recycle,Slot,"
+ "FirstWritten,LastWritten,VolStatus,InChanger "
+ "FROM Media WHERE PoolId=%u AND MediaType='%s' AND VolStatus IN ('Full',"
+ "'Recycle','Purged','Used','Append') "
+ "ORDER BY LastWritten LIMIT 1", mr->PoolId, mr->MediaType);
item = 1;
} else {
/* Find next available volume */
if (InChanger) {
- changer = "AND InChanger=1";
+ changer = "AND InChanger=1";
} else {
- changer = "";
+ changer = "";
}
if (strcmp(mr->VolStatus, "Recycled") == 0 ||
- strcmp(mr->VolStatus, "Purged") == 0) {
- order = "ORDER BY LastWritten ASC,MediaId"; /* take oldest */
+ strcmp(mr->VolStatus, "Purged") == 0) {
+ order = "ORDER BY LastWritten ASC,MediaId"; /* take oldest */
} else {
- order = "ORDER BY LastWritten IS NULL,LastWritten DESC,MediaId"; /* take most recently written */
- }
+ order = "ORDER BY LastWritten IS NULL,LastWritten DESC,MediaId"; /* take most recently written */
+ }
Mmsg(mdb->cmd, "SELECT MediaId,VolumeName,VolJobs,VolFiles,VolBlocks,"
- "VolBytes,VolMounts,VolErrors,VolWrites,MaxVolBytes,VolCapacityBytes,"
- "VolRetention,VolUseDuration,MaxVolJobs,MaxVolFiles,Recycle,Slot,"
- "FirstWritten,LastWritten,VolStatus,InChanger "
- "FROM Media WHERE PoolId=%u AND MediaType='%s' AND VolStatus='%s' "
- "%s "
- "%s LIMIT %d",
+ "VolBytes,VolMounts,VolErrors,VolWrites,MaxVolBytes,VolCapacityBytes,"
+ "VolRetention,VolUseDuration,MaxVolJobs,MaxVolFiles,Recycle,Slot,"
+ "FirstWritten,LastWritten,VolStatus,InChanger "
+ "FROM Media WHERE PoolId=%u AND MediaType='%s' AND VolStatus='%s' "
+ "%s "
+ "%s LIMIT %d",
mr->PoolId, mr->MediaType, mr->VolStatus, changer, order, item);
}
if (!QUERY_DB(jcr, mdb, mdb->cmd)) {
db_unlock(mdb);
return 0;
}
-
- /* Seek to desired item
+
+ /* Seek to desired item
* Note, we use base 1; SQL uses base 0
*/
sql_data_seek(mdb, item-1);
* Bacula Catalog Database Get record interface routines
* Note, these routines generally get a record by id or
* by name. If more logic is involved, the routine
- * should be in find.c
+ * should be in find.c
*
* Kern Sibbald, March 2000
*
return stat;
}
-
+
/*
- * Get a File record
+ * Get a File record
* Returns: 0 on failure
* 1 on success
*
int stat = 0;
if (jcr->JobLevel == L_VERIFY_DISK_TO_CATALOG) {
- Mmsg(mdb->cmd,
+ Mmsg(mdb->cmd,
"SELECT FileId, LStat, MD5 FROM File,Job WHERE "
"File.JobId=Job.JobId AND File.PathId=%u AND "
"File.FilenameId=%u AND Job.Type='B' AND Job.JobSTATUS='T' AND "
"ClientId=%u ORDER BY StartTime DESC LIMIT 1",
fdbr->PathId, fdbr->FilenameId, jr->ClientId);
} else {
- Mmsg(mdb->cmd,
+ Mmsg(mdb->cmd,
"SELECT FileId, LStat, MD5 FROM File WHERE File.JobId=%u AND File.PathId=%u AND "
"File.FilenameId=%u", fdbr->JobId, fdbr->PathId, fdbr->FilenameId);
}
Dmsg3(050, "Get_file_record JobId=%u FilenameId=%u PathId=%u\n",
fdbr->JobId, fdbr->FilenameId, fdbr->PathId);
-
+
Dmsg1(100, "Query=%s\n", mdb->cmd);
if (QUERY_DB(jcr, mdb, mdb->cmd)) {
mdb->num_rows = sql_num_rows(mdb);
Dmsg1(050, "get_file_record num_rows=%d\n", (int)mdb->num_rows);
if (mdb->num_rows > 1) {
- Mmsg1(&mdb->errmsg, _("get_file_record want 1 got rows=%d\n"),
+ Mmsg1(&mdb->errmsg, _("get_file_record want 1 got rows=%d\n"),
mdb->num_rows);
}
if (mdb->num_rows >= 1) {
if ((row = sql_fetch_row(mdb)) == NULL) {
- Mmsg1(&mdb->errmsg, _("Error fetching row: %s\n"), sql_strerror(mdb));
+ Mmsg1(&mdb->errmsg, _("Error fetching row: %s\n"), sql_strerror(mdb));
} else {
fdbr->FileId = (FileId_t)str_to_int64(row[0]);
bstrncpy(fdbr->LStat, row[1], sizeof(fdbr->LStat));
stat = 1;
}
} else {
- Mmsg2(&mdb->errmsg, _("File record for PathId=%u FilenameId=%u not found.\n"),
+ Mmsg2(&mdb->errmsg, _("File record for PathId=%u FilenameId=%u not found.\n"),
fdbr->PathId, fdbr->FilenameId);
}
sql_free_result(mdb);
}
-/* Get Filename record
+/* Get Filename record
* Returns: 0 on failure
* FilenameId on success
*
mdb->esc_name = check_pool_memory_size(mdb->esc_name, 2*mdb->fnl+2);
db_escape_string(mdb->esc_name, mdb->fname, mdb->fnl);
-
+
Mmsg(mdb->cmd, "SELECT FilenameId FROM Filename WHERE Name='%s'", mdb->esc_name);
if (QUERY_DB(jcr, mdb, mdb->cmd)) {
char ed1[30];
mdb->num_rows = sql_num_rows(mdb);
if (mdb->num_rows > 1) {
- Mmsg2(&mdb->errmsg, _("More than one Filename!: %s for file: %s\n"),
+ Mmsg2(&mdb->errmsg, _("More than one Filename!: %s for file: %s\n"),
edit_uint64(mdb->num_rows, ed1), mdb->fname);
- Jmsg(jcr, M_WARNING, 0, "%s", mdb->errmsg);
- }
+ Jmsg(jcr, M_WARNING, 0, "%s", mdb->errmsg);
+ }
if (mdb->num_rows >= 1) {
if ((row = sql_fetch_row(mdb)) == NULL) {
- Mmsg1(&mdb->errmsg, _("error fetching row: %s\n"), sql_strerror(mdb));
+ Mmsg1(&mdb->errmsg, _("error fetching row: %s\n"), sql_strerror(mdb));
} else {
FilenameId = atoi(row[0]);
if (FilenameId <= 0) {
- Mmsg2(&mdb->errmsg, _("Get DB Filename record %s found bad record: %d\n"),
- mdb->cmd, FilenameId);
+ Mmsg2(&mdb->errmsg, _("Get DB Filename record %s found bad record: %d\n"),
+ mdb->cmd, FilenameId);
FilenameId = 0;
}
}
} else {
- Mmsg1(&mdb->errmsg, _("Filename record: %s not found.\n"), mdb->fname);
+ Mmsg1(&mdb->errmsg, _("Filename record: %s not found.\n"), mdb->fname);
}
sql_free_result(mdb);
} else {
return FilenameId;
}
-/* Get path record
+/* Get path record
* Returns: 0 on failure
* PathId on success
*
if (mdb->cached_path_id != 0 && mdb->cached_path_len == mdb->pnl &&
strcmp(mdb->cached_path, mdb->path) == 0) {
return mdb->cached_path_id;
- }
+ }
Mmsg(mdb->cmd, "SELECT PathId FROM Path WHERE Path='%s'", mdb->esc_name);
char ed1[30];
mdb->num_rows = sql_num_rows(mdb);
if (mdb->num_rows > 1) {
- Mmsg2(&mdb->errmsg, _("More than one Path!: %s for path: %s\n"),
+ Mmsg2(&mdb->errmsg, _("More than one Path!: %s for path: %s\n"),
edit_uint64(mdb->num_rows, ed1), mdb->path);
- Jmsg(jcr, M_WARNING, 0, "%s", mdb->errmsg);
- }
+ Jmsg(jcr, M_WARNING, 0, "%s", mdb->errmsg);
+ }
/* Even if there are multiple paths, take the first one */
if (mdb->num_rows >= 1) {
if ((row = sql_fetch_row(mdb)) == NULL) {
- Mmsg1(&mdb->errmsg, _("error fetching row: %s\n"), sql_strerror(mdb));
+ Mmsg1(&mdb->errmsg, _("error fetching row: %s\n"), sql_strerror(mdb));
} else {
PathId = atoi(row[0]);
if (PathId <= 0) {
- Mmsg2(&mdb->errmsg, _("Get DB path record %s found bad record: %u\n"),
- mdb->cmd, PathId);
+ Mmsg2(&mdb->errmsg, _("Get DB path record %s found bad record: %u\n"),
+ mdb->cmd, PathId);
PathId = 0;
} else {
/* Cache path */
}
}
}
- } else {
- Mmsg1(&mdb->errmsg, _("Path record: %s not found.\n"), mdb->path);
+ } else {
+ Mmsg1(&mdb->errmsg, _("Path record: %s not found.\n"), mdb->path);
}
sql_free_result(mdb);
} else {
}
-/*
+/*
* Get Job record for given JobId or Job name
* Returns: 0 on failure
* 1 on success
db_lock(mdb);
/* Get one entry per VolumeName, but "sort" by VolIndex */
- Mmsg(mdb->cmd,
- "SELECT VolumeName,MAX(VolIndex) FROM JobMedia,Media WHERE "
- "JobMedia.JobId=%u AND JobMedia.MediaId=Media.MediaId "
- "GROUP BY VolumeName "
- "ORDER BY 2 ASC", JobId);
+ Mmsg(mdb->cmd,
+ "SELECT VolumeName,MAX(VolIndex) FROM JobMedia,Media WHERE "
+ "JobMedia.JobId=%u AND JobMedia.MediaId=Media.MediaId "
+ "GROUP BY VolumeName "
+ "ORDER BY 2 ASC", JobId);
Dmsg1(130, "VolNam=%s\n", mdb->cmd);
*VolumeNames[0] = 0;
mdb->num_rows = sql_num_rows(mdb);
Dmsg1(130, "Num rows=%d\n", mdb->num_rows);
if (mdb->num_rows <= 0) {
- Mmsg1(&mdb->errmsg, _("No volumes found for JobId=%d\n"), JobId);
+ Mmsg1(&mdb->errmsg, _("No volumes found for JobId=%d\n"), JobId);
stat = 0;
} else {
stat = mdb->num_rows;
for (i=0; i < stat; i++) {
if ((row = sql_fetch_row(mdb)) == NULL) {
- Mmsg2(&mdb->errmsg, _("Error fetching row %d: ERR=%s\n"), i, sql_strerror(mdb));
- Jmsg(jcr, M_ERROR, 0, "%s", mdb->errmsg);
+ Mmsg2(&mdb->errmsg, _("Error fetching row %d: ERR=%s\n"), i, sql_strerror(mdb));
+ Jmsg(jcr, M_ERROR, 0, "%s", mdb->errmsg);
stat = 0;
break;
} else {
if (*VolumeNames[0] != 0) {
- pm_strcat(VolumeNames, "|");
+ pm_strcat(VolumeNames, "|");
}
pm_strcat(VolumeNames, row[0]);
}
VOL_PARAMS *Vols = NULL;
db_lock(mdb);
- Mmsg(mdb->cmd,
+ Mmsg(mdb->cmd,
"SELECT VolumeName,FirstIndex,LastIndex,StartFile,JobMedia.EndFile,"
"StartBlock,JobMedia.EndBlock"
" FROM JobMedia,Media WHERE JobMedia.JobId=%u"
mdb->num_rows = sql_num_rows(mdb);
Dmsg1(130, "Num rows=%d\n", mdb->num_rows);
if (mdb->num_rows <= 0) {
- Mmsg1(&mdb->errmsg, _("No volumes found for JobId=%d\n"), JobId);
+ Mmsg1(&mdb->errmsg, _("No volumes found for JobId=%d\n"), JobId);
stat = 0;
} else {
stat = mdb->num_rows;
}
for (i=0; i < stat; i++) {
if ((row = sql_fetch_row(mdb)) == NULL) {
- Mmsg2(&mdb->errmsg, _("Error fetching row %d: ERR=%s\n"), i, sql_strerror(mdb));
- Jmsg(jcr, M_ERROR, 0, "%s", mdb->errmsg);
+ Mmsg2(&mdb->errmsg, _("Error fetching row %d: ERR=%s\n"), i, sql_strerror(mdb));
+ Jmsg(jcr, M_ERROR, 0, "%s", mdb->errmsg);
stat = 0;
break;
} else {
-/*
+/*
* Get the number of pool records
*
* Returns: -1 on failure
-/* Get Pool Record
+/* Get Pool Record
* If the PoolId is non-zero, we get its record,
* otherwise, we search on the PoolName
*
* Returns: 0 on failure
- * id on success
+ * id on success
*/
int db_get_pool_record(JCR *jcr, B_DB *mdb, POOL_DBR *pdbr)
{
db_lock(mdb);
if (pdbr->PoolId != 0) { /* find by id */
- Mmsg(mdb->cmd,
-"SELECT PoolId,Name,NumVols,MaxVols,UseOnce,UseCatalog,AcceptAnyVolume,\
-AutoPrune,Recycle,VolRetention,VolUseDuration,MaxVolJobs,MaxVolFiles,\
-MaxVolBytes,PoolType,LabelFormat FROM Pool WHERE Pool.PoolId=%u", pdbr->PoolId);
+ Mmsg(mdb->cmd,
+"SELECT PoolId,Name,NumVols,MaxVols,UseOnce,UseCatalog,AcceptAnyVolume,"
+"AutoPrune,Recycle,VolRetention,VolUseDuration,MaxVolJobs,MaxVolFiles,"
+"MaxVolBytes,PoolType,LabelFormat FROM Pool WHERE Pool.PoolId=%u", pdbr->PoolId);
} else { /* find by name */
- Mmsg(mdb->cmd,
-"SELECT PoolId,Name,NumVols,MaxVols,UseOnce,UseCatalog,AcceptAnyVolume,\
-AutoPrune,Recycle,VolRetention,VolUseDuration,MaxVolJobs,MaxVolFiles,\
-MaxVolBytes,PoolType,LabelFormat FROM Pool WHERE Pool.Name='%s'", pdbr->Name);
- }
+ Mmsg(mdb->cmd,
+"SELECT PoolId,Name,NumVols,MaxVols,UseOnce,UseCatalog,AcceptAnyVolume,"
+"AutoPrune,Recycle,VolRetention,VolUseDuration,MaxVolJobs,MaxVolFiles,"
+"MaxVolBytes,PoolType,LabelFormat FROM Pool WHERE Pool.Name='%s'", pdbr->Name);
+ }
if (QUERY_DB(jcr, mdb, mdb->cmd)) {
mdb->num_rows = sql_num_rows(mdb);
if (mdb->num_rows > 1) {
char ed1[30];
- Mmsg1(&mdb->errmsg, _("More than one Pool!: %s\n"),
+ Mmsg1(&mdb->errmsg, _("More than one Pool!: %s\n"),
edit_uint64(mdb->num_rows, ed1));
- Jmsg(jcr, M_ERROR, 0, "%s", mdb->errmsg);
+ Jmsg(jcr, M_ERROR, 0, "%s", mdb->errmsg);
} else if (mdb->num_rows == 1) {
if ((row = sql_fetch_row(mdb)) == NULL) {
- Mmsg1(&mdb->errmsg, _("error fetching row: %s\n"), sql_strerror(mdb));
- Jmsg(jcr, M_ERROR, 0, "%s", mdb->errmsg);
+ Mmsg1(&mdb->errmsg, _("error fetching row: %s\n"), sql_strerror(mdb));
+ Jmsg(jcr, M_ERROR, 0, "%s", mdb->errmsg);
} else {
pdbr->PoolId = str_to_int64(row[0]);
- bstrncpy(pdbr->Name, row[1]!=NULL?row[1]:"", sizeof(pdbr->Name));
+ bstrncpy(pdbr->Name, row[1]!=NULL?row[1]:"", sizeof(pdbr->Name));
pdbr->NumVols = str_to_int64(row[2]);
pdbr->MaxVols = str_to_int64(row[3]);
pdbr->UseOnce = str_to_int64(row[4]);
pdbr->MaxVolJobs = str_to_int64(row[11]);
pdbr->MaxVolFiles = str_to_int64(row[12]);
pdbr->MaxVolBytes = str_to_uint64(row[13]);
- bstrncpy(pdbr->PoolType, row[13]!=NULL?row[14]:"", sizeof(pdbr->PoolType));
- bstrncpy(pdbr->LabelFormat, row[14]!=NULL?row[15]:"", sizeof(pdbr->LabelFormat));
+ bstrncpy(pdbr->PoolType, row[13]!=NULL?row[14]:"", sizeof(pdbr->PoolType));
+ bstrncpy(pdbr->LabelFormat, row[14]!=NULL?row[15]:"", sizeof(pdbr->LabelFormat));
stat = pdbr->PoolId;
}
} else {
- Mmsg(mdb->errmsg, _("Pool record not found in Catalog.\n"));
+ Mmsg(mdb->errmsg, _("Pool record not found in Catalog.\n"));
}
sql_free_result(mdb);
} else {
return stat;
}
-/* Get Client Record
+/* Get Client Record
* If the ClientId is non-zero, we get its record,
* otherwise, we search on the Client Name
*
* Returns: 0 on failure
- * 1 on success
+ * 1 on success
*/
int db_get_client_record(JCR *jcr, B_DB *mdb, CLIENT_DBR *cdbr)
{
db_lock(mdb);
if (cdbr->ClientId != 0) { /* find by id */
- Mmsg(mdb->cmd,
+ Mmsg(mdb->cmd,
"SELECT ClientId,Name,Uname,AutoPrune,FileRetention,JobRetention "
"FROM Client WHERE Client.ClientId=%u", cdbr->ClientId);
} else { /* find by name */
- Mmsg(mdb->cmd,
+ Mmsg(mdb->cmd,
"SELECT ClientId,Name,Uname,AutoPrune,FileRetention,JobRetention "
"FROM Client WHERE Client.Name='%s'", cdbr->Name);
- }
+ }
if (QUERY_DB(jcr, mdb, mdb->cmd)) {
mdb->num_rows = sql_num_rows(mdb);
if (mdb->num_rows > 1) {
char ed1[30];
- Mmsg1(&mdb->errmsg, _("More than one Client!: %s\n"),
+ Mmsg1(&mdb->errmsg, _("More than one Client!: %s\n"),
edit_uint64(mdb->num_rows, ed1));
- Jmsg(jcr, M_ERROR, 0, "%s", mdb->errmsg);
+ Jmsg(jcr, M_ERROR, 0, "%s", mdb->errmsg);
} else if (mdb->num_rows == 1) {
if ((row = sql_fetch_row(mdb)) == NULL) {
- Mmsg1(&mdb->errmsg, _("error fetching row: %s\n"), sql_strerror(mdb));
- Jmsg(jcr, M_ERROR, 0, "%s", mdb->errmsg);
+ Mmsg1(&mdb->errmsg, _("error fetching row: %s\n"), sql_strerror(mdb));
+ Jmsg(jcr, M_ERROR, 0, "%s", mdb->errmsg);
} else {
cdbr->ClientId = str_to_int64(row[0]);
- bstrncpy(cdbr->Name, row[1]!=NULL?row[1]:"", sizeof(cdbr->Name));
- bstrncpy(cdbr->Uname, row[2]!=NULL?row[1]:"", sizeof(cdbr->Uname));
+ bstrncpy(cdbr->Name, row[1]!=NULL?row[1]:"", sizeof(cdbr->Name));
+ bstrncpy(cdbr->Uname, row[2]!=NULL?row[1]:"", sizeof(cdbr->Uname));
cdbr->AutoPrune = str_to_int64(row[3]);
cdbr->FileRetention = str_to_int64(row[4]);
cdbr->JobRetention = str_to_int64(row[5]);
stat = 1;
}
} else {
- Mmsg(mdb->errmsg, _("Client record not found in Catalog.\n"));
+ Mmsg(mdb->errmsg, _("Client record not found in Catalog.\n"));
}
sql_free_result(mdb);
} else {
if (QUERY_DB(jcr, mdb, mdb->cmd)) {
mdb->num_rows = sql_num_rows(mdb);
-
+
/* If more than one, report error, but return first row */
if (mdb->num_rows > 1) {
- Mmsg1(&mdb->errmsg, _("More than one Counter!: %d\n"), (int)(mdb->num_rows));
- Jmsg(jcr, M_ERROR, 0, "%s", mdb->errmsg);
+ Mmsg1(&mdb->errmsg, _("More than one Counter!: %d\n"), (int)(mdb->num_rows));
+ Jmsg(jcr, M_ERROR, 0, "%s", mdb->errmsg);
}
if (mdb->num_rows >= 1) {
if ((row = sql_fetch_row(mdb)) == NULL) {
- Mmsg1(&mdb->errmsg, _("error fetching Counter row: %s\n"), sql_strerror(mdb));
- Jmsg(jcr, M_ERROR, 0, "%s", mdb->errmsg);
+ Mmsg1(&mdb->errmsg, _("error fetching Counter row: %s\n"), sql_strerror(mdb));
+ Jmsg(jcr, M_ERROR, 0, "%s", mdb->errmsg);
sql_free_result(mdb);
db_unlock(mdb);
return 0;
sql_free_result(mdb);
} else {
Mmsg(mdb->errmsg, _("Counter record: %s not found in Catalog.\n"), cr->Counter);
- }
+ }
db_unlock(mdb);
return 0;
}
-/* Get FileSet Record
+/* Get FileSet Record
* If the FileSetId is non-zero, we get its record,
* otherwise, we search on the name
*
* Returns: 0 on failure
- * id on success
+ * id on success
*/
int db_get_fileset_record(JCR *jcr, B_DB *mdb, FILESET_DBR *fsr)
{
db_lock(mdb);
if (fsr->FileSetId != 0) { /* find by id */
- Mmsg(mdb->cmd,
- "SELECT FileSetId,FileSet,MD5,CreateTime FROM FileSet "
- "WHERE FileSetId=%u", fsr->FileSetId);
+ Mmsg(mdb->cmd,
+ "SELECT FileSetId,FileSet,MD5,CreateTime FROM FileSet "
+ "WHERE FileSetId=%u", fsr->FileSetId);
} else { /* find by name */
- Mmsg(mdb->cmd,
- "SELECT FileSetId,FileSet,CreateTime,MD5 FROM FileSet "
- "WHERE FileSet='%s' ORDER BY CreateTime DESC LIMIT 1", fsr->FileSet);
- }
+ Mmsg(mdb->cmd,
+ "SELECT FileSetId,FileSet,CreateTime,MD5 FROM FileSet "
+ "WHERE FileSet='%s' ORDER BY CreateTime DESC LIMIT 1", fsr->FileSet);
+ }
if (QUERY_DB(jcr, mdb, mdb->cmd)) {
mdb->num_rows = sql_num_rows(mdb);
if (mdb->num_rows > 1) {
char ed1[30];
- Mmsg1(&mdb->errmsg, _("Error got %s FileSets but expected only one!\n"),
+ Mmsg1(&mdb->errmsg, _("Error got %s FileSets but expected only one!\n"),
edit_uint64(mdb->num_rows, ed1));
sql_data_seek(mdb, mdb->num_rows-1);
}
if ((row = sql_fetch_row(mdb)) == NULL) {
- Mmsg1(&mdb->errmsg, _("FileSet record \"%s\" not found.\n"), fsr->FileSet);
+ Mmsg1(&mdb->errmsg, _("FileSet record \"%s\" not found.\n"), fsr->FileSet);
} else {
fsr->FileSetId = atoi(row[0]);
- bstrncpy(fsr->FileSet, row[1]!=NULL?row[1]:"", sizeof(fsr->FileSet));
- bstrncpy(fsr->MD5, row[2]!=NULL?row[2]:"", sizeof(fsr->MD5));
- bstrncpy(fsr->cCreateTime, row[3]!=NULL?row[3]:"", sizeof(fsr->cCreateTime));
+ bstrncpy(fsr->FileSet, row[1]!=NULL?row[1]:"", sizeof(fsr->FileSet));
+ bstrncpy(fsr->MD5, row[2]!=NULL?row[2]:"", sizeof(fsr->MD5));
+ bstrncpy(fsr->cCreateTime, row[3]!=NULL?row[3]:"", sizeof(fsr->cCreateTime));
stat = fsr->FileSetId;
}
sql_free_result(mdb);
}
-/*
+/*
* Get the number of Media records
*
* Returns: -1 on failure
}
-/* Get Media Record
+/* Get Media Record
*
* Returns: 0 on failure
- * id on success
+ * id on success
*/
int db_get_media_record(JCR *jcr, B_DB *mdb, MEDIA_DBR *mr)
{
}
if (mr->MediaId != 0) { /* find by id */
Mmsg(mdb->cmd, "SELECT MediaId,VolumeName,VolJobs,VolFiles,VolBlocks,"
- "VolBytes,VolMounts,VolErrors,VolWrites,MaxVolBytes,VolCapacityBytes,"
- "MediaType,VolStatus,PoolId,VolRetention,VolUseDuration,MaxVolJobs,MaxVolFiles,"
- "Recycle,Slot,FirstWritten,LastWritten,InChanger,EndFile,EndBlock "
- "FROM Media WHERE MediaId=%d", mr->MediaId);
+ "VolBytes,VolMounts,VolErrors,VolWrites,MaxVolBytes,VolCapacityBytes,"
+ "MediaType,VolStatus,PoolId,VolRetention,VolUseDuration,MaxVolJobs,MaxVolFiles,"
+ "Recycle,Slot,FirstWritten,LastWritten,InChanger,EndFile,EndBlock "
+ "FROM Media WHERE MediaId=%d", mr->MediaId);
} else { /* find by name */
Mmsg(mdb->cmd, "SELECT MediaId,VolumeName,VolJobs,VolFiles,VolBlocks,"
- "VolBytes,VolMounts,VolErrors,VolWrites,MaxVolBytes,VolCapacityBytes,"
- "MediaType,VolStatus,PoolId,VolRetention,VolUseDuration,MaxVolJobs,MaxVolFiles,"
- "Recycle,Slot,FirstWritten,LastWritten,InChanger,EndFile,EndBlock "
- "FROM Media WHERE VolumeName='%s'", mr->VolumeName);
- }
+ "VolBytes,VolMounts,VolErrors,VolWrites,MaxVolBytes,VolCapacityBytes,"
+ "MediaType,VolStatus,PoolId,VolRetention,VolUseDuration,MaxVolJobs,MaxVolFiles,"
+ "Recycle,Slot,FirstWritten,LastWritten,InChanger,EndFile,EndBlock "
+ "FROM Media WHERE VolumeName='%s'", mr->VolumeName);
+ }
if (QUERY_DB(jcr, mdb, mdb->cmd)) {
mdb->num_rows = sql_num_rows(mdb);
if (mdb->num_rows > 1) {
char ed1[30];
- Mmsg1(&mdb->errmsg, _("More than one Volume!: %s\n"),
+ Mmsg1(&mdb->errmsg, _("More than one Volume!: %s\n"),
edit_uint64(mdb->num_rows, ed1));
- Jmsg(jcr, M_ERROR, 0, "%s", mdb->errmsg);
+ Jmsg(jcr, M_ERROR, 0, "%s", mdb->errmsg);
} else if (mdb->num_rows == 1) {
if ((row = sql_fetch_row(mdb)) == NULL) {
- Mmsg1(&mdb->errmsg, _("error fetching row: %s\n"), sql_strerror(mdb));
- Jmsg(jcr, M_ERROR, 0, "%s", mdb->errmsg);
+ Mmsg1(&mdb->errmsg, _("error fetching row: %s\n"), sql_strerror(mdb));
+ Jmsg(jcr, M_ERROR, 0, "%s", mdb->errmsg);
} else {
/* return values */
mr->MediaId = str_to_int64(row[0]);
- bstrncpy(mr->VolumeName, row[1]!=NULL?row[1]:"", sizeof(mr->VolumeName));
+ bstrncpy(mr->VolumeName, row[1]!=NULL?row[1]:"", sizeof(mr->VolumeName));
mr->VolJobs = str_to_int64(row[2]);
mr->VolFiles = str_to_int64(row[3]);
mr->VolBlocks = str_to_int64(row[4]);
mr->VolWrites = str_to_int64(row[8]);
mr->MaxVolBytes = str_to_uint64(row[9]);
mr->VolCapacityBytes = str_to_uint64(row[10]);
- bstrncpy(mr->MediaType, row[11]!=NULL?row[11]:"", sizeof(mr->MediaType));
- bstrncpy(mr->VolStatus, row[12]!=NULL?row[12]:"", sizeof(mr->VolStatus));
+ bstrncpy(mr->MediaType, row[11]!=NULL?row[11]:"", sizeof(mr->MediaType));
+ bstrncpy(mr->VolStatus, row[12]!=NULL?row[12]:"", sizeof(mr->VolStatus));
mr->PoolId = str_to_int64(row[13]);
mr->VolRetention = str_to_uint64(row[14]);
mr->VolUseDuration = str_to_uint64(row[15]);
mr->MaxVolFiles = str_to_int64(row[17]);
mr->Recycle = str_to_int64(row[18]);
mr->Slot = str_to_int64(row[19]);
- bstrncpy(mr->cFirstWritten, row[20]!=NULL?row[20]:"", sizeof(mr->cFirstWritten));
+ bstrncpy(mr->cFirstWritten, row[20]!=NULL?row[20]:"", sizeof(mr->cFirstWritten));
mr->FirstWritten = (time_t)str_to_utime(mr->cFirstWritten);
- bstrncpy(mr->cLastWritten, row[21]!=NULL?row[21]:"", sizeof(mr->cLastWritten));
+ bstrncpy(mr->cLastWritten, row[21]!=NULL?row[21]:"", sizeof(mr->cLastWritten));
mr->LastWritten = (time_t)str_to_utime(mr->cLastWritten);
mr->InChanger = str_to_uint64(row[22]);
mr->EndFile = str_to_uint64(row[23]);
}
} else {
if (mr->MediaId != 0) {
- Mmsg1(&mdb->errmsg, _("Media record MediaId=%u not found.\n"), mr->MediaId);
+ Mmsg1(&mdb->errmsg, _("Media record MediaId=%u not found.\n"), mr->MediaId);
} else {
- Mmsg1(&mdb->errmsg, _("Media record for Volume \"%s\" not found.\n"),
+ Mmsg1(&mdb->errmsg, _("Media record for Volume \"%s\" not found.\n"),
mr->VolumeName);
}
}
/*
* Bacula Catalog Database List records interface routines
- *
+ *
* Kern Sibbald, March 2000
*
* Version $Id$
extern int QueryDB(const char *file, int line, JCR *jcr, B_DB *db, char *select_cmd);
-/*
+/*
* Submit general SQL query
*/
-int db_list_sql_query(JCR *jcr, B_DB *mdb, char *query, DB_LIST_HANDLER *sendit,
+int db_list_sql_query(JCR *jcr, B_DB *mdb, char *query, DB_LIST_HANDLER *sendit,
void *ctx, int verbose, e_list_type type)
{
db_lock(mdb);
}
void
-db_list_pool_records(JCR *jcr, B_DB *mdb, DB_LIST_HANDLER *sendit, void *ctx, e_list_type type)
+db_list_pool_records(JCR *jcr, B_DB *mdb, DB_LIST_HANDLER *sendit, void *ctx, e_list_type type)
{
db_lock(mdb);
if (type == VERT_LIST) {
Mmsg(mdb->cmd, "SELECT PoolId,Name,NumVols,MaxVols,UseOnce,UseCatalog,"
- "AcceptAnyVolume,VolRetention,VolUseDuration,MaxVolJobs,MaxVolBytes,"
- "AutoPrune,Recycle,PoolType,LabelFormat,Enabled,ScratchPoolId,"
- "RecyclePoolId "
- "FROM Pool ORDER BY PoolId");
+ "AcceptAnyVolume,VolRetention,VolUseDuration,MaxVolJobs,MaxVolBytes,"
+ "AutoPrune,Recycle,PoolType,LabelFormat,Enabled,ScratchPoolId,"
+ "RecyclePoolId "
+ "FROM Pool ORDER BY PoolId");
} else {
Mmsg(mdb->cmd, "SELECT PoolId,Name,NumVols,MaxVols,PoolType,LabelFormat "
- "FROM Pool ORDER BY PoolId");
+ "FROM Pool ORDER BY PoolId");
}
if (!QUERY_DB(jcr, mdb, mdb->cmd)) {
}
list_result(jcr, mdb, sendit, ctx, type);
-
+
sql_free_result(mdb);
db_unlock(mdb);
}
db_lock(mdb);
if (type == VERT_LIST) {
Mmsg(mdb->cmd, "SELECT ClientId,Name,Uname,AutoPrune,FileRetention,"
- "FileRetention,JobRetention "
- "FROM Client ORDER BY ClientId");
+ "FileRetention,JobRetention "
+ "FROM Client ORDER BY ClientId");
} else {
Mmsg(mdb->cmd, "SELECT ClientId,Name,FileRetention,JobRetention "
- "FROM Client ORDER BY ClientId");
+ "FROM Client ORDER BY ClientId");
}
if (!QUERY_DB(jcr, mdb, mdb->cmd)) {
}
list_result(jcr, mdb, sendit, ctx, type);
-
+
sql_free_result(mdb);
db_unlock(mdb);
}
* otherwise, list the Volumes in the Pool specified by PoolId
*/
void
-db_list_media_records(JCR *jcr, B_DB *mdb, MEDIA_DBR *mdbr,
+db_list_media_records(JCR *jcr, B_DB *mdb, MEDIA_DBR *mdbr,
DB_LIST_HANDLER *sendit, void *ctx, e_list_type type)
{
db_lock(mdb);
if (type == VERT_LIST) {
if (mdbr->VolumeName[0] != 0) {
- Mmsg(mdb->cmd, "SELECT MediaId,VolumeName,Slot,PoolId,"
- "MediaType,FirstWritten,LastWritten,LabelDate,VolJobs,"
- "VolFiles,VolBlocks,VolMounts,VolBytes,VolErrors,VolWrites,"
- "VolCapacityBytes,VolStatus,Recycle,VolRetention,"
- "VolUseDuration,MaxVolJobs,MaxVolFiles,MaxVolBytes,InChanger,"
- "EndFile,EndBlock "
- "FROM Media WHERE Media.VolumeName='%s'", mdbr->VolumeName);
+ Mmsg(mdb->cmd, "SELECT MediaId,VolumeName,Slot,PoolId,"
+ "MediaType,FirstWritten,LastWritten,LabelDate,VolJobs,"
+ "VolFiles,VolBlocks,VolMounts,VolBytes,VolErrors,VolWrites,"
+ "VolCapacityBytes,VolStatus,Recycle,VolRetention,"
+ "VolUseDuration,MaxVolJobs,MaxVolFiles,MaxVolBytes,InChanger,"
+ "EndFile,EndBlock "
+ "FROM Media WHERE Media.VolumeName='%s'", mdbr->VolumeName);
} else {
- Mmsg(mdb->cmd, "SELECT MediaId,VolumeName,Slot,PoolId,"
- "MediaType,FirstWritten,LastWritten,LabelDate,VolJobs,"
- "VolFiles,VolBlocks,VolMounts,VolBytes,VolErrors,VolWrites,"
- "VolCapacityBytes,VolStatus,Recycle,VolRetention,"
- "VolUseDuration,MaxVolJobs,MaxVolFiles,MaxVolBytes,InChanger,"
- "EndFile,EndBlock "
- "FROM Media WHERE Media.PoolId=%u ORDER BY MediaId", mdbr->PoolId);
+ Mmsg(mdb->cmd, "SELECT MediaId,VolumeName,Slot,PoolId,"
+ "MediaType,FirstWritten,LastWritten,LabelDate,VolJobs,"
+ "VolFiles,VolBlocks,VolMounts,VolBytes,VolErrors,VolWrites,"
+ "VolCapacityBytes,VolStatus,Recycle,VolRetention,"
+ "VolUseDuration,MaxVolJobs,MaxVolFiles,MaxVolBytes,InChanger,"
+ "EndFile,EndBlock "
+ "FROM Media WHERE Media.PoolId=%u ORDER BY MediaId", mdbr->PoolId);
}
} else {
if (mdbr->VolumeName[0] != 0) {
- Mmsg(mdb->cmd, "SELECT MediaId,VolumeName,VolStatus,"
- "VolBytes,VolFiles,VolRetention,Recycle,Slot,InChanger,MediaType,LastWritten "
- "FROM Media WHERE Media.VolumeName='%s'", mdbr->VolumeName);
+ Mmsg(mdb->cmd, "SELECT MediaId,VolumeName,VolStatus,"
+ "VolBytes,VolFiles,VolRetention,Recycle,Slot,InChanger,MediaType,LastWritten "
+ "FROM Media WHERE Media.VolumeName='%s'", mdbr->VolumeName);
} else {
- Mmsg(mdb->cmd, "SELECT MediaId,VolumeName,VolStatus,"
- "VolBytes,VolFiles,VolRetention,Recycle,Slot,InChanger,MediaType,LastWritten "
- "FROM Media WHERE Media.PoolId=%u ORDER BY MediaId", mdbr->PoolId);
+ Mmsg(mdb->cmd, "SELECT MediaId,VolumeName,VolStatus,"
+ "VolBytes,VolFiles,VolRetention,Recycle,Slot,InChanger,MediaType,LastWritten "
+ "FROM Media WHERE Media.PoolId=%u ORDER BY MediaId", mdbr->PoolId);
}
}
}
list_result(jcr, mdb, sendit, ctx, type);
-
+
sql_free_result(mdb);
db_unlock(mdb);
}
-void db_list_jobmedia_records(JCR *jcr, B_DB *mdb, uint32_t JobId,
+void db_list_jobmedia_records(JCR *jcr, B_DB *mdb, uint32_t JobId,
DB_LIST_HANDLER *sendit, void *ctx, e_list_type type)
{
db_lock(mdb);
if (type == VERT_LIST) {
if (JobId > 0) { /* do by JobId */
- Mmsg(mdb->cmd, "SELECT JobMediaId,JobId,MediaId,Media.VolumeName,"
- "FirstIndex,LastIndex,StartFile,JobMedia.EndFile,StartBlock,"
- "JobMedia.EndBlock "
- "FROM JobMedia,Media WHERE Media.MediaId=JobMedia.MediaId "
- "AND JobMedia.JobId=%u", JobId);
+ Mmsg(mdb->cmd, "SELECT JobMediaId,JobId,MediaId,Media.VolumeName,"
+ "FirstIndex,LastIndex,StartFile,JobMedia.EndFile,StartBlock,"
+ "JobMedia.EndBlock "
+ "FROM JobMedia,Media WHERE Media.MediaId=JobMedia.MediaId "
+ "AND JobMedia.JobId=%u", JobId);
} else {
- Mmsg(mdb->cmd, "SELECT JobMediaId,JobId,MediaId,Media.VolumeName,"
- "FirstIndex,LastIndex,StartFile,JobMedia.EndFile,StartBlock,"
- "JobMedia.EndBlock "
- "FROM JobMedia,Media WHERE Media.MediaId=JobMedia.MediaId");
+ Mmsg(mdb->cmd, "SELECT JobMediaId,JobId,MediaId,Media.VolumeName,"
+ "FirstIndex,LastIndex,StartFile,JobMedia.EndFile,StartBlock,"
+ "JobMedia.EndBlock "
+ "FROM JobMedia,Media WHERE Media.MediaId=JobMedia.MediaId");
}
} else {
if (JobId > 0) { /* do by JobId */
- Mmsg(mdb->cmd, "SELECT JobId,Media.VolumeName,FirstIndex,LastIndex "
- "FROM JobMedia,Media WHERE Media.MediaId=JobMedia.MediaId "
- "AND JobMedia.JobId=%u", JobId);
+ Mmsg(mdb->cmd, "SELECT JobId,Media.VolumeName,FirstIndex,LastIndex "
+ "FROM JobMedia,Media WHERE Media.MediaId=JobMedia.MediaId "
+ "AND JobMedia.JobId=%u", JobId);
} else {
- Mmsg(mdb->cmd, "SELECT JobId,Media.VolumeName,FirstIndex,LastIndex "
- "FROM JobMedia,Media WHERE Media.MediaId=JobMedia.MediaId");
+ Mmsg(mdb->cmd, "SELECT JobId,Media.VolumeName,FirstIndex,LastIndex "
+ "FROM JobMedia,Media WHERE Media.MediaId=JobMedia.MediaId");
}
}
if (!QUERY_DB(jcr, mdb, mdb->cmd)) {
}
list_result(jcr, mdb, sendit, ctx, type);
-
+
sql_free_result(mdb);
db_unlock(mdb);
}
* only the job with the specified id.
*/
void
-db_list_job_records(JCR *jcr, B_DB *mdb, JOB_DBR *jr, DB_LIST_HANDLER *sendit,
+db_list_job_records(JCR *jcr, B_DB *mdb, JOB_DBR *jr, DB_LIST_HANDLER *sendit,
void *ctx, e_list_type type)
{
db_lock(mdb);
if (type == VERT_LIST) {
if (jr->JobId == 0 && jr->Job[0] == 0) {
- Mmsg(mdb->cmd,
- "SELECT JobId,Job,Job.Name,PurgedFiles,Type,Level,"
- "Job.ClientId,Client.Name,JobStatus,SchedTime,"
- "StartTime,EndTime,JobTDate,"
- "VolSessionId,VolSessionTime,JobFiles,JobErrors,"
- "JobMissingFiles,Job.PoolId,Pool.Name,Job.FileSetId,FileSet.FileSet "
- "FROM Job,Client,Pool,FileSet WHERE "
- "Client.ClientId=Job.ClientId AND Pool.PoolId=Job.PoolId "
- "AND FileSet.FileSetId=Job.FileSetId ORDER BY StartTime");
+ Mmsg(mdb->cmd,
+ "SELECT JobId,Job,Job.Name,PurgedFiles,Type,Level,"
+ "Job.ClientId,Client.Name,JobStatus,SchedTime,"
+ "StartTime,EndTime,JobTDate,"
+ "VolSessionId,VolSessionTime,JobFiles,JobErrors,"
+ "JobMissingFiles,Job.PoolId,Pool.Name,Job.FileSetId,FileSet.FileSet "
+ "FROM Job,Client,Pool,FileSet WHERE "
+ "Client.ClientId=Job.ClientId AND Pool.PoolId=Job.PoolId "
+ "AND FileSet.FileSetId=Job.FileSetId ORDER BY StartTime");
} else { /* single record */
- Mmsg(mdb->cmd,
- "SELECT JobId,Job,Job.Name,PurgedFiles,Type,Level,"
- "Job.ClientId,Client.Name,JobStatus,SchedTime,"
- "StartTime,EndTime,JobTDate,"
- "VolSessionId,VolSessionTime,JobFiles,JobErrors,"
- "JobMissingFiles,Job.PoolId,Pool.Name,Job.FileSetId,FileSet.FileSet "
- "FROM Job,Client,Pool,FileSet WHERE Job.JobId=%u AND "
- "Client.ClientId=Job.ClientId AND Pool.PoolId=Job.PoolId "
- "AND FileSet.FileSetId=Job.FileSetId", jr->JobId);
+ Mmsg(mdb->cmd,
+ "SELECT JobId,Job,Job.Name,PurgedFiles,Type,Level,"
+ "Job.ClientId,Client.Name,JobStatus,SchedTime,"
+ "StartTime,EndTime,JobTDate,"
+ "VolSessionId,VolSessionTime,JobFiles,JobErrors,"
+ "JobMissingFiles,Job.PoolId,Pool.Name,Job.FileSetId,FileSet.FileSet "
+ "FROM Job,Client,Pool,FileSet WHERE Job.JobId=%u AND "
+ "Client.ClientId=Job.ClientId AND Pool.PoolId=Job.PoolId "
+ "AND FileSet.FileSetId=Job.FileSetId", jr->JobId);
}
} else {
if (jr->JobId == 0 && jr->Job[0] == 0) {
- Mmsg(mdb->cmd,
- "SELECT JobId,Name,StartTime,Type,Level,JobFiles,JobBytes,JobStatus "
- "FROM Job ORDER BY StartTime");
+ Mmsg(mdb->cmd,
+ "SELECT JobId,Name,StartTime,Type,Level,JobFiles,JobBytes,JobStatus "
+ "FROM Job ORDER BY StartTime");
} else { /* single record */
- Mmsg(mdb->cmd, "SELECT JobId,Name,StartTime,Type,Level,"
- "JobFiles,JobBytes,JobStatus FROM Job WHERE JobId=%u", jr->JobId);
+ Mmsg(mdb->cmd, "SELECT JobId,Name,StartTime,Type,Level,"
+ "JobFiles,JobBytes,JobStatus FROM Job WHERE JobId=%u", jr->JobId);
}
}
if (!QUERY_DB(jcr, mdb, mdb->cmd)) {
return;
}
list_result(jcr, mdb, sendit, ctx, type);
-
+
sql_free_result(mdb);
db_unlock(mdb);
}
}
list_result(jcr, mdb, sendit, ctx, HORZ_LIST);
-
+
sql_free_result(mdb);
/* Do Grand Total */
- Mmsg(mdb->cmd, "SELECT count(*) AS Jobs,sum(JobFiles) \
-AS Files,sum(JobBytes) As Bytes FROM Job");
+ Mmsg(mdb->cmd, "SELECT count(*) AS Jobs,sum(JobFiles) "
+"AS Files,sum(JobBytes) As Bytes FROM Job");
if (!QUERY_DB(jcr, mdb, mdb->cmd)) {
db_unlock(mdb);
}
list_result(jcr, mdb, sendit, ctx, HORZ_LIST);
-
+
sql_free_result(mdb);
db_unlock(mdb);
}
-/*
- * Stupid MySQL is NON-STANDARD !
+/*
+ * Stupid MySQL is NON-STANDARD !
*/
#ifdef HAVE_MYSQL
#define FN "CONCAT(Path.Path,Filename.Name)"
}
list_result(jcr, mdb, sendit, ctx, HORZ_LIST);
-
+
sql_free_result(mdb);
db_unlock(mdb);
}
/*
* Bacula Catalog Database Update record interface routines
- *
+ *
* Kern Sibbald, March 2000
*
* Version $Id$
/* Mark the file record as being visited during database
* verify compare. Stuff JobId into MarkedId field
*/
-int db_mark_file_record(JCR *jcr, B_DB *mdb, FileId_t FileId, JobId_t JobId)
+int db_mark_file_record(JCR *jcr, B_DB *mdb, FileId_t FileId, JobId_t JobId)
{
int stat;
btime_t JobTDate;
int stat;
char ed1[30];
-
+
stime = jr->StartTime;
localtime_r(&stime, &tm);
strftime(dt, sizeof(dt), "%Y-%m-%d %T", &tm);
db_lock(mdb);
Mmsg(mdb->cmd, "UPDATE Job SET JobStatus='%c',Level='%c',StartTime='%s',"
"ClientId=%u,JobTDate=%s WHERE JobId=%u",
- (char)(jcr->JobStatus),
+ (char)(jcr->JobStatus),
(char)(jr->JobLevel), dt, jr->ClientId, edit_uint64(JobTDate, ed1), jr->JobId);
stat = UPDATE_DB(jcr, mdb, mdb->cmd);
*
*/
void edit_num_or_null(char *s, size_t n, uint32_t id) {
- bsnprintf(s, n, id ? "%u" : "NULL", id);
+ bsnprintf(s, n, id ? "%u" : "NULL", id);
}
edit_num_or_null(PoolId, sizeof(PoolId), jr->PoolId);
edit_num_or_null(FileSetId, sizeof(FileSetId), jr->FileSetId);
edit_num_or_null(ClientId, sizeof(ClientId), jr->ClientId);
-
+
ttime = jr->EndTime;
localtime_r(&ttime, &tm);
strftime(dt, sizeof(dt), "%Y-%m-%d %T", &tm);
db_lock(mdb);
Mmsg(mdb->cmd,
- "UPDATE Job SET JobStatus='%c', EndTime='%s', \
-ClientId=%s, JobBytes=%s, JobFiles=%u, JobErrors=%u, VolSessionId=%u, \
-VolSessionTime=%u, PoolId=%s, FileSetId=%s, JobTDate=%s WHERE JobId=%u",
- (char)(jr->JobStatus), dt, ClientId, edit_uint64(jr->JobBytes, ed1),
- jr->JobFiles, jr->JobErrors, jr->VolSessionId, jr->VolSessionTime,
+ "UPDATE Job SET JobStatus='%c', EndTime='%s', "
+"ClientId=%s, JobBytes=%s, JobFiles=%u, JobErrors=%u, VolSessionId=%u, "
+"VolSessionTime=%u, PoolId=%s, FileSetId=%s, JobTDate=%s WHERE JobId=%u",
+ (char)(jr->JobStatus), dt, ClientId, edit_uint64(jr->JobBytes, ed1),
+ jr->JobFiles, jr->JobErrors, jr->VolSessionId, jr->VolSessionTime,
PoolId, FileSetId, edit_uint64(JobTDate, ed2), jr->JobId);
stat = UPDATE_DB(jcr, mdb, mdb->cmd);
/*
- * Update Client record
+ * Update Client record
* Returns: 0 on failure
* 1 on success
*/
}
Mmsg(mdb->cmd,
-"UPDATE Client SET AutoPrune=%d,FileRetention=%s,JobRetention=%s,"
+"UPDATE Client SET AutoPrune=%d,FileRetention=%s,JobRetention=%s,"
"Uname='%s' WHERE Name='%s'",
cr->AutoPrune,
edit_uint64(cr->FileRetention, ed1),
db_lock(mdb);
Mmsg(mdb->cmd,
-"UPDATE Counters SET MinValue=%d,MaxValue=%d,CurrentValue=%d,"
+"UPDATE Counters SET MinValue=%d,MaxValue=%d,CurrentValue=%d,"
"WrapCounter='%s' WHERE Counter='%s'",
cr->MinValue, cr->MaxValue, cr->CurrentValue,
cr->WrapCounter, cr->Counter);
db_lock(mdb);
Mmsg(mdb->cmd,
-"UPDATE Pool SET NumVols=%u,MaxVols=%u,UseOnce=%d,UseCatalog=%d,"
+"UPDATE Pool SET NumVols=%u,MaxVols=%u,UseOnce=%d,UseCatalog=%d,"
"AcceptAnyVolume=%d,VolRetention='%s',VolUseDuration='%s',"
"MaxVolJobs=%u,MaxVolFiles=%u,MaxVolBytes=%s,Recycle=%d,"
"AutoPrune=%d,LabelFormat='%s' WHERE PoolId=%u",
return stat;
}
-/*
+/*
* Update the Media Record at end of Session
*
* Returns: 0 on failure
* numrows on success
*/
int
-db_update_media_record(JCR *jcr, B_DB *mdb, MEDIA_DBR *mr)
+db_update_media_record(JCR *jcr, B_DB *mdb, MEDIA_DBR *mr)
{
char dt[MAX_TIME_LENGTH];
time_t ttime;
struct tm tm;
int stat;
char ed1[30], ed2[30], ed3[30], ed4[30];
-
+
Dmsg1(100, "update_media: FirstWritten=%d\n", mr->FirstWritten);
db_lock(mdb);
ttime = mr->FirstWritten;
localtime_r(&ttime, &tm);
strftime(dt, sizeof(dt), "%Y-%m-%d %T", &tm);
- Mmsg(mdb->cmd, "UPDATE Media SET FirstWritten='%s'\
- WHERE VolumeName='%s'", dt, mr->VolumeName);
+ Mmsg(mdb->cmd, "UPDATE Media SET FirstWritten='%s'"
+" WHERE VolumeName='%s'", dt, mr->VolumeName);
stat = UPDATE_DB(jcr, mdb, mdb->cmd);
Dmsg1(400, "Firstwritten stat=%d\n", stat);
}
localtime_r(&ttime, &tm);
strftime(dt, sizeof(dt), "%Y-%m-%d %T", &tm);
Mmsg(mdb->cmd, "UPDATE Media SET LabelDate='%s' "
- "WHERE VolumeName='%s'", dt, mr->VolumeName);
+ "WHERE VolumeName='%s'", dt, mr->VolumeName);
stat = UPDATE_DB(jcr, mdb, mdb->cmd);
}
-
+
if (mr->LastWritten != 0) {
ttime = mr->LastWritten;
localtime_r(&ttime, &tm);
strftime(dt, sizeof(dt), "%Y-%m-%d %T", &tm);
Mmsg(mdb->cmd, "UPDATE Media SET VolJobs=%u,"
- "VolFiles=%u,VolBlocks=%u,VolBytes=%s,VolMounts=%u,VolErrors=%u,"
- "VolWrites=%u,MaxVolBytes=%s,LastWritten='%s',VolStatus='%s',"
- "Slot=%d,InChanger=%d,VolReadTime=%s,VolWriteTime=%s "
- " WHERE VolumeName='%s'",
+ "VolFiles=%u,VolBlocks=%u,VolBytes=%s,VolMounts=%u,VolErrors=%u,"
+ "VolWrites=%u,MaxVolBytes=%s,LastWritten='%s',VolStatus='%s',"
+ "Slot=%d,InChanger=%d,VolReadTime=%s,VolWriteTime=%s "
+ " WHERE VolumeName='%s'",
mr->VolJobs, mr->VolFiles, mr->VolBlocks, edit_uint64(mr->VolBytes, ed1),
- mr->VolMounts, mr->VolErrors, mr->VolWrites,
- edit_uint64(mr->MaxVolBytes, ed2), dt,
- mr->VolStatus, mr->Slot, mr->InChanger,
+ mr->VolMounts, mr->VolErrors, mr->VolWrites,
+ edit_uint64(mr->MaxVolBytes, ed2), dt,
+ mr->VolStatus, mr->Slot, mr->InChanger,
edit_uint64(mr->VolReadTime, ed3),
edit_uint64(mr->VolWriteTime, ed4),
mr->VolumeName);
} else {
Mmsg(mdb->cmd, "UPDATE Media SET VolJobs=%u,"
- "VolFiles=%u,VolBlocks=%u,VolBytes=%s,VolMounts=%u,VolErrors=%u,"
- "VolWrites=%u,MaxVolBytes=%s,VolStatus='%s',"
- "Slot=%d,InChanger=%d,VolReadTime=%s,VolWriteTime=%s "
- " WHERE VolumeName='%s'",
+ "VolFiles=%u,VolBlocks=%u,VolBytes=%s,VolMounts=%u,VolErrors=%u,"
+ "VolWrites=%u,MaxVolBytes=%s,VolStatus='%s',"
+ "Slot=%d,InChanger=%d,VolReadTime=%s,VolWriteTime=%s "
+ " WHERE VolumeName='%s'",
mr->VolJobs, mr->VolFiles, mr->VolBlocks, edit_uint64(mr->VolBytes, ed1),
- mr->VolMounts, mr->VolErrors, mr->VolWrites,
- edit_uint64(mr->MaxVolBytes, ed2),
- mr->VolStatus, mr->Slot, mr->InChanger,
+ mr->VolMounts, mr->VolErrors, mr->VolWrites,
+ edit_uint64(mr->MaxVolBytes, ed2),
+ mr->VolStatus, mr->Slot, mr->InChanger,
edit_uint64(mr->VolReadTime, ed3),
edit_uint64(mr->VolWriteTime, ed4),
mr->VolumeName);
return stat;
}
-/*
+/*
* Update the Media Record Default values from Pool
*
* Returns: 0 on failure
* numrows on success
*/
int
-db_update_media_defaults(JCR *jcr, B_DB *mdb, MEDIA_DBR *mr)
+db_update_media_defaults(JCR *jcr, B_DB *mdb, MEDIA_DBR *mr)
{
int stat;
char ed1[30], ed2[30], ed3[30];
-
+
db_lock(mdb);
if (mr->VolumeName[0]) {
Mmsg(mdb->cmd, "UPDATE Media SET "
- "Recycle=%d,VolRetention=%s,VolUseDuration=%s,"
- "MaxVolJobs=%u,MaxVolFiles=%u,MaxVolBytes=%s"
- " WHERE VolumeName='%s'",
- mr->Recycle,edit_uint64(mr->VolRetention, ed1),
+ "Recycle=%d,VolRetention=%s,VolUseDuration=%s,"
+ "MaxVolJobs=%u,MaxVolFiles=%u,MaxVolBytes=%s"
+ " WHERE VolumeName='%s'",
+ mr->Recycle,edit_uint64(mr->VolRetention, ed1),
edit_uint64(mr->VolUseDuration, ed2),
mr->MaxVolJobs, mr->MaxVolFiles,
edit_uint64(mr->VolBytes, ed3),
mr->VolumeName);
} else {
Mmsg(mdb->cmd, "UPDATE Media SET "
- "Recycle=%d,VolRetention=%s,VolUseDuration=%s,"
- "MaxVolJobs=%u,MaxVolFiles=%u,MaxVolBytes=%s"
- " WHERE PoolId=%u",
- mr->Recycle,edit_uint64(mr->VolRetention, ed1),
+ "Recycle=%d,VolRetention=%s,VolUseDuration=%s,"
+ "MaxVolJobs=%u,MaxVolFiles=%u,MaxVolBytes=%s"
+ " WHERE PoolId=%u",
+ mr->Recycle,edit_uint64(mr->VolRetention, ed1),
edit_uint64(mr->VolUseDuration, ed2),
mr->MaxVolJobs, mr->MaxVolFiles,
edit_uint64(mr->VolBytes, ed3),
}
-/*
+/*
* If we have a non-zero InChanger, ensure that no other Media
* record has InChanger set on the same Slot.
*
* This routine assumes the database is already locked.
*/
void
-db_make_inchanger_unique(JCR *jcr, B_DB *mdb, MEDIA_DBR *mr)
+db_make_inchanger_unique(JCR *jcr, B_DB *mdb, MEDIA_DBR *mr)
{
if (mr->InChanger != 0 && mr->Slot != 0) {
Mmsg(mdb->cmd, "UPDATE Media SET InChanger=0 WHERE "
- "Slot=%d AND PoolId=%u AND MediaId!=%u",
+ "Slot=%d AND PoolId=%u AND MediaId!=%u",
mr->Slot, mr->PoolId, mr->MediaId);
Dmsg1(400, "%s\n", mdb->cmd);
UPDATE_DB(jcr, mdb, mdb->cmd);
*/
B_DB *
db_init_database(JCR *jcr, const char *db_name, const char *db_user, const char *db_password,
- const char *db_address, int db_port, const char *db_socket,
+ const char *db_address, int db_port, const char *db_socket,
int mult_db_connections)
{
B_DB *mdb;
if (!mult_db_connections) {
for (mdb=NULL; (mdb=(B_DB *)qnext(&db_list, &mdb->bq)); ) {
if (strcmp(mdb->db_name, db_name) == 0) {
- Dmsg2(300, "DB REopen %d %s\n", mdb->ref_count, db_name);
+ Dmsg2(300, "DB REopen %d %s\n", mdb->ref_count, db_name);
mdb->ref_count++;
V(mutex);
return mdb; /* already open */
mdb = (B_DB *) malloc(sizeof(B_DB));
memset(mdb, 0, sizeof(B_DB));
mdb->db_name = bstrdup(db_name);
- mdb->have_insert_id = TRUE;
+ mdb->have_insert_id = TRUE;
mdb->errmsg = get_pool_memory(PM_EMSG); /* get error message buffer */
*mdb->errmsg = 0;
mdb->cmd = get_pool_memory(PM_EMSG); /* get command buffer */
mdb->connected = FALSE;
if ((errstat=rwl_init(&mdb->lock)) != 0) {
- Mmsg1(&mdb->errmsg, _("Unable to initialize DB lock. ERR=%s\n"),
+ Mmsg1(&mdb->errmsg, _("Unable to initialize DB lock. ERR=%s\n"),
strerror(errstat));
V(mutex);
return 0;
}
/* open the database */
- len = strlen(working_directory) + strlen(mdb->db_name) + 5;
+ len = strlen(working_directory) + strlen(mdb->db_name) + 5;
db_name = (char *)malloc(len);
strcpy(db_name, working_directory);
strcat(db_name, "/");
strcat(db_name, mdb->db_name);
strcat(db_name, ".db");
if (stat(db_name, &statbuf) != 0) {
- Mmsg1(&mdb->errmsg, _("Database %s does not exist, please create it.\n"),
+ Mmsg1(&mdb->errmsg, _("Database %s does not exist, please create it.\n"),
db_name);
free(db_name);
V(mutex);
&mdb->sqlite_errmsg); /* error message */
Dmsg0(300, "sqlite_open\n");
-
+
if (mdb->db == NULL) {
Mmsg2(&mdb->errmsg, _("Unable to open Database=%s. ERR=%s\n"),
- db_name, mdb->sqlite_errmsg ? mdb->sqlite_errmsg : _("unknown"));
+ db_name, mdb->sqlite_errmsg ? mdb->sqlite_errmsg : _("unknown"));
free(db_name);
V(mutex);
return 0;
if (mdb->connected && mdb->db) {
sqlite_close(mdb->db);
}
- rwl_destroy(&mdb->lock);
+ rwl_destroy(&mdb->lock);
free_pool_memory(mdb->errmsg);
free_pool_memory(mdb->cmd);
free_pool_memory(mdb->cached_path);
db_unlock(mdb);
return 1;
-}
+}
/*
while (len--) {
switch (*o) {
case '\'':
- *n++ = '\'';
- *n++ = '\'';
+ *n++ = '\'';
+ *n++ = '\'';
o++;
break;
case 0:
- *n++ = '\\';
+ *n++ = '\\';
*n++ = 0;
o++;
break;
void *ctx;
};
-/*
- * Convert SQLite's callback into Bacula DB callback
+/*
+ * Convert SQLite's callback into Bacula DB callback
*/
static int sqlite_result(void *arh_data, int num_fields, char **rows, char **col_names)
{
- struct rh_data *rh_data = (struct rh_data *)arh_data;
+ struct rh_data *rh_data = (struct rh_data *)arh_data;
if (rh_data->result_handler) {
(*(rh_data->result_handler))(rh_data->ctx, num_fields, rows);
/*
* Submit a sqlite query and retrieve all the data
*/
-int my_sqlite_query(B_DB *mdb, char *cmd)
+int my_sqlite_query(B_DB *mdb, char *cmd)
{
int stat;
mdb->fields_defined = false;
}
sqlite_free_table(mdb->result);
- mdb->nrow = mdb->ncolumn = 0;
+ mdb->nrow = mdb->ncolumn = 0;
}
void my_sqlite_field_seek(B_DB *mdb, int field)
You should have received a copy of the GNU General Public
License along with this program; if not, write to the Free
- Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+ Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA.
*/
void senditf(const char *fmt, ...);
-void sendit(const char *buf);
+void sendit(const char *buf);
/* Commands sent to Director */
static char hello[] = "Hello %s calling\n";
char bashed_name[MAX_NAME_LENGTH];
char *password;
- /*
+ /*
* Send my name to the Director then do authentication
*/
if (cons) {
btimer_t *tid = start_bsock_timer(dir, 60 * 5);
bnet_fsend(dir, hello, bashed_name);
- if (!cram_md5_get_auth(dir, password, ssl_need) ||
+ if (!cram_md5_get_auth(dir, password, ssl_need) ||
!cram_md5_auth(dir, password, ssl_need)) {
stop_bsock_timer(tid);
sendit( _("Director authorization problem.\n"
- "Most likely the passwords do not agree.\n"
+ "Most likely the passwords do not agree.\n"
"Please see http://www.bacula.org/html-manual/faq.html#AuthorizationErrors for help.\n"));
return 0;
}
-/*
- Generalized console input/output handler
+/*
+ Generalized console input/output handler
A maintanable replacement for readline()
Updated for Bacula, Kern Sibbald, December MMIII
This code is in part derived from code that I wrote in
1981, so some of it is a bit old and could use a cleanup.
-
+
*/
/*
Copyright (C) 1981-2004 Kern Sibbald and John Walker
*/
-/*
+/*
* UTF-8
* If the top bit of a UTF-8 string is 0 (8 bits), then it
* is a normal ASCII character.
#include <stdlib.h>
#include <signal.h>
#include <string.h>
-#include <ctype.h>
+#include <ctype.h>
#else
/* We are in Bacula */
void trapctlc();
int usrbrk();
void clrbrk();
-
+
void con_init(FILE *input)
{
- atexit(con_term);
+ atexit(con_term);
rawmode(input);
trapctlc();
}
static unsigned do_smap(unsigned c)
{
char str[MAX_STAB];
- int len = 0;
+ int len = 0;
stab_t *tstab;
int i, found;
unsigned cm;
for (j=0; j<tstab->len; j++) {
c = tstab->str[j];
if (c < 0x20 || c > 0x7F) {
- sprintf(buf, " 0x%x ", c);
+ sprintf(buf, " 0x%x ", c);
t_send(buf);
} else {
buf[0] = c;
t_sendl(buf, 1);
}
}
- sprintf(buf, " func=%d len=%d\n\r", tstab->func, tstab->len);
+ sprintf(buf, " func=%d len=%d\n\r", tstab->func, tstab->len);
t_send(buf);
}
}
{
stab_t *tstab;
int len;
-
+
if (!str) {
return;
}
}
tstab->next = stab[tstab->len-1];
stab[tstab->len-1] = tstab;
-/* printf("Add_smap tstab=%x len=%d func=%d tstab->next=%x\n\r", tstab, len,
+/* printf("Add_smap tstab=%x len=%d func=%d tstab->next=%x\n\r", tstab, len,
func, tstab->next); */
}
}
switch (c=input_char()) {
case F_RETURN: /* CR */
- t_sendl("\r\n", 2); /* yes, print it and */
+ t_sendl("\r\n", 2); /* yes, print it and */
goto done; /* get out */
case F_CLRSCRN: /* clear screen */
asclrs();
backup(curline);
delchr(1, curline, sizeof(curline));
if (cp == 0) {
- t_char(' ');
+ t_char(' ');
t_char(0x8);
}
break;
t_clrline(0, t_width); /* erase line */
cp = 0;
cl = 0; /* reset cursor counter */
- t_char(' ');
+ t_char(' ');
t_char(0x8);
break;
case F_SOL:
curline[cp++] = c; /* store character in line being built */
t_char(c); /* echo character to terminal */
while (more--) {
- c= input_char();
+ c= input_char();
insert_hole(curline, sizeof(curline));
curline[cp++] = c; /* store character in line being built */
t_char(c); /* echo character to terminal */
}
/* How many characters under the cursor */
-static int
+static int
char_count(int cptr, char *str)
{
int cnt = 1;
/* Backup cursor keeping characters under it */
static void
-backup(char *str)
+backup(char *str)
{
if (cp == 0) {
return;
/* Delete the character under the cursor */
static void
-delchr(int del, char *curline, int line_len)
+delchr(int del, char *curline, int line_len)
{
int i, cnt;
printf("%s buf=%x nextl=%x prevl=%x len=%d used=%d\n",
msg,ptr,ptr->nextl,ptr->prevl,ptr->len,ptr->used);
if (ptr->used)
- printf("line=%s\n",&ptr->line);
+ printf("line=%s\n",&ptr->line);
}
#endif /* DEBUGOUT */
asclrl(pos, width); /* clear to end of line */
}
-/* Helper function to add string preceded by
+/* Helper function to add string preceded by
* ESC to smap table */
static void add_esc_smap(const char *str, int func)
{
exit(1);
}
old_term_params_set = true;
- t = old_term_params;
+ t = old_term_params;
t.c_cc[VMIN] = 1; /* satisfy read after 1 char */
t.c_cc[VTIME] = 0;
- t.c_iflag &= ~(BRKINT | IGNPAR | PARMRK | INPCK |
- ISTRIP | ICRNL | IXON | IXOFF | INLCR | IGNCR);
+ t.c_iflag &= ~(BRKINT | IGNPAR | PARMRK | INPCK |
+ ISTRIP | ICRNL | IXON | IXOFF | INLCR | IGNCR);
t.c_iflag |= IGNBRK;
t.c_oflag |= ONLCR;
t.c_lflag &= ~(ECHO | ECHOE | ECHOK | ECHONL | ICANON |
signal(SIGHUP, SIG_IGN);
// signal(SIGSTOP, SIG_IGN);
signal(SIGINT, sigintcatcher);
- signal(SIGWINCH, SIG_IGN);
+ signal(SIGWINCH, SIG_IGN);
signal(SIGQUIT, SIG_IGN);
signal(SIGCHLD, SIG_IGN);
// signal(SIGTSTP, SIG_IGN);
if (read(0, &c, 1) != 1) {
c = 0;
}
- return (unsigned)c;
+ return (unsigned)c;
}
-
+
/* Send message to terminal - primitive routine */
void
t_sendl(const char *msg, int len)
/* ASCLRL() -- Clear to end of line from current position */
-static void asclrl(int pos, int width)
+static void asclrl(int pos, int width)
{
int i;
for (i=1; i<=width-pos+1; i++) /* backspace to original position */
t_char(0x8);
return;
-
+
}
{
t_send((char *)tgoto(t_cm, x, y));
}
-
+
/* ASCLRS -- Clear whole screen */
-static void asclrs()
+static void asclrs()
{
ascurs(0,0);
t_send(t_cs);
#ifdef HAVE_CONIO
#include "conio.h"
#else
-#define con_init(x)
+#define con_init(x)
#define con_term()
#define con_set_zed_keys();
#define trapctlc()
#define clrbrk()
-#define usrbrk() 0
+#define usrbrk() 0
#endif
#ifdef HAVE_WIN32
#define isatty(fd) (fd==0)
DWORD g_platform_id = VER_PLATFORM_WIN32_WINDOWS;
#endif
-
+
/* Exported variables */
#ifdef HAVE_CYGWIN
/* Static variables */
static char *configfile = NULL;
static BSOCK *UA_sock = NULL;
-static DIRRES *dir;
+static DIRRES *dir;
static FILE *output = stdout;
static bool tee = false; /* output to output and stdout */
static bool stop = false;
" -dnn set debug level to nn\n"
" -s no signals\n"
" -t test - read configuration and exit\n"
-" -? print this message.\n"
+" -? print this message.\n"
"\n"), HOST_OS, DISTNAME, DISTVER);
}
-extern "C"
+extern "C"
void got_sigstop(int sig)
{
stop = true;
}
-extern "C"
+extern "C"
void got_sigcontinue(int sig)
{
stop = false;
}
-extern "C"
-void got_sigtout(int sig)
+extern "C"
+void got_sigtout(int sig)
{
// printf("Got tout\n");
}
-extern "C"
+extern "C"
void got_sigtin(int sig)
-{
+{
// printf("Got tin\n");
}
/*
* These are the @command
*/
-struct cmdstruct { const char *key; int (*func)(FILE *input, BSOCK *UA_sock); const char *help; };
+struct cmdstruct { const char *key; int (*func)(FILE *input, BSOCK *UA_sock); const char *help; };
static struct cmdstruct commands[] = {
{ N_("input"), inputcmd, _("input from file")},
{ N_("output"), outputcmd, _("output to file")},
}
-static void read_and_process_input(FILE *input, BSOCK *UA_sock)
+static void read_and_process_input(FILE *input, BSOCK *UA_sock)
{
const char *prompt = "*";
bool at_prompt = false;
int tty_input = isatty(fileno(input));
int stat;
- for ( ;; ) {
+ for ( ;; ) {
if (at_prompt) { /* don't prompt multiple times */
- prompt = "";
+ prompt = "";
} else {
- prompt = "*";
+ prompt = "*";
at_prompt = true;
}
if (tty_input) {
if (stat < 0) {
break; /* error or interrupt */
} else if (stat == 0) { /* timeout */
- if (strcmp(prompt, "*") == 0) {
- bnet_fsend(UA_sock, ".messages");
+ if (strcmp(prompt, "*") == 0) {
+ bnet_fsend(UA_sock, ".messages");
} else {
continue;
}
} else {
at_prompt = FALSE;
/* @ => internal command for us */
- if (UA_sock->msg[0] == '@') {
+ if (UA_sock->msg[0] == '@') {
parse_args(UA_sock->msg, &args, &argc, argk, argv, MAX_CMD_ARGS);
if (!do_a_command(input, UA_sock)) {
break;
while ((stat = bnet_recv(UA_sock)) >= 0) {
if (at_prompt) {
if (!stop) {
- sendit("\n");
+ sendit("\n");
}
at_prompt = false;
}
if (UA_sock->msglen == BNET_PROMPT) {
at_prompt = true;
}
- Dmsg1(100, "Got poll %s\n", bnet_sig_to_ascii(UA_sock));
+ Dmsg1(100, "Got poll %s\n", bnet_sig_to_ascii(UA_sock));
}
}
}
usage();
con_term();
exit(1);
- }
+ }
}
argc -= optind;
argv += optind;
UnlockRes();
if (ndir == 0) {
con_term();
- Emsg1(M_ERROR_TERM, 0, _("No Director resource defined in %s\n\
-Without that I don't how to speak to the Director :-(\n"), configfile);
+ Emsg1(M_ERROR_TERM, 0, _("No Director resource defined in %s\n"
+"Without that I don't how to speak to the Director :-(\n"), configfile);
}
if (test_config) {
LockRes();
ndir = 0;
foreach_res(dir, R_DIRECTOR) {
- senditf( _("%d %s at %s:%d\n"), 1+ndir++, dir->hdr.name, dir->address,
+ senditf( _("%d %s at %s:%d\n"), 1+ndir++, dir->hdr.name, dir->address,
dir->DIRport);
}
UnlockRes();
}
item = atoi(UA_sock->msg);
if (item < 0 || item > ndir) {
- senditf(_("You must enter a number between 1 and %d\n"), ndir);
+ senditf(_("You must enter a number between 1 and %d\n"), ndir);
goto try_again;
}
LockRes();
dir = (DIRRES *)GetNextRes(R_DIRECTOR, NULL);
UnlockRes();
}
-
+
senditf(_("Connecting to Director %s:%d\n"), dir->address,dir->DIRport);
- UA_sock = bnet_connect(NULL, 5, 15, "Director daemon", dir->address,
+ UA_sock = bnet_connect(NULL, 5, 15, "Director daemon", dir->address,
NULL, dir->DIRport, 0);
if (UA_sock == NULL) {
terminate_console(0);
#include "history.h"
-int
+int
get_cmd(FILE *input, const char *prompt, BSOCK *sock, int sec)
{
char *line;
}
}
-/*
- * Get next input command from terminal.
+/*
+ * Get next input command from terminal.
*
* Returns: 1 if got input
* 0 if timeout
* -1 if EOF or error
*/
-int
+int
get_cmd(FILE *input, const char *prompt, BSOCK *sock, int sec)
{
- int len;
+ int len;
if (!stop) {
if (output == stdout || tee) {
sendit(prompt);
switch (wait_for_data(fileno(input), sec)) {
case 0:
return 0; /* timeout */
- case -1:
+ case -1:
return -1; /* error */
default:
len = sizeof_pool_memory(sock->msg) - 1;
}
fd = fopen(argk[1], "r");
if (!fd) {
- senditf(_("Cannot open file %s for input. ERR=%s\n"),
+ senditf(_("Cannot open file %s for input. ERR=%s\n"),
argk[1], strerror(errno));
- return 1;
+ return 1;
}
read_and_process_input(fd, UA_sock);
fclose(fd);
}
fd = fopen(argk[1], mode);
if (!fd) {
- senditf(_("Cannot open file %s for output. ERR=%s\n"),
+ senditf(_("Cannot open file %s for output. ERR=%s\n"),
argk[1], strerror(errno));
- return 1;
+ return 1;
}
output = fd;
return 1;
{
#ifdef xHAVE_CONIO
if (output == stdout || tee) {
- char *p, *q;
+ char *p, *q;
/*
- * Here, we convert every \n into \r\n because the
- * terminal is in raw mode when we are using
+ * Here, we convert every \n into \r\n because the
+ * terminal is in raw mode when we are using
* conio.
*/
for (p=q=buf; (p=strchr(q, '\n')); ) {
if (p-q > 0) {
t_sendl(q, p-q);
}
- t_sendl("\r\n", 2);
- q = ++p; /* point after \n */
+ t_sendl("\r\n", 2);
+ q = ++p; /* point after \n */
}
if (*q) {
t_send(q);
*
* 1. The generic lexical scanner in lib/lex.c and lib/lex.h
*
- * 2. The generic config scanner in lib/parse_config.c and
+ * 2. The generic config scanner in lib/parse_config.c and
* lib/parse_config.h.
* These files contain the parser code, some utility
* routines, and the common store routines (name, int,
#endif
/* Definition of records permitted within each
- * resource with the routine to process the record
+ * resource with the routine to process the record
* information.
- */
+ */
/* Console "globals" */
static RES_ITEM cons_items[] = {
{"historyfile", store_dir, ITEM(res_cons.hist_file), 0, 0, 0},
{"requiressl", store_yesno, ITEM(res_cons.require_ssl), 1, ITEM_DEFAULT, 0},
{"password", store_password, ITEM(res_cons.password), 0, ITEM_REQUIRED, 0},
- {NULL, NULL, NULL, 0, 0, 0}
+ {NULL, NULL, NULL, 0, 0, 0}
};
{"address", store_str, ITEM(res_dir.address), 0, 0, 0},
{"password", store_password, ITEM(res_dir.password), 0, ITEM_REQUIRED, 0},
{"enablessl", store_yesno, ITEM(res_dir.enable_ssl), 1, ITEM_DEFAULT, 0},
- {NULL, NULL, NULL, 0, 0, 0}
+ {NULL, NULL, NULL, 0, 0, 0}
};
-/*
- * This is the master resource definition.
+/*
+ * This is the master resource definition.
* It must have one item for each of the resources.
*/
RES_TABLE resources[] = {
- {"console", cons_items, R_CONSOLE},
+ {"console", cons_items, R_CONSOLE},
{"director", dir_items, R_DIRECTOR},
{NULL, NULL, 0}
};
res->res_cons.rc_file, res->res_cons.hist_file);
break;
case R_DIRECTOR:
- printf("Director: name=%s address=%s DIRport=%d\n", reshdr->name,
+ printf("Director: name=%s address=%s DIRport=%d\n", reshdr->name,
res->res_dir.address, res->res_dir.DIRport);
break;
default:
}
}
-/*
- * Free memory of resource.
+/*
+ * Free memory of resource.
* NB, we don't need to worry about freeing any references
- * to other resources as they will be freed when that
+ * to other resources as they will be freed when that
* resource chain is traversed. Mainly we worry about freeing
* allocated strings (names).
*/
{
URES *res;
int rindex = type - r_first;
- int i, size;
+ int i, size;
int error = 0;
- /*
+ /*
* Ensure that all required items are present
*/
for (i=0; items[i].name; i++) {
if (items[i].flags & ITEM_REQUIRED) {
- if (!bit_is_set(i, res_all.res_dir.hdr.item_present)) {
- Emsg2(M_ABORT, 0, "%s item is required in %s resource, but not found.\n",
+ if (!bit_is_set(i, res_all.res_dir.hdr.item_present)) {
+ Emsg2(M_ABORT, 0, "%s item is required in %s resource, but not found.\n",
items[i].name, resources[rindex]);
}
}
break;
default:
- Emsg1(M_ERROR, 0, "Unknown resource type %d\n", type);
+ Emsg1(M_ERROR, 0, "Unknown resource type %d\n", type);
error = 1;
break;
}
for (next=res_head[rindex]; next->next; next=next->next) {
if (strcmp(next->name, res->res_dir.hdr.name) == 0) {
Emsg2(M_ERROR_TERM, 0,
- _("Attempt to define second %s resource named \"%s\" is not permitted.\n"),
+ _("Attempt to define second %s resource named \"%s\" is not permitted.\n"),
resources[rindex].name, res->res_dir.hdr.name);
}
}
next->next = (RES *)res;
- Dmsg2(90, "Inserting %s res: %s\n", res_to_str(type),
+ Dmsg2(90, "Inserting %s res: %s\n", res_to_str(type),
res->res_dir.hdr.name);
}
}
*/
/*
- * Resource codes -- they must be sequential for indexing
+ * Resource codes -- they must be sequential for indexing
*/
enum {
/* External functions */
-/*
+/*
* Returns: 0 on failure
* 1 on success
*/
-int do_admin(JCR *jcr)
+int do_admin(JCR *jcr)
{
jcr->jr.JobId = jcr->JobId;
set_jcr_job_status(jcr, TermCode);
update_job_end_record(jcr); /* update database */
-
+
if (!db_get_job_record(jcr, jcr->db, &jcr->jr)) {
- Jmsg(jcr, M_WARNING, 0, _("Error getting job record for stats: %s"),
+ Jmsg(jcr, M_WARNING, 0, _("Error getting job record for stats: %s"),
db_strerror(jcr->db));
set_jcr_job_status(jcr, JS_ErrorTerminated);
}
break;
case JS_FatalError:
case JS_ErrorTerminated:
- term_msg = _("*** Admin Error ***");
+ term_msg = _("*** Admin Error ***");
msg_type = M_ERROR; /* Generate error message */
break;
case JS_Canceled:
bstrftime(sdt, sizeof(sdt), jcr->jr.StartTime);
bstrftime(edt, sizeof(edt), jcr->jr.EndTime);
- Jmsg(jcr, msg_type, 0, _("Bacula " VERSION " (" LSMDATE "): %s\n\
- JobId: %d\n\
- Job: %s\n\
- Start time: %s\n\
- End time: %s\n\
- Termination: %s\n\n"),
+ Jmsg(jcr, msg_type, 0, _("Bacula " VERSION " (" LSMDATE "): %s\n"
+" JobId: %d\n"
+" Job: %s\n"
+" Start time: %s\n"
+" End time: %s\n"
+" Termination: %s\n\n"),
edt,
jcr->jr.JobId,
jcr->jr.Job,
term_msg);
Dmsg0(100, "Leave admin_cleanup()\n");
-}
+}
/*
* Authenticate Storage daemon connection
*/
-bool authenticate_storage_daemon(JCR *jcr, STORE *store)
+bool authenticate_storage_daemon(JCR *jcr, STORE *store)
{
BSOCK *sd = jcr->store_bsock;
char dirname[MAX_NAME_LENGTH];
int ssl_need = BNET_SSL_NONE;
bool get_auth, auth = false;
- /*
+ /*
* Send my name to the Storage daemon then do authentication
*/
bstrncpy(dirname, director->hdr.name, sizeof(dirname));
Jmsg(jcr, M_FATAL, 0, _("Error sending Hello to Storage daemon. ERR=%s\n"), bnet_strerror(sd));
return 0;
}
- get_auth = cram_md5_get_auth(sd, store->password, ssl_need);
+ get_auth = cram_md5_get_auth(sd, store->password, ssl_need);
if (get_auth) {
- auth = cram_md5_auth(sd, store->password, ssl_need);
+ auth = cram_md5_auth(sd, store->password, ssl_need);
if (!auth) {
- Dmsg1(50, "cram_auth failed for %s\n", sd->who);
+ Dmsg1(50, "cram_auth failed for %s\n", sd->who);
}
} else {
Dmsg1(50, "cram_get_auth failed for %s\n", sd->who);
stop_bsock_timer(tid);
Dmsg0(50, _("Director and Storage daemon passwords or names not the same.\n"));
Jmsg0(jcr, M_FATAL, 0,
- _("Unable to authenticate with Storage daemon. Possible causes:\n"
- "Passwords or names not the same or\n"
- "Maximum Concurrent Jobs exceeded on the SD or\n"
- "SD networking messed up (restart daemon).\n"
- "Please see http://www.bacula.org/html-manual/faq.html#AuthorizationErrors for help.\n"));
+ _("Unable to authenticate with Storage daemon. Possible causes:\n"
+ "Passwords or names not the same or\n"
+ "Maximum Concurrent Jobs exceeded on the SD or\n"
+ "SD networking messed up (restart daemon).\n"
+ "Please see http://www.bacula.org/html-manual/faq.html#AuthorizationErrors for help.\n"));
return 0;
}
Dmsg1(116, ">stored: %s", sd->msg);
int ssl_need = BNET_SSL_NONE;
bool get_auth, auth = false;
- /*
+ /*
* Send my name to the File daemon then do authentication
*/
bstrncpy(dirname, director->hdr.name, sizeof(dirname));
Jmsg(jcr, M_FATAL, 0, _("Error sending Hello to File daemon. ERR=%s\n"), bnet_strerror(fd));
return 0;
}
- get_auth = cram_md5_get_auth(fd, jcr->client->password, ssl_need);
+ get_auth = cram_md5_get_auth(fd, jcr->client->password, ssl_need);
if (get_auth) {
- auth = cram_md5_auth(fd, jcr->client->password, ssl_need);
+ auth = cram_md5_auth(fd, jcr->client->password, ssl_need);
if (!auth) {
- Dmsg1(50, "cram_auth failed for %s\n", fd->who);
+ Dmsg1(50, "cram_auth failed for %s\n", fd->who);
}
} else {
Dmsg1(50, "cram_get_auth failed for %s\n", fd->who);
stop_bsock_timer(tid);
Dmsg0(50, _("Director and File daemon passwords or names not the same.\n"));
Jmsg(jcr, M_FATAL, 0,
- _("Unable to authenticate with File daemon. Possible causes:\n"
- "Passwords or names not the same or\n"
- "Maximum Concurrent Jobs exceeded on the FD or\n"
- "FD networking messed up (restart daemon).\n"
- "Please see http://www.bacula.org/html-manual/faq.html#AuthorizationErrors for help.\n"));
+ _("Unable to authenticate with File daemon. Possible causes:\n"
+ "Passwords or names not the same or\n"
+ "Maximum Concurrent Jobs exceeded on the FD or\n"
+ "FD networking messed up (restart daemon).\n"
+ "Please see http://www.bacula.org/html-manual/faq.html#AuthorizationErrors for help.\n"));
return 0;
}
Dmsg1(116, ">filed: %s", fd->msg);
return 1;
}
-/*********************************************************************
+/*********************************************************************
*
*/
-int authenticate_user_agent(UAContext *uac)
+int authenticate_user_agent(UAContext *uac)
{
char name[MAX_NAME_LENGTH];
int ssl_need = BNET_SSL_NONE;
- bool ok;
+ bool ok;
BSOCK *ua = uac->UA_sock;
// Emsg4(M_INFO, 0, _("UA Hello from %s:%s:%d is invalid. Len=%d\n"), ua->who,
ok = cram_md5_auth(ua, director->password, ssl_need) &&
cram_md5_get_auth(ua, director->password, ssl_need);
} else {
- unbash_spaces(name);
+ unbash_spaces(name);
CONRES *cons = (CONRES *)GetResWithName(R_CONSOLE, name);
if (cons) {
ok = cram_md5_auth(ua, cons->password, ssl_need) &&
/*
*
- * Bacula Director -- Automatic Pruning
+ * Bacula Director -- Automatic Pruning
* Applies retention periods
*
* Kern Sibbald, May MMII
} else {
pruned = false;
}
-
+
if (jcr->job->PruneFiles || jcr->client->AutoPrune) {
Jmsg(jcr, M_INFO, 0, _("Begin pruning Files.\n"));
prune_files(ua, client);
}
free_ua_context(ua);
- return 1;
+ return 1;
}
/*
for (i=0; i<num_ids; i++) {
mr.MediaId = ids[i];
if (!db_get_media_record(jcr, jcr->db, &mr)) {
- Jmsg(jcr, M_ERROR, 0, "%s", db_strerror(jcr->db));
+ Jmsg(jcr, M_ERROR, 0, "%s", db_strerror(jcr->db));
continue;
}
/* Prune only Volumes from current Pool */
continue;
}
/* Prune only Volumes with status "Full", "Used", or "Append" */
- if (strcmp(mr.VolStatus, "Full") == 0 ||
- strcmp(mr.VolStatus, "Append") == 0 ||
- strcmp(mr.VolStatus, "Used") == 0) {
- Dmsg1(200, "Prune Volume %s\n", mr.VolumeName);
- stat += prune_volume(ua, &mr);
- Dmsg1(200, "Num pruned = %d\n", stat);
+ if (strcmp(mr.VolStatus, "Full") == 0 ||
+ strcmp(mr.VolStatus, "Append") == 0 ||
+ strcmp(mr.VolStatus, "Used") == 0) {
+ Dmsg1(200, "Prune Volume %s\n", mr.VolumeName);
+ stat += prune_volume(ua, &mr);
+ Dmsg1(200, "Num pruned = %d\n", stat);
}
- }
+ }
bail_out:
db_unlock(jcr->db);
static char OKbackup[] = "2000 OK backup\n";
static char OKstore[] = "2000 OK storage\n";
static char EndJob[] = "2800 End Job TermCode=%d JobFiles=%u "
- "ReadBytes=%" lld " JobBytes=%" lld " Errors=%u\n";
+ "ReadBytes=%" lld " JobBytes=%" lld " Errors=%u\n";
/* Forward referenced functions */
/* External functions */
-/*
+/*
* Do a backup of the specified FileSet
- *
+ *
* Returns: 0 on failure
* 1 on success
*/
-int do_backup(JCR *jcr)
+int do_backup(JCR *jcr)
{
char since[MAXSTRING];
int stat;
jcr->fname = get_pool_memory(PM_FNAME);
- /*
- * Get the Pool record -- first apply any level defined pools
+ /*
+ * Get the Pool record -- first apply any level defined pools
*/
switch (jcr->JobLevel) {
case L_FULL:
if (jcr->full_pool) {
- jcr->pool = jcr->full_pool;
+ jcr->pool = jcr->full_pool;
}
break;
case L_INCREMENTAL:
if (jcr->inc_pool) {
- jcr->pool = jcr->inc_pool;
+ jcr->pool = jcr->inc_pool;
}
break;
case L_DIFFERENTIAL:
if (jcr->dif_pool) {
- jcr->pool = jcr->dif_pool;
+ jcr->pool = jcr->dif_pool;
}
break;
}
while (!db_get_pool_record(jcr, jcr->db, &pr)) { /* get by Name */
/* Try to create the pool */
if (create_pool(jcr, jcr->db, jcr->pool, POOL_OP_CREATE) < 0) {
- Jmsg(jcr, M_FATAL, 0, _("Pool %s not in database. %s"), pr.Name,
+ Jmsg(jcr, M_FATAL, 0, _("Pool %s not in database. %s"), pr.Name,
db_strerror(jcr->db));
goto bail_out;
} else {
- Jmsg(jcr, M_INFO, 0, _("Pool %s created in database.\n"), pr.Name);
+ Jmsg(jcr, M_INFO, 0, _("Pool %s created in database.\n"), pr.Name);
}
}
jcr->PoolId = pr.PoolId; /****FIXME**** this can go away */
Dmsg0(110, "Open connection with storage daemon\n");
set_jcr_job_status(jcr, JS_WaitSD);
/*
- * Start conversation with Storage daemon
+ * Start conversation with Storage daemon
*/
if (!connect_to_storage_daemon(jcr, 10, SDConnectTimeout, 1)) {
goto bail_out;
goto bail_out;
}
- /*
+ /*
* send Storage daemon address to the File daemon
*/
store = jcr->store;
goto bail_out;
}
- /* Pickup Job termination data */
+ /* Pickup Job termination data */
stat = wait_for_job_termination(jcr);
backup_cleanup(jcr, stat, since, &fsr);
return 1;
* Here we wait for the File daemon to signal termination,
* then we wait for the Storage daemon. When both
* are done, we return the job status.
- * Also used by restore.c
+ * Also used by restore.c
*/
int wait_for_job_termination(JCR *jcr)
{
&ReadBytes, &JobBytes, &Errors) == 5) {
fd_ok = true;
set_jcr_job_status(jcr, jcr->FDJobStatus);
- Dmsg1(100, "FDStatus=%c\n", (char)jcr->JobStatus);
+ Dmsg1(100, "FDStatus=%c\n", (char)jcr->JobStatus);
} else {
- Jmsg(jcr, M_WARNING, 0, _("Unexpected Client Job message: %s\n"),
+ Jmsg(jcr, M_WARNING, 0, _("Unexpected Client Job message: %s\n"),
fd->msg);
}
if (job_canceled(jcr)) {
// jcr->JobStatus, jcr->SDJobStatus);
/* Return the first error status we find Dir, FD, or SD */
- if (!fd_ok || is_bnet_error(fd)) {
+ if (!fd_ok || is_bnet_error(fd)) {
jcr->FDJobStatus = JS_ErrorTerminated;
}
if (jcr->JobStatus != JS_Terminated) {
/*
* Release resources allocated during backup.
*/
-static void backup_cleanup(JCR *jcr, int TermCode, char *since, FILESET_DBR *fsr)
+static void backup_cleanup(JCR *jcr, int TermCode, char *since, FILESET_DBR *fsr)
{
char sdt[50], edt[50];
char ec1[30], ec2[30], ec3[30], ec4[30], ec5[30], compress[50];
set_jcr_job_status(jcr, TermCode);
update_job_end_record(jcr); /* update database */
-
+
if (!db_get_job_record(jcr, jcr->db, &jcr->jr)) {
- Jmsg(jcr, M_WARNING, 0, _("Error getting job record for stats: %s"),
+ Jmsg(jcr, M_WARNING, 0, _("Error getting job record for stats: %s"),
db_strerror(jcr->db));
set_jcr_job_status(jcr, JS_ErrorTerminated);
}
bstrncpy(mr.VolumeName, jcr->VolumeName, sizeof(mr.VolumeName));
if (!db_get_media_record(jcr, jcr->db, &mr)) {
- Jmsg(jcr, M_WARNING, 0, _("Error getting Media record for Volume \"%s\": ERR=%s"),
+ Jmsg(jcr, M_WARNING, 0, _("Error getting Media record for Volume \"%s\": ERR=%s"),
mr.VolumeName, db_strerror(jcr->db));
set_jcr_job_status(jcr, JS_ErrorTerminated);
}
/* Now update the bootstrap file if any */
- if (jcr->JobStatus == JS_Terminated && jcr->jr.JobBytes &&
+ if (jcr->JobStatus == JS_Terminated && jcr->jr.JobBytes &&
jcr->job->WriteBootstrap) {
FILE *fd;
BPIPE *bpipe = NULL;
if (*fname == '|') {
fname++;
got_pipe = 1;
- bpipe = open_bpipe(fname, 0, "w");
+ bpipe = open_bpipe(fname, 0, "w");
fd = bpipe ? bpipe->wfd : NULL;
} else {
/* ***FIXME*** handle BASE */
- fd = fopen(fname, jcr->JobLevel==L_FULL?"w+":"a+");
+ fd = fopen(fname, jcr->JobLevel==L_FULL?"w+":"a+");
}
if (fd) {
VolCount = db_get_job_volume_parameters(jcr, jcr->db, jcr->JobId,
&VolParams);
if (VolCount == 0) {
- Jmsg(jcr, M_ERROR, 0, _("Could not get Job Volume Parameters to "
- "update Bootstrap file. ERR=%s\n"), db_strerror(jcr->db));
+ Jmsg(jcr, M_ERROR, 0, _("Could not get Job Volume Parameters to "
+ "update Bootstrap file. ERR=%s\n"), db_strerror(jcr->db));
if (jcr->SDJobFiles != 0) {
set_jcr_job_status(jcr, JS_ErrorTerminated);
}
}
for (int i=0; i < VolCount; i++) {
/* Write the record */
- fprintf(fd, "Volume=\"%s\"\n", VolParams[i].VolumeName);
- fprintf(fd, "VolSessionId=%u\n", jcr->VolSessionId);
- fprintf(fd, "VolSessionTime=%u\n", jcr->VolSessionTime);
- fprintf(fd, "VolFile=%u-%u\n", VolParams[i].StartFile,
+ fprintf(fd, "Volume=\"%s\"\n", VolParams[i].VolumeName);
+ fprintf(fd, "VolSessionId=%u\n", jcr->VolSessionId);
+ fprintf(fd, "VolSessionTime=%u\n", jcr->VolSessionTime);
+ fprintf(fd, "VolFile=%u-%u\n", VolParams[i].StartFile,
VolParams[i].EndFile);
- fprintf(fd, "VolBlock=%u-%u\n", VolParams[i].StartBlock,
+ fprintf(fd, "VolBlock=%u-%u\n", VolParams[i].StartBlock,
VolParams[i].EndBlock);
- fprintf(fd, "FileIndex=%d-%d\n", VolParams[i].FirstIndex,
+ fprintf(fd, "FileIndex=%d-%d\n", VolParams[i].FirstIndex,
VolParams[i].LastIndex);
}
if (VolParams) {
}
} else {
berrno be;
- Jmsg(jcr, M_ERROR, 0, _("Could not open WriteBootstrap file:\n"
- "%s: ERR=%s\n"), fname, be.strerror());
+ Jmsg(jcr, M_ERROR, 0, _("Could not open WriteBootstrap file:\n"
+ "%s: ERR=%s\n"), fname, be.strerror());
set_jcr_job_status(jcr, JS_ErrorTerminated);
}
}
switch (jcr->JobStatus) {
case JS_Terminated:
if (jcr->Errors || jcr->SDErrors) {
- term_msg = _("Backup OK -- with warnings");
+ term_msg = _("Backup OK -- with warnings");
} else {
- term_msg = _("Backup OK");
+ term_msg = _("Backup OK");
}
break;
case JS_FatalError:
case JS_ErrorTerminated:
- term_msg = _("*** Backup Error ***");
+ term_msg = _("*** Backup Error ***");
msg_type = M_ERROR; /* Generate error message */
if (jcr->store_bsock) {
bnet_sig(jcr->store_bsock, BNET_TERMINATE);
}
break;
case JS_Canceled:
- term_msg = _("Backup Canceled");
+ term_msg = _("Backup Canceled");
if (jcr->store_bsock) {
bnet_sig(jcr->store_bsock, BNET_TERMINATE);
if (jcr->SD_msg_chan) {
break;
default:
term_msg = term_code;
- sprintf(term_code, _("Inappropriate term code: %c\n"), jcr->JobStatus);
+ sprintf(term_code, _("Inappropriate term code: %c\n"), jcr->JobStatus);
break;
}
bstrftimes(sdt, sizeof(sdt), jcr->jr.StartTime);
* it is normal. Or look at it the other way, only for a
* normal exit should we complain about this error.
*/
- if (jcr->JobStatus == JS_Terminated && jcr->jr.JobBytes) {
- Jmsg(jcr, M_ERROR, 0, "%s", db_strerror(jcr->db));
+ if (jcr->JobStatus == JS_Terminated && jcr->jr.JobBytes) {
+ Jmsg(jcr, M_ERROR, 0, "%s", db_strerror(jcr->db));
}
jcr->VolumeName[0] = 0; /* none */
}
} else {
compression = (double)100 - 100.0 * ((double)jcr->JobBytes / (double)jcr->ReadBytes);
if (compression < 0.5) {
- bstrncpy(compress, "None", sizeof(compress));
+ bstrncpy(compress, "None", sizeof(compress));
} else {
- bsnprintf(compress, sizeof(compress), "%.1f %%", (float)compression);
+ bsnprintf(compress, sizeof(compress), "%.1f %%", (float)compression);
}
}
jobstatus_to_ascii(jcr->FDJobStatus, fd_term_msg, sizeof(fd_term_msg));
// bmicrosleep(15, 0); /* for debugging SIGHUP */
- Jmsg(jcr, msg_type, 0, _("Bacula " VERSION " (" LSMDATE "): %s\n\
- JobId: %d\n\
- Job: %s\n\
- Backup Level: %s%s\n\
- Client: %s\n\
- FileSet: \"%s\" %s\n\
- Pool: \"%s\"\n\
- Storage: \"%s\"\n\
- Start time: %s\n\
- End time: %s\n\
- FD Files Written: %s\n\
- SD Files Written: %s\n\
- FD Bytes Written: %s\n\
- SD Bytes Written: %s\n\
- Rate: %.1f KB/s\n\
- Software Compression: %s\n\
- Volume name(s): %s\n\
- Volume Session Id: %d\n\
- Volume Session Time: %d\n\
- Last Volume Bytes: %s\n\
- Non-fatal FD errors: %d\n\
- SD Errors: %d\n\
- FD termination status: %s\n\
- SD termination status: %s\n\
- Termination: %s\n\n"),
+ Jmsg(jcr, msg_type, 0, _("Bacula " VERSION " (" LSMDATE "): %s\n"
+" JobId: %d\n"
+" Job: %s\n"
+" Backup Level: %s%s\n"
+" Client: %s\n"
+" FileSet: \"%s\" %s\n"
+" Pool: \"%s\"\n"
+" Storage: \"%s\"\n"
+" Start time: %s\n"
+" End time: %s\n"
+" FD Files Written: %s\n"
+" SD Files Written: %s\n"
+" FD Bytes Written: %s\n"
+" SD Bytes Written: %s\n"
+" Rate: %.1f KB/s\n"
+" Software Compression: %s\n"
+" Volume name(s): %s\n"
+" Volume Session Id: %d\n"
+" Volume Session Time: %d\n"
+" Last Volume Bytes: %s\n"
+" Non-fatal FD errors: %d\n"
+" SD Errors: %d\n"
+" FD termination status: %s\n"
+" SD termination status: %s\n"
+" Termination: %s\n\n"),
edt,
jcr->jr.JobId,
jcr->jr.Job,
*
* Bacula Director -- Bootstrap Record routines.
*
- * BSR (bootstrap record) handling routines split from
+ * BSR (bootstrap record) handling routines split from
* ua_restore.c July MMIII
*
* Kern Sibbald, July MMII
/*
- * Create new FileIndex entry for BSR
+ * Create new FileIndex entry for BSR
*/
-RBSR_FINDEX *new_findex()
+RBSR_FINDEX *new_findex()
{
RBSR_FINDEX *fi = (RBSR_FINDEX *)bmalloc(sizeof(RBSR_FINDEX));
memset(fi, 0, sizeof(RBSR_FINDEX));
* Our data structures were not designed completely
* correctly, so the file indexes cover the full
* range regardless of volume. The FirstIndex and LastIndex
- * passed in here are for the current volume, so when
+ * passed in here are for the current volume, so when
* writing out the fi, constrain them to those values.
*
* We are called here once for each JobMedia record
* for each Volume.
*/
-static uint32_t write_findex(UAContext *ua, RBSR_FINDEX *fi,
- int32_t FirstIndex, int32_t LastIndex, FILE *fd)
+static uint32_t write_findex(UAContext *ua, RBSR_FINDEX *fi,
+ int32_t FirstIndex, int32_t LastIndex, FILE *fd)
{
uint32_t count = 0;
for ( ; fi; fi=fi->next) {
findex = fi->findex < FirstIndex ? FirstIndex : fi->findex;
findex2 = fi->findex2 > LastIndex ? LastIndex : fi->findex2;
if (findex == findex2) {
- fprintf(fd, "FileIndex=%d\n", findex);
+ fprintf(fd, "FileIndex=%d\n", findex);
count++;
} else {
- fprintf(fd, "FileIndex=%d-%d\n", findex, findex2);
+ fprintf(fd, "FileIndex=%d-%d\n", findex, findex2);
count += findex2 - findex + 1;
}
}
* Find out if Volume defined with FirstIndex and LastIndex
* falls within the range of selected files in the bsr.
*/
-static bool is_volume_selected(RBSR_FINDEX *fi,
- int32_t FirstIndex, int32_t LastIndex)
+static bool is_volume_selected(RBSR_FINDEX *fi,
+ int32_t FirstIndex, int32_t LastIndex)
{
if (fi) {
if ((fi->findex >= FirstIndex && fi->findex <= LastIndex) ||
bsendmsg(ua, "fi=0x%lx\n", fi);
for ( ; fi; fi=fi->next) {
if (fi->findex == fi->findex2) {
- bsendmsg(ua, "FileIndex=%d\n", fi->findex);
+ bsendmsg(ua, "FileIndex=%d\n", fi->findex);
// Dmsg1(100, "FileIndex=%d\n", fi->findex);
} else {
- bsendmsg(ua, "FileIndex=%d-%d\n", fi->findex, fi->findex2);
+ bsendmsg(ua, "FileIndex=%d-%d\n", fi->findex, fi->findex2);
// Dmsg2(100, "FileIndex=%d-%d\n", fi->findex, fi->findex2);
}
}
memset(&jr, 0, sizeof(jr));
jr.JobId = bsr->JobId;
if (!db_get_job_record(ua->jcr, ua->db, &jr)) {
- bsendmsg(ua, _("Unable to get Job record. ERR=%s\n"), db_strerror(ua->db));
+ bsendmsg(ua, _("Unable to get Job record. ERR=%s\n"), db_strerror(ua->db));
return 0;
}
bsr->VolSessionId = jr.VolSessionId;
bsr->VolSessionTime = jr.VolSessionTime;
- if ((bsr->VolCount=db_get_job_volume_parameters(ua->jcr, ua->db, bsr->JobId,
+ if ((bsr->VolCount=db_get_job_volume_parameters(ua->jcr, ua->db, bsr->JobId,
&(bsr->VolParams))) == 0) {
- bsendmsg(ua, _("Unable to get Job Volume Parameters. ERR=%s\n"), db_strerror(ua->db));
+ bsendmsg(ua, _("Unable to get Job Volume Parameters. ERR=%s\n"), db_strerror(ua->db));
if (bsr->VolParams) {
free(bsr->VolParams);
bsr->VolParams = NULL;
fd = fopen(fname, "w+");
if (!fd) {
berrno be;
- bsendmsg(ua, _("Unable to create bootstrap file %s. ERR=%s\n"),
+ bsendmsg(ua, _("Unable to create bootstrap file %s. ERR=%s\n"),
fname, be.strerror());
goto bail_out;
}
static uint32_t write_bsr(UAContext *ua, RBSR *bsr, FILE *fd)
{
uint32_t count = 0;
- uint32_t total_count = 0;
+ uint32_t total_count = 0;
uint32_t LastIndex = 0;
bool first = true;
if (bsr) {
bsr->VolParams[i].VolumeName[0] = 0; /* zap VolumeName */
continue;
}
- fprintf(fd, "Volume=\"%s\"\n", bsr->VolParams[i].VolumeName);
- fprintf(fd, "VolSessionId=%u\n", bsr->VolSessionId);
- fprintf(fd, "VolSessionTime=%u\n", bsr->VolSessionTime);
+ fprintf(fd, "Volume=\"%s\"\n", bsr->VolParams[i].VolumeName);
+ fprintf(fd, "VolSessionId=%u\n", bsr->VolSessionId);
+ fprintf(fd, "VolSessionTime=%u\n", bsr->VolSessionTime);
if (bsr->VolParams[i].StartFile == bsr->VolParams[i].EndFile) {
- fprintf(fd, "VolFile=%u\n", bsr->VolParams[i].StartFile);
+ fprintf(fd, "VolFile=%u\n", bsr->VolParams[i].StartFile);
} else {
- fprintf(fd, "VolFile=%u-%u\n", bsr->VolParams[i].StartFile,
+ fprintf(fd, "VolFile=%u-%u\n", bsr->VolParams[i].StartFile,
bsr->VolParams[i].EndFile);
}
if (bsr->VolParams[i].StartBlock == bsr->VolParams[i].EndBlock) {
- fprintf(fd, "VolFile=%u\n", bsr->VolParams[i].StartBlock);
+ fprintf(fd, "VolFile=%u\n", bsr->VolParams[i].StartBlock);
} else {
- fprintf(fd, "VolBlock=%u-%u\n", bsr->VolParams[i].StartBlock,
+ fprintf(fd, "VolBlock=%u-%u\n", bsr->VolParams[i].StartBlock,
bsr->VolParams[i].EndBlock);
}
// Dmsg2(100, "bsr VolParam FI=%u LI=%u\n",
count = write_findex(ua, bsr->fi, bsr->VolParams[i].FirstIndex,
bsr->VolParams[i].LastIndex, fd);
if (count) {
- fprintf(fd, "Count=%u\n", count);
+ fprintf(fd, "Count=%u\n", count);
}
total_count += count;
/* If the same file is present on two tapes or in two files
{
if (bsr) {
for (int i=0; i < bsr->VolCount; i++) {
- bsendmsg(ua, "Volume=\"%s\"\n", bsr->VolParams[i].VolumeName);
- bsendmsg(ua, "VolSessionId=%u\n", bsr->VolSessionId);
- bsendmsg(ua, "VolSessionTime=%u\n", bsr->VolSessionTime);
- bsendmsg(ua, "VolFile=%u-%u\n", bsr->VolParams[i].StartFile,
+ bsendmsg(ua, "Volume=\"%s\"\n", bsr->VolParams[i].VolumeName);
+ bsendmsg(ua, "VolSessionId=%u\n", bsr->VolSessionId);
+ bsendmsg(ua, "VolSessionTime=%u\n", bsr->VolSessionTime);
+ bsendmsg(ua, "VolFile=%u-%u\n", bsr->VolParams[i].StartFile,
bsr->VolParams[i].EndFile);
- bsendmsg(ua, "VolBlock=%u-%u\n", bsr->VolParams[i].StartBlock,
+ bsendmsg(ua, "VolBlock=%u-%u\n", bsr->VolParams[i].StartBlock,
bsr->VolParams[i].EndBlock);
print_findex(ua, bsr->fi);
}
if (findex == 0) {
return; /* probably a dummy directory */
}
-
+
if (bsr->fi == NULL) { /* if no FI add one */
/* This is the first FileIndex item in the chain */
bsr->fi = new_findex();
if (!nbsr) { /* Must add new JobId */
/* Add new JobId at end of chain */
- for (nbsr=bsr; nbsr->next; nbsr=nbsr->next)
+ for (nbsr=bsr; nbsr->next; nbsr=nbsr->next)
{ }
nbsr->next = new_bsr();
nbsr->next->JobId = JobId;
}
}
- /*
+ /*
* At this point, bsr points to bsr containing this JobId,
* and we are sure that there is at least one fi record.
*/
/* Walk down fi chain and find where to insert insert new FileIndex */
for ( ; fi; fi=fi->next) {
if (findex == (fi->findex2 + 1)) { /* extend up */
- RBSR_FINDEX *nfi;
+ RBSR_FINDEX *nfi;
fi->findex2 = findex;
/*
* If the following record contains one higher, merge its
* file index by extending it up.
*/
- if (fi->next && ((findex+1) == fi->next->findex)) {
+ if (fi->next && ((findex+1) == fi->next->findex)) {
nfi = fi->next;
fi->findex2 = nfi->findex2;
fi->next = nfi->next;
*
* Bootstrap Record header file
*
- * BSR (bootstrap record) handling routines split from
+ * BSR (bootstrap record) handling routines split from
* ua_restore.c July MMIII
*
* Kern Sibbald, July MMII
int32_t findex2;
};
-/*
- * Restore bootstrap record -- not the real one, but useful here
+/*
+ * Restore bootstrap record -- not the real one, but useful here
* The restore bsr is a chain of BSR records (linked by next).
* Each BSR represents a single JobId, and within it, it
* contains a linked list of file indexes for that JobId.
struct RBSR {
RBSR *next; /* next JobId */
uint32_t JobId; /* JobId this bsr */
- uint32_t VolSessionId;
+ uint32_t VolSessionId;
uint32_t VolSessionTime;
int VolCount; /* Volume parameter count */
VOL_PARAMS *VolParams; /* Volume, start/end file/blocks */
static char Find_media[] = "CatReq Job=%127s FindMedia=%d\n";
static char Get_Vol_Info[] = "CatReq Job=%127s GetVolInfo VolName=%127s write=%d\n";
-static char Update_media[] = "CatReq Job=%127s UpdateMedia VolName=%s\
- VolJobs=%u VolFiles=%u VolBlocks=%u VolBytes=%" lld " VolMounts=%u\
- VolErrors=%u VolWrites=%u MaxVolBytes=%" lld " EndTime=%d VolStatus=%10s\
- Slot=%d relabel=%d InChanger=%d VolReadTime=%" lld " VolWriteTime=%" lld "\n";
+static char Update_media[] = "CatReq Job=%127s UpdateMedia VolName=%s"
+" VolJobs=%u VolFiles=%u VolBlocks=%u VolBytes=%" lld " VolMounts=%u"
+" VolErrors=%u VolWrites=%u MaxVolBytes=%" lld " EndTime=%d VolStatus=%10s"
+" Slot=%d relabel=%d InChanger=%d VolReadTime=%" lld " VolWriteTime=%" lld "\n";
-static char Create_job_media[] = "CatReq Job=%127s CreateJobMedia \
- FirstIndex=%u LastIndex=%u StartFile=%u EndFile=%u \
- StartBlock=%u EndBlock=%u\n";
+static char Create_job_media[] = "CatReq Job=%127s CreateJobMedia "
+" FirstIndex=%u LastIndex=%u StartFile=%u EndFile=%u "
+" StartBlock=%u EndBlock=%u\n";
/* Responses sent to Storage daemon */
static char OK_create[] = "1000 OK CreateJobMedia\n";
-static int send_volume_info_to_storage_daemon(JCR *jcr, BSOCK *sd, MEDIA_DBR *mr)
+static int send_volume_info_to_storage_daemon(JCR *jcr, BSOCK *sd, MEDIA_DBR *mr)
{
int stat;
char ed1[50], ed2[50], ed3[50], ed4[50], ed5[50];
bash_spaces(mr->VolumeName);
stat = bnet_fsend(sd, OK_media, mr->VolumeName, mr->VolJobs,
mr->VolFiles, mr->VolBlocks, edit_uint64(mr->VolBytes, ed1),
- mr->VolMounts, mr->VolErrors, mr->VolWrites,
- edit_uint64(mr->MaxVolBytes, ed2),
+ mr->VolMounts, mr->VolErrors, mr->VolWrites,
+ edit_uint64(mr->MaxVolBytes, ed2),
edit_uint64(mr->VolCapacityBytes, ed3),
mr->VolStatus, mr->Slot, mr->MaxVolJobs, mr->MaxVolFiles,
mr->InChanger,
void catalog_request(JCR *jcr, BSOCK *bs, char *msg)
{
- MEDIA_DBR mr, sdmr;
+ MEDIA_DBR mr, sdmr;
JOBMEDIA_DBR jm;
char Job[MAX_NAME_LENGTH];
int index, ok, label, writing;
if (sscanf(bs->msg, Find_media, &Job, &index) == 2) {
ok = find_next_volume_for_append(jcr, &mr, true /*permit create new vol*/);
/*
- * Send Find Media response to Storage daemon
+ * Send Find Media response to Storage daemon
*/
if (ok) {
send_volume_info_to_storage_daemon(jcr, bs, &mr);
} else {
- bnet_fsend(bs, "1901 No Media.\n");
+ bnet_fsend(bs, "1901 No Media.\n");
}
- /*
+ /*
* Request to find specific Volume information
*/
} else if (sscanf(bs->msg, Get_Vol_Info, &Job, &mr.VolumeName, &writing) == 3) {
unbash_spaces(mr.VolumeName);
if (db_get_media_record(jcr, jcr->db, &mr)) {
const char *reason = NULL; /* detailed reason for rejection */
- /*
+ /*
* If we are reading, accept any volume (reason == NULL)
- * If we are writing, check if the Volume is valid
+ * If we are writing, check if the Volume is valid
* for this job, and do a recycle if necessary
- */
+ */
if (writing) {
- /*
+ /*
* SD wants to write this Volume, so make
* sure it is suitable for this job, i.e.
- * Pool matches, and it is either Append or Recycle
+ * Pool matches, and it is either Append or Recycle
* and Media Type matches and Pool allows any volume.
*/
if (mr.PoolId != jcr->PoolId) {
- reason = "not in Pool";
+ reason = "not in Pool";
} else if (strcmp(mr.MediaType, jcr->store->media_type) != 0) {
- reason = "not correct MediaType";
+ reason = "not correct MediaType";
} else {
- /*
- * ****FIXME***
+ /*
+ * ****FIXME***
* This test (accept_any_volume) is turned off
- * because it doesn't properly check if the volume
+ * because it doesn't properly check if the volume
* really is out of sequence!
*
* } else if (!jcr->pool->accept_any_volume) {
- * reason = "Volume not in sequence";
+ * reason = "Volume not in sequence";
*/
- /*
+ /*
* Now try recycling if necessary
* reason set non-NULL if we cannot use it
*/
}
if (reason == NULL) {
/*
- * Send Find Media response to Storage daemon
+ * Send Find Media response to Storage daemon
*/
send_volume_info_to_storage_daemon(jcr, bs, &mr);
- } else {
+ } else {
/* Not suitable volume */
- bnet_fsend(bs, "1998 Volume \"%s\" status is %s, %s.\n", mr.VolumeName,
+ bnet_fsend(bs, "1998 Volume \"%s\" status is %s, %s.\n", mr.VolumeName,
mr.VolStatus, reason);
}
} else {
- bnet_fsend(bs, "1997 Volume \"%s\" not in catalog.\n", mr.VolumeName);
+ bnet_fsend(bs, "1997 Volume \"%s\" not in catalog.\n", mr.VolumeName);
}
-
+
/*
* Request to update Media record. Comes typically at the end
* of a Storage daemon Job Session, when labeling/relabeling a
*/
} else if (sscanf(bs->msg, Update_media, &Job, &sdmr.VolumeName, &sdmr.VolJobs,
&sdmr.VolFiles, &sdmr.VolBlocks, &sdmr.VolBytes, &sdmr.VolMounts, &sdmr.VolErrors,
- &sdmr.VolWrites, &sdmr.MaxVolBytes, &sdmr.LastWritten, &sdmr.VolStatus,
- &sdmr.Slot, &label, &sdmr.InChanger, &sdmr.VolReadTime,
+ &sdmr.VolWrites, &sdmr.MaxVolBytes, &sdmr.LastWritten, &sdmr.VolStatus,
+ &sdmr.Slot, &label, &sdmr.InChanger, &sdmr.VolReadTime,
&sdmr.VolWriteTime) == 17) {
db_lock(jcr->db);
bstrncpy(mr.VolumeName, sdmr.VolumeName, sizeof(mr.VolumeName)); /* copy Volume name */
unbash_spaces(mr.VolumeName);
if (!db_get_media_record(jcr, jcr->db, &mr)) {
- Jmsg(jcr, M_ERROR, 0, _("Unable to get Media record for Volume %s: ERR=%s\n"),
+ Jmsg(jcr, M_ERROR, 0, _("Unable to get Media record for Volume %s: ERR=%s\n"),
mr.VolumeName, db_strerror(jcr->db));
- bnet_fsend(bs, "1991 Catalog Request failed: %s", db_strerror(jcr->db));
+ bnet_fsend(bs, "1991 Catalog Request failed: %s", db_strerror(jcr->db));
db_unlock(jcr->db);
return;
}
* Insanity check for VolFiles get set to a smaller value
*/
if (sdmr.VolFiles < mr.VolFiles) {
- Jmsg(jcr, M_ERROR, 0, _("ERROR!! Volume Files at %u being set to %u. This is probably wrong.\n"),
+ Jmsg(jcr, M_ERROR, 0, _("ERROR!! Volume Files at %u being set to %u. This is probably wrong.\n"),
mr.VolFiles, sdmr.VolFiles);
}
}
} else if (db_update_media_record(jcr, jcr->db, &mr)) {
send_volume_info_to_storage_daemon(jcr, bs, &mr);
} else {
- Jmsg(jcr, M_ERROR, 0, _("Catalog error updating Media record. %s"),
+ Jmsg(jcr, M_ERROR, 0, _("Catalog error updating Media record. %s"),
db_strerror(jcr->db));
- bnet_fsend(bs, "1992 Update Media error\n");
- Dmsg0(190, "send error\n");
+ bnet_fsend(bs, "1992 Update Media error\n");
+ Dmsg0(190, "send error\n");
}
db_unlock(jcr->db);
Dmsg6(300, "create_jobmedia JobId=%d MediaId=%d SF=%d EF=%d FI=%d LI=%d\n",
jm.JobId, jm.MediaId, jm.StartFile, jm.EndFile, jm.FirstIndex, jm.LastIndex);
if (!db_create_jobmedia_record(jcr, jcr->db, &jm)) {
- Jmsg(jcr, M_ERROR, 0, _("Catalog error creating JobMedia record. %s"),
+ Jmsg(jcr, M_ERROR, 0, _("Catalog error creating JobMedia record. %s"),
db_strerror(jcr->db));
- bnet_fsend(bs, "1991 Update JobMedia error\n");
+ bnet_fsend(bs, "1991 Update JobMedia error\n");
} else {
- Dmsg0(300, "JobMedia record created\n");
+ Dmsg0(300, "JobMedia record created\n");
bnet_fsend(bs, OK_create);
}
} else {
omsg = get_memory(bs->msglen+1);
pm_strcpy(omsg, bs->msg);
- bnet_fsend(bs, "1990 Invalid Catalog Request: %s", omsg);
+ bnet_fsend(bs, "1990 Invalid Catalog Request: %s", omsg);
Jmsg1(jcr, M_ERROR, 0, _("Invalid Catalog request: %s"), omsg);
free_memory(omsg);
}
* Update File Attributes in the catalog with data
* sent by the Storage daemon. Note, we receive the whole
* attribute record, but we select out only the stat packet,
- * VolSessionId, VolSessionTime, FileIndex, and file name
+ * VolSessionId, VolSessionTime, FileIndex, and file name
* to store in the catalog.
*/
void catalog_update(JCR *jcr, BSOCK *bs, char *msg)
Dmsg2(300, "dird<stored: stream=%d %s\n", Stream, fname);
Dmsg1(300, "dird<stored: attr=%s\n", attr);
- ar.attr = attr;
+ ar.attr = attr;
ar.fname = fname;
ar.FileIndex = FileIndex;
ar.Stream = Stream;
Dmsg1(120, "dird<filed: attr=%s\n", attr);
if (!db_create_file_attributes_record(jcr, jcr->db, &ar)) {
- Jmsg1(jcr, M_FATAL, 0, _("Attribute create error. %s"), db_strerror(jcr->db));
+ Jmsg1(jcr, M_FATAL, 0, _("Attribute create error. %s"), db_strerror(jcr->db));
}
/* Save values for SIG update */
jcr->FileId = ar.FileId;
jcr->FileIndex = FileIndex;
} else if (Stream == STREAM_MD5_SIGNATURE || Stream == STREAM_SHA1_SIGNATURE) {
fname = p;
- if (jcr->FileIndex != FileIndex) {
- Jmsg(jcr, M_WARNING, 0, "Got MD5/SHA1 but not same File as attributes\n");
+ if (jcr->FileIndex != FileIndex) {
+ Jmsg(jcr, M_WARNING, 0, "Got MD5/SHA1 but not same File as attributes\n");
} else {
/* Update signature in catalog */
char SIGbuf[50]; /* 24 bytes should be enough */
type = SHA1_SIG;
}
bin_to_base64(SIGbuf, fname, len);
- Dmsg3(190, "SIGlen=%d SIG=%s type=%d\n", strlen(SIGbuf), SIGbuf, Stream);
+ Dmsg3(190, "SIGlen=%d SIG=%s type=%d\n", strlen(SIGbuf), SIGbuf, Stream);
if (!db_add_SIG_to_file_record(jcr, jcr->db, jcr->FileId, SIGbuf, type)) {
- Jmsg(jcr, M_ERROR, 0, _("Catalog error updating MD5/SHA1. %s"),
+ Jmsg(jcr, M_ERROR, 0, _("Catalog error updating MD5/SHA1. %s"),
db_strerror(jcr->db));
}
}
" -t test - read configuration and exit\n"
" -u userid\n"
" -v verbose user messages\n"
-" -? print this message.\n"
+" -? print this message.\n"
"\n"));
exit(1);
case 'd': /* set debug level */
debug_level = atoi(optarg);
if (debug_level <= 0) {
- debug_level = 1;
+ debug_level = 1;
}
- Dmsg1(0, "Debug level = %d\n", debug_level);
+ Dmsg1(0, "Debug level = %d\n", debug_level);
break;
case 'f': /* run in foreground */
default:
usage();
- }
+ }
}
argc -= optind;
argv += optind;
free(configfile);
}
configfile = bstrdup(*argv);
- argc--;
+ argc--;
argv++;
}
if (argc) {
init_jcr_subsystem(); /* start JCR watchdogs etc. */
init_job_server(director->MaxConcurrentJobs);
-
+
Dmsg0(200, "wait for next job\n");
/* Main loop -- call scheduler to get next job to run */
while ((jcr = wait_for_next_job(runjob))) {
free(configfile);
}
if (debug_level > 5) {
- print_memory_pool_stats();
+ print_memory_pool_stats();
}
free_config_resources();
term_ua_server();
term_msg(); /* terminate message handler */
stop_watchdog();
close_memory_pool(); /* release free memory in pool */
- sm_dump(false);
+ sm_dump(false);
exit(sig);
}
static const int max_reloads = 10;
static RELOAD_TABLE reload_table[max_reloads];
-static void init_reload(void)
+static void init_reload(void)
{
for (int i=0; i < max_reloads; i++) {
reload_table[i].job_count = 0;
/*
* If we get here, we have received a SIGHUP, which means to
- * reread our configuration file.
+ * reread our configuration file.
*
* The algorithm used is as follows: we count how many jobs are
- * running and mark the running jobs to make a callback on
+ * running and mark the running jobs to make a callback on
* exiting. The old config is saved with the reload table
* id in a reload table. The new config file is read. Now, as
* each job exits, it calls back to the reload_job_end_cb(), which
void reload_config(int sig)
{
static bool already_here = false;
- sigset_t set;
+ sigset_t set;
JCR *jcr;
int njobs = 0; /* number of running jobs */
int table, rtable;
if (!check_resources()) {
rtable = find_free_reload_table_entry(); /* save new, bad table */
if (rtable < 0) {
- Jmsg(NULL, M_ERROR, 0, _("Please correct configuration file: %s\n"), configfile);
- Jmsg(NULL, M_ERROR_TERM, 0, _("Out of reload table entries. Giving up.\n"));
+ Jmsg(NULL, M_ERROR, 0, _("Please correct configuration file: %s\n"), configfile);
+ Jmsg(NULL, M_ERROR_TERM, 0, _("Out of reload table entries. Giving up.\n"));
} else {
- Jmsg(NULL, M_ERROR, 0, _("Please correct configuration file: %s\n"), configfile);
+ Jmsg(NULL, M_ERROR, 0, _("Please correct configuration file: %s\n"), configfile);
}
reload_table[rtable].res_table = save_config_resources();
/* Now restore old resoure values */
table = rtable; /* release new, bad, saved table below */
} else {
/*
- * Hook all active jobs so that they release this table
+ * Hook all active jobs so that they release this table
*/
foreach_jcr(jcr) {
if (jcr->JobType != JT_SYSTEM) {
FDConnectTimeout = director->FDConnectTimeout;
SDConnectTimeout = director->SDConnectTimeout;
Dmsg0(0, "Director's configuration file reread.\n");
-
+
/* Now release saved resources, if no jobs using the resources */
if (njobs == 0) {
free_saved_resources(table);
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\
-Without that I don't know who I am :-(\n"), configfile);
+ Jmsg(NULL, M_FATAL, 0, _("No Director resource defined in %s\n"
+"Without that I don't know who I am :-(\n"), configfile);
OK = false;
} else {
set_working_directory(director->working_directory);
if (!director->messages) { /* If message resource not specified */
director->messages = (MSGS *)GetNextRes(R_MSGS, NULL);
if (!director->messages) {
- Jmsg(NULL, M_FATAL, 0, _("No Messages resource defined in %s\n"), configfile);
+ Jmsg(NULL, M_FATAL, 0, _("No Messages resource defined in %s\n"), configfile);
OK = false;
}
}
if (GetNextRes(R_DIRECTOR, (RES *)director) != NULL) {
- Jmsg(NULL, M_FATAL, 0, _("Only one Director resource permitted in %s\n"),
+ Jmsg(NULL, M_FATAL, 0, _("Only one Director resource permitted in %s\n"),
configfile);
OK = false;
- }
+ }
}
if (!job) {
int64_t *def_lvalue, *lvalue; /* 64 bit values */
uint32_t offset;
- Dmsg4(400, "Job \"%s\", field \"%s\" bit=%d def=%d\n",
- job->hdr.name, job_items[i].name,
- bit_is_set(i, job->hdr.item_present),
+ Dmsg4(400, "Job \"%s\", field \"%s\" bit=%d def=%d\n",
+ job->hdr.name, job_items[i].name,
+ bit_is_set(i, job->hdr.item_present),
bit_is_set(i, job->jobdefs->hdr.item_present));
if (!bit_is_set(i, job->hdr.item_present) &&
- bit_is_set(i, job->jobdefs->hdr.item_present)) {
- Dmsg2(400, "Job \"%s\", field \"%s\": getting default.\n",
+ bit_is_set(i, job->jobdefs->hdr.item_present)) {
+ Dmsg2(400, "Job \"%s\", field \"%s\": getting default.\n",
job->hdr.name, job_items[i].name);
- offset = (char *)(job_items[i].value) - (char *)&res_all;
+ offset = (char *)(job_items[i].value) - (char *)&res_all;
/*
* Handle strings and directory strings
*/
if (job_items[i].handler == store_str ||
job_items[i].handler == store_dir) {
def_svalue = (char **)((char *)(job->jobdefs) + offset);
- Dmsg5(400, "Job \"%s\", field \"%s\" def_svalue=%s item %d offset=%u\n",
+ Dmsg5(400, "Job \"%s\", field \"%s\" def_svalue=%s item %d offset=%u\n",
job->hdr.name, job_items[i].name, *def_svalue, i, offset);
svalue = (char **)((char *)job + offset);
if (*svalue) {
- Pmsg1(000, "Hey something is wrong. p=0x%lu\n", *svalue);
+ Pmsg1(000, "Hey something is wrong. p=0x%lu\n", *svalue);
}
*svalue = bstrdup(*def_svalue);
set_bit(i, job->hdr.item_present);
/*
- * Handle resources
+ * Handle resources
*/
} else if (job_items[i].handler == store_res) {
def_svalue = (char **)((char *)(job->jobdefs) + offset);
- Dmsg4(400, "Job \"%s\", field \"%s\" item %d offset=%u\n",
+ Dmsg4(400, "Job \"%s\", field \"%s\" item %d offset=%u\n",
job->hdr.name, job_items[i].name, i, offset);
svalue = (char **)((char *)job + offset);
if (*svalue) {
- Pmsg1(000, "Hey something is wrong. p=0x%lu\n", *svalue);
+ Pmsg1(000, "Hey something is wrong. p=0x%lu\n", *svalue);
}
*svalue = *def_svalue;
set_bit(i, job->hdr.item_present);
* Handle alist resources
*/
} else if (job_items[i].handler == store_alist_res) {
- if (bit_is_set(i, job->jobdefs->hdr.item_present)) {
+ if (bit_is_set(i, job->jobdefs->hdr.item_present)) {
set_bit(i, job->hdr.item_present);
}
/*
- * Handle integer fields
+ * Handle integer fields
* Note, our store_yesno does not handle bitmaped fields
*/
} else if (job_items[i].handler == store_yesno ||
job_items[i].handler == store_pint ||
job_items[i].handler == store_replace) {
def_ivalue = (int *)((char *)(job->jobdefs) + offset);
- Dmsg5(400, "Job \"%s\", field \"%s\" def_ivalue=%d item %d offset=%u\n",
+ Dmsg5(400, "Job \"%s\", field \"%s\" def_ivalue=%d item %d offset=%u\n",
job->hdr.name, job_items[i].name, *def_ivalue, i, offset);
ivalue = (int *)((char *)job + offset);
*ivalue = *def_ivalue;
set_bit(i, job->hdr.item_present);
/*
- * Handle 64 bit integer fields
+ * Handle 64 bit integer fields
*/
} else if (job_items[i].handler == store_time ||
job_items[i].handler == store_size ||
job_items[i].handler == store_int64) {
def_lvalue = (int64_t *)((char *)(job->jobdefs) + offset);
- Dmsg5(400, "Job \"%s\", field \"%s\" def_lvalue=%" lld " item %d offset=%u\n",
+ Dmsg5(400, "Job \"%s\", field \"%s\" def_lvalue=%" lld " item %d offset=%u\n",
job->hdr.name, job_items[i].name, *def_lvalue, i, offset);
lvalue = (int64_t *)((char *)job + offset);
*lvalue = *def_lvalue;
}
}
}
- /*
+ /*
* Ensure that all required items are present
*/
for (i=0; job_items[i].name; i++) {
if (job_items[i].flags & ITEM_REQUIRED) {
- if (!bit_is_set(i, job->hdr.item_present)) {
- Jmsg(NULL, M_FATAL, 0, "\"%s\" directive in Job \"%s\" resource is required, but not found.\n",
+ if (!bit_is_set(i, job->hdr.item_present)) {
+ Jmsg(NULL, M_FATAL, 0, "\"%s\" directive in Job \"%s\" resource is required, but not found.\n",
job_items[i].name, job->hdr.name);
OK = false;
}
}
/* If this triggers, take a look at lib/parse_conf.h */
if (i >= MAX_RES_ITEMS) {
- Emsg0(M_ERROR_TERM, 0, "Too many items in Job resource\n");
+ Emsg0(M_ERROR_TERM, 0, "Too many items in Job resource\n");
}
}
} /* End loop over Job res */
*/
db = db_init_database(NULL, catalog->db_name, catalog->db_user,
catalog->db_password, catalog->db_address,
- catalog->db_port, catalog->db_socket,
+ catalog->db_port, catalog->db_socket,
catalog->mult_db_connections);
if (!db || !db_open_database(NULL, db)) {
- Jmsg(NULL, M_FATAL, 0, _("Could not open database \"%s\".\n"),
+ Jmsg(NULL, M_FATAL, 0, _("Could not open database \"%s\".\n"),
catalog->db_name);
if (db) {
- Jmsg(NULL, M_FATAL, 0, _("%s"), db_strerror(db));
+ Jmsg(NULL, M_FATAL, 0, _("%s"), db_strerror(db));
}
OK = false;
continue;
- }
+ }
/* Loop over all pools, defining/updating them in each database */
POOL *pool;
foreach_res(pool, R_POOL) {
create_pool(NULL, db, pool, POOL_OP_UPDATE); /* update request */
- }
+ }
/* Loop over all counters, defining them in each database */
/* Set default value in all counters */
if (db_create_counter_record(NULL, db, &cr)) {
counter->CurrentValue = cr.CurrentValue;
counter->created = true;
- Dmsg2(100, "Create counter %s val=%d\n", counter->hdr.name, counter->CurrentValue);
+ Dmsg2(100, "Create counter %s val=%d\n", counter->hdr.name, counter->CurrentValue);
}
- }
+ }
if (!counter->created) {
counter->CurrentValue = counter->MinValue; /* default value */
}
*
* 1. The generic lexical scanner in lib/lex.c and lib/lex.h
*
- * 2. The generic config scanner in lib/parse_config.c and
+ * 2. The generic config scanner in lib/parse_config.c and
* lib/parse_config.h.
* These files contain the parser code, some utility
* routines, and the common store routines (name, int,
/* Definition of records permitted within each
- * resource with the routine to process the record
+ * resource with the routine to process the record
* information. NOTE! quoted names must be in lower case.
- */
-/*
+ */
+/*
* Director Resource
*
* name handler value code flags default_value
{NULL, NULL, NULL, 0, 0, 0}
};
-/*
+/*
* Console Resource
*
* name handler value code flags default_value
};
-/*
+/*
* Client or File daemon resource
*
* name handler value code flags default_value
{"autoprune", store_yesno, ITEM(res_client.AutoPrune), 1, ITEM_DEFAULT, 1},
{"enablessl", store_yesno, ITEM(res_client.enable_ssl), 1, ITEM_DEFAULT, 0},
{"maximumconcurrentjobs", store_pint, ITEM(res_client.MaxConcurrentJobs), 0, ITEM_DEFAULT, 1},
- {NULL, NULL, NULL, 0, 0, 0}
+ {NULL, NULL, NULL, 0, 0, 0}
};
/* Storage daemon resource
{"enablessl", store_yesno, ITEM(res_store.enable_ssl), 1, ITEM_DEFAULT, 0},
{"maximumconcurrentjobs", store_pint, ITEM(res_store.MaxConcurrentJobs), 0, ITEM_DEFAULT, 1},
{"sddport", store_pint, ITEM(res_store.SDDport), 0, 0, 0}, /* deprecated */
- {NULL, NULL, NULL, 0, 0, 0}
+ {NULL, NULL, NULL, 0, 0, 0}
};
-/*
+/*
* Catalog Resource Directives
*
* name handler value code flags default_value
{"dbpassword", store_str, ITEM(res_cat.db_password), 0, 0, 0},
{"user", store_str, ITEM(res_cat.db_user), 0, 0, 0},
{"dbname", store_str, ITEM(res_cat.db_name), 0, ITEM_REQUIRED, 0},
- {"dbsocket", store_str, ITEM(res_cat.db_socket), 0, 0, 0},
+ {"dbsocket", store_str, ITEM(res_cat.db_socket), 0, 0, 0},
{"multipleconnections", store_yesno, ITEM(res_cat.mult_db_connections), 1, 0, 0},
- {NULL, NULL, NULL, 0, 0, 0}
+ {NULL, NULL, NULL, 0, 0, 0}
};
-/*
+/*
* Job Resource Directives
*
* name handler value code flags default_value
{"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},
- {NULL, NULL, NULL, 0, 0, 0}
+ {NULL, NULL, NULL, 0, 0, 0}
};
/* FileSet resource
{"include", store_inc, NULL, 0, ITEM_NO_EQUALS, 0},
{"exclude", store_inc, NULL, 1, ITEM_NO_EQUALS, 0},
{"ignorefilesetchanges", store_yesno, ITEM(res_fs.ignore_fs_changes), 1, ITEM_DEFAULT, 0},
- {NULL, NULL, NULL, 0, 0, 0}
+ {NULL, NULL, NULL, 0, 0, 0}
};
/* Schedule -- see run_conf.c */
{"name", store_name, ITEM(res_sch.hdr.name), 0, ITEM_REQUIRED, 0},
{"description", store_str, ITEM(res_sch.hdr.desc), 0, 0, 0},
{"run", store_run, ITEM(res_sch.run), 0, 0, 0},
- {NULL, NULL, NULL, 0, 0, 0}
+ {NULL, NULL, NULL, 0, 0, 0}
};
/* Pool resource
{"volumeuseduration", store_time, ITEM(res_pool.VolUseDuration),0, 0, 0},
{"autoprune", store_yesno, ITEM(res_pool.AutoPrune), 1, ITEM_DEFAULT, 1},
{"recycle", store_yesno, ITEM(res_pool.Recycle), 1, ITEM_DEFAULT, 1},
- {NULL, NULL, NULL, 0, 0, 0}
+ {NULL, NULL, NULL, 0, 0, 0}
};
-/*
+/*
* Counter Resource
* name handler value code flags default_value
*/
{"maximum", store_pint, ITEM(res_counter.MaxValue), 0, ITEM_DEFAULT, INT32_MAX},
{"wrapcounter", store_res, ITEM(res_counter.WrapCounter), R_COUNTER, 0, 0},
{"catalog", store_res, ITEM(res_counter.Catalog), R_CATALOG, 0, 0},
- {NULL, NULL, NULL, 0, 0, 0}
+ {NULL, NULL, NULL, 0, 0, 0}
};
/* Message resource */
extern RES_ITEM msgs_items[];
-/*
- * This is the master resource definition.
+/*
+ * This is the master resource definition.
* It must have one item for each of the resources.
*
* NOTE!!! keep it in the same order as the R_codes
};
-/* Keywords (RHS) permitted in Job Level records
+/* Keywords (RHS) permitted in Job Level records
*
* level_name level job_type
*/
{NULL, 0, 0}
};
-/* Keywords (RHS) permitted in Job type records
+/* Keywords (RHS) permitted in Job type records
*
* type_name job_type
*/
static struct s_kw BakVerFields[] = {
{"client", 'C'},
{"fileset", 'F'},
- {"level", 'L'},
+ {"level", 'L'},
{NULL, 0}
};
}
switch (type) {
case R_DIRECTOR:
- sendit(sock, "Director: name=%s MaxJobs=%d FDtimeout=%s SDtimeout=%s\n",
- reshdr->name, res->res_dir.MaxConcurrentJobs,
+ sendit(sock, "Director: name=%s MaxJobs=%d FDtimeout=%s SDtimeout=%s\n",
+ reshdr->name, res->res_dir.MaxConcurrentJobs,
edit_uint64(res->res_dir.FDConnectTimeout, ed1),
edit_uint64(res->res_dir.SDConnectTimeout, ed2));
if (res->res_dir.query_file) {
- sendit(sock, " query_file=%s\n", res->res_dir.query_file);
+ sendit(sock, " query_file=%s\n", res->res_dir.query_file);
}
if (res->res_dir.messages) {
- sendit(sock, " --> ");
+ sendit(sock, " --> ");
dump_resource(-R_MSGS, (RES *)res->res_dir.messages, sendit, sock);
}
break;
case R_CONSOLE:
- sendit(sock, "Console: name=%s SSL=%d\n",
+ sendit(sock, "Console: name=%s SSL=%d\n",
res->res_con.hdr.name, res->res_con.enable_ssl);
break;
case R_COUNTER:
if (res->res_counter.WrapCounter) {
- sendit(sock, "Counter: name=%s min=%d max=%d cur=%d wrapcntr=%s\n",
- res->res_counter.hdr.name, res->res_counter.MinValue,
+ sendit(sock, "Counter: name=%s min=%d max=%d cur=%d wrapcntr=%s\n",
+ res->res_counter.hdr.name, res->res_counter.MinValue,
res->res_counter.MaxValue, res->res_counter.CurrentValue,
res->res_counter.WrapCounter->hdr.name);
} else {
- sendit(sock, "Counter: name=%s min=%d max=%d\n",
- res->res_counter.hdr.name, res->res_counter.MinValue,
+ sendit(sock, "Counter: name=%s min=%d max=%d\n",
+ res->res_counter.hdr.name, res->res_counter.MinValue,
res->res_counter.MaxValue);
}
if (res->res_counter.Catalog) {
- sendit(sock, " --> ");
+ sendit(sock, " --> ");
dump_resource(-R_CATALOG, (RES *)res->res_counter.Catalog, sendit, sock);
}
break;
edit_utime(res->res_client.FileRetention, ed2, sizeof(ed2)),
res->res_client.AutoPrune);
if (res->res_client.catalog) {
- sendit(sock, " --> ");
+ sendit(sock, " --> ");
dump_resource(-R_CATALOG, (RES *)res->res_client.catalog, sendit, sock);
}
break;
case R_STORAGE:
- sendit(sock, "Storage: name=%s address=%s SDport=%d MaxJobs=%u\n\
- DeviceName=%s MediaType=%s\n",
+ sendit(sock, "Storage: name=%s address=%s SDport=%d MaxJobs=%u\n"
+" DeviceName=%s MediaType=%s\n",
res->res_store.hdr.name, res->res_store.address, res->res_store.SDport,
res->res_store.MaxConcurrentJobs,
res->res_store.dev_name, res->res_store.media_type);
break;
case R_CATALOG:
- sendit(sock, "Catalog: name=%s address=%s DBport=%d db_name=%s\n\
- db_user=%s MutliDBConn=%d\n",
+ sendit(sock, "Catalog: name=%s address=%s DBport=%d db_name=%s\n"
+" db_user=%s MutliDBConn=%d\n",
res->res_cat.hdr.name, NPRT(res->res_cat.db_address),
- res->res_cat.db_port, res->res_cat.db_name, NPRT(res->res_cat.db_user),
+ res->res_cat.db_port, res->res_cat.db_name, NPRT(res->res_cat.db_user),
res->res_cat.mult_db_connections);
break;
case R_JOB:
case R_JOBDEFS:
- sendit(sock, "%s: name=%s JobType=%d level=%s Priority=%d MaxJobs=%u\n",
- type == R_JOB ? "Job" : "JobDefs",
- res->res_job.hdr.name, res->res_job.JobType,
+ sendit(sock, "%s: name=%s JobType=%d level=%s Priority=%d MaxJobs=%u\n",
+ type == R_JOB ? "Job" : "JobDefs",
+ res->res_job.hdr.name, res->res_job.JobType,
level_to_str(res->res_job.JobLevel), res->res_job.Priority,
res->res_job.MaxConcurrentJobs);
sendit(sock, " Resched=%d Times=%d Interval=%s Spool=%d\n",
edit_uint64_with_commas(res->res_job.RescheduleInterval, ed1),
res->res_job.spool_data);
if (res->res_job.client) {
- sendit(sock, " --> ");
+ sendit(sock, " --> ");
dump_resource(-R_CLIENT, (RES *)res->res_job.client, sendit, sock);
}
if (res->res_job.fileset) {
- sendit(sock, " --> ");
+ sendit(sock, " --> ");
dump_resource(-R_FILESET, (RES *)res->res_job.fileset, sendit, sock);
}
if (res->res_job.schedule) {
- sendit(sock, " --> ");
+ sendit(sock, " --> ");
dump_resource(-R_SCHEDULE, (RES *)res->res_job.schedule, sendit, sock);
}
if (res->res_job.RestoreWhere) {
- sendit(sock, " --> Where=%s\n", NPRT(res->res_job.RestoreWhere));
+ sendit(sock, " --> Where=%s\n", NPRT(res->res_job.RestoreWhere));
}
if (res->res_job.RestoreBootstrap) {
- sendit(sock, " --> Bootstrap=%s\n", NPRT(res->res_job.RestoreBootstrap));
+ sendit(sock, " --> Bootstrap=%s\n", NPRT(res->res_job.RestoreBootstrap));
}
if (res->res_job.RunBeforeJob) {
- sendit(sock, " --> RunBefore=%s\n", NPRT(res->res_job.RunBeforeJob));
+ sendit(sock, " --> RunBefore=%s\n", NPRT(res->res_job.RunBeforeJob));
}
if (res->res_job.RunAfterJob) {
- sendit(sock, " --> RunAfter=%s\n", NPRT(res->res_job.RunAfterJob));
+ sendit(sock, " --> RunAfter=%s\n", NPRT(res->res_job.RunAfterJob));
}
if (res->res_job.RunAfterFailedJob) {
- sendit(sock, " --> RunAfterFailed=%s\n", NPRT(res->res_job.RunAfterFailedJob));
+ sendit(sock, " --> RunAfterFailed=%s\n", NPRT(res->res_job.RunAfterFailedJob));
}
if (res->res_job.WriteBootstrap) {
- sendit(sock, " --> WriteBootstrap=%s\n", NPRT(res->res_job.WriteBootstrap));
+ sendit(sock, " --> WriteBootstrap=%s\n", NPRT(res->res_job.WriteBootstrap));
}
if (res->res_job.storage[0]) {
- sendit(sock, " --> ");
+ sendit(sock, " --> ");
/* ***FIXME*** */
// dump_resource(-R_STORAGE, (RES *)res->res_job.storage, sendit, sock);
}
if (res->res_job.pool) {
- sendit(sock, " --> ");
+ sendit(sock, " --> ");
dump_resource(-R_POOL, (RES *)res->res_job.pool, sendit, sock);
}
if (res->res_job.full_pool) {
- sendit(sock, " --> ");
+ sendit(sock, " --> ");
dump_resource(-R_POOL, (RES *)res->res_job.full_pool, sendit, sock);
}
if (res->res_job.inc_pool) {
- sendit(sock, " --> ");
+ sendit(sock, " --> ");
dump_resource(-R_POOL, (RES *)res->res_job.inc_pool, sendit, sock);
}
if (res->res_job.dif_pool) {
- sendit(sock, " --> ");
+ sendit(sock, " --> ");
dump_resource(-R_POOL, (RES *)res->res_job.dif_pool, sendit, sock);
}
if (res->res_job.verify_job) {
- sendit(sock, " --> ");
+ sendit(sock, " --> ");
dump_resource(-type, (RES *)res->res_job.verify_job, sendit, sock);
}
break;
if (res->res_job.messages) {
- sendit(sock, " --> ");
+ sendit(sock, " --> ");
dump_resource(-R_MSGS, (RES *)res->res_job.messages, sendit, sock);
}
break;
INCEXE *incexe = res->res_fs.include_items[i];
for (j=0; j<incexe->num_opts; j++) {
FOPTS *fo = incexe->opts_list[j];
- sendit(sock, " O %s\n", fo->opts);
+ sendit(sock, " O %s\n", fo->opts);
for (k=0; k<fo->regex.size(); k++) {
- sendit(sock, " R %s\n", fo->regex.get(k));
+ sendit(sock, " R %s\n", fo->regex.get(k));
}
for (k=0; k<fo->wild.size(); k++) {
- sendit(sock, " W %s\n", fo->wild.get(k));
+ sendit(sock, " W %s\n", fo->wild.get(k));
}
for (k=0; k<fo->base.size(); k++) {
- sendit(sock, " B %s\n", fo->base.get(k));
+ sendit(sock, " B %s\n", fo->base.get(k));
}
for (k=0; k<fo->fstype.size(); k++) {
- sendit(sock, " X %s\n", fo->fstype.get(k));
+ sendit(sock, " X %s\n", fo->fstype.get(k));
}
if (fo->reader) {
- sendit(sock, " D %s\n", fo->reader);
+ sendit(sock, " D %s\n", fo->reader);
}
if (fo->writer) {
- sendit(sock, " T %s\n", fo->writer);
+ sendit(sock, " T %s\n", fo->writer);
}
- sendit(sock, " N\n");
+ sendit(sock, " N\n");
}
for (j=0; j<incexe->name_list.size(); j++) {
- sendit(sock, " I %s\n", incexe->name_list.get(j));
+ sendit(sock, " I %s\n", incexe->name_list.get(j));
}
if (incexe->name_list.size()) {
- sendit(sock, " N\n");
+ sendit(sock, " N\n");
}
}
-
+
for (i=0; i<res->res_fs.num_excludes; i++) {
INCEXE *incexe = res->res_fs.exclude_items[i];
for (j=0; j<incexe->name_list.size(); j++) {
- sendit(sock, " E %s\n", incexe->name_list.get(j));
+ sendit(sock, " E %s\n", incexe->name_list.get(j));
}
if (incexe->name_list.size()) {
- sendit(sock, " N\n");
+ sendit(sock, " N\n");
}
}
break;
int i;
RUN *run = res->res_sch.run;
char buf[1000], num[30];
- sendit(sock, "Schedule: name=%s\n", res->res_sch.hdr.name);
+ sendit(sock, "Schedule: name=%s\n", res->res_sch.hdr.name);
if (!run) {
break;
}
next_run:
- sendit(sock, " --> Run Level=%s\n", level_to_str(run->level));
- bstrncpy(buf, " hour=", sizeof(buf));
+ sendit(sock, " --> Run Level=%s\n", level_to_str(run->level));
+ bstrncpy(buf, " hour=", sizeof(buf));
for (i=0; i<24; i++) {
if (bit_is_set(i, run->hour)) {
- bsnprintf(num, sizeof(num), "%d ", i);
+ bsnprintf(num, sizeof(num), "%d ", i);
bstrncat(buf, num, sizeof(buf));
}
}
- bstrncat(buf, "\n", sizeof(buf));
+ bstrncat(buf, "\n", sizeof(buf));
sendit(sock, buf);
- bstrncpy(buf, " mday=", sizeof(buf));
+ bstrncpy(buf, " mday=", sizeof(buf));
for (i=0; i<31; i++) {
if (bit_is_set(i, run->mday)) {
- bsnprintf(num, sizeof(num), "%d ", i);
+ bsnprintf(num, sizeof(num), "%d ", i);
bstrncat(buf, num, sizeof(buf));
}
}
- bstrncat(buf, "\n", sizeof(buf));
+ bstrncat(buf, "\n", sizeof(buf));
sendit(sock, buf);
- bstrncpy(buf, " month=", sizeof(buf));
+ bstrncpy(buf, " month=", sizeof(buf));
for (i=0; i<12; i++) {
if (bit_is_set(i, run->month)) {
- bsnprintf(num, sizeof(num), "%d ", i);
+ bsnprintf(num, sizeof(num), "%d ", i);
bstrncat(buf, num, sizeof(buf));
}
}
- bstrncat(buf, "\n", sizeof(buf));
+ bstrncat(buf, "\n", sizeof(buf));
sendit(sock, buf);
- bstrncpy(buf, " wday=", sizeof(buf));
+ bstrncpy(buf, " wday=", sizeof(buf));
for (i=0; i<7; i++) {
if (bit_is_set(i, run->wday)) {
- bsnprintf(num, sizeof(num), "%d ", i);
+ bsnprintf(num, sizeof(num), "%d ", i);
bstrncat(buf, num, sizeof(buf));
}
}
- bstrncat(buf, "\n", sizeof(buf));
+ bstrncat(buf, "\n", sizeof(buf));
sendit(sock, buf);
- bstrncpy(buf, " wom=", sizeof(buf));
+ bstrncpy(buf, " wom=", sizeof(buf));
for (i=0; i<5; i++) {
if (bit_is_set(i, run->wom)) {
- bsnprintf(num, sizeof(num), "%d ", i);
+ bsnprintf(num, sizeof(num), "%d ", i);
bstrncat(buf, num, sizeof(buf));
}
}
- bstrncat(buf, "\n", sizeof(buf));
+ bstrncat(buf, "\n", sizeof(buf));
sendit(sock, buf);
- bstrncpy(buf, " woy=", sizeof(buf));
+ bstrncpy(buf, " woy=", sizeof(buf));
for (i=0; i<54; i++) {
if (bit_is_set(i, run->woy)) {
- bsnprintf(num, sizeof(num), "%d ", i);
+ bsnprintf(num, sizeof(num), "%d ", i);
bstrncat(buf, num, sizeof(buf));
}
}
- bstrncat(buf, "\n", sizeof(buf));
+ bstrncat(buf, "\n", sizeof(buf));
sendit(sock, buf);
- sendit(sock, " mins=%d\n", run->minute);
+ sendit(sock, " mins=%d\n", run->minute);
if (run->pool) {
- sendit(sock, " --> ");
+ sendit(sock, " --> ");
dump_resource(-R_POOL, (RES *)run->pool, sendit, sock);
}
if (run->storage) {
- sendit(sock, " --> ");
+ sendit(sock, " --> ");
dump_resource(-R_STORAGE, (RES *)run->storage, sendit, sock);
}
if (run->msgs) {
- sendit(sock, " --> ");
+ sendit(sock, " --> ");
dump_resource(-R_MSGS, (RES *)run->msgs, sendit, sock);
}
/* If another Run record is chained in, go print it */
goto next_run;
}
} else {
- sendit(sock, "Schedule: name=%s\n", res->res_sch.hdr.name);
+ sendit(sock, "Schedule: name=%s\n", res->res_sch.hdr.name);
}
break;
case R_POOL:
sendit(sock, " max_vols=%d auto_prune=%d VolRetention=%s\n",
res->res_pool.max_volumes, res->res_pool.AutoPrune,
edit_utime(res->res_pool.VolRetention, ed1, sizeof(ed1)));
- sendit(sock, " VolUse=%s recycle=%d LabelFormat=%s\n",
+ sendit(sock, " VolUse=%s recycle=%d LabelFormat=%s\n",
edit_utime(res->res_pool.VolUseDuration, ed1, sizeof(ed1)),
res->res_pool.Recycle,
NPRT(res->res_pool.label_format));
sendit(sock, " CleaningPrefix=%s\n",
NPRT(res->res_pool.cleaning_prefix));
sendit(sock, " RecyleOldest=%d PurgeOldest=%d MaxVolJobs=%d MaxVolFiles=%d\n",
- res->res_pool.recycle_oldest_volume,
- res->res_pool.purge_oldest_volume,
+ res->res_pool.recycle_oldest_volume,
+ res->res_pool.purge_oldest_volume,
res->res_pool.MaxVolJobs, res->res_pool.MaxVolFiles);
break;
case R_MSGS:
sendit(sock, "Messages: name=%s\n", res->res_msgs.hdr.name);
- if (res->res_msgs.mail_cmd)
- sendit(sock, " mailcmd=%s\n", res->res_msgs.mail_cmd);
- if (res->res_msgs.operator_cmd)
- sendit(sock, " opcmd=%s\n", res->res_msgs.operator_cmd);
+ if (res->res_msgs.mail_cmd)
+ sendit(sock, " mailcmd=%s\n", res->res_msgs.mail_cmd);
+ if (res->res_msgs.operator_cmd)
+ sendit(sock, " opcmd=%s\n", res->res_msgs.operator_cmd);
break;
default:
sendit(sock, "Unknown resource type %d in dump_resource.\n", type);
free(incexe);
}
-/*
+/*
* 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
+ * to other resources as they will be freed when that
* resource chain is traversed. Mainly we worry about freeing
* allocated strings (names).
*/
break;
case R_FILESET:
if ((num=res->res_fs.num_includes)) {
- while (--num >= 0) {
+ while (--num >= 0) {
free_incexe(res->res_fs.include_items[num]);
}
free(res->res_fs.include_items);
}
res->res_fs.num_includes = 0;
if ((num=res->res_fs.num_excludes)) {
- while (--num >= 0) {
+ while (--num >= 0) {
free_incexe(res->res_fs.exclude_items[num]);
}
free(res->res_fs.exclude_items);
/*
* Save the new resource by chaining it into the head list for
* the resource. If this is pass 2, we update any resource
- * pointers because they may not have been defined until
+ * pointers because they may not have been defined until
* later in pass 1.
*/
void save_resource(int type, RES_ITEM *items, int pass)
int rindex = type - r_first;
int i, size;
int error = 0;
-
+
/* Check Job requirements after applying JobDefs */
if (type != R_JOB && type != R_JOBDEFS) {
- /*
+ /*
* Ensure that all required items are present
*/
for (i=0; items[i].name; i++) {
if (items[i].flags & ITEM_REQUIRED) {
- if (!bit_is_set(i, res_all.res_dir.hdr.item_present)) {
- Emsg2(M_ERROR_TERM, 0, "%s item is required in %s resource, but not found.\n",
+ if (!bit_is_set(i, res_all.res_dir.hdr.item_present)) {
+ Emsg2(M_ERROR_TERM, 0, "%s item is required in %s resource, but not found.\n",
items[i].name, resources[rindex]);
}
}
/* If this triggers, take a look at lib/parse_conf.h */
if (i >= MAX_RES_ITEMS) {
- Emsg1(M_ERROR_TERM, 0, "Too many items in %s resource\n", resources[rindex]);
+ Emsg1(M_ERROR_TERM, 0, "Too many items in %s resource\n", resources[rindex]);
}
}
}
/*
- * 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.
/* Resources containing another resource */
case R_DIRECTOR:
if ((res = (URES *)GetResWithName(R_DIRECTOR, res_all.res_dir.hdr.name)) == NULL) {
- Emsg1(M_ERROR_TERM, 0, "Cannot find Director resource %s\n", res_all.res_dir.hdr.name);
+ Emsg1(M_ERROR_TERM, 0, "Cannot find Director resource %s\n", res_all.res_dir.hdr.name);
}
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",
+ Emsg1(M_ERROR_TERM, 0, "Cannot find Job resource %s\n",
res_all.res_dir.hdr.name);
}
res->res_job.messages = res_all.res_job.messages;
break;
case R_COUNTER:
if ((res = (URES *)GetResWithName(R_COUNTER, res_all.res_counter.hdr.name)) == NULL) {
- Emsg1(M_ERROR_TERM, 0, "Cannot find Counter resource %s\n", res_all.res_counter.hdr.name);
+ Emsg1(M_ERROR_TERM, 0, "Cannot find Counter resource %s\n", res_all.res_counter.hdr.name);
}
res->res_counter.Catalog = res_all.res_counter.Catalog;
res->res_counter.WrapCounter = res_all.res_counter.WrapCounter;
case R_CLIENT:
if ((res = (URES *)GetResWithName(R_CLIENT, res_all.res_client.hdr.name)) == NULL) {
- Emsg1(M_ERROR_TERM, 0, "Cannot find Client resource %s\n", res_all.res_client.hdr.name);
+ Emsg1(M_ERROR_TERM, 0, "Cannot find Client resource %s\n", res_all.res_client.hdr.name);
}
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
- * 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.
+ * 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.
*/
if ((res = (URES *)GetResWithName(R_SCHEDULE, res_all.res_client.hdr.name)) == NULL) {
- Emsg1(M_ERROR_TERM, 0, "Cannot find Schedule resource %s\n", res_all.res_client.hdr.name);
+ Emsg1(M_ERROR_TERM, 0, "Cannot find Schedule resource %s\n", res_all.res_client.hdr.name);
}
res->res_sch.run = res_all.res_sch.run;
break;
default:
- Emsg1(M_ERROR, 0, "Unknown resource type %d in save_resource.\n", type);
+ Emsg1(M_ERROR, 0, "Unknown resource type %d in save_resource.\n", type);
error = 1;
break;
}
}
/*
- * The following code is only executed during pass 1
+ * The following code is only executed during pass 1
*/
switch (type) {
case R_DIRECTOR:
size =sizeof(CLIENT);
break;
case R_STORAGE:
- size = sizeof(STORE);
+ size = sizeof(STORE);
break;
case R_CATALOG:
size = sizeof(CAT);
memcpy(res, &res_all, size);
if (!res_head[rindex]) {
res_head[rindex] = (RES *)res; /* store first entry */
- Dmsg3(900, "Inserting first %s res: %s index=%d\n", res_to_str(type),
+ Dmsg3(900, "Inserting first %s res: %s index=%d\n", res_to_str(type),
res->res_dir.hdr.name, rindex);
} else {
RES *next;
for (next=res_head[rindex]; next->next; next=next->next) {
if (strcmp(next->name, res->res_dir.hdr.name) == 0) {
Emsg2(M_ERROR_TERM, 0,
- _("Attempt to define second %s resource named \"%s\" is not permitted.\n"),
+ _("Attempt to define second %s resource named \"%s\" is not permitted.\n"),
resources[rindex].name, res->res_dir.hdr.name);
}
}
next->next = (RES *)res;
- Dmsg4(900, "Inserting %s res: %s index=%d pass=%d\n", res_to_str(type),
+ Dmsg4(900, "Inserting %s res: %s index=%d pass=%d\n", res_to_str(type),
res->res_dir.hdr.name, rindex, pass);
}
}
}
-/*
+/*
* Store JobType (backup, verify, restore)
*
*/
void store_jobtype(LEX *lc, RES_ITEM *item, int index, int pass)
{
- int token, i;
+ int token, i;
token = lex_get_token(lc, T_NAME);
/* Store the type both pass 1 and pass 2 */
set_bit(index, res_all.hdr.item_present);
}
-/*
+/*
* Store Job Level (Full, Incremental, ...)
*
*/
set_bit(index, res_all.hdr.item_present);
}
-/*
+/*
* Store ACL (access control list)
*
*/
for (;;) {
token = lex_get_token(lc, T_NAME);
if (pass == 1) {
- if (((alist **)item->value)[item->code] == NULL) {
- ((alist **)item->value)[item->code] = New(alist(10, owned_by_alist));
- Dmsg1(900, "Defined new ACL alist at %d\n", item->code);
+ if (((alist **)item->value)[item->code] == NULL) {
+ ((alist **)item->value)[item->code] = New(alist(10, owned_by_alist));
+ Dmsg1(900, "Defined new ACL alist at %d\n", item->code);
}
((alist **)item->value)[item->code]->append(bstrdup(lc->str));
- Dmsg2(900, "Appended to %d %s\n", item->code, lc->str);
+ Dmsg2(900, "Appended to %d %s\n", item->code, lc->str);
}
token = lex_get_token(lc, T_ALL);
if (token == T_COMMA) {
/* NOTE: #includes at the end of this file */
/*
- * Resource codes -- they must be sequential for indexing
+ * Resource codes -- they must be sequential for indexing
*/
enum {
R_DIRECTOR = 1001,
/* Used for certain KeyWord tables */
-struct s_kw {
+struct s_kw {
const char *name;
- int token;
+ int token;
};
/* Job Level keyword structure */
struct POOL;
struct RUN;
-/*
- * Director Resource
+/*
+ * Director Resource
*
*/
struct DIRRES {
Num_ACL /* keep last */
};
-/*
+/*
* Console Resource
*/
struct CONRES {
/*
* Store Resource
- *
+ *
*/
struct STORE {
RES hdr;
char *address;
char *password;
char *media_type;
- char *dev_name;
+ char *dev_name;
int autochanger; /* set if autochanger */
uint32_t MaxConcurrentJobs; /* Maximume concurrent jobs */
uint32_t NumConcurrentJobs; /* number of concurrent jobs running */
int RescheduleTimes; /* Number of times to reschedule job */
utime_t RescheduleInterval; /* Reschedule interval */
utime_t JobRetention; /* job retention period in seconds */
-
+
MSGS *messages; /* How and where to send messages */
SCHED *schedule; /* When -- Automatic schedule */
CLIENT *client; /* Who to backup */
alist name_list; /* filename list -- holds char * */
};
-/*
+/*
* FileSet Resource
*
*/
int ignore_fs_changes; /* Don't force Full if FS changed */
};
-
-/*
+
+/*
* Schedule Resource
*
*/
};
/*
- * Pool Resource
+ * Pool Resource
*
*/
struct POOL {
RUN *next; /* points to next run record */
int level; /* level override */
int Priority; /* priority override */
- int job_type;
+ int job_type;
bool spool_data; /* Data spooling override */
bool spool_data_set; /* Data spooling override given */
POOL *pool; /* Pool override */
-static int date_item(JCR *jcr, int code,
+static int date_item(JCR *jcr, int code,
const char **val_ptr, int *val_len, int *val_size)
{
struct tm tm;
return 1;
}
-static int job_item(JCR *jcr, int code,
+static int job_item(JCR *jcr, int code,
const char **val_ptr, int *val_len, int *val_size)
{
const char *str = " ";
case 6: /* Client */
str = jcr->client->hdr.name;
if (!str) {
- str = " ";
+ str = " ";
}
break;
case 7: /* NumVols */
str = buf;
break;
case 8: /* Pool */
- str = jcr->pool->hdr.name;
+ str = jcr->pool->hdr.name;
break;
case 9: /* Storage */
str = jcr->store->hdr.name;
* Search the table of built-in variables, and if found,
* call the appropriate subroutine to do the work.
*/
-static var_rc_t lookup_built_in_var(var_t *ctx, void *my_ctx,
- const char *var_ptr, int var_len, int var_index,
+static var_rc_t lookup_built_in_var(var_t *ctx, void *my_ctx,
+ const char *var_ptr, int var_len, int var_index,
const char **val_ptr, int *val_len, int *val_size)
{
JCR *jcr = (JCR *)my_ctx;
/*
- * Search counter variables
+ * Search counter variables
*/
-static var_rc_t lookup_counter_var(var_t *ctx, void *my_ctx,
- const char *var_ptr, int var_len, int var_inc, int var_index,
+static var_rc_t lookup_counter_var(var_t *ctx, void *my_ctx,
+ const char *var_ptr, int var_len, int var_inc, int var_index,
const char **val_ptr, int *val_len, int *val_size)
{
char buf[MAXSTRING];
LockRes();
for (COUNTER *counter=NULL; (counter = (COUNTER *)GetNextRes(R_COUNTER, (RES *)counter)); ) {
if (strcmp(counter->hdr.name, buf) == 0) {
- Dmsg2(100, "Counter=%s val=%d\n", buf, counter->CurrentValue);
+ Dmsg2(100, "Counter=%s val=%d\n", buf, counter->CurrentValue);
/* -1 => return size of array */
if (var_index == -1) {
- bsnprintf(buf, sizeof(buf), "%d", counter->CurrentValue);
- *val_len = bsnprintf(buf, sizeof(buf), "%d", strlen(buf));
+ bsnprintf(buf, sizeof(buf), "%d", counter->CurrentValue);
+ *val_len = bsnprintf(buf, sizeof(buf), "%d", strlen(buf));
*val_ptr = buf;
- *val_size = 0; /* don't try to free val_ptr */
+ *val_size = 0; /* don't try to free val_ptr */
return VAR_OK;
} else {
- bsnprintf(buf, sizeof(buf), "%d", counter->CurrentValue);
+ bsnprintf(buf, sizeof(buf), "%d", counter->CurrentValue);
*val_ptr = bstrdup(buf);
*val_len = strlen(buf);
*val_size = *val_len + 1;
cr.MinValue = counter->MinValue;
cr.MaxValue = counter->MaxValue;
cr.CurrentValue = counter->CurrentValue;
- Dmsg1(100, "New value=%d\n", cr.CurrentValue);
+ Dmsg1(100, "New value=%d\n", cr.CurrentValue);
if (counter->WrapCounter) {
bstrncpy(cr.WrapCounter, counter->WrapCounter->hdr.name, sizeof(cr.WrapCounter));
} else {
cr.WrapCounter[0] = 0;
}
if (!db_update_counter_record(jcr, jcr->db, &cr)) {
- Jmsg(jcr, M_ERROR, 0, _("Count not update counter %s: ERR=%s\n"),
+ Jmsg(jcr, M_ERROR, 0, _("Count not update counter %s: ERR=%s\n"),
counter->hdr.name, db_strerror(jcr->db));
}
}
- }
+ }
stat = VAR_OK;
break;
}
/*
- * Called here from "core" expand code to look up a variable
+ * Called here from "core" expand code to look up a variable
*/
-static var_rc_t lookup_var(var_t *ctx, void *my_ctx,
- const char *var_ptr, int var_len, int var_inc, int var_index,
+static var_rc_t lookup_var(var_t *ctx, void *my_ctx,
+ const char *var_ptr, int var_len, int var_inc, int var_index,
const char **val_ptr, int *val_len, int *val_size)
{
char buf[MAXSTRING], *val, *p, *v;
}
/* He wants to index the "array" */
count = 1;
- /* Find the size of the "array"
- * each element is separated by a |
+ /* Find the size of the "array"
+ * each element is separated by a |
*/
for (p = val; *p; p++) {
if (*p == '|') {
v[p-val] = 0;
*val_ptr = v;
*val_len = p-val;
- *val_size = p-val+1;
+ *val_size = p-val+1;
Dmsg1(100, "v=%s\n", v);
return VAR_OK;
}
* val_ptr points to the value string
* out_ptr points to string to be returned
*/
-static var_rc_t operate_var(var_t *var, void *my_ctx,
- const char *op_ptr, int op_len,
+static var_rc_t operate_var(var_t *var, void *my_ctx,
+ const char *op_ptr, int op_len,
const char *arg_ptr, int arg_len,
- const char *val_ptr, int val_len,
+ const char *val_ptr, int val_len,
char **out_ptr, int *out_len, int *out_size)
{
var_rc_t stat = VAR_ERR_UNDEFINED_OPERATION;
buf[arg_len] = 0;
Dmsg1(100, "Arg=%s\n", buf);
memcpy(buf, val_ptr, val_len);
- buf[val_len] = 0;
+ buf[val_len] = 0;
Dmsg1(100, "Val=%s\n", buf);
LockRes();
for (COUNTER *counter=NULL; (counter = (COUNTER *)GetNextRes(R_COUNTER, (RES *)counter)); ) {
if (strcmp(counter->hdr.name, buf) == 0) {
- Dmsg2(100, "counter=%s val=%s\n", counter->hdr.name, buf);
+ Dmsg2(100, "counter=%s val=%s\n", counter->hdr.name, buf);
break;
}
}
}
-/*
+/*
* Expand an input line and return it.
*
* Returns: 0 on failure
/* expand variables */
if ((stat = var_expand(var_ctx, inp, in_len, &outp, &out_len, 0)) != VAR_OK) {
- Jmsg(jcr, M_ERROR, 0, _("Cannot expand expression \"%s\": ERR=%s\n"),
+ Jmsg(jcr, M_ERROR, 0, _("Cannot expand expression \"%s\": ERR=%s\n"),
inp, var_strerror(var_ctx, stat));
goto bail_out;
}
pm_strcpy(exp, outp);
- rtn_stat = 1;
+ rtn_stat = 1;
bail_out:
/* destroy expansion context */
*
* This routine is run as a separate thread. There may be more
* work to be done to make it totally reentrant!!!!
- *
+ *
* Utility functions for sending info to File Daemon.
* These functions are used by both backup and verify.
- *
+ *
* Version $Id$
*/
/*
/* External functions */
extern int debug_level;
-extern DIRRES *director;
+extern DIRRES *director;
extern int FDConnectTimeout;
#define INC_LIST 0
#define EXC_LIST 1
/*
- * Open connection with File daemon.
+ * Open connection with File daemon.
* Try connecting every retry_interval (default 10 sec), and
* give up after max_retry_time (default 30 mins).
*/
if (!jcr->file_bsock) {
fd = bnet_connect(jcr, retry_interval, max_retry_time,
- _("File daemon"), jcr->client->address,
+ _("File daemon"), jcr->client->address,
NULL, jcr->client->FDport, verbose);
if (fd == NULL) {
set_jcr_job_status(jcr, JS_ErrorTerminated);
set_jcr_job_status(jcr, JS_ErrorTerminated);
return 0;
}
-
+
/*
* Now send JobId and authorization key
*/
- bnet_fsend(fd, jobcmd, jcr->JobId, jcr->Job, jcr->VolSessionId,
+ bnet_fsend(fd, jobcmd, jcr->JobId, jcr->Job, jcr->VolSessionId,
jcr->VolSessionTime, jcr->sd_auth_key);
if (strcmp(jcr->sd_auth_key, "dummy") != 0) {
memset(jcr->sd_auth_key, 0, strlen(jcr->sd_auth_key));
if (bget_dirmsg(fd) > 0) {
Dmsg1(110, "<filed: %s", fd->msg);
if (strncmp(fd->msg, OKjob, strlen(OKjob)) != 0) {
- Jmsg(jcr, M_FATAL, 0, _("File daemon \"%s\" rejected Job command: %s\n"),
+ Jmsg(jcr, M_FATAL, 0, _("File daemon \"%s\" rejected Job command: %s\n"),
jcr->client->hdr.name, fd->msg);
set_jcr_job_status(jcr, JS_ErrorTerminated);
return 0;
cr.JobRetention = jcr->client->JobRetention;
bstrncpy(cr.Uname, fd->msg+strlen(OKjob)+1, sizeof(cr.Uname));
if (!db_update_client_record(jcr, jcr->db, &cr)) {
- Jmsg(jcr, M_WARNING, 0, _("Error updating Client record. ERR=%s\n"),
+ Jmsg(jcr, M_WARNING, 0, _("Error updating Client record. ERR=%s\n"),
db_strerror(jcr->db));
}
}
/*
* This subroutine edits the last job start time into a
- * "since=date/time" buffer that is returned in the
+ * "since=date/time" buffer that is returned in the
* variable since. This is used for display purposes in
- * the job report. The time in jcr->stime is later
+ * the job report. The time in jcr->stime is later
* passed to tell the File daemon what to do.
*/
void get_level_since_time(JCR *jcr, char *since, int since_len)
{
int JobLevel;
- /* Lookup the last FULL backup job to get the time/date for a
+ /* Lookup the last FULL backup job to get the time/date for a
* differential or incremental save.
*/
if (!jcr->stime) {
jcr->jr.JobId = 0; /* flag for db_find_job_start time */
if (!db_find_job_start_time(jcr, jcr->db, &jcr->jr, &jcr->stime)) {
/* No job found, so upgrade this one to Full */
- Jmsg(jcr, M_INFO, 0, "%s", db_strerror(jcr->db));
- Jmsg(jcr, M_INFO, 0, _("No prior or suitable Full backup found. Doing FULL backup.\n"));
- bsnprintf(since, since_len, " (upgraded from %s)",
+ Jmsg(jcr, M_INFO, 0, "%s", db_strerror(jcr->db));
+ Jmsg(jcr, M_INFO, 0, _("No prior or suitable Full backup found. Doing FULL backup.\n"));
+ bsnprintf(since, since_len, " (upgraded from %s)",
level_to_str(jcr->JobLevel));
jcr->JobLevel = jcr->jr.JobLevel = L_FULL;
} else {
if (jcr->job->rerun_failed_levels) {
if (db_find_failed_job_since(jcr, jcr->db, &jcr->jr, jcr->stime, JobLevel)) {
- Jmsg(jcr, M_INFO, 0, _("Prior failed job found. Upgrading to %s.\n"),
+ Jmsg(jcr, M_INFO, 0, _("Prior failed job found. Upgrading to %s.\n"),
level_to_str(JobLevel));
- bsnprintf(since, since_len, " (upgraded from %s)",
+ bsnprintf(since, since_len, " (upgraded from %s)",
level_to_str(jcr->JobLevel));
jcr->JobLevel = jcr->jr.JobLevel = JobLevel;
jcr->jr.JobId = jcr->JobId;
break;
}
- }
- bstrncpy(since, ", since=", since_len);
+ }
+ bstrncpy(since, ", since=", since_len);
bstrncat(since, jcr->stime, since_len);
}
jcr->jr.JobId = jcr->JobId;
/*
- * Send level command to FD.
+ * Send level command to FD.
* Used for backup jobs and estimate command.
*/
-int send_level_command(JCR *jcr)
+int send_level_command(JCR *jcr)
{
BSOCK *fd = jcr->file_bsock;
utime_t stime;
char ed1[50];
- /*
+ /*
* Send Level command to File daemon
*/
switch (jcr->JobLevel) {
stime = str_to_utime(jcr->stime);
bnet_fsend(fd, levelcmd, "since_utime ", edit_uint64(stime, ed1), 0);
while (bget_dirmsg(fd) >= 0) { /* allow him to poll us to sync clocks */
- Jmsg(jcr, M_INFO, 0, "%s\n", fd->msg);
+ Jmsg(jcr, M_INFO, 0, "%s\n", fd->msg);
}
break;
case L_SINCE:
default:
- Jmsg2(jcr, M_FATAL, 0, _("Unimplemented backup level %d %c\n"),
+ Jmsg2(jcr, M_FATAL, 0, _("Unimplemented backup level %d %c\n"),
jcr->JobLevel, jcr->JobLevel);
return 0;
}
for (int j=0; j<ie->name_list.size(); j++) {
p = (char *)ie->name_list.get(j);
switch (*p) {
- case '|':
+ case '|':
p++; /* skip over the | */
- fd->msg = edit_job_codes(jcr, fd->msg, p, "");
- bpipe = open_bpipe(fd->msg, 0, "r");
+ fd->msg = edit_job_codes(jcr, fd->msg, p, "");
+ bpipe = open_bpipe(fd->msg, 0, "r");
if (!bpipe) {
berrno be;
- Jmsg(jcr, M_FATAL, 0, _("Cannot run program: %s. ERR=%s\n"),
+ Jmsg(jcr, M_FATAL, 0, _("Cannot run program: %s. ERR=%s\n"),
p, be.strerror());
goto bail_out;
}
/* Copy File options */
if (ie->num_opts) {
bstrncpy(buf, ie->opts_list[0]->opts, sizeof(buf));
- bstrncat(buf, " ", sizeof(buf));
+ bstrncat(buf, " ", sizeof(buf));
} else {
- bstrncpy(buf, "0 ", sizeof(buf));
+ bstrncpy(buf, "0 ", sizeof(buf));
}
- Dmsg1(500, "Opts=%s\n", buf);
+ Dmsg1(500, "Opts=%s\n", buf);
optlen = strlen(buf);
while (fgets(buf+optlen, sizeof(buf)-optlen, bpipe->rfd)) {
- fd->msglen = Mmsg(fd->msg, "%s", buf);
- Dmsg2(500, "Inc/exc len=%d: %s", fd->msglen, fd->msg);
+ fd->msglen = Mmsg(fd->msg, "%s", buf);
+ Dmsg2(500, "Inc/exc len=%d: %s", fd->msglen, fd->msg);
if (!bnet_send(fd)) {
- Jmsg(jcr, M_FATAL, 0, _(">filed: write error on socket\n"));
+ Jmsg(jcr, M_FATAL, 0, _(">filed: write error on socket\n"));
goto bail_out;
}
}
if ((stat=close_bpipe(bpipe)) != 0) {
berrno be;
- Jmsg(jcr, M_FATAL, 0, _("Error running program %p: ERR=%s\n"),
+ Jmsg(jcr, M_FATAL, 0, _("Error running program %p: ERR=%s\n"),
p, be.strerror(stat));
goto bail_out;
}
break;
- case '<':
+ case '<':
p++; /* skip over < */
- if ((ffd = fopen(p, "r")) == NULL) {
- Jmsg(jcr, M_FATAL, 0, _("Cannot open %s file: %s. ERR=%s\n"),
- list==INC_LIST?"included":"excluded", p, strerror(errno));
+ if ((ffd = fopen(p, "r")) == NULL) {
+ Jmsg(jcr, M_FATAL, 0, _("Cannot open %s file: %s. ERR=%s\n"),
+ list==INC_LIST?"included":"excluded", p, strerror(errno));
goto bail_out;
}
/* Copy File options */
if (ie->num_opts) {
bstrncpy(buf, ie->opts_list[0]->opts, sizeof(buf));
- bstrncat(buf, " ", sizeof(buf));
+ bstrncat(buf, " ", sizeof(buf));
} else {
- bstrncpy(buf, "0 ", sizeof(buf));
+ bstrncpy(buf, "0 ", sizeof(buf));
}
- Dmsg1(500, "Opts=%s\n", buf);
+ Dmsg1(500, "Opts=%s\n", buf);
optlen = strlen(buf);
while (fgets(buf+optlen, sizeof(buf)-optlen, ffd)) {
- fd->msglen = Mmsg(fd->msg, "%s", buf);
+ fd->msglen = Mmsg(fd->msg, "%s", buf);
if (!bnet_send(fd)) {
- Jmsg(jcr, M_FATAL, 0, _(">filed: write error on socket\n"));
+ Jmsg(jcr, M_FATAL, 0, _(">filed: write error on socket\n"));
goto bail_out;
}
}
fclose(ffd);
break;
- case '\\':
- p++; /* skip over \ */
+ case '\\':
+ p++; /* skip over \ */
/* Note, fall through wanted */
default:
if (ie->num_opts) {
- Dmsg2(500, "numopts=%d opts=%s\n", ie->num_opts, NPRT(ie->opts_list[0]->opts));
+ Dmsg2(500, "numopts=%d opts=%s\n", ie->num_opts, NPRT(ie->opts_list[0]->opts));
pm_strcpy(fd->msg, ie->opts_list[0]->opts);
- pm_strcat(fd->msg, " ");
+ pm_strcat(fd->msg, " ");
} else {
- pm_strcpy(fd->msg, "0 ");
+ pm_strcpy(fd->msg, "0 ");
}
fd->msglen = pm_strcat(fd->msg, p);
- Dmsg1(500, "Inc/Exc name=%s\n", fd->msg);
+ Dmsg1(500, "Inc/Exc name=%s\n", fd->msg);
if (!bnet_send(fd)) {
- Jmsg(jcr, M_FATAL, 0, _(">filed: write error on socket\n"));
+ Jmsg(jcr, M_FATAL, 0, _(">filed: write error on socket\n"));
goto bail_out;
}
break;
num = fileset->num_includes;
} else {
num = fileset->num_excludes;
- }
+ }
for (int i=0; i<num; i++) {
BPIPE *bpipe;
FILE *ffd;
if (include) {
ie = fileset->include_items[i];
- bnet_fsend(fd, "I\n");
+ bnet_fsend(fd, "I\n");
} else {
ie = fileset->exclude_items[i];
- bnet_fsend(fd, "E\n");
- }
+ bnet_fsend(fd, "E\n");
+ }
for (j=0; j<ie->num_opts; j++) {
FOPTS *fo = ie->opts_list[j];
- bnet_fsend(fd, "O %s\n", fo->opts);
+ bnet_fsend(fd, "O %s\n", fo->opts);
for (k=0; k<fo->regex.size(); k++) {
- bnet_fsend(fd, "R %s\n", fo->regex.get(k));
+ bnet_fsend(fd, "R %s\n", fo->regex.get(k));
}
for (k=0; k<fo->wild.size(); k++) {
- bnet_fsend(fd, "W %s\n", fo->wild.get(k));
+ bnet_fsend(fd, "W %s\n", fo->wild.get(k));
}
for (k=0; k<fo->base.size(); k++) {
- bnet_fsend(fd, "B %s\n", fo->base.get(k));
+ bnet_fsend(fd, "B %s\n", fo->base.get(k));
}
for (k=0; k<fo->fstype.size(); k++) {
- bnet_fsend(fd, "X %s\n", fo->fstype.get(k));
+ bnet_fsend(fd, "X %s\n", fo->fstype.get(k));
}
if (fo->reader) {
- bnet_fsend(fd, "D %s\n", fo->reader);
+ bnet_fsend(fd, "D %s\n", fo->reader);
}
if (fo->writer) {
- bnet_fsend(fd, "T %s\n", fo->writer);
+ bnet_fsend(fd, "T %s\n", fo->writer);
}
- bnet_fsend(fd, "N\n");
+ bnet_fsend(fd, "N\n");
}
for (j=0; j<ie->name_list.size(); j++) {
p = (char *)ie->name_list.get(j);
switch (*p) {
- case '|':
+ case '|':
p++; /* skip over the | */
- fd->msg = edit_job_codes(jcr, fd->msg, p, "");
- bpipe = open_bpipe(fd->msg, 0, "r");
+ fd->msg = edit_job_codes(jcr, fd->msg, p, "");
+ bpipe = open_bpipe(fd->msg, 0, "r");
if (!bpipe) {
berrno be;
- Jmsg(jcr, M_FATAL, 0, _("Cannot run program: %s. ERR=%s\n"),
+ Jmsg(jcr, M_FATAL, 0, _("Cannot run program: %s. ERR=%s\n"),
p, be.strerror());
goto bail_out;
}
- bstrncpy(buf, "F ", sizeof(buf));
- Dmsg1(500, "Opts=%s\n", buf);
+ bstrncpy(buf, "F ", sizeof(buf));
+ Dmsg1(500, "Opts=%s\n", buf);
optlen = strlen(buf);
while (fgets(buf+optlen, sizeof(buf)-optlen, bpipe->rfd)) {
- fd->msglen = Mmsg(fd->msg, "%s", buf);
- Dmsg2(500, "Inc/exc len=%d: %s", fd->msglen, fd->msg);
+ fd->msglen = Mmsg(fd->msg, "%s", buf);
+ Dmsg2(500, "Inc/exc len=%d: %s", fd->msglen, fd->msg);
if (!bnet_send(fd)) {
- Jmsg(jcr, M_FATAL, 0, _(">filed: write error on socket\n"));
+ Jmsg(jcr, M_FATAL, 0, _(">filed: write error on socket\n"));
goto bail_out;
}
}
if ((stat=close_bpipe(bpipe)) != 0) {
berrno be;
- Jmsg(jcr, M_FATAL, 0, _("Error running program: %s. ERR=%s\n"),
+ Jmsg(jcr, M_FATAL, 0, _("Error running program: %s. ERR=%s\n"),
p, be.strerror(stat));
goto bail_out;
}
break;
- case '<':
+ case '<':
p++; /* skip over < */
- if ((ffd = fopen(p, "r")) == NULL) {
+ if ((ffd = fopen(p, "r")) == NULL) {
berrno be;
- Jmsg(jcr, M_FATAL, 0, _("Cannot open included file: %s. ERR=%s\n"),
+ Jmsg(jcr, M_FATAL, 0, _("Cannot open included file: %s. ERR=%s\n"),
p, be.strerror());
goto bail_out;
}
- bstrncpy(buf, "F ", sizeof(buf));
- Dmsg1(500, "Opts=%s\n", buf);
+ bstrncpy(buf, "F ", sizeof(buf));
+ Dmsg1(500, "Opts=%s\n", buf);
optlen = strlen(buf);
while (fgets(buf+optlen, sizeof(buf)-optlen, ffd)) {
- fd->msglen = Mmsg(fd->msg, "%s", buf);
+ fd->msglen = Mmsg(fd->msg, "%s", buf);
if (!bnet_send(fd)) {
- Jmsg(jcr, M_FATAL, 0, _(">filed: write error on socket\n"));
+ Jmsg(jcr, M_FATAL, 0, _(">filed: write error on socket\n"));
goto bail_out;
}
}
fclose(ffd);
break;
- case '\\':
- p++; /* skip over \ */
+ case '\\':
+ p++; /* skip over \ */
/* Note, fall through wanted */
default:
- pm_strcpy(fd->msg, "F ");
+ pm_strcpy(fd->msg, "F ");
fd->msglen = pm_strcat(fd->msg, p);
- Dmsg1(500, "Inc/Exc name=%s\n", fd->msg);
+ Dmsg1(500, "Inc/Exc name=%s\n", fd->msg);
if (!bnet_send(fd)) {
- Jmsg(jcr, M_FATAL, 0, _(">filed: write error on socket\n"));
+ Jmsg(jcr, M_FATAL, 0, _(">filed: write error on socket\n"));
goto bail_out;
}
break;
}
}
- bnet_fsend(fd, "N\n");
+ bnet_fsend(fd, "N\n");
}
if (!include) { /* If we just did excludes */
break; /* all done */
/*
- * Send exclude list to File daemon
+ * Send exclude list to File daemon
*/
int send_exclude_list(JCR *jcr)
{
bs = fopen(jcr->RestoreBootstrap, "r");
if (!bs) {
berrno be;
- Jmsg(jcr, M_FATAL, 0, _("Could not open bootstrap file %s: ERR=%s\n"),
+ Jmsg(jcr, M_FATAL, 0, _("Could not open bootstrap file %s: ERR=%s\n"),
jcr->RestoreBootstrap, be.strerror());
set_jcr_job_status(jcr, JS_ErrorTerminated);
return 0;
}
bnet_fsend(fd, bootstrap);
while (fgets(buf, sizeof(buf), bs)) {
- bnet_fsend(fd, "%s", buf);
+ bnet_fsend(fd, "%s", buf);
}
bnet_sig(fd, BNET_EOD);
fclose(bs);
}
-/*
+/*
* Read the attributes from the File daemon for
* a Verify job and store them in the catalog.
*/
/* Pickup file attributes and signature */
while (!fd->errors && (n = bget_dirmsg(fd)) > 0) {
- /*****FIXME****** improve error handling to stop only on
+ /*****FIXME****** improve error handling to stop only on
* really fatal problems, or the number of errors is too
* large.
*/
jcr->fname = check_pool_memory_size(jcr->fname, fd->msglen);
if ((len = sscanf(fd->msg, "%ld %d %s", &file_index, &stream, Opts_SIG)) != 3) {
- Jmsg(jcr, M_FATAL, 0, _("<filed: bad attributes, expected 3 fields got %d\n\
-msglen=%d msg=%s\n"), len, fd->msglen, fd->msg);
+ Jmsg(jcr, M_FATAL, 0, _("<filed: bad attributes, expected 3 fields got %d\n"
+"msglen=%d msg=%s\n"), len, fd->msglen, fd->msg);
set_jcr_job_status(jcr, JS_ErrorTerminated);
return 0;
}
skip_spaces(&p);
skip_nonspaces(&p); /* skip Stream */
skip_spaces(&p);
- skip_nonspaces(&p); /* skip Opts_SHA1 */
+ skip_nonspaces(&p); /* skip Opts_SHA1 */
p++; /* skip space */
fn = jcr->fname;
while (*p != 0) {
ar.PathId = 0;
ar.FilenameId = 0;
- Dmsg2(111, "dird<filed: stream=%d %s\n", stream, jcr->fname);
- Dmsg1(120, "dird<filed: attr=%s\n", attr);
+ Dmsg2(111, "dird<filed: stream=%d %s\n", stream, jcr->fname);
+ Dmsg1(120, "dird<filed: attr=%s\n", attr);
if (!db_create_file_attributes_record(jcr, jcr->db, &ar)) {
- Jmsg1(jcr, M_ERROR, 0, "%s", db_strerror(jcr->db));
+ Jmsg1(jcr, M_ERROR, 0, "%s", db_strerror(jcr->db));
set_jcr_job_status(jcr, JS_Error);
continue;
}
jcr->FileId = ar.FileId;
} else if (stream == STREAM_MD5_SIGNATURE || stream == STREAM_SHA1_SIGNATURE) {
if (jcr->FileIndex != (uint32_t)file_index) {
- Jmsg2(jcr, M_ERROR, 0, _("MD5/SHA1 index %d not same as attributes %d\n"),
+ Jmsg2(jcr, M_ERROR, 0, _("MD5/SHA1 index %d not same as attributes %d\n"),
file_index, jcr->FileIndex);
set_jcr_job_status(jcr, JS_Error);
continue;
}
db_escape_string(SIG, Opts_SIG, strlen(Opts_SIG));
- Dmsg2(120, "SIGlen=%d SIG=%s\n", strlen(SIG), SIG);
- if (!db_add_SIG_to_file_record(jcr, jcr->db, jcr->FileId, SIG,
+ Dmsg2(120, "SIGlen=%d SIG=%s\n", strlen(SIG), SIG);
+ if (!db_add_SIG_to_file_record(jcr, jcr->db, jcr->FileId, SIG,
stream==STREAM_MD5_SIGNATURE?MD5_SIG:SHA1_SIG)) {
- Jmsg1(jcr, M_ERROR, 0, "%s", db_strerror(jcr->db));
+ Jmsg1(jcr, M_ERROR, 0, "%s", db_strerror(jcr->db));
set_jcr_job_status(jcr, JS_Error);
}
}
jcr->jr.JobFiles = jcr->JobFiles = file_index;
jcr->jr.LastIndex = file_index;
- }
+ }
if (is_bnet_error(fd)) {
Jmsg1(jcr, M_FATAL, 0, _("<filed: Network error getting attributes. ERR=%s\n"),
bnet_strerror(fd));
* This routine runs as a thread and must be thread reentrant.
*
* Basic tasks done here:
- * Handle network signals (signals).
+ * Handle network signals (signals).
* Signals always have return status 0 from bnet_recv() and
* a zero or negative message length.
- * Pass appropriate messages back to the caller (responses).
+ * Pass appropriate messages back to the caller (responses).
* Responses always have a digit as the first character.
- * Handle requests for message and catalog services (requests).
+ * Handle requests for message and catalog services (requests).
* Requests are any message that does not begin with a digit.
* In affect, they are commands.
*
* another daemon. If the message is in canonical message
* format and the type is known, it will be dispatched
* to the appropriate handler. If the message is
- * in any other format, it will be returned.
+ * in any other format, it will be returned.
*
* E.g. any message beginning with a digit will be returned.
* any message beginning with Jmsg will be processed.
break;
case BNET_STATUS:
/* *****FIXME***** Implement more completely */
- bnet_fsend(bs, "Status OK\n");
+ bnet_fsend(bs, "Status OK\n");
bnet_sig(bs, BNET_EOD);
break;
case BNET_BTIME: /* send Bacula time */
char ed1[50];
- bnet_fsend(bs, "btime %s\n", edit_uint64(get_current_btime(),ed1));
+ bnet_fsend(bs, "btime %s\n", edit_uint64(get_current_btime(),ed1));
break;
default:
- Emsg1(M_WARNING, 0, _("bget_dirmsg: unknown bnet signal %d\n"), bs->msglen);
+ Emsg1(M_WARNING, 0, _("bget_dirmsg: unknown bnet signal %d\n"), bs->msglen);
return n;
}
continue;
}
-
+
/* Handle normal data */
if (n > 0 && B_ISDIGIT(bs->msg[0])) { /* response? */
return n; /* yes, return it */
}
-
+
/*
* If we get here, it must be a request. Either
* a message to dispatch, or a catalog request.
* Try to fulfill it.
*/
if (sscanf(bs->msg, "%020s Job=%127s ", MsgType, Job) != 2) {
- Emsg1(M_ERROR, 0, _("Malformed message: %s\n"), bs->msg);
+ Emsg1(M_ERROR, 0, _("Malformed message: %s\n"), bs->msg);
continue;
}
if (!(jcr=get_jcr_by_full_name(Job))) {
- Emsg1(M_ERROR, 0, _("Job not found: %s\n"), bs->msg);
+ Emsg1(M_ERROR, 0, _("Job not found: %s\n"), bs->msg);
continue;
}
Dmsg1(200, "Getmsg got jcr 0x%x\n", jcr);
/* Skip past "Jmsg Job=nnn" */
if (!(msg=find_msg_start(bs->msg))) {
- Emsg1(M_ERROR, 0, _("Malformed message: %s\n"), bs->msg);
+ Emsg1(M_ERROR, 0, _("Malformed message: %s\n"), bs->msg);
free_jcr(jcr);
continue;
}
- /*
+ /*
* Here we are expecting a message of the following format:
* Jmsg Job=nnn type=nnn level=nnn Message-string
*/
if (bs->msg[0] == 'J') { /* Job message */
- if (sscanf(bs->msg, "Jmsg Job=%127s type=%d level=%d",
+ if (sscanf(bs->msg, "Jmsg Job=%127s type=%d level=%d",
Job, &type, &level) != 3) {
- Emsg1(M_ERROR, 0, _("Malformed message: %s\n"), bs->msg);
+ Emsg1(M_ERROR, 0, _("Malformed message: %s\n"), bs->msg);
free_jcr(jcr);
continue;
}
- Dmsg1(120, "Got msg: %s\n", bs->msg);
+ Dmsg1(120, "Got msg: %s\n", bs->msg);
skip_spaces(&msg);
skip_nonspaces(&msg); /* skip type=nnn */
skip_spaces(&msg);
skip_nonspaces(&msg); /* skip level=nnn */
- if (*msg == ' ') {
+ if (*msg == ' ') {
msg++; /* skip leading space */
}
- Dmsg1(120, "Dispatch msg: %s", msg);
+ Dmsg1(120, "Dispatch msg: %s", msg);
dispatch_message(jcr, type, level, msg);
free_jcr(jcr);
continue;
}
- /*
+ /*
* Here we expact a CatReq message
* CatReq Job=nn Catalog-Request-Message
*/
if (bs->msg[0] == 'C') { /* Catalog request */
- Dmsg2(120, "Catalog req jcr 0x%x: %s", jcr, bs->msg);
+ Dmsg2(120, "Catalog req jcr 0x%x: %s", jcr, bs->msg);
catalog_request(jcr, bs, msg);
- Dmsg1(200, "Calling freejcr 0x%x\n", jcr);
+ Dmsg1(200, "Calling freejcr 0x%x\n", jcr);
free_jcr(jcr);
continue;
}
if (bs->msg[0] == 'U') { /* Catalog update */
- Dmsg2(120, "Catalog upd jcr 0x%x: %s", jcr, bs->msg);
+ Dmsg2(120, "Catalog upd jcr 0x%x: %s", jcr, bs->msg);
catalog_update(jcr, bs, msg);
- Dmsg1(200, "Calling freejcr 0x%x\n", jcr);
+ Dmsg1(200, "Calling freejcr 0x%x\n", jcr);
free_jcr(jcr);
continue;
}
if (bs->msg[0] == 'M') { /* Mount request */
- Dmsg1(120, "Mount req: %s", bs->msg);
+ Dmsg1(120, "Mount req: %s", bs->msg);
mount_request(jcr, bs, msg);
free_jcr(jcr);
continue;
return 1;
}
if (prtmsg == DISPLAY_ERROR) {
- Jmsg(jcr, M_FATAL, 0, _("FD gave bad response to %s command: wanted %s got: %s\n"),
+ Jmsg(jcr, M_FATAL, 0, _("FD gave bad response to %s command: wanted %s got: %s\n"),
cmd, resp, fd->msg);
}
return 0;
- }
+ }
Jmsg(jcr, M_FATAL, 0, _("Socket error from Filed on %s command: ERR=%s\n"),
cmd, bnet_strerror(fd));
return 0;
* Version $Id$
*/
/*
- Copyright (C) 2003-2004 Kern Sibbald and John Walker
+ Copyright (C) 2003-2004 Kern Sibbald
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
/* We build the current new Include and Exclude items here */
static INCEXE res_incexe;
-/*
+/*
* new Include/Exclude items
* name handler value code flags default_value
*/
static RES_ITEM newinc_items[] = {
{"file", store_fname, NULL, 0, 0, 0},
{"options", options_res, NULL, 0, 0, 0},
- {NULL, NULL, NULL, 0, 0, 0}
+ {NULL, NULL, NULL, 0, 0, 0}
};
/*
{"ignorecase", store_opts, NULL, 0, 0, 0},
{"fstype", store_fstype, NULL, 0, 0, 0},
{"hfsplussupport", store_opts, NULL, 0, 0, 0},
- {NULL, NULL, NULL, 0, 0, 0}
+ {NULL, NULL, NULL, 0, 0, 0}
};
};
/*
- * Options permitted for each keyword and resulting value.
+ * Options permitted for each keyword and resulting value.
* The output goes into opts, which are then transmitted to
* the FD for application as options to the following list of
* included files.
-/*
- * Scan for right hand side of Include options (keyword=option) is
+/*
+ * Scan for right hand side of Include options (keyword=option) is
* converted into one or two characters. Verifyopts=xxxx is Vxxxx:
* Whatever is found is concatenated to the opts string.
* This code is also used inside an Options resource.
{
int token, i;
char option[3];
+ int lcopts = lc->options;
option[0] = 0; /* default option = none */
option[2] = 0; /* terminate options */
- token = lex_get_token(lc, T_NAME); /* expect at least one option */
+ lc->options |= LOPT_STRING; /* force string */
+ token = lex_get_token(lc, T_STRING); /* expect at least one option */
if (keyword == INC_KW_VERIFY) { /* special case */
/* ***FIXME**** ensure these are in permitted set */
bstrncat(opts, "V", optlen); /* indicate Verify */
Dmsg3(900, "Catopts=%s option=%s optlen=%d\n", opts, option,optlen);
/*
- * Standard keyword options for Include/Exclude
+ * Standard keyword options for Include/Exclude
*/
} else {
for (i=0; FS_options[i].name; i++) {
Dmsg3(900, "Catopts=%s option=%s optlen=%d\n", opts, option,optlen);
}
}
+ lc->options = lcopts;
/* If option terminated by comma, eat it */
if (lc->ch == ',') {
}
}
-/*
- *
- * Store FileSet Include/Exclude info
+/*
+ *
+ * Store FileSet Include/Exclude info
* NEW style includes are handled in store_newinc()
*/
void store_inc(LEX *lc, RES_ITEM *item, int index, int pass)
* new Include is followed immediately by open brace, whereas the
* old include has options following the Include.
*/
- token = lex_get_token(lc, T_SKIP_EOL);
+ token = lex_get_token(lc, T_SKIP_EOL);
if (token == T_BOB) {
store_newinc(lc, item, index, pass);
return;
/* Get include options */
inc_opts[0] = 0;
while ((token=lex_get_token(lc, T_SKIP_EOL)) != T_BOB) {
-
+
keyword = INC_KW_NONE;
for (i=0; FS_option_kw[i].name; i++) {
if (strcasecmp(lc->str, FS_option_kw[i].name) == 0) {
break;
default:
scan_err1(lc, "Expected a filename, got: %s", lc->str);
- }
+ }
}
/* Note, MD5Final is done in backup.c */
} else { /* pass 2 */
- while (lex_get_token(lc, T_ALL) != T_EOB)
+ while (lex_get_token(lc, T_ALL) != T_EOB)
{}
}
scan_to_eol(lc);
/*
- * Store NEW style FileSet FInclude/FExclude info
+ * Store NEW style FileSet FInclude/FExclude info
*
* Note, when this routine is called, we are inside a FileSet
* resource. We treat the Include/Execlude like a sort of
{
int token, i;
INCEXE *incexe;
- bool options;
+ bool options;
if (!res_all.res_fs.have_MD5) {
MD5Init(&res_all.res_fs.md5c);
regex_t preg;
char prbuf[500];
- token = lex_get_token(lc, T_SKIP_EOL);
+ token = lex_get_token(lc, T_SKIP_EOL);
if (pass == 1) {
/* Pickup regex string
*/
}
regfree(&preg);
res_incexe.current_opts->regex.append(bstrdup(lc->str));
- Dmsg3(900, "set regex %p size=%d %s\n",
+ Dmsg3(900, "set regex %p size=%d %s\n",
res_incexe.current_opts, res_incexe.current_opts->regex.size(),lc->str);
break;
default:
scan_err1(lc, _("Expected a regex string, got: %s\n"), lc->str);
- }
+ }
}
scan_to_eol(lc);
}
{
int token;
- token = lex_get_token(lc, T_NAME);
+ token = lex_get_token(lc, T_NAME);
if (pass == 1) {
/*
* Pickup Base Job Name
{
int token;
- token = lex_get_token(lc, T_NAME);
+ token = lex_get_token(lc, T_NAME);
if (pass == 1) {
/*
* Pickup reader command
*/
- res_incexe.current_opts->reader = bstrdup(lc->str);
+ res_incexe.current_opts->reader = bstrdup(lc->str);
}
scan_to_eol(lc);
}
{
int token;
- token = lex_get_token(lc, T_NAME);
+ token = lex_get_token(lc, T_NAME);
if (pass == 1) {
/*
* Pickup writer command
{
int token;
- token = lex_get_token(lc, T_SKIP_EOL);
+ token = lex_get_token(lc, T_SKIP_EOL);
if (pass == 1) {
/*
* Pickup Wild-card string
case T_UNQUOTED_STRING:
case T_QUOTED_STRING:
res_incexe.current_opts->wild.append(bstrdup(lc->str));
- Dmsg3(900, "set wild %p size=%d %s\n",
+ Dmsg3(900, "set wild %p size=%d %s\n",
res_incexe.current_opts, res_incexe.current_opts->wild.size(),lc->str);
break;
default:
scan_err1(lc, _("Expected a wild-card string, got: %s\n"), lc->str);
- }
+ }
}
scan_to_eol(lc);
}
{
int token;
- token = lex_get_token(lc, T_SKIP_EOL);
+ token = lex_get_token(lc, T_SKIP_EOL);
if (pass == 1) {
/* Pickup fstype string */
switch (token) {
case T_UNQUOTED_STRING:
case T_QUOTED_STRING:
res_incexe.current_opts->fstype.append(bstrdup(lc->str));
- Dmsg3(900, "set fstype %p size=%d %s\n",
+ Dmsg3(900, "set fstype %p size=%d %s\n",
res_incexe.current_opts, res_incexe.current_opts->fstype.size(), lc->str);
break;
default:
scan_err1(lc, _("Expected an fstype string, got: %s\n"), lc->str);
- }
+ }
}
scan_to_eol(lc);
}
int token;
INCEXE *incexe;
- token = lex_get_token(lc, T_SKIP_EOL);
+ token = lex_get_token(lc, T_SKIP_EOL);
if (pass == 1) {
/* Pickup Filename string
*/
break;
default:
scan_err1(lc, _("Expected a filename, got: %s"), lc->str);
- }
+ }
}
scan_to_eol(lc);
}
{
int token, i;
- token = lex_get_token(lc, T_SKIP_EOL);
+ token = lex_get_token(lc, T_SKIP_EOL);
if (token != T_BOB) {
scan_err1(lc, "Expecting open brace. Got %s", lc->str);
}
if (pass == 1) {
setup_current_opts();
}
-
+
while ((token = lex_get_token(lc, T_ALL)) != T_EOF) {
if (token == T_EOL) {
continue;
{
int stat;
watchdog_t *wd;
-
+
if ((stat = jobq_init(&job_queue, max_workers, job_thread)) != 0) {
berrno be;
Emsg1(M_ABORT, 0, _("Could not init job queue: ERR=%s\n"), be.strerror(stat));
Dmsg0(50, "DB opened\n");
/*
- * Create Job record
+ * Create Job record
*/
create_unique_job_name(jcr, jcr->job->hdr.name);
set_jcr_job_status(jcr, JS_Created);
}
JobId = jcr->JobId = jcr->jr.JobId;
- Dmsg4(100, "Created job record JobId=%d Name=%s Type=%c Level=%c\n",
+ Dmsg4(100, "Created job record JobId=%d Name=%s Type=%c Level=%c\n",
jcr->JobId, jcr->Job, jcr->jr.JobType, jcr->jr.JobLevel);
Dmsg0(200, "Add jrc to work queue\n");
}
-/*
- * This is the engine called by jobq.c:jobq_add() when we were pulled
+/*
+ * This is the engine called by jobq.c:jobq_add() when we were pulled
* from the work queue.
* At this point, we are running in our own thread and all
* necessary resources are allocated -- see jobq.c
int status;
BPIPE *bpipe;
char line[MAXSTRING];
-
+
before = edit_job_codes(jcr, before, jcr->job->RunBeforeJob, "");
bpipe = open_bpipe(before, 0, "r");
free_pool_memory(before);
int status;
BPIPE *bpipe;
char line[MAXSTRING];
-
+
if (jcr->JobStatus == JS_Terminated) {
after = edit_job_codes(jcr, after, jcr->job->RunAfterJob, "");
} else {
status = close_bpipe(bpipe);
/*
* Note, if we get an error here, do not mark the
- * job in error, simply report the error condition.
+ * job in error, simply report the error condition.
*/
if (status != 0) {
berrno be;
/*
* Cancel a job -- typically called by the UA (Console program), but may also
* be called by the job watchdog.
- *
+ *
* Returns: 1 if cancel appears to be successful
* 0 on failure. Message sent to ua->jcr.
*/
jcr->JobId, jcr->Job);
jobq_remove(&job_queue, jcr); /* attempt to remove it from queue */
return 1;
-
+
default:
set_jcr_job_status(jcr, JS_Canceled);
}
pm_strcpy(jcr->client_name, jcr->client->hdr.name);
if (!db_create_client_record(jcr, jcr->db, &cr)) {
- Jmsg(jcr, M_FATAL, 0, _("Could not create Client record. ERR=%s\n"),
+ Jmsg(jcr, M_FATAL, 0, _("Could not create Client record. ERR=%s\n"),
db_strerror(jcr->db));
return false;
}
}
pm_strcpy(jcr->client_uname, cr.Uname);
}
- Dmsg2(100, "Created Client %s record %d\n", jcr->client->hdr.name,
+ Dmsg2(100, "Created Client %s record %d\n", jcr->client->hdr.name,
jcr->jr.ClientId);
return true;
}
if (!jcr->fileset->ignore_fs_changes ||
!db_get_fileset_record(jcr, jcr->db, fsr)) {
if (!db_create_fileset_record(jcr, jcr->db, fsr)) {
- Jmsg(jcr, M_ERROR, 0, _("Could not create FileSet \"%s\" record. ERR=%s\n"),
+ Jmsg(jcr, M_ERROR, 0, _("Could not create FileSet \"%s\" record. ERR=%s\n"),
fsr->FileSet, db_strerror(jcr->db));
return false;
- }
+ }
}
jcr->jr.FileSetId = fsr->FileSetId;
if (fsr->created) {
- Jmsg(jcr, M_INFO, 0, _("Created new FileSet record \"%s\" %s\n"),
+ Jmsg(jcr, M_INFO, 0, _("Created new FileSet record \"%s\" %s\n"),
fsr->FileSet, fsr->cCreateTime);
}
- Dmsg2(119, "Created FileSet %s record %u\n", jcr->fileset->hdr.name,
+ Dmsg2(119, "Created FileSet %s record %u\n", jcr->fileset->hdr.name,
jcr->jr.FileSetId);
return true;
}
jcr->jr.VolSessionId = jcr->VolSessionId;
jcr->jr.VolSessionTime = jcr->VolSessionTime;
if (!db_update_job_end_record(jcr, jcr->db, &jcr->jr)) {
- Jmsg(jcr, M_WARNING, 0, _("Error updating job record. %s"),
+ Jmsg(jcr, M_WARNING, 0, _("Error updating job record. %s"),
db_strerror(jcr->db));
}
}
char *p;
/* Guarantee unique start time -- maximum one per second, and
- * thus unique Job Name
+ * thus unique Job Name
*/
P(mutex); /* lock creation of jobs */
now = time(NULL);
/* Form Unique JobName */
localtime_r(&now, &tm);
/* Use only characters that are permitted in Windows filenames */
- strftime(dt, sizeof(dt), "%Y-%m-%d_%H.%M.%S", &tm);
+ strftime(dt, sizeof(dt), "%Y-%m-%d_%H.%M.%S", &tm);
bstrncpy(name, base_name, sizeof(name));
name[sizeof(name)-22] = 0; /* truncate if too long */
bsnprintf(jcr->Job, sizeof(jcr->Job), "%s.%s", name, dt); /* add date & time */
bnet_close(jcr->store_bsock);
jcr->store_bsock = NULL;
}
- if (jcr->fname) {
+ if (jcr->fname) {
Dmsg0(200, "Free JCR fname\n");
free_pool_memory(jcr->fname);
jcr->fname = NULL;
}
jcr->JobPriority = job->Priority;
/* Copy storage definitions -- deleted in dir_free_jcr above */
- for (int i=0; i<MAX_STORE; i++) {
+ for (int i=0; i < MAX_STORE; i++) {
STORE *st;
if (job->storage[i]) {
+ if (jcr->storage[i]) {
+ delete jcr->storage[i];
+ }
jcr->storage[i] = New(alist(10, not_owned_by_alist));
foreach_alist(st, job->storage[i]) {
jcr->storage[i]->append(st);
jcr->dif_pool = job->dif_pool;
jcr->catalog = job->client->catalog;
jcr->fileset = job->fileset;
- jcr->messages = job->messages;
+ jcr->messages = job->messages;
jcr->spool_data = job->spool_data;
if (jcr->RestoreBootstrap) {
free(jcr->RestoreBootstrap);
}
}
-/*
+/*
* copy the storage definitions from an old JCR to a new one
*/
-void copy_storage(JCR *new_jcr, JCR *old_jcr)
+void copy_storage(JCR *new_jcr, JCR *old_jcr)
{
for (int i=0; i < MAX_STORE; i++) {
if (old_jcr->storage[i]) {
-/*
+/*
* Initialize a job queue
*
* Returns: 0 on success
{
int stat;
jobq_item_t *item = NULL;
-
+
if ((stat = pthread_attr_init(&jq->attr)) != 0) {
berrno be;
Jmsg1(NULL, M_ERROR, 0, "pthread_attr_init: ERR=%s\n", be.strerror(stat));
jq->num_workers = 0; /* no threads yet */
jq->idle_workers = 0; /* no idle threads */
jq->engine = engine; /* routine to run */
- jq->valid = JOBQ_VALID;
+ jq->valid = JOBQ_VALID;
/* Initialize the job queues */
jq->waiting_jobs = New(dlist(item, &item->link));
jq->running_jobs = New(dlist(item, &item->link));
* most jobs are put into the job queue only when their
* scheduled time arives.
*/
-extern "C"
+extern "C"
void *sched_wait(void *arg)
{
JCR *jcr = ((wait_pkt *)arg)->jcr;
set_jcr_job_status(jcr, JS_WaitStartTime);
/* Wait until scheduled time arrives */
if (wtime > 0) {
- Jmsg(jcr, M_INFO, 0, _("Job %s waiting %d seconds for scheduled start time.\n"),
+ Jmsg(jcr, M_INFO, 0, _("Job %s waiting %d seconds for scheduled start time.\n"),
jcr->Job, wtime);
}
- /* Check every 30 seconds if canceled */
+ /* Check every 30 seconds if canceled */
while (wtime > 0) {
Dmsg2(300, "Waiting on sched time, jobid=%d secs=%d\n", jcr->JobId, wtime);
if (wtime > 30) {
/*
* Add a job to the queue
* jq is a queue that was created with jobq_init
- *
+ *
* On entry jcr->mutex must be locked.
- *
+ *
*/
int jobq_add(jobq_t *jq, JCR *jcr)
{
time_t wtime = jcr->sched_time - time(NULL);
pthread_t id;
wait_pkt *sched_pkt;
-
+
Dmsg3(300, "jobq_add jobid=%d jcr=0x%x use_count=%d\n", jcr->JobId, jcr, jcr->use_count);
if (jq->valid != JOBQ_VALID) {
Jmsg0(jcr, M_ERROR, 0, "Jobq_add queue not initialized.\n");
} else {
/* Add this job to the wait queue in priority sorted order */
foreach_dlist(li, jq->waiting_jobs) {
- Dmsg2(300, "waiting item jobid=%d priority=%d\n",
+ Dmsg2(300, "waiting item jobid=%d priority=%d\n",
li->jcr->JobId, li->jcr->JobPriority);
if (li->jcr->JobPriority > jcr->JobPriority) {
jq->waiting_jobs->insert_before(item, li);
- Dmsg2(300, "insert_before jobid=%d before waiting job=%d\n",
+ Dmsg2(300, "insert_before jobid=%d before waiting job=%d\n",
li->jcr->JobId, jcr->JobId);
inserted = true;
break;
/* If not jobs in wait queue, append it */
if (!inserted) {
jq->waiting_jobs->append(item);
- Dmsg1(300, "Appended item jobid=%d to waiting queue\n", jcr->JobId);
+ Dmsg1(300, "Appended item jobid=%d to waiting queue\n", jcr->JobId);
}
}
int stat;
bool found = false;
jobq_item_t *item;
-
+
Dmsg2(300, "jobq_remove jobid=%d jcr=0x%x\n", jcr->JobId, jcr);
if (jq->valid != JOBQ_VALID) {
return EINVAL;
jq->waiting_jobs->remove(item);
jq->ready_jobs->prepend(item);
Dmsg2(300, "jobq_remove jobid=%d jcr=0x%x moved to ready queue\n", jcr->JobId, jcr);
-
+
stat = start_server(jq);
pthread_mutex_unlock(&jq->mutex);
}
-/*
+/*
* This is the worker thread that serves the job queue.
- * When all the resources are acquired for the job,
+ * When all the resources are acquired for the job,
* it will call the user's engine.
*/
-extern "C"
+extern "C"
void *jobq_server(void *arg)
{
struct timespec timeout;
/*
* Wait 4 seconds, then if no more work, exit
*/
- Dmsg0(300, "pthread_cond_timedwait()\n");
+ Dmsg0(300, "pthread_cond_timedwait()\n");
stat = pthread_cond_timedwait(&jq->work, &jq->mutex, &timeout);
if (stat == ETIMEDOUT) {
- Dmsg0(300, "timedwait timedout.\n");
+ Dmsg0(300, "timedwait timedout.\n");
timedout = true;
break;
} else if (stat != 0) {
- /* This shouldn't happen */
- Dmsg0(300, "This shouldn't happen\n");
+ /* This shouldn't happen */
+ Dmsg0(300, "This shouldn't happen\n");
jq->num_workers--;
pthread_mutex_unlock(&jq->mutex);
return NULL;
}
break;
- }
+ }
}
- /*
+ /*
* If anything is in the ready queue, run it
*/
Dmsg0(300, "Checking ready queue.\n");
while (!jq->ready_jobs->empty() && !jq->quit) {
JCR *jcr;
- je = (jobq_item_t *)jq->ready_jobs->first();
+ je = (jobq_item_t *)jq->ready_jobs->first();
jcr = je->jcr;
jq->ready_jobs->remove(je);
if (!jq->ready_jobs->empty()) {
- Dmsg0(300, "ready queue not empty start server\n");
+ Dmsg0(300, "ready queue not empty start server\n");
if (start_server(jq) != 0) {
jq->num_workers--;
pthread_mutex_unlock(&jq->mutex);
}
Dmsg0(200, "Done lock mutex after running job. Release locks.\n");
jq->running_jobs->remove(je);
- /*
+ /*
* Release locks if acquired. Note, they will not have
* been acquired for jobs canceled before they were
* put into the ready queue.
if (jcr->acquired_resource_locks) {
jcr->store->NumConcurrentJobs--;
if (jcr->JobType == JT_RESTORE || jcr->JobType == JT_VERIFY) {
- jcr->store->MaxConcurrentJobs = jcr->saveMaxConcurrentJobs;
+ jcr->store->MaxConcurrentJobs = jcr->saveMaxConcurrentJobs;
}
jcr->client->NumConcurrentJobs--;
jcr->job->NumConcurrentJobs--;
/*
* Reschedule the job if necessary and requested
*/
- if (jcr->job->RescheduleOnError &&
+ if (jcr->job->RescheduleOnError &&
jcr->JobStatus != JS_Terminated &&
- jcr->JobStatus != JS_Canceled &&
- jcr->job->RescheduleTimes > 0 &&
+ jcr->JobStatus != JS_Canceled &&
+ jcr->job->RescheduleTimes > 0 &&
jcr->reschedule_count < jcr->job->RescheduleTimes) {
char dt[50];
*/
jcr->reschedule_count++;
jcr->sched_time = time(NULL) + jcr->job->RescheduleInterval;
- Dmsg2(300, "Rescheduled Job %s to re-run in %d seconds.\n", jcr->Job,
+ Dmsg2(300, "Rescheduled Job %s to re-run in %d seconds.\n", jcr->Job,
(int)jcr->job->RescheduleInterval);
bstrftime(dt, sizeof(dt), time(NULL));
- Jmsg(jcr, M_INFO, 0, _("Rescheduled Job %s at %s to re-run in %d seconds.\n"),
+ Jmsg(jcr, M_INFO, 0, _("Rescheduled Job %s at %s to re-run in %d seconds.\n"),
jcr->Job, dt, (int)jcr->job->RescheduleInterval);
dird_free_jcr(jcr); /* partial cleanup old stuff */
jcr->JobStatus = JS_WaitStartTime;
jcr->SDJobStatus = 0;
if (jcr->JobBytes == 0) {
- Dmsg1(300, "Requeue job=%d\n", jcr->JobId);
+ Dmsg1(300, "Requeue job=%d\n", jcr->JobId);
jcr->JobStatus = JS_WaitStartTime;
V(jq->mutex);
jobq_add(jq, jcr); /* queue the job to run again */
free(je); /* free the job entry */
continue; /* look for another job to run */
}
- /*
+ /*
* Something was actually backed up, so we cannot reuse
* the old JobId or there will be database record
* conflicts. We now create a new job, copying the
njcr->JobStatus = jcr->JobStatus;
copy_storage(njcr, jcr);
njcr->messages = jcr->messages;
- Dmsg0(300, "Call to run new job\n");
+ Dmsg0(300, "Call to run new job\n");
V(jq->mutex);
- run_job(njcr); /* This creates a "new" job */
- free_jcr(njcr); /* release "new" jcr */
+ run_job(njcr); /* This creates a "new" job */
+ free_jcr(njcr); /* release "new" jcr */
P(jq->mutex);
- Dmsg0(300, "Back from running new job.\n");
+ Dmsg0(300, "Back from running new job.\n");
}
/* Clean up and release old jcr */
if (jcr->db) {
db_close_database(jcr, jcr->db);
jcr->db = NULL;
}
- Dmsg2(300, "====== Termination job=%d use_cnt=%d\n", jcr->JobId, jcr->use_count);
+ Dmsg2(300, "====== Termination job=%d use_cnt=%d\n", jcr->JobId, jcr->use_count);
jcr->SDJobStatus = 0;
V(jq->mutex); /* release internal lock */
free_jcr(jcr);
Dmsg0(300, "Done check ready, now check wait queue.\n");
while (!jq->waiting_jobs->empty() && !jq->quit) {
int Priority;
- je = (jobq_item_t *)jq->waiting_jobs->first();
+ je = (jobq_item_t *)jq->waiting_jobs->first();
jobq_item_t *re = (jobq_item_t *)jq->running_jobs->first();
if (re) {
Priority = re->jcr->JobPriority;
- Dmsg2(300, "JobId %d is running. Look for pri=%d\n", re->jcr->JobId, Priority);
+ Dmsg2(300, "JobId %d is running. Look for pri=%d\n", re->jcr->JobId, Priority);
} else {
Priority = je->jcr->JobPriority;
- Dmsg1(300, "No job running. Look for Job pri=%d\n", Priority);
+ Dmsg1(300, "No job running. Look for Job pri=%d\n", Priority);
}
/*
* Walk down the list of waiting jobs and attempt
JCR *jcr = je->jcr;
bool skip_this_jcr = false;
jobq_item_t *jn = (jobq_item_t *)jq->waiting_jobs->next(je);
- Dmsg3(300, "Examining Job=%d JobPri=%d want Pri=%d\n",
+ Dmsg3(300, "Examining Job=%d JobPri=%d want Pri=%d\n",
jcr->JobId, jcr->JobPriority, Priority);
/* Take only jobs of correct Priority */
if (jcr->JobPriority != Priority) {
} else if (jcr->store->NumConcurrentJobs == 0 &&
jcr->store->NumConcurrentJobs < jcr->store->MaxConcurrentJobs) {
/* Simple case, first job */
- jcr->store->NumConcurrentJobs = 1;
+ jcr->store->NumConcurrentJobs = 1;
} else if (jcr->store->NumConcurrentJobs < jcr->store->MaxConcurrentJobs) {
/*
- * At this point, we already have at least one Job running
+ * At this point, we already have at least one Job running
* for this Storage daemon, so we must ensure that there
* is no Volume conflict. In general, it should be OK, if
* all Jobs pull from the same Pool, so we check the Pools.
skip_this_jcr = true;
break;
}
- }
+ }
unlock_jcr_chain();
if (!skip_this_jcr) {
- jcr->store->NumConcurrentJobs++;
+ jcr->store->NumConcurrentJobs++;
}
- }
+ }
if (skip_this_jcr) {
set_jcr_job_status(jcr, JS_WaitStoreRes);
je = jn; /* point to next waiting job */
/* Back out previous locks */
jcr->store->NumConcurrentJobs--;
if (jcr->JobType == JT_RESTORE || jcr->JobType == JT_VERIFY) {
- jcr->store->MaxConcurrentJobs = jcr->saveMaxConcurrentJobs;
+ jcr->store->MaxConcurrentJobs = jcr->saveMaxConcurrentJobs;
}
set_jcr_job_status(jcr, JS_WaitClientRes);
je = jn; /* point to next waiting job */
/* Back out previous locks */
jcr->store->NumConcurrentJobs--;
if (jcr->JobType == JT_RESTORE || jcr->JobType == JT_VERIFY) {
- jcr->store->MaxConcurrentJobs = jcr->saveMaxConcurrentJobs;
+ jcr->store->MaxConcurrentJobs = jcr->saveMaxConcurrentJobs;
}
jcr->client->NumConcurrentJobs--;
set_jcr_job_status(jcr, JS_WaitJobRes);
continue;
}
/* Got all locks, now remove it from wait queue and append it
- * to the ready queue
+ * to the ready queue
*/
jcr->acquired_resource_locks = true;
jq->waiting_jobs->remove(je);
jq->ready_jobs->append(je);
- Dmsg1(300, "moved JobId=%d from wait to ready queue\n", je->jcr->JobId);
+ Dmsg1(300, "moved JobId=%d from wait to ready queue\n", je->jcr->JobId);
je = jn; /* Point to next waiting job */
} /* end for loop */
break;
if (jq->ready_jobs->empty() && jq->quit) {
jq->num_workers--;
if (jq->num_workers == 0) {
- Dmsg0(300, "Wake up destroy routine\n");
+ Dmsg0(300, "Wake up destroy routine\n");
/* Wake up destroy routine if he is waiting */
pthread_cond_broadcast(&jq->work);
}
break;
}
Dmsg0(300, "Check for work request\n");
- /*
+ /*
* If no more work requests, and we waited long enough, quit
*/
Dmsg2(300, "timedout=%d read empty=%d\n", timedout,
jq->ready_jobs->empty());
if (jq->ready_jobs->empty() && timedout) {
- Dmsg0(300, "break big loop\n");
+ Dmsg0(300, "break big loop\n");
jq->num_workers--;
break;
}
work = !jq->ready_jobs->empty() || !jq->waiting_jobs->empty();
if (work) {
- /*
+ /*
* If a job is waiting on a Resource, don't consume all
* the CPU time looping looking for work, and even more
* important, release the lock so that a job that has
/*
- * Bacula job queue routines.
+ * Bacula job queue routines.
*
* Kern Sibbald, July MMIII
*
*/
-#ifndef __JOBQ_H
+#ifndef __JOBQ_H
#define __JOBQ_H 1
-/*
+/*
* Structure to keep track of job queue request
*/
struct jobq_item_t {
JCR *jcr;
};
-/*
+/*
* Structure describing a work queue
*/
struct jobq_t {
/*
*
- * Bacula Director -- mac.c -- responsible for doing
+ * Bacula Director -- mac.c -- responsible for doing
* migration, archive, and copy jobs.
*
* Kern Sibbald, September MMIV
/* External functions */
-/*
+/*
* Do a Migration, Archive, or Copy of a previous job
- *
+ *
* Returns: false on failure
* true on success
*/
-bool do_mac(JCR *jcr)
+bool do_mac(JCR *jcr)
{
char since[MAXSTRING];
int stat;
Dmsg1(100, "find last jobid for: %s\n", NPRT(Name));
if (!db_find_last_jobid(jcr, jcr->db, Name, &jr)) {
Jmsg(jcr, M_FATAL, 0, _(
- "Unable to find JobId of previous Job for this client.\n"));
+ "Unable to find JobId of previous Job for this client.\n"));
goto bail_out;
}
input_jobid = jr.JobId;
jcr->fname = get_pool_memory(PM_FNAME);
- /*
- * Get the Pool record -- first apply any level defined pools
+ /*
+ * Get the Pool record -- first apply any level defined pools
*/
switch (jcr->JobLevel) {
case L_FULL:
if (jcr->full_pool) {
- jcr->pool = jcr->full_pool;
+ jcr->pool = jcr->full_pool;
}
break;
case L_INCREMENTAL:
if (jcr->inc_pool) {
- jcr->pool = jcr->inc_pool;
+ jcr->pool = jcr->inc_pool;
}
break;
case L_DIFFERENTIAL:
if (jcr->dif_pool) {
- jcr->pool = jcr->dif_pool;
+ jcr->pool = jcr->dif_pool;
}
break;
}
while (!db_get_pool_record(jcr, jcr->db, &pr)) { /* get by Name */
/* Try to create the pool */
if (create_pool(jcr, jcr->db, jcr->pool, POOL_OP_CREATE) < 0) {
- Jmsg(jcr, M_FATAL, 0, _("Pool %s not in database. %s"), pr.Name,
+ Jmsg(jcr, M_FATAL, 0, _("Pool %s not in database. %s"), pr.Name,
db_strerror(jcr->db));
goto bail_out;
} else {
- Jmsg(jcr, M_INFO, 0, _("Pool %s created in database.\n"), pr.Name);
+ Jmsg(jcr, M_INFO, 0, _("Pool %s created in database.\n"), pr.Name);
}
}
jcr->PoolId = pr.PoolId; /****FIXME**** this can go away */
Dmsg0(110, "Open connection with storage daemon\n");
set_jcr_job_status(jcr, JS_WaitSD);
/*
- * Start conversation with Storage daemon
+ * Start conversation with Storage daemon
*/
if (!connect_to_storage_daemon(jcr, 10, SDConnectTimeout, 1)) {
goto bail_out;
}
Dmsg0(150, "Storage daemon connection OK\n");
- /* Pickup Job termination data */
+ /* Pickup Job termination data */
set_jcr_job_status(jcr, JS_Running);
/* Note, the SD stores in jcr->JobFiles/ReadBytes/JobBytes/Errors */
set_jcr_job_status(jcr, TermCode);
update_job_end_record(jcr); /* update database */
-
+
if (!db_get_job_record(jcr, jcr->db, &jcr->jr)) {
- Jmsg(jcr, M_WARNING, 0, _("Error getting job record for stats: %s"),
+ Jmsg(jcr, M_WARNING, 0, _("Error getting job record for stats: %s"),
db_strerror(jcr->db));
set_jcr_job_status(jcr, JS_ErrorTerminated);
}
bstrncpy(mr.VolumeName, jcr->VolumeName, sizeof(mr.VolumeName));
if (!db_get_media_record(jcr, jcr->db, &mr)) {
- Jmsg(jcr, M_WARNING, 0, _("Error getting Media record for Volume \"%s\": ERR=%s"),
+ Jmsg(jcr, M_WARNING, 0, _("Error getting Media record for Volume \"%s\": ERR=%s"),
mr.VolumeName, db_strerror(jcr->db));
set_jcr_job_status(jcr, JS_ErrorTerminated);
}
/* Now update the bootstrap file if any */
- if (jcr->JobStatus == JS_Terminated && jcr->jr.JobBytes &&
+ if (jcr->JobStatus == JS_Terminated && jcr->jr.JobBytes &&
jcr->job->WriteBootstrap) {
FILE *fd;
BPIPE *bpipe = NULL;
if (*fname == '|') {
fname++;
got_pipe = 1;
- bpipe = open_bpipe(fname, 0, "w");
+ bpipe = open_bpipe(fname, 0, "w");
fd = bpipe ? bpipe->wfd : NULL;
} else {
/* ***FIXME*** handle BASE */
- fd = fopen(fname, jcr->JobLevel==L_FULL?"w+":"a+");
+ fd = fopen(fname, jcr->JobLevel==L_FULL?"w+":"a+");
}
if (fd) {
VolCount = db_get_job_volume_parameters(jcr, jcr->db, jcr->JobId,
&VolParams);
if (VolCount == 0) {
- Jmsg(jcr, M_ERROR, 0, _("Could not get Job Volume Parameters to "
- "update Bootstrap file. ERR=%s\n"), db_strerror(jcr->db));
+ Jmsg(jcr, M_ERROR, 0, _("Could not get Job Volume Parameters to "
+ "update Bootstrap file. ERR=%s\n"), db_strerror(jcr->db));
if (jcr->SDJobFiles != 0) {
set_jcr_job_status(jcr, JS_ErrorTerminated);
}
}
for (int i=0; i < VolCount; i++) {
/* Write the record */
- fprintf(fd, "Volume=\"%s\"\n", VolParams[i].VolumeName);
- fprintf(fd, "VolSessionId=%u\n", jcr->VolSessionId);
- fprintf(fd, "VolSessionTime=%u\n", jcr->VolSessionTime);
- fprintf(fd, "VolFile=%u-%u\n", VolParams[i].StartFile,
+ fprintf(fd, "Volume=\"%s\"\n", VolParams[i].VolumeName);
+ fprintf(fd, "VolSessionId=%u\n", jcr->VolSessionId);
+ fprintf(fd, "VolSessionTime=%u\n", jcr->VolSessionTime);
+ fprintf(fd, "VolFile=%u-%u\n", VolParams[i].StartFile,
VolParams[i].EndFile);
- fprintf(fd, "VolBlock=%u-%u\n", VolParams[i].StartBlock,
+ fprintf(fd, "VolBlock=%u-%u\n", VolParams[i].StartBlock,
VolParams[i].EndBlock);
- fprintf(fd, "FileIndex=%d-%d\n", VolParams[i].FirstIndex,
+ fprintf(fd, "FileIndex=%d-%d\n", VolParams[i].FirstIndex,
VolParams[i].LastIndex);
}
if (VolParams) {
}
} else {
berrno be;
- Jmsg(jcr, M_ERROR, 0, _("Could not open WriteBootstrap file:\n"
- "%s: ERR=%s\n"), fname, be.strerror());
+ Jmsg(jcr, M_ERROR, 0, _("Could not open WriteBootstrap file:\n"
+ "%s: ERR=%s\n"), fname, be.strerror());
set_jcr_job_status(jcr, JS_ErrorTerminated);
}
}
switch (jcr->JobStatus) {
case JS_Terminated:
if (jcr->Errors || jcr->SDErrors) {
- term_msg = _("Backup OK -- with warnings");
+ term_msg = _("Backup OK -- with warnings");
} else {
- term_msg = _("Backup OK");
+ term_msg = _("Backup OK");
}
break;
case JS_FatalError:
case JS_ErrorTerminated:
- term_msg = _("*** Backup Error ***");
+ term_msg = _("*** Backup Error ***");
msg_type = M_ERROR; /* Generate error message */
if (jcr->store_bsock) {
bnet_sig(jcr->store_bsock, BNET_TERMINATE);
}
break;
case JS_Canceled:
- term_msg = _("Backup Canceled");
+ term_msg = _("Backup Canceled");
if (jcr->store_bsock) {
bnet_sig(jcr->store_bsock, BNET_TERMINATE);
if (jcr->SD_msg_chan) {
break;
default:
term_msg = term_code;
- sprintf(term_code, _("Inappropriate term code: %c\n"), jcr->JobStatus);
+ sprintf(term_code, _("Inappropriate term code: %c\n"), jcr->JobStatus);
break;
}
bstrftimes(sdt, sizeof(sdt), jcr->jr.StartTime);
* it is normal. Or look at it the other way, only for a
* normal exit should we complain about this error.
*/
- if (jcr->JobStatus == JS_Terminated && jcr->jr.JobBytes) {
- Jmsg(jcr, M_ERROR, 0, "%s", db_strerror(jcr->db));
+ if (jcr->JobStatus == JS_Terminated && jcr->jr.JobBytes) {
+ Jmsg(jcr, M_ERROR, 0, "%s", db_strerror(jcr->db));
}
jcr->VolumeName[0] = 0; /* none */
}
} else {
compression = (double)100 - 100.0 * ((double)jcr->JobBytes / (double)jcr->ReadBytes);
if (compression < 0.5) {
- bstrncpy(compress, "None", sizeof(compress));
+ bstrncpy(compress, "None", sizeof(compress));
} else {
- bsnprintf(compress, sizeof(compress), "%.1f %%", (float)compression);
+ bsnprintf(compress, sizeof(compress), "%.1f %%", (float)compression);
}
}
jobstatus_to_ascii(jcr->FDJobStatus, fd_term_msg, sizeof(fd_term_msg));
// bmicrosleep(15, 0); /* for debugging SIGHUP */
- Jmsg(jcr, msg_type, 0, _("Bacula " VERSION " (" LSMDATE "): %s\n\
- JobId: %d\n\
- Job: %s\n\
- Backup Level: %s%s\n\
- Client: %s\n\
- FileSet: \"%s\" %s\n\
- Pool: \"%s\"\n\
- Start time: %s\n\
- End time: %s\n\
- FD Files Written: %s\n\
- SD Files Written: %s\n\
- FD Bytes Written: %s\n\
- SD Bytes Written: %s\n\
- Rate: %.1f KB/s\n\
- Software Compression: %s\n\
- Volume name(s): %s\n\
- Volume Session Id: %d\n\
- Volume Session Time: %d\n\
- Last Volume Bytes: %s\n\
- Non-fatal FD errors: %d\n\
- SD Errors: %d\n\
- FD termination status: %s\n\
- SD termination status: %s\n\
- Termination: %s\n\n"),
+ Jmsg(jcr, msg_type, 0, _("Bacula " VERSION " (" LSMDATE "): %s\n"
+" JobId: %d\n"
+" Job: %s\n"
+" Backup Level: %s%s\n"
+" Client: %s\n"
+" FileSet: \"%s\" %s\n"
+" Pool: \"%s\"\n"
+" Start time: %s\n"
+" End time: %s\n"
+" FD Files Written: %s\n"
+" SD Files Written: %s\n"
+" FD Bytes Written: %s\n"
+" SD Bytes Written: %s\n"
+" Rate: %.1f KB/s\n"
+" Software Compression: %s\n"
+" Volume name(s): %s\n"
+" Volume Session Id: %d\n"
+" Volume Session Time: %d\n"
+" Last Volume Bytes: %s\n"
+" Non-fatal FD errors: %d\n"
+" SD Errors: %d\n"
+" FD termination status: %s\n"
+" SD termination status: %s\n"
+" Termination: %s\n\n"),
edt,
jcr->jr.JobId,
jcr->jr.Job,
#include "dird.h"
/* Commands sent to Storage daemon */
-static char jobcmd[] = "JobId=%d job=%s job_name=%s client_name=%s \
-type=%d level=%d FileSet=%s NoAttr=%d SpoolAttr=%d FileSetMD5=%s SpoolData=%d";
+static char jobcmd[] = "JobId=%d job=%s job_name=%s client_name=%s "
+"type=%d level=%d FileSet=%s NoAttr=%d SpoolAttr=%d FileSetMD5=%s SpoolData=%d";
static char use_device[] = "use device=%s media_type=%s pool_name=%s pool_type=%s\n";
/* Response from Storage daemon */
/* Storage Daemon requests */
static char Job_start[] = "3010 Job %127s start\n";
-static char Job_end[] =
+static char Job_end[] =
"3099 Job %127s end JobStatus=%d JobFiles=%d JobBytes=%" lld "\n";
static char Job_status[] = "3012 Job %127s jobstatus %d\n";
/*
* Establish a message channel connection with the Storage daemon
- * and perform authentication.
+ * and perform authentication.
*/
-bool connect_to_storage_daemon(JCR *jcr, int retry_interval,
+bool connect_to_storage_daemon(JCR *jcr, int retry_interval,
int max_retry_time, int verbose)
{
BSOCK *sd;
store = (STORE *)jcr->storage[0]->first();
/*
- * Open message channel with the Storage daemon
+ * Open message channel with the Storage daemon
*/
Dmsg2(200, "bnet_connect to Storage daemon %s:%d\n", store->address,
store->SDport);
sd = bnet_connect(jcr, retry_interval, max_retry_time,
- _("Storage daemon"), store->address,
+ _("Storage daemon"), store->address,
NULL, store->SDport, verbose);
if (sd == NULL) {
return false;
if (jcr->fileset->MD5[0] == 0) {
strcpy(jcr->fileset->MD5, "**Dummy**");
}
- bnet_fsend(sd, jobcmd, jcr->JobId, jcr->Job, jcr->job->hdr.name,
- jcr->client->hdr.name, jcr->JobType, jcr->JobLevel,
+ bnet_fsend(sd, jobcmd, jcr->JobId, jcr->Job, jcr->job->hdr.name,
+ jcr->client->hdr.name, jcr->JobType, jcr->JobLevel,
jcr->fileset->hdr.name, !jcr->pool->catalog_files,
jcr->job->SpoolAttributes, jcr->fileset->MD5, jcr->spool_data);
Dmsg1(200, "Jobcmd=%s\n", sd->msg);
unbash_spaces(jcr->fileset->hdr.name);
if (bget_dirmsg(sd) > 0) {
Dmsg1(110, "<stored: %s", sd->msg);
- if (sscanf(sd->msg, OKjob, &jcr->VolSessionId,
+ if (sscanf(sd->msg, OKjob, &jcr->VolSessionId,
&jcr->VolSessionTime, &auth_key) != 3) {
- Dmsg1(100, "BadJob=%s\n", sd->msg);
- Jmsg(jcr, M_FATAL, 0, _("Storage daemon rejected Job command: %s\n"), sd->msg);
+ Dmsg1(100, "BadJob=%s\n", sd->msg);
+ Jmsg(jcr, M_FATAL, 0, _("Storage daemon rejected Job command: %s\n"), sd->msg);
return 0;
} else {
jcr->sd_auth_key = bstrdup(auth_key);
- Dmsg1(150, "sd_auth_key=%s\n", jcr->sd_auth_key);
+ Dmsg1(150, "sd_auth_key=%s\n", jcr->sd_auth_key);
}
} else {
Jmsg(jcr, M_FATAL, 0, _("<stored: bad response to Job command: %s\n"),
bash_spaces(media_type);
bash_spaces(pool_type);
bash_spaces(pool_name);
- bnet_fsend(sd, use_device, device_name.c_str(),
+ bnet_fsend(sd, use_device, device_name.c_str(),
media_type.c_str(), pool_name.c_str(), pool_type.c_str());
- Dmsg1(110, ">stored: %s", sd->msg);
- status = response(jcr, sd, OK_device, "Use Device", NO_DISPLAY);
+ Dmsg1(110, ">stored: %s", sd->msg);
+ status = response(jcr, sd, OK_device, "Use Device", NO_DISPLAY);
if (!status) {
pm_strcpy(pool_type, sd->msg); /* save message */
- Jmsg(jcr, M_FATAL, 0, _("\n"
- " Storage daemon didn't accept Device \"%s\" because:\n %s"),
+ Jmsg(jcr, M_FATAL, 0, _("\n"
+ " Storage daemon didn't accept Device \"%s\" because:\n %s"),
device_name.c_str(), pool_type.c_str()/* sd->msg */);
}
}
return status;
}
-/*
+/*
* Start a thread to handle Storage daemon messages and
* Catalog requests.
*/
Dmsg0(100, "Start SD msg_thread.\n");
if ((status=pthread_create(&thid, NULL, msg_thread, (void *)jcr)) != 0) {
Jmsg1(jcr, M_ABORT, 0, _("Cannot create message thread: %s\n"), strerror(status));
- }
+ }
Dmsg0(100, "SD msg_thread started.\n");
/* Wait for thread to start */
while (jcr->SD_msg_chan == 0) {
bmicrosleep(0, 50);
- }
+ }
return 1;
}
jcr->SDJobFiles = JobFiles;
jcr->SDJobBytes = JobBytes;
break;
- }
+ }
if (sscanf(sd->msg, Job_status, &Job, &JobStatus) == 2) {
jcr->SDJobStatus = JobStatus; /* current status */
continue;
}
}
- if (is_bnet_error(sd)) {
+ if (is_bnet_error(sd)) {
jcr->SDJobStatus = JS_ErrorTerminated;
}
pthread_cleanup_pop(1);
set_pool_dbr_defaults_in_media_dbr(mr, &pr);
jcr->VolumeName[0] = 0;
bstrncpy(mr->MediaType, jcr->store->media_type, sizeof(mr->MediaType));
- if (generate_event(jcr, "NewVolume") == 1 && jcr->VolumeName[0]) {
+ if (generate_event(jcr, "NewVolume") == 1 && jcr->VolumeName[0]) {
bstrncpy(mr->VolumeName, jcr->VolumeName, sizeof(mr->VolumeName));
/* Check for special characters */
} else if (is_volume_name_legal(NULL, pr.LabelFormat)) {
}
} else { /* try full substitution */
/* Found special characters, so try substitution */
- if (!perform_full_name_substitution(jcr, mr, &pr)) {
+ if (!perform_full_name_substitution(jcr, mr, &pr)) {
goto bail_out;
}
if (!is_volume_name_legal(NULL, mr->VolumeName)) {
- Jmsg(jcr, M_ERROR, 0, _("Illegal character in Volume name \"%s\"\n"),
+ Jmsg(jcr, M_ERROR, 0, _("Illegal character in Volume name \"%s\"\n"),
mr->VolumeName);
goto bail_out;
}
if (db_create_media_record(jcr, jcr->db, mr) &&
db_update_pool_record(jcr, jcr->db, &pr)) {
db_unlock(jcr->db);
- Jmsg(jcr, M_INFO, 0, _("Created new Volume \"%s\" in catalog.\n"), mr->VolumeName);
- Dmsg1(90, "Created new Volume=%s\n", mr->VolumeName);
+ Jmsg(jcr, M_INFO, 0, _("Created new Volume \"%s\" in catalog.\n"), mr->VolumeName);
+ Dmsg1(90, "Created new Volume=%s\n", mr->VolumeName);
return true;
} else {
- Jmsg(jcr, M_ERROR, 0, "%s", db_strerror(jcr->db));
+ Jmsg(jcr, M_ERROR, 0, "%s", db_strerror(jcr->db));
}
}
}
bstrncpy(tmr.VolumeName, name, sizeof(tmr.VolumeName));
bstrncat(tmr.VolumeName, num, sizeof(tmr.VolumeName));
if (db_get_media_record(jcr, jcr->db, &tmr)) {
- Jmsg(jcr, M_WARNING, 0,
- _("Wanted to create Volume \"%s\", but it already exists. Trying again.\n"),
+ Jmsg(jcr, M_WARNING, 0,
+ _("Wanted to create Volume \"%s\", but it already exists. Trying again.\n"),
tmr.VolumeName);
continue;
}
bstrncpy(mr->MediaType, store->media_type, sizeof(mr->MediaType));
Dmsg2(120, "CatReq FindMedia: Id=%d, MediaType=%s\n", mr->PoolId, mr->MediaType);
/*
- * If we are using an Autochanger, restrict Volume
- * search to the Autochanger on the first pass
+ * If we are using an Autochanger, restrict Volume
+ * search to the Autochanger on the first pass
*/
InChanger = store->autochanger;
/*
/*
* 1. Look for volume with "Append" status.
*/
- ok = db_find_next_volume(jcr, jcr->db, 1, InChanger, mr);
+ ok = db_find_next_volume(jcr, jcr->db, 1, InChanger, mr);
Dmsg2(100, "catreq after find_next_vol ok=%d FW=%d\n", ok, mr->FirstWritten);
if (!ok) {
/*
* 2. Try finding a recycled volume
*/
ok = find_recycled_volume(jcr, InChanger, mr);
- Dmsg2(100, "find_recycled_volume %d FW=%d\n", ok, mr->FirstWritten);
+ Dmsg2(100, "find_recycled_volume %d FW=%d\n", ok, mr->FirstWritten);
if (!ok) {
- /*
+ /*
* 3. Try recycling any purged volume
*/
ok = recycle_oldest_purged_volume(jcr, InChanger, mr);
/*
* 4. Try pruning Volumes
*/
- prune_volumes(jcr);
+ prune_volumes(jcr);
ok = recycle_oldest_purged_volume(jcr, InChanger, mr);
if (InChanger) {
InChanger = false;
continue; /* retry again accepting any volume */
}
}
- Dmsg2(200, "find_recycled_volume2 %d FW=%d\n", ok, mr->FirstWritten);
+ Dmsg2(200, "find_recycled_volume2 %d FW=%d\n", ok, mr->FirstWritten);
if (!ok && create) {
/*
- * 5. Try "creating" a new Volume
+ * 5. Try "creating" a new Volume
*/
ok = newVolume(jcr, mr);
}
}
}
- /*
+ /*
* Look at more drastic ways to find an Appendable Volume
- */
+ */
if (!ok && (jcr->pool->purge_oldest_volume ||
jcr->pool->recycle_oldest_volume)) {
- Dmsg2(200, "No next volume found. PurgeOldest=%d\n RecyleOldest=%d",
+ Dmsg2(200, "No next volume found. PurgeOldest=%d\n RecyleOldest=%d",
jcr->pool->purge_oldest_volume, jcr->pool->recycle_oldest_volume);
/* Find oldest volume to recycle */
ok = db_find_next_volume(jcr, jcr->db, -1, InChanger, mr);
- Dmsg1(400, "Find oldest=%d\n", ok);
+ Dmsg1(400, "Find oldest=%d\n", ok);
if (ok) {
UAContext *ua;
- Dmsg0(400, "Try purge.\n");
- /*
+ Dmsg0(400, "Try purge.\n");
+ /*
* 5. Try to purging oldest volume only if not UA calling us.
*/
ua = new_ua_context(jcr);
if (jcr->pool->purge_oldest_volume && create) {
- Jmsg(jcr, M_INFO, 0, _("Purging oldest volume \"%s\"\n"), mr->VolumeName);
+ Jmsg(jcr, M_INFO, 0, _("Purging oldest volume \"%s\"\n"), mr->VolumeName);
ok = purge_jobs_from_volume(ua, mr);
/*
* 5. or try recycling the oldest volume
*/
} else if (jcr->pool->recycle_oldest_volume) {
- Jmsg(jcr, M_INFO, 0, _("Pruning oldest volume \"%s\"\n"), mr->VolumeName);
+ Jmsg(jcr, M_INFO, 0, _("Pruning oldest volume \"%s\"\n"), mr->VolumeName);
ok = prune_volume(ua, mr);
}
free_ua_context(ua);
if (ok) {
ok = recycle_volume(jcr, mr);
- Dmsg1(400, "Recycle after purge oldest=%d\n", ok);
+ Dmsg1(400, "Recycle after purge oldest=%d\n", ok);
}
}
}
if (strcmp(mr->VolStatus, "Append") == 0 && mr->VolJobs > 0) {
/* First handle Max Volume Bytes */
if ((mr->MaxVolBytes > 0 && mr->VolBytes >= mr->MaxVolBytes)) {
- Jmsg(jcr, M_INFO, 0, _("Max Volume bytes exceeded. "
- "Marking Volume \"%s\" as Full.\n"), mr->VolumeName);
- bstrncpy(mr->VolStatus, "Full", sizeof(mr->VolStatus));
+ Jmsg(jcr, M_INFO, 0, _("Max Volume bytes exceeded. "
+ "Marking Volume \"%s\" as Full.\n"), mr->VolumeName);
+ bstrncpy(mr->VolStatus, "Full", sizeof(mr->VolStatus));
expired = true;
/* Now see if Volume should only be used once */
} else if (mr->VolBytes > 0 && jcr->pool->use_volume_once) {
- Jmsg(jcr, M_INFO, 0, _("Volume used once. "
- "Marking Volume \"%s\" as Used.\n"), mr->VolumeName);
- bstrncpy(mr->VolStatus, "Used", sizeof(mr->VolStatus));
+ Jmsg(jcr, M_INFO, 0, _("Volume used once. "
+ "Marking Volume \"%s\" as Used.\n"), mr->VolumeName);
+ bstrncpy(mr->VolStatus, "Used", sizeof(mr->VolStatus));
expired = true;
/* Now see if Max Jobs written to volume */
} else if (mr->MaxVolJobs > 0 && mr->MaxVolJobs <= mr->VolJobs) {
- Jmsg(jcr, M_INFO, 0, _("Max Volume jobs exceeded. "
- "Marking Volume \"%s\" as Used.\n"), mr->VolumeName);
- bstrncpy(mr->VolStatus, "Used", sizeof(mr->VolStatus));
+ Jmsg(jcr, M_INFO, 0, _("Max Volume jobs exceeded. "
+ "Marking Volume \"%s\" as Used.\n"), mr->VolumeName);
+ bstrncpy(mr->VolStatus, "Used", sizeof(mr->VolStatus));
expired = true;
/* Now see if Max Files written to volume */
} else if (mr->MaxVolFiles > 0 && mr->MaxVolFiles <= mr->VolFiles) {
- Jmsg(jcr, M_INFO, 0, _("Max Volume files exceeded. "
- "Marking Volume \"%s\" as Used.\n"), mr->VolumeName);
- bstrncpy(mr->VolStatus, "Used", sizeof(mr->VolStatus));
+ Jmsg(jcr, M_INFO, 0, _("Max Volume files exceeded. "
+ "Marking Volume \"%s\" as Used.\n"), mr->VolumeName);
+ bstrncpy(mr->VolStatus, "Used", sizeof(mr->VolStatus));
expired = true;
/* Finally, check Use duration expiration */
utime_t now = time(NULL);
/* See if Vol Use has expired */
if (mr->VolUseDuration <= (now - mr->FirstWritten)) {
- Jmsg(jcr, M_INFO, 0, _("Max configured use duration exceeded. "
- "Marking Volume \"%s\" as Used.\n"), mr->VolumeName);
- bstrncpy(mr->VolStatus, "Used", sizeof(mr->VolStatus));
+ Jmsg(jcr, M_INFO, 0, _("Max configured use duration exceeded. "
+ "Marking Volume \"%s\" as Used.\n"), mr->VolumeName);
+ bstrncpy(mr->VolStatus, "Used", sizeof(mr->VolStatus));
expired = true;
}
}
if (expired) {
/* Need to update media */
if (!db_update_media_record(jcr, jcr->db, mr)) {
- Jmsg(jcr, M_ERROR, 0, _("Catalog error updating volume \"%s\". ERR=%s"),
+ Jmsg(jcr, M_ERROR, 0, _("Catalog error updating volume \"%s\". ERR=%s"),
mr->VolumeName, db_strerror(jcr->db));
- }
- }
+ }
+ }
return expired;
}
*reason = NULL;
return;
}
-
+
/*
* Check if the Volume is already marked for recycling
*/
if (strcmp(mr->VolStatus, "Purged") == 0) {
if (recycle_volume(jcr, mr)) {
- Jmsg(jcr, M_INFO, 0, "Recycled current volume \"%s\"\n", mr->VolumeName);
+ Jmsg(jcr, M_INFO, 0, "Recycled current volume \"%s\"\n", mr->VolumeName);
*reason = NULL;
return;
} else {
- /* In principle this shouldn't happen */
- *reason = "and recycling of current volume failed";
+ /* In principle this shouldn't happen */
+ *reason = "and recycling of current volume failed";
return;
}
}
-
+
/* At this point, the volume is not valid for writing */
*reason = "but should be Append, Purged or Recycle";
-
+
/*
* What we're trying to do here is see if the current volume is
* "recyclable" - ie. if we prune all expired jobs off it, is
*/
if ((mr->LastWritten + mr->VolRetention) < (utime_t)time(NULL)
&& mr->Recycle && jcr->pool->recycle_current_volume
- && (strcmp(mr->VolStatus, "Full") == 0 ||
- strcmp(mr->VolStatus, "Used") == 0)) {
+ && (strcmp(mr->VolStatus, "Full") == 0 ||
+ strcmp(mr->VolStatus, "Used") == 0)) {
/*
* Attempt prune of current volume to see if we can
* recycle it for use.
*/
UAContext *ua;
-
+
ua = new_ua_context(jcr);
ok = prune_volume(ua, mr);
free_ua_context(ua);
-
+
if (ok) {
/* If fully purged, recycle current volume */
if (recycle_volume(jcr, mr)) {
- Jmsg(jcr, M_INFO, 0, "Recycled current volume \"%s\"\n", mr->VolumeName);
+ Jmsg(jcr, M_INFO, 0, "Recycled current volume \"%s\"\n", mr->VolumeName);
*reason = NULL;
} else {
- *reason = "but should be Append, Purged or Recycle (recycling of the "
- "current volume failed)";
+ *reason = "but should be Append, Purged or Recycle (recycling of the "
+ "current volume failed)";
}
} else {
- *reason = "but should be Append, Purged or Recycle (cannot automatically "
- "recycle current volume, as it still contains unpruned data)";
+ *reason = "but should be Append, Purged or Recycle (cannot automatically "
+ "recycle current volume, as it still contains unpruned data)";
}
}
}
extern int send_level_command(JCR *jcr);
extern int get_attributes_and_put_in_catalog(JCR *jcr);
extern int get_attributes_and_compare_to_catalog(JCR *jcr, JobId_t JobId);
-extern int put_file_into_catalog(JCR *jcr, long file_index, char *fname,
+extern int put_file_into_catalog(JCR *jcr, long file_index, char *fname,
char *link, char *attr, int stream);
extern void get_level_since_time(JCR *jcr, char *since, int since_len);
extern int send_run_before_and_after_commands(JCR *jcr);
extern void mount_request(JCR *jcr, BSOCK *bs, char *buf);
/* msgchan.c */
-extern bool connect_to_storage_daemon(JCR *jcr, int retry_interval,
+extern bool connect_to_storage_daemon(JCR *jcr, int retry_interval,
int max_retry_time, int verbose);
extern int start_storage_daemon_job(JCR *jcr);
extern int start_storage_daemon_message_thread(JCR *jcr);
int open_db(UAContext *ua);
void close_db(UAContext *ua);
enum e_pool_op {
- POOL_OP_UPDATE,
+ POOL_OP_UPDATE,
POOL_OP_CREATE
};
int create_pool(JCR *jcr, B_DB *db, POOL *pool, e_pool_op op);
void start_prompt(UAContext *ua, const char *msg);
void add_prompt(UAContext *ua, const char *prompt);
int do_prompt(UAContext *ua, const char *automsg, const char *msg, char *prompt, int max_prompt);
-CAT *get_catalog_resource(UAContext *ua);
+CAT *get_catalog_resource(UAContext *ua);
STORE *get_storage_resource(UAContext *ua, int use_default);
int get_media_type(UAContext *ua, char *MediaType, int max_media);
bool get_pool_dbr(UAContext *ua, POOL_DBR *pr);
/*
- *
+ *
* Bacula interface to Python for the Director
*
* Kern Sibbald, November MMIV
*/
/*
-
+
Copyright (C) 2004 Kern Sibbald
This program is free software; you can redistribute it and/or
PyMethodDef BaculaMethods[] = {
{"get", bacula_get, METH_VARARGS, "Get Bacula variables."},
{"set", (PyCFunction)bacula_set, METH_VARARGS|METH_KEYWORDS,
- "Set Bacula variables."},
+ "Set Bacula variables."},
{"run", (PyCFunction)bacula_run, METH_VARARGS, "Run a Bacula command."},
{NULL, NULL, 0, NULL} /* last item */
};
struct s_vars {
const char *name;
char *fmt;
-};
+};
static struct s_vars vars[] = {
{ N_("Job"), "s"},
{ N_("MediaType"), "s"},
{ N_("JobName"), "s"},
{ N_("JobStatus"), "s"},
-
+
{ NULL, NULL}
};
char *msg = NULL;
char *VolumeName = NULL;
static char *kwlist[] = {"jcr", "JobReport", "VolumeName", NULL};
- if (!PyArg_ParseTupleAndKeywords(args, keyw, "O|ss:set", kwlist,
+ if (!PyArg_ParseTupleAndKeywords(args, keyw, "O|ss:set", kwlist,
&CObject, &msg, &VolumeName)) {
return NULL;
}
struct s_oldest_ctx oldest;
POOLMEM *query = get_pool_memory(PM_EMSG);
const char *select =
- "SELECT MediaId,LastWritten FROM Media "
- "WHERE PoolId=%u AND Recycle=1 AND VolStatus='Purged' "
- "AND MediaType='%s' %s"
- "ORDER BY LastWritten ASC,MediaId LIMIT 1";
+ "SELECT MediaId,LastWritten FROM Media "
+ "WHERE PoolId=%u AND Recycle=1 AND VolStatus='Purged' "
+ "AND MediaType='%s' %s"
+ "ORDER BY LastWritten ASC,MediaId LIMIT 1";
Dmsg0(100, "Enter recycle_oldest_purged_volume\n");
oldest.MediaId = 0;
mr->MediaId = oldest.MediaId;
if (db_get_media_record(jcr, jcr->db, mr)) {
if (recycle_volume(jcr, mr)) {
- Jmsg(jcr, M_INFO, 0, "Recycled volume \"%s\"\n", mr->VolumeName);
- Dmsg1(100, "return 1 recycle_oldest_purged_volume Vol=%s\n", mr->VolumeName);
+ Jmsg(jcr, M_INFO, 0, "Recycled volume \"%s\"\n", mr->VolumeName);
+ Dmsg1(100, "return 1 recycle_oldest_purged_volume Vol=%s\n", mr->VolumeName);
return 1;
}
}
Jmsg(jcr, M_ERROR, 0, "%s", db_strerror(jcr->db));
}
Dmsg0(100, "return 0 recycle_oldest_purged_volume end\n");
- return 0;
+ return 0;
}
/*
*
* Kern Sibbald, November MM
*
- * This routine is run as a separate thread.
- *
+ * This routine is run as a separate thread.
+ *
* Current implementation is Catalog verification only (i.e. no
* verification versus tape).
*
/* Commands sent to File daemon */
static char restorecmd[] = "restore replace=%c prelinks=%d where=%s\n";
static char storaddr[] = "storage address=%s port=%d ssl=0\n";
-static char sessioncmd[] = "session %s %ld %ld %ld %ld %ld %ld\n";
+static char sessioncmd[] = "session %s %ld %ld %ld %ld %ld %ld\n";
/* Responses received from File daemon */
static char OKrestore[] = "2000 OK restore\n";
/* External functions */
-/*
+/*
* Do a restore of the specified files
- *
+ *
* Returns: 0 on failure
* 1 on success
*/
-int do_restore(JCR *jcr)
+int do_restore(JCR *jcr)
{
BSOCK *fd;
JOB_DBR rjr; /* restore job record */
Dmsg1(20, "RestoreJobId=%d\n", jcr->job->RestoreJobId);
- /*
+ /*
* The following code is kept temporarily for compatibility.
* It is the predecessor to the Bootstrap file.
* DEPRECATED
rjr.JobId = jcr->job->RestoreJobId; /* specified by Job Resource */
}
if (!db_get_job_record(jcr, jcr->db, &rjr)) {
- Jmsg2(jcr, M_FATAL, 0, _("Cannot get job record id=%d %s"), rjr.JobId,
+ Jmsg2(jcr, M_FATAL, 0, _("Cannot get job record id=%d %s"), rjr.JobId,
db_strerror(jcr->db));
restore_cleanup(jcr, JS_ErrorTerminated);
return 0;
jcr->VolumeName[0] = 0;
if (!db_get_job_volume_names(jcr, jcr->db, rjr.JobId, &jcr->VolumeName) ||
jcr->VolumeName[0] == 0) {
- Jmsg(jcr, M_FATAL, 0, _("Cannot find Volume names for restore Job %d. %s"),
+ Jmsg(jcr, M_FATAL, 0, _("Cannot find Volume names for restore Job %d. %s"),
rjr.JobId, db_strerror(jcr->db));
restore_cleanup(jcr, JS_ErrorTerminated);
return 0;
}
Dmsg1(20, "Got job Volume Names: %s\n", jcr->VolumeName);
}
-
+
/* Print Job Start message */
Jmsg(jcr, M_INFO, 0, _("Start Restore Job %s\n"), jcr->Job);
Dmsg0(10, "Open connection with storage daemon\n");
set_jcr_job_status(jcr, JS_WaitSD);
/*
- * Start conversation with Storage daemon
+ * Start conversation with Storage daemon
*/
if (!connect_to_storage_daemon(jcr, 10, SDConnectTimeout, 1)) {
restore_cleanup(jcr, JS_ErrorTerminated);
}
Dmsg0(50, "Storage daemon connection OK\n");
- /*
- * Start conversation with File daemon
+ /*
+ * Start conversation with File daemon
*/
set_jcr_job_status(jcr, JS_WaitFD);
if (!connect_to_file_daemon(jcr, 10, FDConnectTimeout, 1)) {
return 0;
}
- /*
+ /*
* send Storage daemon address to the File daemon,
* then wait for File daemon to make connection
* with Storage daemon.
return 0;
}
- /*
+ /*
* Send the bootstrap file -- what Volumes/files to restore
*/
if (!send_bootstrap_file(jcr)) {
return 0;
}
- /*
- * The following code is deprecated
+ /*
+ * The following code is deprecated
*/
if (!jcr->RestoreBootstrap) {
/*
* Pass the VolSessionId, VolSessionTime, Start and
* end File and Blocks on the session command.
*/
- bnet_fsend(fd, sessioncmd,
+ bnet_fsend(fd, sessioncmd,
jcr->VolumeName,
- rjr.VolSessionId, rjr.VolSessionTime,
- rjr.StartFile, rjr.EndFile, rjr.StartBlock,
+ rjr.VolSessionId, rjr.VolSessionTime,
+ rjr.StartFile, rjr.EndFile, rjr.StartBlock,
rjr.EndBlock);
if (!response(jcr, fd, OKsession, "Session", DISPLAY_ERROR)) {
restore_cleanup(jcr, JS_ErrorTerminated);
/* Send restore command */
char replace, *where;
char empty = '\0';
-
+
if (jcr->replace != 0) {
replace = jcr->replace;
} else if (jcr->job->replace != 0) {
switch (TermCode) {
case JS_Terminated:
if (jcr->ExpectedFiles > jcr->jr.JobFiles) {
- term_msg = _("Restore OK -- warning file count mismatch");
+ term_msg = _("Restore OK -- warning file count mismatch");
} else {
- term_msg = _("Restore OK");
+ term_msg = _("Restore OK");
}
break;
case JS_FatalError:
case JS_ErrorTerminated:
- term_msg = _("*** Restore Error ***");
+ term_msg = _("*** Restore Error ***");
msg_type = M_ERROR; /* Generate error message */
if (jcr->store_bsock) {
bnet_sig(jcr->store_bsock, BNET_TERMINATE);
jobstatus_to_ascii(jcr->FDJobStatus, fd_term_msg, sizeof(fd_term_msg));
jobstatus_to_ascii(jcr->SDJobStatus, sd_term_msg, sizeof(sd_term_msg));
- Jmsg(jcr, msg_type, 0, _("Bacula " VERSION " (" LSMDATE "): %s\n\
- JobId: %d\n\
- Job: %s\n\
- Client: %s\n\
- Start time: %s\n\
- End time: %s\n\
- Files Expected: %s\n\
- Files Restored: %s\n\
- Bytes Restored: %s\n\
- Rate: %.1f KB/s\n\
- FD Errors: %d\n\
- FD termination status: %s\n\
- SD termination status: %s\n\
- Termination: %s\n\n"),
+ Jmsg(jcr, msg_type, 0, _("Bacula " VERSION " (" LSMDATE "): %s\n"
+" JobId: %d\n"
+" Job: %s\n"
+" Client: %s\n"
+" Start time: %s\n"
+" End time: %s\n"
+" Files Expected: %s\n"
+" Files Restored: %s\n"
+" Bytes Restored: %s\n"
+" Rate: %.1f KB/s\n"
+" FD Errors: %d\n"
+" FD termination status: %s\n"
+" SD termination status: %s\n"
+" Termination: %s\n\n"),
edt,
jcr->jr.JobId,
jcr->jr.Job,
s_hourly,
s_wom, /* 1st, 2nd, ...*/
s_woy /* week of year w00 - w53 */
-};
+};
struct s_keyw {
const char *name; /* keyword */
{NULL, 0}
};
-/*
- * Store Schedule Run information
- *
+/*
+ * Store Schedule Run information
+ *
* Parse Run statement:
*
* Run <keyword=value ...> [on] 2 january at 23:45
*
* Default Run time is daily at 0:0
- *
+ *
* There can be multiple run statements, they are simply chained
* together.
*
bool found;
int token, state, state2 = 0, code = 0, code2 = 0;
int options = lc->options;
- RUN **run = (RUN **)(item->value);
+ RUN **run = (RUN **)(item->value);
RUN *trun;
char *p;
RES *res;
if (strcasecmp(lc->str, RunFields[i].name) == 0) {
found = true;
if (lex_get_token(lc, T_ALL) != T_EQUALS) {
- scan_err1(lc, "Expected an equals, got: %s", lc->str);
- /* NOT REACHED */
+ scan_err1(lc, "Expected an equals, got: %s", lc->str);
+ /* NOT REACHED */
}
switch (RunFields[i].token) {
- case 's': /* Data spooling */
+ case 's': /* Data spooling */
token = lex_get_token(lc, T_NAME);
- if (strcasecmp(lc->str, "yes") == 0) {
+ if (strcasecmp(lc->str, "yes") == 0) {
lrun.spool_data = true;
lrun.spool_data_set = true;
- } else if (strcasecmp(lc->str, "no") == 0) {
+ } else if (strcasecmp(lc->str, "no") == 0) {
lrun.spool_data = false;
lrun.spool_data_set = true;
} else {
- scan_err1(lc, _("Expect a YES or NO, got: %s"), lc->str);
+ scan_err1(lc, _("Expect a YES or NO, got: %s"), lc->str);
}
break;
- case 'L': /* level */
+ case 'L': /* level */
token = lex_get_token(lc, T_NAME);
for (j=0; joblevels[j].level_name; j++) {
if (strcasecmp(lc->str, joblevels[j].level_name) == 0) {
}
}
if (j != 0) {
- scan_err1(lc, _("Job level field: %s not found in run record"), lc->str);
+ scan_err1(lc, _("Job level field: %s not found in run record"), lc->str);
/* NOT REACHED */
}
break;
- case 'p': /* Priority */
+ case 'p': /* Priority */
token = lex_get_token(lc, T_PINT32);
if (pass == 2) {
lrun.Priority = lc->pint32_val;
}
break;
- case 'P': /* Pool */
- case 'f': /* FullPool */
- case 'i': /* IncPool */
- case 'd': /* DifPool */
+ case 'P': /* Pool */
+ case 'f': /* FullPool */
+ case 'i': /* IncPool */
+ case 'd': /* DifPool */
token = lex_get_token(lc, T_NAME);
if (pass == 2) {
res = GetResWithName(R_POOL, lc->str);
if (res == NULL) {
- scan_err1(lc, "Could not find specified Pool Resource: %s",
+ scan_err1(lc, "Could not find specified Pool Resource: %s",
lc->str);
/* NOT REACHED */
}
switch(RunFields[i].token) {
- case 'P':
+ case 'P':
lrun.pool = (POOL *)res;
break;
- case 'f':
+ case 'f':
lrun.full_pool = (POOL *)res;
break;
- case 'i':
+ case 'i':
lrun.inc_pool = (POOL *)res;
break;
- case 'd':
+ case 'd':
lrun.dif_pool = (POOL *)res;
break;
}
}
break;
- case 'S': /* storage */
+ case 'S': /* storage */
token = lex_get_token(lc, T_NAME);
if (pass == 2) {
res = GetResWithName(R_STORAGE, lc->str);
if (res == NULL) {
- scan_err1(lc, "Could not find specified Storage Resource: %s",
+ scan_err1(lc, "Could not find specified Storage Resource: %s",
lc->str);
/* NOT REACHED */
}
lrun.storage = (STORE *)res;
}
break;
- case 'M': /* messages */
+ case 'M': /* messages */
token = lex_get_token(lc, T_NAME);
if (pass == 2) {
res = GetResWithName(R_MSGS, lc->str);
if (res == NULL) {
- scan_err1(lc, "Could not find specified Messages Resource: %s",
+ scan_err1(lc, "Could not find specified Messages Resource: %s",
lc->str);
/* NOT REACHED */
}
}
break;
default:
- scan_err1(lc, "Expected a keyword name, got: %s", lc->str);
+ scan_err1(lc, "Expected a keyword name, got: %s", lc->str);
/* NOT REACHED */
break;
- } /* end switch */
+ } /* end switch */
} /* end if strcasecmp */
} /* end for RunFields */
state = s_mday;
code = atoi(lc->str) - 1;
if (code < 0 || code > 30) {
- scan_err0(lc, _("Day number out of range (1-31)"));
+ scan_err0(lc, _("Day number out of range (1-31)"));
}
break;
case T_NAME: /* this handles drop through from keyword */
case T_UNQUOTED_STRING:
- if (strchr(lc->str, (int)'-')) {
+ if (strchr(lc->str, (int)'-')) {
state = s_range;
break;
}
- if (strchr(lc->str, (int)':')) {
+ if (strchr(lc->str, (int)':')) {
state = s_time;
break;
}
- if (lc->str_len == 3 && (lc->str[0] == 'w' || lc->str[0] == 'W') &&
+ if (lc->str_len == 3 && (lc->str[0] == 'w' || lc->str[0] == 'W') &&
is_an_integer(lc->str+1)) {
code = atoi(lc->str+1);
if (code < 0 || code > 53) {
- scan_err0(lc, _("Week number out of range (0-53)"));
+ scan_err0(lc, _("Week number out of range (0-53)"));
}
state = s_woy; /* week of year */
break;
}
}
if (i != 0) {
- scan_err1(lc, _("Job type field: %s in run record not found"), lc->str);
+ scan_err1(lc, _("Job type field: %s in run record not found"), lc->str);
/* NOT REACHED */
}
break;
case T_COMMA:
continue;
default:
- scan_err2(lc, _("Unexpected token: %d:%s"), token, lc->str);
+ scan_err2(lc, _("Unexpected token: %d:%s"), token, lc->str);
/* NOT REACHED */
break;
}
break;
case s_time: /* time */
if (!have_at) {
- scan_err0(lc, _("Time must be preceded by keyword AT."));
+ scan_err0(lc, _("Time must be preceded by keyword AT."));
/* NOT REACHED */
}
if (!have_hour) {
clear_bits(0, 23, lrun.hour);
}
- p = strchr(lc->str, ':');
+ p = strchr(lc->str, ':');
if (!p) {
- scan_err0(lc, _("Time logic error.\n"));
+ scan_err0(lc, _("Time logic error.\n"));
/* NOT REACHED */
}
*p++ = 0; /* separate two halves */
code = atoi(lc->str);
len = strlen(p);
- if (len > 2 && p[len-1] == 'm') {
- if (p[len-2] == 'a') {
+ if (len > 2 && p[len-1] == 'm') {
+ if (p[len-2] == 'a') {
pm = 0;
- } else if (p[len-2] == 'p') {
+ } else if (p[len-2] == 'p') {
pm = 1;
} else {
- scan_err0(lc, _("Bad time specification."));
+ scan_err0(lc, _("Bad time specification."));
/* NOT REACHED */
}
} else {
code += 12;
}
if (code < 0 || code > 23 || code2 < 0 || code2 > 59) {
- scan_err0(lc, _("Bad time specification."));
+ scan_err0(lc, _("Bad time specification."));
/* NOT REACHED */
}
/****FIXME**** convert to UTC */
have_at = true;
break;
case s_range:
- p = strchr(lc->str, '-');
+ p = strchr(lc->str, '-');
if (!p) {
- scan_err0(lc, _("Range logic error.\n"));
+ scan_err0(lc, _("Range logic error.\n"));
}
*p++ = 0; /* separate two halves */
code = atoi(lc->str) - 1;
code2 = atoi(p) - 1;
if (code < 0 || code > 30 || code2 < 0 || code2 > 30) {
- scan_err0(lc, _("Bad day range specification."));
+ scan_err0(lc, _("Bad day range specification."));
}
if (!have_mday) {
clear_bits(0, 30, lrun.mday);
}
/* Check for week of year range */
if (strlen(lc->str) == 3 && strlen(p) == 3 &&
- (lc->str[0] == 'w' || lc->str[0] == 'W') &&
- (p[0] == 'w' || p[0] == 'W') &&
+ (lc->str[0] == 'w' || lc->str[0] == 'W') &&
+ (p[0] == 'w' || p[0] == 'W') &&
is_an_integer(lc->str+1) && is_an_integer(p+1)) {
code = atoi(lc->str+1);
code2 = atoi(p+1);
if (code < 0 || code > 53 || code2 < 0 || code2 > 53) {
- scan_err0(lc, _("Week number out of range (0-53)"));
+ scan_err0(lc, _("Week number out of range (0-53)"));
}
if (!have_woy) {
clear_bits(0, 53, lrun.woy);
}
}
if (i != 0 || (state != s_month && state != s_wday && state != s_wom)) {
- scan_err0(lc, _("Invalid month, week or position day range"));
+ scan_err0(lc, _("Invalid month, week or position day range"));
/* NOT REACHED */
}
}
}
if (i != 0 || state != state2 || code == code2) {
- scan_err0(lc, _("Invalid month, weekday or position range"));
+ scan_err0(lc, _("Invalid month, weekday or position range"));
/* NOT REACHED */
}
if (state == s_wday) {
set_bits(code, 4, lrun.wom);
set_bits(0, code2, lrun.wom);
}
- }
+ }
break;
case s_hourly:
have_hour = true;
set_bits(0, 11, lrun.month);
break;
default:
- scan_err0(lc, _("Unexpected run state\n"));
+ scan_err0(lc, _("Unexpected run state\n"));
/* NOT REACHED */
break;
}
}
/* Allocate run record, copy new stuff into it,
- * and link it into the list of run records
+ * and link it into the list of run records
* in the schedule resource.
*/
if (pass == 2) {
*
* Bacula scheduler
* It looks at what jobs are to be run and when
- * and waits around until it is time to
+ * and waits around until it is time to
* fire them up.
*
* Kern Sibbald, May MM, major revision December MMIII
/* Local variables */
-struct job_item {
+struct job_item {
RUN *run;
JOB *job;
time_t runtime;
int Priority;
dlink link; /* link for list */
-};
+};
/* List of jobs to be run. They were scheduled in this hour or the next */
static dlist *jobs_to_run; /* list of jobs to be run */
if (one_shot_job_to_run) { /* one shot */
job = (JOB *)GetResWithName(R_JOB, one_shot_job_to_run);
if (!job) {
- Emsg1(M_ABORT, 0, _("Job %s not found\n"), one_shot_job_to_run);
+ Emsg1(M_ABORT, 0, _("Job %s not found\n"), one_shot_job_to_run);
}
- Dmsg1(5, "Found one_shot_job_to_run %s\n", one_shot_job_to_run);
+ Dmsg1(5, "Found one_shot_job_to_run %s\n", one_shot_job_to_run);
jcr = new_jcr(sizeof(JCR), dird_free_jcr);
set_jcr_defaults(jcr, job);
return jcr;
dump_job(je, "Walk queue");
}
#endif
- /*
+ /*
* Pull the first job to run (already sorted by runtime and
* Priority, then wait around until it is time to run it.
*/
/*
- * Shutdown the scheduler
+ * Shutdown the scheduler
*/
void term_scheduler()
{
}
}
-/*
+/*
* Find all jobs to be run this hour and the next hour.
*/
static void find_runs()
Dmsg0(200, "enter find_runs()\n");
-
+
/* compute values for time now */
now = time(NULL);
localtime_r(&now, &tm);
wom = mday / 7;
woy = tm_woy(now); /* get week of year */
- /*
+ /*
* Compute values for next hour from now.
* We do this to be sure we don't miss a job while
* sleeping.
*/
- next_hour = now + 3600;
+ next_hour = now + 3600;
localtime_r(&next_hour, &tm);
nh_hour = tm.tm_hour;
nh_mday = tm.tm_mday - 1;
Dmsg1(200, "Got job: %s\n", job->hdr.name);
for (run=sched->run; run; run=run->next) {
bool run_now, run_nh;
- /*
+ /*
* Find runs scheduled between now and the next hour.
*/
#ifdef xxxx
- Dmsg0(000, "\n");
- Dmsg6(000, "run h=%d m=%d md=%d wd=%d wom=%d woy=%d\n",
+ Dmsg0(000, "\n");
+ Dmsg6(000, "run h=%d m=%d md=%d wd=%d wom=%d woy=%d\n",
hour, month, mday, wday, wom, woy);
- Dmsg6(000, "bitset bsh=%d bsm=%d bsmd=%d bswd=%d bswom=%d bswoy=%d\n",
+ Dmsg6(000, "bitset bsh=%d bsm=%d bsmd=%d bswd=%d bswom=%d bswoy=%d\n",
bit_is_set(hour, run->hour),
bit_is_set(month, run->month),
bit_is_set(mday, run->mday),
bit_is_set(wom, run->wom),
bit_is_set(woy, run->woy));
- Dmsg6(000, "nh_run h=%d m=%d md=%d wd=%d wom=%d woy=%d\n",
+ Dmsg6(000, "nh_run h=%d m=%d md=%d wd=%d wom=%d woy=%d\n",
nh_hour, nh_month, nh_mday, nh_wday, nh_wom, nh_woy);
- Dmsg6(000, "nh_bitset bsh=%d bsm=%d bsmd=%d bswd=%d bswom=%d bswoy=%d\n",
+ Dmsg6(000, "nh_bitset bsh=%d bsm=%d bsmd=%d bswd=%d bswom=%d bswoy=%d\n",
bit_is_set(nh_hour, run->hour),
bit_is_set(nh_month, run->month),
bit_is_set(nh_mday, run->mday),
#endif
run_now = bit_is_set(hour, run->hour) &&
- bit_is_set(mday, run->mday) &&
+ bit_is_set(mday, run->mday) &&
bit_is_set(wday, run->wday) &&
bit_is_set(month, run->month) &&
bit_is_set(wom, run->wom) &&
bit_is_set(woy, run->woy);
run_nh = bit_is_set(nh_hour, run->hour) &&
- bit_is_set(nh_mday, run->mday) &&
+ bit_is_set(nh_mday, run->mday) &&
bit_is_set(nh_wday, run->wday) &&
bit_is_set(nh_month, run->month) &&
bit_is_set(nh_wom, run->wom) &&
bit_is_set(nh_woy, run->woy);
- Dmsg2(200, "run_now=%d run_nh=%d\n", run_now, run_nh);
+ Dmsg2(200, "run_now=%d run_nh=%d\n", run_now, run_nh);
/* find time (time_t) job is to be run */
localtime_r(&now, &tm); /* reset tm structure */
runtime = mktime(&tm);
add_job(job, run, now, runtime);
}
- }
+ }
}
UnlockRes();
Dmsg0(200, "Leave find_runs()\n");
if (((runtime - run->last_run) < 61) || ((runtime+59) < now)) {
#ifdef SCHED_DEBUG
char dt[50], dt1[50], dt2[50];
- bstrftime_nc(dt, sizeof(dt), runtime);
+ bstrftime_nc(dt, sizeof(dt), runtime);
bstrftime_nc(dt1, sizeof(dt1), run->last_run);
bstrftime_nc(dt2, sizeof(dt2), now);
- Dmsg4(000, "Drop: Job=\"%s\" run=%s. last_run=%s. now=%s\n", job->hdr.name,
+ Dmsg4(000, "Drop: Job=\"%s\" run=%s. last_run=%s. now=%s\n", job->hdr.name,
dt, dt1, dt2);
fflush(stdout);
#endif
/* Add this job to the wait queue in runtime, priority sorted order */
foreach_dlist(ji, jobs_to_run) {
- if (ji->runtime > je->runtime ||
+ if (ji->runtime > je->runtime ||
(ji->runtime == je->runtime && ji->Priority > je->Priority)) {
jobs_to_run->insert_before(je, ji);
- dump_job(je, "Inserted job");
+ dump_job(je, "Inserted job");
inserted = true;
break;
}
#endif
}
-static void dump_job(job_item *ji, const char *msg)
+static void dump_job(job_item *ji, const char *msg)
{
#ifdef SCHED_DEBUG
char dt[MAX_TIME_LENGTH];
if (debug_level < 200) {
return;
}
- bstrftime_nc(dt, sizeof(dt), ji->runtime);
- Dmsg4(200, "%s: Job=%s priority=%d run %s\n", msg, ji->job->hdr.name,
+ bstrftime_nc(dt, sizeof(dt), ji->runtime);
+ Dmsg4(200, "%s: Job=%s priority=%d run %s\n", msg, ji->job->hdr.name,
ji->Priority, dt);
fflush(stdout);
debug_level = save_debug;
const char *upd_Purged = "UPDATE Job Set PurgedFiles=1 WHERE JobId=%u";
const char *cnt_DelCand = "SELECT count(*) FROM DelCandidates";
const char *del_Job = "DELETE FROM Job WHERE JobId=%u";
-const char *del_JobMedia = "DELETE FROM JobMedia WHERE JobId=%u";
+const char *del_JobMedia = "DELETE FROM JobMedia WHERE JobId=%u";
const char *cnt_JobMedia = "SELECT count(*) FROM JobMedia WHERE MediaId=%u";
const char *sel_JobMedia = "SELECT JobId FROM JobMedia WHERE MediaId=%u";
/* Select JobIds for File deletion. */
const char *select_job =
- "SELECT JobId from Job "
+ "SELECT JobId from Job "
"WHERE JobTDate<%s "
"AND ClientId=%u "
"AND PurgedFiles=0";
/* Fill candidates table with all Jobs subject to being deleted.
* This is used for pruning Jobs (first the files, then the Jobs).
*/
-const char *insert_delcand =
+const char *insert_delcand =
"INSERT INTO DelCandidates "
"SELECT JobId,PurgedFiles,FileSetId,JobFiles,JobStatus FROM Job "
"WHERE Type='%c' "
- "AND JobTDate<%s "
+ "AND JobTDate<%s "
"AND ClientId=%u";
/* Select Jobs from the DelCandidates table that have a
"FROM Job,DelCandidates "
"WHERE (Job.JobTdate<%s AND delCandidates.JobStatus!='T') OR "
"(Job.JobTDate>%s "
- "AND Job.ClientId=%u "
+ "AND Job.ClientId=%u "
"AND Job.Type='R')";
/* Select Jobs from the DelCandidates table.
"FROM Job,DelCandidates "
"WHERE (Job.JobTdate<%s AND delCandidates.JobStatus!='T') OR "
"(Job.JobTDate>%s "
- "AND Job.ClientId=%u "
+ "AND Job.ClientId=%u "
"AND Job.Type='D')";
"SELECT JobFiles FROM Job WHERE JobId=%u";
/* List last 20 Jobs */
-const char *uar_list_jobs =
+const char *uar_list_jobs =
"SELECT JobId,Client.Name as Client,StartTime,Level as "
"JobLevel,JobFiles,JobBytes "
"FROM Client,Job WHERE Client.ClientId=Job.ClientId AND JobStatus='T' "
#ifdef HAVE_MYSQL
/* MYSQL IS NOT STANDARD SQL !!!!! */
/* List Jobs where a particular file is saved */
-const char *uar_file =
+const char *uar_file =
"SELECT Job.JobId as JobId, Client.Name as Client, "
"CONCAT(Path.Path,Filename.Name) as Name, "
"StartTime,Type as JobType,JobFiles,JobBytes "
"AND Filename.Name='%s' ORDER BY StartTime DESC LIMIT 20";
#else
/* List Jobs where a particular file is saved */
-const char *uar_file =
+const char *uar_file =
"SELECT Job.JobId as JobId, Client.Name as Client, "
"Path.Path||Filename.Name as Name, "
"StartTime,Type as JobType,JobFiles,JobBytes "
* Find all files for a particular JobId and insert them into
* the tree during a restore.
*/
-const char *uar_sel_files =
+const char *uar_sel_files =
"SELECT Path.Path,Filename.Name,FileIndex,JobId,LStat "
"FROM File,Filename,Path "
"WHERE File.JobId=%u AND Filename.FilenameId=File.FilenameId "
const char *uar_del_temp = "DROP TABLE temp";
const char *uar_del_temp1 = "DROP TABLE temp1";
-const char *uar_create_temp =
+const char *uar_create_temp =
"CREATE TABLE temp ("
#ifdef HAVE_POSTGRESQL
"JobId INTEGER NOT NULL,"
"VolSessionTime INTEGER UNSIGNED)";
#endif
-const char *uar_create_temp1 =
+const char *uar_create_temp1 =
"CREATE TABLE temp1 ("
#ifdef HAVE_POSTGRESQL
"JobId INTEGER NOT NULL,"
"%s"
"ORDER BY Job.JobTDate DESC LIMIT 1";
-const char *uar_full =
- "INSERT INTO temp SELECT Job.JobId,Job.JobTDate,"
+const char *uar_full =
+ "INSERT INTO temp SELECT Job.JobId,Job.JobTDate,"
" Job.ClientId,Job.Level,Job.JobFiles,"
" StartTime,VolumeName,JobMedia.StartFile,VolSessionId,VolSessionTime "
"FROM temp1,Job,JobMedia,Media WHERE temp1.JobId=Job.JobId "
"AND JobMedia.JobId=Job.JobId "
"AND JobMedia.MediaId=Media.MediaId";
-const char *uar_dif =
+const char *uar_dif =
"INSERT INTO temp SELECT Job.JobId,Job.JobTDate,Job.ClientId,"
"Job.Level,Job.JobFiles,Job.StartTime,Media.VolumeName,JobMedia.StartFile,"
"Job.VolSessionId,Job.VolSessionTime "
"AND Job.Level='D' AND JobStatus='T' "
"AND Job.FileSetId=FileSet.FileSetId "
"AND FileSet.FileSet='%s' "
- "%s"
+ "%s"
"ORDER BY Job.JobTDate DESC LIMIT 1";
const char *uar_inc =
"AND FileSet.FileSet='%s' "
"%s";
-const char *uar_list_temp =
+const char *uar_list_temp =
"SELECT JobId,Level,JobFiles,StartTime,VolumeName,StartFile,"
"VolSessionId,VolSessionTime FROM temp "
"ORDER BY StartTime ASC";
/* Select FileSet names for this Client */
-const char *uar_sel_fileset =
+const char *uar_sel_fileset =
"SELECT DISTINCT FileSet.FileSet FROM Job,"
"Client,FileSet WHERE Job.FileSetId=FileSet.FileSetId "
"AND Job.ClientId=%u AND Client.ClientId=%u "
"SELECT MediaType FROM JobMedia,Media WHERE JobMedia.JobId=%u "
"AND JobMedia.MediaId=Media.MediaId";
-/*
- * Find JobId, FileIndex for a given path/file and date
+/*
+ * Find JobId, FileIndex for a given path/file and date
* for use when inserting individual files into the tree.
*/
-const char *uar_jobid_fileindex =
+const char *uar_jobid_fileindex =
"SELECT Job.JobId, File.FileIndex FROM Job,File,Path,Filename,Client "
"WHERE Job.JobId=File.JobId "
"AND Job.StartTime<'%s' "
"AND Filename.FilenameId=File.FilenameId "
"ORDER BY Job.StartTime DESC LIMIT 1";
-const char *uar_jobids_fileindex =
+const char *uar_jobids_fileindex =
"SELECT Job.JobId, File.FileIndex FROM Job,File,Path,Filename,Client "
"WHERE Job.JobId IN (%s) "
"AND Job.JobId=File.JobId "
bool batch; /* set for non-interactive mode */
uint32_t pint32_val; /* positive integer */
int32_t int32_val; /* positive/negative */
-};
+};
/* Context for insert_tree_handler() */
struct TREE_CTX {
*
* Bacula Director -- User Agent Access Control List (ACL) handling
*
- * Kern Sibbald, January MMIV
+ * Kern Sibbald, January MMIV
*
* Version $Id$
*/
#include "bacula.h"
#include "dird.h"
-/*
- * Check if access is permitted to item in acl
+/*
+ * Check if access is permitted to item in acl
*/
bool acl_access_ok(UAContext *ua, int acl, char *item)
{
/* Search list for item */
for (int i=0; i<list->size(); i++) {
if (strncasecmp(item, (char *)list->get(i), len) == 0) {
- Dmsg3(400, "Found %s in %d %s\n", item, acl, (char *)list->get(i));
+ Dmsg3(400, "Found %s in %d %s\n", item, acl, (char *)list->get(i));
return true;
}
}
extern int update_slots(UAContext *ua); /* ua_label.c */
/* Forward referenced functions */
-static int add_cmd(UAContext *ua, const char *cmd);
-static int create_cmd(UAContext *ua, const char *cmd);
-static int cancel_cmd(UAContext *ua, const char *cmd);
+static int add_cmd(UAContext *ua, const char *cmd);
+static int create_cmd(UAContext *ua, const char *cmd);
+static int cancel_cmd(UAContext *ua, const char *cmd);
static int setdebug_cmd(UAContext *ua, const char *cmd);
static int trace_cmd(UAContext *ua, const char *cmd);
static int var_cmd(UAContext *ua, const char *cmd);
int quit_cmd(UAContext *ua, const char *cmd);
-struct cmdstruct { const char *key; int (*func)(UAContext *ua, const char *cmd); const char *help; };
+struct cmdstruct { const char *key; int (*func)(UAContext *ua, const char *cmd); const char *help; };
static struct cmdstruct commands[] = {
{ N_("add"), add_cmd, _("add media to a pool")},
{ N_("autodisplay"), autodisplay_cmd, _("autodisplay [on/off] -- console messages")},
{ N_("automount"), automount_cmd, _("automount [on/off] -- after label")},
{ N_("cancel"), cancel_cmd, _("cancel job=nnn -- cancel a job")},
- { N_("create"), create_cmd, _("create DB Pool from resource")},
- { N_("delete"), delete_cmd, _("delete [pool=<pool-name> | media volume=<volume-name>]")},
+ { N_("create"), create_cmd, _("create DB Pool from resource")},
+ { N_("delete"), delete_cmd, _("delete [pool=<pool-name> | media volume=<volume-name>]")},
{ N_("estimate"), estimate_cmd, _("performs FileSet estimate, listing gives full listing")},
{ N_("exit"), quit_cmd, _("exit = quit")},
{ N_("gui"), gui_cmd, _("gui [on/off] -- non-interactive gui mode")},
{ N_("setdebug"), setdebug_cmd, _("sets debug level")},
{ N_("setip"), setip_cmd, _("sets new client address -- if authorized")},
{ N_("show"), show_cmd, _("show (resource records) [jobs | pools | ... | all]")},
- { N_("sqlquery"), sqlquerycmd, _("use SQL to query catalog")},
+ { N_("sqlquery"), sqlquerycmd, _("use SQL to query catalog")},
{ N_("time"), time_cmd, _("print current time")},
{ N_("trace"), trace_cmd, _("turn on/off trace to file")},
{ N_("unmount"), unmount_cmd, _("unmount <storage-name>")},
/*
* This is a common routine used to stuff the Pool DB record defaults
- * into the Media DB record just before creating a media (Volume)
+ * into the Media DB record just before creating a media (Volume)
* record.
*/
void set_pool_dbr_defaults_in_media_dbr(MEDIA_DBR *mr, POOL_DBR *pr)
/*
* Add Volumes to an existing Pool
*/
-static int add_cmd(UAContext *ua, const char *cmd)
+static int add_cmd(UAContext *ua, const char *cmd)
{
POOL_DBR pr;
MEDIA_DBR mr;
while (pr.MaxVols > 0 && pr.NumVols >= pr.MaxVols) {
bsendmsg(ua, _("Pool already has maximum volumes = %d\n"), pr.MaxVols);
for (;;) {
- if (!get_pint(ua, _("Enter new maximum (zero for unlimited): "))) {
+ if (!get_pint(ua, _("Enter new maximum (zero for unlimited): "))) {
return 1;
}
pr.MaxVols = ua->pint32_val;
} else if (!get_media_type(ua, mr.MediaType, sizeof(mr.MediaType))) {
return 1;
}
-
+
if (pr.MaxVols == 0) {
max = 1000;
} else {
max = pr.MaxVols - pr.NumVols;
}
for (;;) {
- char buf[100];
+ char buf[100];
bsnprintf(buf, sizeof(buf), _("Enter number of Volumes to create. 0=>fixed name. Max=%d: "), max);
if (!get_pint(ua, buf)) {
return 1;
}
num = ua->pint32_val;
if (num < 0 || num > max) {
- bsendmsg(ua, _("The number must be between 0 and %d\n"), max);
+ bsendmsg(ua, _("The number must be between 0 and %d\n"), max);
continue;
}
break;
strcat(name, "%04d");
for (;;) {
- if (!get_pint(ua, _("Enter the starting number: "))) {
+ if (!get_pint(ua, _("Enter the starting number: "))) {
return 1;
}
startnum = ua->pint32_val;
if (startnum < 1) {
- bsendmsg(ua, _("Start number must be greater than zero.\n"));
+ bsendmsg(ua, _("Start number must be greater than zero.\n"));
continue;
}
break;
}
InChanger = ua->pint32_val;
}
-
+
set_pool_dbr_defaults_in_media_dbr(&mr, &pr);
- for (i=startnum; i < num+startnum; i++) {
+ for (i=startnum; i < num+startnum; i++) {
bsnprintf(mr.VolumeName, sizeof(mr.VolumeName), name, i);
mr.Slot = Slot++;
mr.InChanger = InChanger;
Dmsg1(200, "Create Volume %s\n", mr.VolumeName);
if (!db_create_media_record(ua->jcr, ua->db, &mr)) {
- bsendmsg(ua, "%s", db_strerror(ua->db));
+ bsendmsg(ua, "%s", db_strerror(ua->db));
return 1;
}
if (i == startnum) {
}
}
pr.NumVols += num;
- Dmsg0(200, "Update pool record.\n");
+ Dmsg0(200, "Update pool record.\n");
if (db_update_pool_record(ua->jcr, ua->db, &pr) != 1) {
bsendmsg(ua, "%s", db_strerror(ua->db));
return 1;
}
/*
- * Turn auto mount on/off
- *
- * automount on
+ * Turn auto mount on/off
+ *
+ * automount on
* automount off
*/
int automount_cmd(UAContext *ua, const char *cmd)
}
ua->automount = (strcasecmp(onoff, _("off")) == 0) ? 0 : 1;
- return 1;
+ return 1;
}
}
JobId = str_to_int64(ua->argv[i]);
if (!(jcr=get_jcr_by_id(JobId))) {
- bsendmsg(ua, _("JobId %d is not running.\n"), JobId);
+ bsendmsg(ua, _("JobId %d is not running.\n"), JobId);
return 1;
}
break;
break;
}
if (!(jcr=get_jcr_by_partial_name(ua->argv[i]))) {
- bsendmsg(ua, _("Job %s is not running.\n"), ua->argv[i]);
+ bsendmsg(ua, _("Job %s is not running.\n"), ua->argv[i]);
return 1;
}
break;
unlock_jcr_chain();
if (njobs == 0) {
- bsendmsg(ua, _("No Jobs running.\n"));
+ bsendmsg(ua, _("No Jobs running.\n"));
return 1;
}
start_prompt(ua, _("Select Job:\n"));
return 1;
}
if (njobs == 1) {
- if (!get_yesno(ua, _("Confirm cancel (yes/no): ")) || ua->pint32_val == 0) {
+ if (!get_yesno(ua, _("Confirm cancel (yes/no): ")) || ua->pint32_val == 0) {
return 1;
}
}
/* NOTE! This increments the ref_count */
jcr = get_jcr_by_full_name(JobName);
if (!jcr) {
- bsendmsg(ua, _("Job %s not found.\n"), JobName);
+ bsendmsg(ua, _("Job %s not found.\n"), JobName);
return 1;
}
}
* Create a Pool Record in the database.
* It is always created from the Resource record.
*/
-static int create_cmd(UAContext *ua, const char *cmd)
+static int create_cmd(UAContext *ua, const char *cmd)
{
POOL *pool;
switch (create_pool(ua->jcr, ua->db, pool, POOL_OP_CREATE)) {
case 0:
bsendmsg(ua, _("Error: Pool %s already exists.\n"
- "Use update to change it.\n"), pool->hdr.name);
+ "Use update to change it.\n"), pool->hdr.name);
break;
case -1:
if (strcasecmp(ua->argk[1], _("restart")) == 0) {
term_python_interpreter();
init_python_interpreter(director->hdr.name, director->scripts_directory ?
- director->scripts_directory : ".");
+ director->scripts_directory : ".");
bsendmsg(ua, _("Python interpreter restarted.\n"));
} else {
bsendmsg(ua, _("Nothing done.\n"));
/*
* Set a new address in a Client resource. We do this only
- * if the Console name is the same as the Client name
+ * if the Console name is the same as the Client name
* and the Console can access the client.
*/
-static int setip_cmd(UAContext *ua, const char *cmd)
+static int setip_cmd(UAContext *ua, const char *cmd)
{
CLIENT *client;
- char buf[1024];
+ char buf[1024];
if (!ua->cons || !acl_access_ok(ua, Client_ACL, ua->cons->hdr.name)) {
bsendmsg(ua, _("Illegal command from this console.\n"));
return 1;
free(client->address);
}
/* MA Bug 6 remove ifdef */
- sockaddr_to_ascii(&(ua->UA_sock->client_addr), buf, sizeof(buf));
+ sockaddr_to_ascii(&(ua->UA_sock->client_addr), buf, sizeof(buf));
client->address = bstrdup(buf);
bsendmsg(ua, _("Client \"%s\" address set to %s\n"),
client->hdr.name, client->address);
* update slots [scan=...]
* updates autochanger slots
*/
-static int update_cmd(UAContext *ua, const char *cmd)
+static int update_cmd(UAContext *ua, const char *cmd)
{
static const char *kw[] = {
N_("media"), /* 0 */
default:
break;
}
-
+
start_prompt(ua, _("Update choice:\n"));
add_prompt(ua, _("Volume parameters"));
add_prompt(ua, _("Pool from resource"));
"Archive",
"Disabled",
"Full",
- "Used",
- "Cleaning",
+ "Used",
+ "Cleaning",
"Recycle",
"Read-Only",
NULL};
bstrncpy(mr->VolStatus, kw[i], sizeof(mr->VolStatus));
Mmsg(query, "UPDATE Media SET VolStatus='%s' WHERE MediaId=%u",
mr->VolStatus, mr->MediaId);
- if (!db_sql_query(ua->db, query, NULL, NULL)) {
- bsendmsg(ua, "%s", db_strerror(ua->db));
+ if (!db_sql_query(ua->db, query, NULL, NULL)) {
+ bsendmsg(ua, "%s", db_strerror(ua->db));
} else {
- bsendmsg(ua, _("New Volume status is: %s\n"), mr->VolStatus);
+ bsendmsg(ua, _("New Volume status is: %s\n"), mr->VolStatus);
}
}
free_pool_memory(query);
query = get_pool_memory(PM_MESSAGE);
Mmsg(query, "UPDATE Media SET VolRetention=%s WHERE MediaId=%u",
edit_uint64(mr->VolRetention, ed1), mr->MediaId);
- if (!db_sql_query(ua->db, query, NULL, NULL)) {
+ if (!db_sql_query(ua->db, query, NULL, NULL)) {
bsendmsg(ua, "%s", db_strerror(ua->db));
} else {
bsendmsg(ua, _("New retention period is: %s\n"),
query = get_pool_memory(PM_MESSAGE);
Mmsg(query, "UPDATE Media SET VolUseDuration=%s WHERE MediaId=%u",
edit_uint64(mr->VolUseDuration, ed1), mr->MediaId);
- if (!db_sql_query(ua->db, query, NULL, NULL)) {
+ if (!db_sql_query(ua->db, query, NULL, NULL)) {
bsendmsg(ua, "%s", db_strerror(ua->db));
} else {
bsendmsg(ua, _("New use duration is: %s\n"),
POOLMEM *query = get_pool_memory(PM_MESSAGE);
Mmsg(query, "UPDATE Media SET MaxVolJobs=%s WHERE MediaId=%u",
val, mr->MediaId);
- if (!db_sql_query(ua->db, query, NULL, NULL)) {
+ if (!db_sql_query(ua->db, query, NULL, NULL)) {
bsendmsg(ua, "%s", db_strerror(ua->db));
} else {
bsendmsg(ua, _("New max jobs is: %s\n"), val);
POOLMEM *query = get_pool_memory(PM_MESSAGE);
Mmsg(query, "UPDATE Media SET MaxVolFiles=%s WHERE MediaId=%u",
val, mr->MediaId);
- if (!db_sql_query(ua->db, query, NULL, NULL)) {
+ if (!db_sql_query(ua->db, query, NULL, NULL)) {
bsendmsg(ua, "%s", db_strerror(ua->db));
} else {
bsendmsg(ua, _("New max files is: %s\n"), val);
if (!size_to_uint64(val, strlen(val), &maxbytes)) {
bsendmsg(ua, _("Invalid max. bytes specification: %s\n"), val);
return;
- }
+ }
query = get_pool_memory(PM_MESSAGE);
Mmsg(query, "UPDATE Media SET MaxVolBytes=%s WHERE MediaId=%u",
edit_uint64(maxbytes, ed1), mr->MediaId);
- if (!db_sql_query(ua->db, query, NULL, NULL)) {
+ if (!db_sql_query(ua->db, query, NULL, NULL)) {
bsendmsg(ua, "%s", db_strerror(ua->db));
} else {
bsendmsg(ua, _("New Max bytes is: %s\n"), edit_uint64(maxbytes, ed1));
query = get_pool_memory(PM_MESSAGE);
Mmsg(query, "UPDATE Media SET Recycle=%d WHERE MediaId=%u",
recycle, mr->MediaId);
- if (!db_sql_query(ua->db, query, NULL, NULL)) {
+ if (!db_sql_query(ua->db, query, NULL, NULL)) {
bsendmsg(ua, "%s", db_strerror(ua->db));
- } else {
+ } else {
bsendmsg(ua, _("New Recycle flag is: %s\n"),
- mr->Recycle==1?_("yes"):_("no"));
+ mr->Recycle==1?_("yes"):_("no"));
}
free_pool_memory(query);
}
db_lock(ua->db);
Mmsg(query, "UPDATE Media SET PoolId=%d WHERE MediaId=%u",
mr->PoolId, mr->MediaId);
- if (!db_sql_query(ua->db, query, NULL, NULL)) {
+ if (!db_sql_query(ua->db, query, NULL, NULL)) {
bsendmsg(ua, "%s", db_strerror(ua->db));
- } else {
+ } else {
bsendmsg(ua, _("New Pool is: %s\n"), pr.Name);
opr->NumVols--;
if (!db_update_pool_record(ua->jcr, ua->db, opr)) {
- bsendmsg(ua, "%s", db_strerror(ua->db));
+ bsendmsg(ua, "%s", db_strerror(ua->db));
}
pr.NumVols++;
if (!db_update_pool_record(ua->jcr, ua->db, &pr)) {
- bsendmsg(ua, "%s", db_strerror(ua->db));
+ bsendmsg(ua, "%s", db_strerror(ua->db));
}
db_make_inchanger_unique(ua->jcr, ua->db, mr);
}
* Volume status. E.g. if you want Bacula to stop
* writing on the volume, set it to anything other
* than Append.
- */
+ */
static int update_volume(UAContext *ua)
{
MEDIA_DBR mr;
memset(&pr, 0, sizeof(POOL_DBR));
pr.PoolId = mr.PoolId;
if (!db_get_pool_record(ua->jcr, ua->db, &pr)) {
- bsendmsg(ua, "%s", db_strerror(ua->db));
+ bsendmsg(ua, "%s", db_strerror(ua->db));
break;
}
update_vol_pool(ua, ua->argv[j], &mr, &pr);
switch (do_prompt(ua, "", _("Select parameter to modify"), NULL, 0)) {
case 0: /* Volume Status */
/* Modify Volume Status */
- bsendmsg(ua, _("Current Volume status is: %s\n"), mr.VolStatus);
- start_prompt(ua, _("Possible Values are:\n"));
- add_prompt(ua, "Append"); /* Better not translate these as */
- add_prompt(ua, "Archive"); /* They are known in the database code */
- add_prompt(ua, "Disabled");
- add_prompt(ua, "Full");
- add_prompt(ua, "Used");
- add_prompt(ua, "Cleaning");
- if (strcmp(mr.VolStatus, "Purged") == 0) {
- add_prompt(ua, "Recycle");
+ bsendmsg(ua, _("Current Volume status is: %s\n"), mr.VolStatus);
+ start_prompt(ua, _("Possible Values are:\n"));
+ add_prompt(ua, "Append"); /* Better not translate these as */
+ add_prompt(ua, "Archive"); /* They are known in the database code */
+ add_prompt(ua, "Disabled");
+ add_prompt(ua, "Full");
+ add_prompt(ua, "Used");
+ add_prompt(ua, "Cleaning");
+ if (strcmp(mr.VolStatus, "Purged") == 0) {
+ add_prompt(ua, "Recycle");
}
- add_prompt(ua, "Read-Only");
- if (do_prompt(ua, "", _("Choose new Volume Status"), ua->cmd, sizeof(mr.VolStatus)) < 0) {
+ add_prompt(ua, "Read-Only");
+ if (do_prompt(ua, "", _("Choose new Volume Status"), ua->cmd, sizeof(mr.VolStatus)) < 0) {
return 1;
}
update_volstatus(ua, ua->cmd, &mr);
break;
case 1: /* Retention */
- bsendmsg(ua, _("Current retention period is: %s\n"),
+ bsendmsg(ua, _("Current retention period is: %s\n"),
edit_utime(mr.VolRetention, ed1, sizeof(ed1)));
- if (!get_cmd(ua, _("Enter Volume Retention period: "))) {
+ if (!get_cmd(ua, _("Enter Volume Retention period: "))) {
return 0;
}
update_volretention(ua, ua->cmd, &mr);
break;
case 2: /* Use Duration */
- bsendmsg(ua, _("Current use duration is: %s\n"),
+ bsendmsg(ua, _("Current use duration is: %s\n"),
edit_utime(mr.VolUseDuration, ed1, sizeof(ed1)));
- if (!get_cmd(ua, _("Enter Volume Use Duration: "))) {
+ if (!get_cmd(ua, _("Enter Volume Use Duration: "))) {
return 0;
}
update_voluseduration(ua, ua->cmd, &mr);
break;
case 3: /* Max Jobs */
- bsendmsg(ua, _("Current max jobs is: %u\n"), mr.MaxVolJobs);
- if (!get_pint(ua, _("Enter new Maximum Jobs: "))) {
+ bsendmsg(ua, _("Current max jobs is: %u\n"), mr.MaxVolJobs);
+ if (!get_pint(ua, _("Enter new Maximum Jobs: "))) {
return 0;
}
update_volmaxjobs(ua, ua->cmd, &mr);
break;
case 4: /* Max Files */
- bsendmsg(ua, _("Current max files is: %u\n"), mr.MaxVolFiles);
- if (!get_pint(ua, _("Enter new Maximum Files: "))) {
+ bsendmsg(ua, _("Current max files is: %u\n"), mr.MaxVolFiles);
+ if (!get_pint(ua, _("Enter new Maximum Files: "))) {
return 0;
}
update_volmaxfiles(ua, ua->cmd, &mr);
break;
case 5: /* Max Bytes */
- bsendmsg(ua, _("Current value is: %s\n"), edit_uint64(mr.MaxVolBytes, ed1));
- if (!get_cmd(ua, _("Enter new Maximum Bytes: "))) {
+ bsendmsg(ua, _("Current value is: %s\n"), edit_uint64(mr.MaxVolBytes, ed1));
+ if (!get_cmd(ua, _("Enter new Maximum Bytes: "))) {
return 0;
}
update_volmaxbytes(ua, ua->cmd, &mr);
case 6: /* Recycle */
- bsendmsg(ua, _("Current recycle flag is: %s\n"),
- mr.Recycle==1?_("yes"):_("no"));
- if (!get_yesno(ua, _("Enter new Recycle status: "))) {
+ bsendmsg(ua, _("Current recycle flag is: %s\n"),
+ mr.Recycle==1?_("yes"):_("no"));
+ if (!get_yesno(ua, _("Enter new Recycle status: "))) {
return 0;
}
update_volrecycle(ua, ua->cmd, &mr);
memset(&pr, 0, sizeof(POOL_DBR));
pr.PoolId = mr.PoolId;
if (!db_get_pool_record(ua->jcr, ua->db, &pr)) {
- bsendmsg(ua, "%s", db_strerror(ua->db));
+ bsendmsg(ua, "%s", db_strerror(ua->db));
return 0;
}
- bsendmsg(ua, _("Current Slot is: %d\n"), mr.Slot);
- if (!get_pint(ua, _("Enter new Slot: "))) {
+ bsendmsg(ua, _("Current Slot is: %d\n"), mr.Slot);
+ if (!get_pint(ua, _("Enter new Slot: "))) {
return 0;
}
Slot = ua->pint32_val;
if (pr.MaxVols > 0 && Slot > (int)pr.MaxVols) {
- bsendmsg(ua, _("Invalid slot, it must be between 0 and %d\n"),
+ bsendmsg(ua, _("Invalid slot, it must be between 0 and %d\n"),
pr.MaxVols);
break;
}
mr.Slot = Slot;
/*
* Make sure to use db_update... rather than doing this directly,
- * so that any Slot is handled correctly.
+ * so that any Slot is handled correctly.
*/
if (!db_update_media_record(ua->jcr, ua->db, &mr)) {
- bsendmsg(ua, _("Error updating media record Slot: ERR=%s"), db_strerror(ua->db));
+ bsendmsg(ua, _("Error updating media record Slot: ERR=%s"), db_strerror(ua->db));
} else {
- bsendmsg(ua, _("New Slot is: %d\n"), mr.Slot);
+ bsendmsg(ua, _("New Slot is: %d\n"), mr.Slot);
}
break;
case 8: /* InChanger */
- bsendmsg(ua, _("Current InChanger flag is: %d\n"), mr.InChanger);
- if (!get_yesno(ua, _("Set InChanger flag? yes/no: "))) {
+ bsendmsg(ua, _("Current InChanger flag is: %d\n"), mr.InChanger);
+ if (!get_yesno(ua, _("Set InChanger flag? yes/no: "))) {
return 0;
}
mr.InChanger = ua->pint32_val;
/*
* Make sure to use db_update... rather than doing this directly,
- * so that any Slot is handled correctly.
+ * so that any Slot is handled correctly.
*/
if (!db_update_media_record(ua->jcr, ua->db, &mr)) {
- bsendmsg(ua, _("Error updating media record Slot: ERR=%s"), db_strerror(ua->db));
+ bsendmsg(ua, _("Error updating media record Slot: ERR=%s"), db_strerror(ua->db));
} else {
- bsendmsg(ua, _("New InChanger flag is: %d\n"), mr.InChanger);
+ bsendmsg(ua, _("New InChanger flag is: %d\n"), mr.InChanger);
}
break;
case 9: /* Volume Files */
int32_t VolFiles;
- bsendmsg(ua, _("Warning changing Volume Files can result\n"
- "in loss of data on your Volume\n\n"));
- bsendmsg(ua, _("Current Volume Files is: %u\n"), mr.VolFiles);
- if (!get_pint(ua, _("Enter new number of Files for Volume: "))) {
+ bsendmsg(ua, _("Warning changing Volume Files can result\n"
+ "in loss of data on your Volume\n\n"));
+ bsendmsg(ua, _("Current Volume Files is: %u\n"), mr.VolFiles);
+ if (!get_pint(ua, _("Enter new number of Files for Volume: "))) {
return 0;
}
VolFiles = ua->pint32_val;
if (VolFiles != (int)(mr.VolFiles + 1)) {
- bsendmsg(ua, _("Normally, you should only increase Volume Files by one!\n"));
- if (!get_yesno(ua, _("Continue? (yes/no): ")) || ua->pint32_val == 0) {
+ bsendmsg(ua, _("Normally, you should only increase Volume Files by one!\n"));
+ if (!get_yesno(ua, _("Continue? (yes/no): ")) || ua->pint32_val == 0) {
break;
}
}
query = get_pool_memory(PM_MESSAGE);
- Mmsg(query, "UPDATE Media SET VolFiles=%u WHERE MediaId=%u",
+ Mmsg(query, "UPDATE Media SET VolFiles=%u WHERE MediaId=%u",
VolFiles, mr.MediaId);
- if (!db_sql_query(ua->db, query, NULL, NULL)) {
- bsendmsg(ua, "%s", db_strerror(ua->db));
+ if (!db_sql_query(ua->db, query, NULL, NULL)) {
+ bsendmsg(ua, "%s", db_strerror(ua->db));
} else {
- bsendmsg(ua, _("New Volume Files is: %u\n"), VolFiles);
+ bsendmsg(ua, _("New Volume Files is: %u\n"), VolFiles);
}
free_pool_memory(query);
break;
memset(&pr, 0, sizeof(POOL_DBR));
pr.PoolId = mr.PoolId;
if (!db_get_pool_record(ua->jcr, ua->db, &pr)) {
- bsendmsg(ua, "%s", db_strerror(ua->db));
+ bsendmsg(ua, "%s", db_strerror(ua->db));
return 0;
}
- bsendmsg(ua, _("Current Pool is: %s\n"), pr.Name);
- if (!get_cmd(ua, _("Enter new Pool name: "))) {
+ bsendmsg(ua, _("Current Pool is: %s\n"), pr.Name);
+ if (!get_cmd(ua, _("Enter new Pool name: "))) {
return 0;
}
update_vol_pool(ua, ua->cmd, &mr, &pr);
update_all_vols_from_pool(ua);
return 1;
default: /* Done or error */
- bsendmsg(ua, "Selection done.\n");
+ bsendmsg(ua, "Selection done.\n");
return 1;
}
}
return 1;
}
-/*
+/*
* Update pool record -- pull info from current POOL resource
*/
static int update_pool(UAContext *ua)
POOL_DBR pr;
int id;
POOL *pool;
- POOLMEM *query;
-
+ POOLMEM *query;
+
pool = get_pool_resource(ua);
if (!pool) {
return 0;
set_storage(jcr, store);
/* Try connecting for up to 15 seconds */
- bsendmsg(ua, _("Connecting to Storage daemon %s at %s:%d\n"),
+ bsendmsg(ua, _("Connecting to Storage daemon %s at %s:%d\n"),
store->hdr.name, store->address, store->SDport);
if (!connect_to_storage_daemon(jcr, 1, 15, 0)) {
bsendmsg(ua, _("Failed to connect to Storage daemon.\n"));
bnet_sig(sd, BNET_TERMINATE);
bnet_close(sd);
jcr->store_bsock = NULL;
- return;
+ return;
}
-
+
static void do_client_setdebug(UAContext *ua, CLIENT *client, int level, int trace_flag)
{
BSOCK *fd;
ua->jcr->client = client;
/* Try to connect for 15 seconds */
- bsendmsg(ua, _("Connecting to Client %s at %s:%d\n"),
+ bsendmsg(ua, _("Connecting to Client %s at %s:%d\n"),
client->hdr.name, client->address, client->FDport);
if (!connect_to_file_daemon(ua->jcr, 1, 15, 0)) {
bsendmsg(ua, _("Failed to connect to Client.\n"));
bnet_sig(fd, BNET_TERMINATE);
bnet_close(fd);
ua->jcr->file_bsock = NULL;
- return;
+ return;
}
i++;
}
unique_store = (STORE **) malloc(i * sizeof(STORE));
- /* Find Unique Storage address/port */
+ /* Find Unique Storage address/port */
store = (STORE *)GetNextRes(R_STORAGE, NULL);
i = 0;
unique_store[i++] = store;
}
if (!found) {
unique_store[i++] = store;
- Dmsg2(140, "Stuffing: %s:%d\n", store->address, store->SDport);
+ Dmsg2(140, "Stuffing: %s:%d\n", store->address, store->SDport);
}
}
UnlockRes();
i++;
}
unique_client = (CLIENT **) malloc(i * sizeof(CLIENT));
- /* Find Unique Client address/port */
+ /* Find Unique Client address/port */
client = (CLIENT *)GetNextRes(R_CLIENT, NULL);
i = 0;
unique_client[i++] = client;
}
if (!found) {
unique_client[i++] = client;
- Dmsg2(140, "Stuffing: %s:%d\n", client->address, client->FDport);
+ Dmsg2(140, "Stuffing: %s:%d\n", client->address, client->FDport);
}
}
UnlockRes();
return 1;
}
if (strcasecmp(ua->argk[i], _("dir")) == 0 ||
- strcasecmp(ua->argk[i], _("director")) == 0) {
+ strcasecmp(ua->argk[i], _("director")) == 0) {
debug_level = level;
set_trace(trace_flag);
return 1;
}
if (strcasecmp(ua->argk[i], _("client")) == 0 ||
- strcasecmp(ua->argk[i], _("fd")) == 0) {
+ strcasecmp(ua->argk[i], _("fd")) == 0) {
client = NULL;
if (ua->argv[i]) {
client = (CLIENT *)GetResWithName(R_CLIENT, ua->argv[i]);
return 1;
}
}
- client = select_client_resource(ua);
+ client = select_client_resource(ua);
if (client) {
do_client_setdebug(ua, client, level, trace_flag);
return 1;
}
if (strcasecmp(ua->argk[i], _("store")) == 0 ||
- strcasecmp(ua->argk[i], _("storage")) == 0 ||
- strcasecmp(ua->argk[i], _("sd")) == 0) {
+ strcasecmp(ua->argk[i], _("storage")) == 0 ||
+ strcasecmp(ua->argk[i], _("sd")) == 0) {
store = NULL;
if (ua->argv[i]) {
store = (STORE *)GetResWithName(R_STORAGE, ua->argv[i]);
return 1;
}
}
- }
+ }
/*
* We didn't find an appropriate keyword above, so
* prompt the user.
}
set_trace((strcasecmp(onoff, _("off")) == 0) ? false : true);
- return 1;
+ return 1;
}
var++;
}
Dmsg1(100, "Var=%s:\n", var);
- variable_expansion(ua->jcr, var, &val);
+ variable_expansion(ua->jcr, var, &val);
bsendmsg(ua, "%s\n", val);
free_pool_memory(val);
return 1;
jcr->JobLevel = L_FULL;
for (int i=1; i<ua->argc; i++) {
if (strcasecmp(ua->argk[i], _("client")) == 0 ||
- strcasecmp(ua->argk[i], _("fd")) == 0) {
+ strcasecmp(ua->argk[i], _("fd")) == 0) {
if (ua->argv[i]) {
client = (CLIENT *)GetResWithName(R_CLIENT, ua->argv[i]);
continue;
}
if (strcasecmp(ua->argk[i], _("level")) == 0) {
if (!get_level_from_name(ua->jcr, ua->argv[i])) {
- bsendmsg(ua, _("Level %s not valid.\n"), ua->argv[i]);
+ bsendmsg(ua, _("Level %s not valid.\n"), ua->argv[i]);
}
continue;
}
- }
+ }
if (!job && !(client && fileset)) {
if (!(job = select_job_resource(ua))) {
return 1;
if (!job) {
job = (JOB *)GetResWithName(R_JOB, ua->argk[1]);
if (!job) {
- bsendmsg(ua, _("No job specified.\n"));
+ bsendmsg(ua, _("No job specified.\n"));
return 1;
}
}
if (!get_or_create_fileset_record(jcr, &fsr)) {
return 1;
}
-
+
get_level_since_time(ua->jcr, since, sizeof(since));
bsendmsg(ua, _("Connecting to Client %s at %s:%d\n"),
static int reload_cmd(UAContext *ua, const char *cmd)
{
- reload_config(1);
+ reload_config(1);
return 1;
}
return 1;
}
- switch (find_arg_keyword(ua, keywords)) {
+ switch (find_arg_keyword(ua, keywords)) {
case 0:
- delete_volume(ua);
+ delete_volume(ua);
return 1;
case 1:
delete_pool(ua);
* delete_job has been modified to parse JobID lists like the
* following:
* delete job JobID=3,4,6,7-11,14
- *
+ *
* Thanks to Phil Stracchino for the above addition.
*/
s = bstrdup(ua->argv[i]);
tok = s;
/*
- * We could use strtok() here. But we're not going to, because:
+ * We could use strtok() here. But we're not going to, because:
* (a) strtok() is deprecated, having been replaced by strsep();
* (b) strtok() is broken in significant ways.
- * we could use strsep() instead, but it's not universally available.
+ * we could use strsep() instead, but it's not universally available.
* so we grow our own using strchr().
*/
- sep = strchr(tok, ',');
+ sep = strchr(tok, ',');
while (sep != NULL) {
- *sep = '\0';
- if (strchr(tok, '-')) {
+ *sep = '\0';
+ if (strchr(tok, '-')) {
delete_job_id_range(ua, tok);
} else {
JobId = str_to_int64(tok);
do_job_delete(ua, JobId);
}
tok = ++sep;
- sep = strchr(tok, ',');
+ sep = strchr(tok, ',');
}
/* pick up the last token */
- if (strchr(tok, '-')) {
+ if (strchr(tok, '-')) {
delete_job_id_range(ua, tok);
} else {
JobId = str_to_int64(tok);
do_job_delete(ua, JobId);
}
-
+
free(s);
} else {
JobId = str_to_int64(ua->argv[i]);
}
/*
- * Delete media records from database -- dangerous
+ * Delete media records from database -- dangerous
*/
static int delete_volume(UAContext *ua)
{
}
/*
- * Delete a pool record from the database -- dangerous
+ * Delete a pool record from the database -- dangerous
*/
static int delete_pool(UAContext *ua)
{
POOL_DBR pr;
-
+
memset(&pr, 0, sizeof(pr));
if (!get_pool_dbr(ua, &pr)) {
return 1;
}
-int quit_cmd(UAContext *ua, const char *cmd)
+int quit_cmd(UAContext *ua, const char *cmd)
{
ua->quit = TRUE;
return 1;
}
/*
- * Wait until no job is running
+ * Wait until no job is running
*/
-int wait_cmd(UAContext *ua, const char *cmd)
+int wait_cmd(UAContext *ua, const char *cmd)
{
JCR *jcr;
bmicrosleep(0, 200000); /* let job actually start */
LockRes();
ua->catalog = (CAT *)GetNextRes(R_CATALOG, NULL);
UnlockRes();
- if (!ua->catalog) {
- bsendmsg(ua, _("Could not find a Catalog resource\n"));
+ if (!ua->catalog) {
+ bsendmsg(ua, _("Could not find a Catalog resource\n"));
return 0;
} else {
- bsendmsg(ua, _("Using default Catalog name=%s DB=%s\n"),
+ bsendmsg(ua, _("Using default Catalog name=%s DB=%s\n"),
ua->catalog->hdr.name, ua->catalog->db_name);
}
}
bsendmsg(ua, _("Could not open database \"%s\".\n"),
ua->catalog->db_name);
if (ua->db) {
- bsendmsg(ua, "%s", db_strerror(ua->db));
+ bsendmsg(ua, "%s", db_strerror(ua->db));
}
close_db(ua);
return 0;
static int backupscmd(UAContext *ua, const char *cmd);
static int levelscmd(UAContext *ua, const char *cmd);
-struct cmdstruct { const char *key; int (*func)(UAContext *ua, const char *cmd); const char *help; };
+struct cmdstruct { const char *key; int (*func)(UAContext *ua, const char *cmd); const char *help; };
static struct cmdstruct commands[] = {
{ N_(".die"), diecmd, NULL},
{ N_(".jobs"), jobscmd, NULL},
{ N_(".messages"), qmessagescmd, NULL},
{ N_(".help"), qhelp_cmd, NULL},
{ N_(".quit"), quit_cmd, NULL},
- { N_(".exit"), quit_cmd, NULL}
+ { N_(".exit"), quit_cmd, NULL}
};
#define comsize (sizeof(commands)/sizeof(struct cmdstruct))
int do_a_dot_command(UAContext *ua, const char *cmd)
{
int i;
- int len, stat;
+ int len, stat;
bool found = false;
stat = 1;
}
/*
- * Create segmentation fault
+ * Create segmentation fault
*/
static int diecmd(UAContext *ua, const char *cmd)
{
JCR *jcr = NULL;
int a;
-
+
bsendmsg(ua, "The Director will segment fault.\n");
a = jcr->JobId; /* ref NULL pointer */
jcr->JobId = 1000; /* another ref NULL pointer */
*/
static int defaultscmd(UAContext *ua, const char *cmd)
{
- JOB *job;
+ JOB *job;
if (ua->argc == 2 && strcmp(ua->argk[1], "job") == 0) {
job = (JOB *)GetResWithName(R_JOB, ua->argv[1]);
if (job) {
STORE *store;
- bsendmsg(ua, "job=%s", job->hdr.name);
- bsendmsg(ua, "pool=%s", job->pool->hdr.name);
- bsendmsg(ua, "messages=%s", job->messages->hdr.name);
- bsendmsg(ua, "client=%s", job->client->hdr.name);
+ bsendmsg(ua, "job=%s", job->hdr.name);
+ bsendmsg(ua, "pool=%s", job->pool->hdr.name);
+ bsendmsg(ua, "messages=%s", job->messages->hdr.name);
+ bsendmsg(ua, "client=%s", job->client->hdr.name);
store = (STORE *)job->storage[0]->first();
- bsendmsg(ua, "storage=%s", store->hdr.name);
- bsendmsg(ua, "where=%s", job->RestoreWhere?job->RestoreWhere:"");
- bsendmsg(ua, "level=%s", level_to_str(job->JobLevel));
- bsendmsg(ua, "type=%s", job_type_to_str(job->JobType));
- bsendmsg(ua, "fileset=%s", job->fileset->hdr.name);
+ bsendmsg(ua, "storage=%s", store->hdr.name);
+ bsendmsg(ua, "where=%s", job->RestoreWhere?job->RestoreWhere:"");
+ bsendmsg(ua, "level=%s", level_to_str(job->JobLevel));
+ bsendmsg(ua, "type=%s", job_type_to_str(job->JobType));
+ bsendmsg(ua, "fileset=%s", job->fileset->hdr.name);
}
}
return 1;
return 1;
}
-/*
+/*
* Get a positive integer
* Returns: 0 if failure
* 1 if success => value in ua->pint32_val
return 0;
}
if (!is_a_number(ua->cmd)) {
- bsendmsg(ua, "Expected a positive integer, got: %s\n", ua->cmd);
+ bsendmsg(ua, "Expected a positive integer, got: %s\n", ua->cmd);
continue;
}
errno = 0;
dval = strtod(ua->cmd, NULL);
if (errno != 0 || dval < 0) {
- bsendmsg(ua, "Expected a positive integer, got: %s\n", ua->cmd);
+ bsendmsg(ua, "Expected a positive integer, got: %s\n", ua->cmd);
continue;
}
ua->pint32_val = (uint32_t)dval;
}
}
-/*
+/*
* Gets a yes or no response
* Returns: 0 if failure
* 1 if success => ua->pint32_val == 1 for yes
bsendmsg(ua, _("Invalid response. You must answer yes or no.\n"));
}
}
-
+
void parse_ua_args(UAContext *ua)
{
/* Forward referenced functions */
static int do_label(UAContext *ua, const char *cmd, int relabel);
static void label_from_barcodes(UAContext *ua);
-static bool send_label_request(UAContext *ua, MEDIA_DBR *mr, MEDIA_DBR *omr,
+static bool send_label_request(UAContext *ua, MEDIA_DBR *mr, MEDIA_DBR *omr,
POOL_DBR *pr, int relabel, bool media_record_exits);
static vol_list_t *get_vol_list_from_SD(UAContext *ua, bool scan);
static void free_vol_list(vol_list_t *vol_list);
/*
- * Label a tape
- *
+ * Label a tape
+ *
* label storage=xxx volume=vvv
*/
int label_cmd(UAContext *ua, const char *cmd)
strip_trailing_junk(ua->argv[i]);
for (p=ua->argv[i]; p && *p; p=e) {
/* Check for list */
- e = strchr(p, ',');
+ e = strchr(p, ',');
if (e) {
*e++ = 0;
}
/* Check for range */
- h = strchr(p, '-'); /* range? */
+ h = strchr(p, '-'); /* range? */
if (h == p) {
- msg = _("Negative numbers not permitted\n");
+ msg = _("Negative numbers not permitted\n");
goto bail_out;
}
if (h) {
*h++ = 0;
if (!is_an_integer(h)) {
- msg = _("Range end is not integer.\n");
+ msg = _("Range end is not integer.\n");
goto bail_out;
}
skip_spaces(&p);
if (!is_an_integer(p)) {
- msg = _("Range start is not an integer.\n");
+ msg = _("Range start is not an integer.\n");
goto bail_out;
}
beg = atoi(p);
end = atoi(h);
if (end < beg) {
- msg = _("Range end not bigger than start.\n");
+ msg = _("Range end not bigger than start.\n");
goto bail_out;
}
} else {
skip_spaces(&p);
if (!is_an_integer(p)) {
- msg = _("Input value is not an integer.\n");
+ msg = _("Input value is not an integer.\n");
goto bail_out;
}
beg = end = atoi(p);
}
if (beg <= 0 || end <= 0) {
- msg = _("Values must be be greater than zero.\n");
+ msg = _("Values must be be greater than zero.\n");
goto bail_out;
}
if (end >= num_slots) {
- msg = _("Slot too large.\n");
+ msg = _("Slot too large.\n");
goto bail_out;
}
for (i=beg; i<=end; i++) {
slot_list[i] = 1; /* Turn on specified range */
}
}
- } else {
+ } else {
/* Turn everything on */
for (i=0; i<num_slots; i++) {
slot_list[i] = 1;
printf("Slots turned on:\n");
for (i=1; i<num_slots; i++) {
if (slot_list[i]) {
- printf("%d\n", i);
+ printf("%d\n", i);
}
}
#endif
}
/*
- * Update Slots corresponding to Volumes in autochanger
+ * Update Slots corresponding to Volumes in autochanger
*/
int update_slots(UAContext *ua)
{
vol_list_t *vl, *vol_list = NULL;
MEDIA_DBR mr;
char *slot_list;
- bool scan;
+ bool scan;
if (!open_db(ua)) {
return 1;
/* Walk through the list updating the media records */
for (vl=vol_list; vl; vl=vl->next) {
if (vl->Slot >= max_slots) {
- bsendmsg(ua, _("Slot %d larger than max %d ignored.\n"));
+ bsendmsg(ua, _("Slot %d larger than max %d ignored.\n"));
continue;
}
/* Check if user wants us to look at this slot */
if (!slot_list[vl->Slot]) {
- Dmsg1(100, "Skipping slot=%d\n", vl->Slot);
+ Dmsg1(100, "Skipping slot=%d\n", vl->Slot);
continue;
}
/* If scanning, we read the label rather than the barcode */
vl->VolName = NULL;
}
vl->VolName = get_volume_name_from_SD(ua, vl->Slot);
- Dmsg2(100, "Got Vol=%s from SD for Slot=%d\n", vl->VolName, vl->Slot);
+ Dmsg2(100, "Got Vol=%s from SD for Slot=%d\n", vl->VolName, vl->Slot);
}
slot_list[vl->Slot] = 0; /* clear Slot */
if (!vl->VolName) {
- Dmsg1(100, "No VolName for Slot=%d setting InChanger to zero.\n", vl->Slot);
+ Dmsg1(100, "No VolName for Slot=%d setting InChanger to zero.\n", vl->Slot);
memset(&mr, 0, sizeof(mr));
mr.Slot = vl->Slot;
mr.InChanger = 1;
db_lock(ua->db);
db_make_inchanger_unique(ua->jcr, ua->db, &mr);
db_unlock(ua->db);
- bsendmsg(ua, _("No VolName for Slot=%d set InChanger to zero.\n"), vl->Slot);
+ bsendmsg(ua, _("No VolName for Slot=%d set InChanger to zero.\n"), vl->Slot);
continue;
}
memset(&mr, 0, sizeof(mr));
mr.Slot = vl->Slot;
mr.InChanger = 1;
if (!db_update_media_record(ua->jcr, ua->db, &mr)) {
- bsendmsg(ua, "%s", db_strerror(ua->db));
+ bsendmsg(ua, "%s", db_strerror(ua->db));
} else {
bsendmsg(ua, _(
- "Catalog record for Volume \"%s\" updated to reference slot %d.\n"),
+ "Catalog record for Volume \"%s\" updated to reference slot %d.\n"),
mr.VolumeName, mr.Slot);
}
} else {
- bsendmsg(ua, _("Catalog record for Volume \"%s\" is up to date.\n"),
+ bsendmsg(ua, _("Catalog record for Volume \"%s\" is up to date.\n"),
mr.VolumeName);
- }
+ }
db_unlock(ua->db);
continue;
} else {
- bsendmsg(ua, _("Record for Volume \"%s\" not found in catalog.\n"),
+ bsendmsg(ua, _("Record for Volume \"%s\" not found in catalog.\n"),
mr.VolumeName);
}
db_unlock(ua->db);
}
}
db_unlock(ua->db);
-
+
bail_out:
free_vol_list(vol_list);
/* If relabel get name of Volume to relabel */
if (relabel) {
/* Check for oldvolume=name */
- i = find_arg_with_value(ua, "oldvolume");
+ i = find_arg_with_value(ua, "oldvolume");
if (i >= 0) {
memset(&omr, 0, sizeof(omr));
bstrncpy(omr.VolumeName, ua->argv[i], sizeof(omr.VolumeName));
if (db_get_media_record(ua->jcr, ua->db, &omr)) {
goto checkVol;
- }
- bsendmsg(ua, "%s", db_strerror(ua->db));
+ }
+ bsendmsg(ua, "%s", db_strerror(ua->db));
}
/* No keyword or Vol not found, ask user to select */
if (!select_media_dbr(ua, &omr)) {
/* Require Volume to be Purged or Recycled */
checkVol:
if (strcmp(omr.VolStatus, "Purged") != 0 && strcmp(omr.VolStatus, "Recycle") != 0) {
- bsendmsg(ua, _("Volume \"%s\" has VolStatus %s. It must be Purged or Recycled before relabeling.\n"),
+ bsendmsg(ua, _("Volume \"%s\" has VolStatus %s. It must be Purged or Recycled before relabeling.\n"),
omr.VolumeName, omr.VolStatus);
return 1;
}
/* If VolBytes are zero the Volume is not labeled */
if (db_get_media_record(ua->jcr, ua->db, &mr)) {
if (mr.VolBytes != 0) {
- bsendmsg(ua, _("Media record for new Volume \"%s\" already exists.\n"),
+ bsendmsg(ua, _("Media record for new Volume \"%s\" already exists.\n"),
mr.VolumeName);
continue;
}
/* If autochanger, request slot */
if (store->autochanger) {
- i = find_arg_with_value(ua, "slot");
+ i = find_arg_with_value(ua, "slot");
if (i >= 0) {
mr.Slot = atoi(ua->argv[i]);
} else if (!get_pint(ua, _("Enter slot (0 for none): "))) {
if (relabel) {
/* Delete the old media record */
if (!db_delete_media_record(ua->jcr, ua->db, &omr)) {
- bsendmsg(ua, _("Delete of Volume \"%s\" failed. ERR=%s"),
+ bsendmsg(ua, _("Delete of Volume \"%s\" failed. ERR=%s"),
omr.VolumeName, db_strerror(ua->db));
} else {
- bsendmsg(ua, _("Old volume \"%s\" deleted from catalog.\n"),
+ bsendmsg(ua, _("Old volume \"%s\" deleted from catalog.\n"),
omr.VolumeName);
/* Update the number of Volumes in the pool */
pr.NumVols--;
if (!db_update_pool_record(ua->jcr, ua->db, &pr)) {
- bsendmsg(ua, "%s", db_strerror(ua->db));
+ bsendmsg(ua, "%s", db_strerror(ua->db));
}
}
}
if (ua->automount) {
bstrncpy(dev_name, store->dev_name, sizeof(dev_name));
- bsendmsg(ua, _("Requesting to mount %s ...\n"), dev_name);
+ bsendmsg(ua, _("Requesting to mount %s ...\n"), dev_name);
bash_spaces(dev_name);
- bnet_fsend(sd, "mount %s", dev_name);
+ bnet_fsend(sd, "mount %s", dev_name);
unbash_spaces(dev_name);
while (bnet_recv(sd) >= 0) {
- bsendmsg(ua, "%s", sd->msg);
+ bsendmsg(ua, "%s", sd->msg);
/* Here we can get
* 3001 OK mount. Device=xxx or
* 3001 Mounted Volume vvvv
* 3906 is cannot mount non-tape
* So for those, no need to print a reminder
*/
- if (strncmp(sd->msg, "3001 ", 5) == 0 ||
- strncmp(sd->msg, "3906 ", 5) == 0) {
+ if (strncmp(sd->msg, "3001 ", 5) == 0 ||
+ strncmp(sd->msg, "3906 ", 5) == 0) {
print_reminder = false;
}
}
/* Display list of Volumes and ask if he really wants to proceed */
bsendmsg(ua, _("The following Volumes will be labeled:\n"
- "Slot Volume\n"
- "==============\n"));
+ "Slot Volume\n"
+ "==============\n"));
for (vl=vol_list; vl; vl=vl->next) {
if (!vl->VolName || !slot_list[vl->Slot]) {
continue;
media_record_exists = false;
if (db_get_media_record(ua->jcr, ua->db, &mr)) {
if (mr.VolBytes != 0) {
- bsendmsg(ua, _("Media record for Slot %d Volume \"%s\" already exists.\n"),
+ bsendmsg(ua, _("Media record for Slot %d Volume \"%s\" already exists.\n"),
vl->Slot, mr.VolumeName);
if (!mr.InChanger) {
mr.InChanger = 1;
if (!db_update_media_record(ua->jcr, ua->db, &mr)) {
- bsendmsg(ua, "Error setting InChanger: ERR=%s", db_strerror(ua->db));
+ bsendmsg(ua, "Error setting InChanger: ERR=%s", db_strerror(ua->db));
}
}
continue;
- }
+ }
media_record_exists = true;
}
mr.InChanger = 1;
if (media_record_exists) { /* we update it */
mr.VolBytes = 1;
if (!db_update_media_record(ua->jcr, ua->db, &mr)) {
- bsendmsg(ua, "%s", db_strerror(ua->db));
+ bsendmsg(ua, "%s", db_strerror(ua->db));
}
} else { /* create the media record */
set_pool_dbr_defaults_in_media_dbr(&mr, &pr);
if (db_create_media_record(ua->jcr, ua->db, &mr)) {
- bsendmsg(ua, _("Catalog record for cleaning tape \"%s\" successfully created.\n"),
+ bsendmsg(ua, _("Catalog record for cleaning tape \"%s\" successfully created.\n"),
mr.VolumeName);
pr.NumVols++; /* this is a bit suspect */
if (!db_update_pool_record(ua->jcr, ua->db, &pr)) {
- bsendmsg(ua, "%s", db_strerror(ua->db));
+ bsendmsg(ua, "%s", db_strerror(ua->db));
}
} else {
- bsendmsg(ua, "Catalog error on cleaning tape: %s", db_strerror(ua->db));
+ bsendmsg(ua, "Catalog error on cleaning tape: %s", db_strerror(ua->db));
}
}
continue; /* done, go handle next volume */
return;
}
-/*
+/*
* Check if the Volume name has legal characters
* If ua is non-NULL send the message
*/
continue;
}
if (ua) {
- bsendmsg(ua, _("Illegal character \"%c\" in a volume name.\n"), *p);
+ bsendmsg(ua, _("Illegal character \"%c\" in a volume name.\n"), *p);
}
return 0;
}
len = strlen(name);
if (len >= MAX_NAME_LENGTH) {
if (ua) {
- bsendmsg(ua, _("Volume name too long.\n"));
+ bsendmsg(ua, _("Volume name too long.\n"));
}
return 0;
}
if (len == 0) {
if (ua) {
- bsendmsg(ua, _("Volume name must be at least one character long.\n"));
+ bsendmsg(ua, _("Volume name must be at least one character long.\n"));
}
return 0;
}
/*
* NOTE! This routine opens the SD socket but leaves it open
*/
-static bool send_label_request(UAContext *ua, MEDIA_DBR *mr, MEDIA_DBR *omr,
+static bool send_label_request(UAContext *ua, MEDIA_DBR *mr, MEDIA_DBR *omr,
POOL_DBR *pr, int relabel, bool media_record_exists)
{
BSOCK *sd;
bash_spaces(pr->Name);
if (relabel) {
bash_spaces(omr->VolumeName);
- bnet_fsend(sd, "relabel %s OldName=%s NewName=%s PoolName=%s MediaType=%s Slot=%d",
+ bnet_fsend(sd, "relabel %s OldName=%s NewName=%s PoolName=%s MediaType=%s Slot=%d",
dev_name, omr->VolumeName, mr->VolumeName, pr->Name, mr->MediaType, mr->Slot);
bsendmsg(ua, _("Sending relabel command from \"%s\" to \"%s\" ...\n"),
omr->VolumeName, mr->VolumeName);
} else {
- bnet_fsend(sd, "label %s VolumeName=%s PoolName=%s MediaType=%s Slot=%d",
+ bnet_fsend(sd, "label %s VolumeName=%s PoolName=%s MediaType=%s Slot=%d",
dev_name, mr->VolumeName, pr->Name, mr->MediaType, mr->Slot);
- bsendmsg(ua, _("Sending label command for Volume \"%s\" Slot %d ...\n"),
+ bsendmsg(ua, _("Sending label command for Volume \"%s\" Slot %d ...\n"),
mr->VolumeName, mr->Slot);
- Dmsg5(200, "label %s VolumeName=%s PoolName=%s MediaType=%s Slot=%d\n",
+ Dmsg5(200, "label %s VolumeName=%s PoolName=%s MediaType=%s Slot=%d\n",
dev_name, mr->VolumeName, pr->Name, mr->MediaType, mr->Slot);
}
bsendmsg(ua, "%s", sd->msg);
if (strncmp(sd->msg, "3000 OK label.", 14) == 0) {
ok = true;
- }
+ }
}
unbash_spaces(mr->VolumeName);
unbash_spaces(mr->MediaType);
mr->VolBytes = 1;
mr->InChanger = 1;
if (!db_update_media_record(ua->jcr, ua->db, mr)) {
- bsendmsg(ua, "%s", db_strerror(ua->db));
+ bsendmsg(ua, "%s", db_strerror(ua->db));
ok = false;
}
} else { /* create the media record */
mr->VolBytes = 1; /* flag indicating Volume labeled */
mr->InChanger = 1;
if (db_create_media_record(ua->jcr, ua->db, mr)) {
- bsendmsg(ua, _("Catalog record for Volume \"%s\", Slot %d successfully created.\n"),
+ bsendmsg(ua, _("Catalog record for Volume \"%s\", Slot %d successfully created.\n"),
mr->VolumeName, mr->Slot);
/* Update number of volumes in pool */
pr->NumVols++;
if (!db_update_pool_record(ua->jcr, ua->db, pr)) {
- bsendmsg(ua, "%s", db_strerror(ua->db));
+ bsendmsg(ua, "%s", db_strerror(ua->db));
}
} else {
- bsendmsg(ua, "%s", db_strerror(ua->db));
+ bsendmsg(ua, "%s", db_strerror(ua->db));
ok = false;
}
}
return ok;
}
-static BSOCK *open_sd_bsock(UAContext *ua)
+static BSOCK *open_sd_bsock(UAContext *ua)
{
STORE *store = ua->jcr->store;
if (!ua->jcr->store_bsock) {
- bsendmsg(ua, _("Connecting to Storage daemon %s at %s:%d ...\n"),
+ bsendmsg(ua, _("Connecting to Storage daemon %s at %s:%d ...\n"),
store->hdr.name, store->address, store->SDport);
if (!connect_to_storage_daemon(ua->jcr, 10, SDConnectTimeout, 1)) {
- bsendmsg(ua, _("Failed to connect to Storage daemon.\n"));
+ bsendmsg(ua, _("Failed to connect to Storage daemon.\n"));
return NULL;
}
}
}
}
-static char *get_volume_name_from_SD(UAContext *ua, int Slot)
+static char *get_volume_name_from_SD(UAContext *ua, int Slot)
{
STORE *store = ua->jcr->store;
BSOCK *sd;
Dmsg1(100, "Got: %s", sd->msg);
if (strncmp(sd->msg, "3001 Volume=", 12) == 0) {
VolName = (char *)malloc(sd->msglen);
- if (sscanf(sd->msg, "3001 Volume=%s Slot=%d", VolName, &rtn_slot) == 2) {
+ if (sscanf(sd->msg, "3001 Volume=%s Slot=%d", VolName, &rtn_slot) == 2) {
break;
}
free(VolName);
* If scan is set, we return all slots found,
* otherwise, we return only slots with valid barcodes (Volume names)
*/
-static vol_list_t *get_vol_list_from_SD(UAContext *ua, bool scan)
+static vol_list_t *get_vol_list_from_SD(UAContext *ua, bool scan)
{
STORE *store = ua->jcr->store;
char dev_name[MAX_NAME_LENGTH];
/* Check for returned SD messages */
if (sd->msg[0] == '3' && B_ISDIGIT(sd->msg[1]) &&
B_ISDIGIT(sd->msg[2]) && B_ISDIGIT(sd->msg[3]) &&
- sd->msg[4] == ' ') {
- bsendmsg(ua, "%s\n", sd->msg); /* pass them on to user */
+ sd->msg[4] == ' ') {
+ bsendmsg(ua, "%s\n", sd->msg); /* pass them on to user */
continue;
}
Slot = atoi(sd->msg);
if (Slot <= 0) {
p--;
- *p = ':';
- bsendmsg(ua, _("Invalid Slot number: %s\n"), sd->msg);
+ *p = ':';
+ bsendmsg(ua, _("Invalid Slot number: %s\n"), sd->msg);
continue;
}
} else {
*p++ = 0;
if (!is_an_integer(sd->msg) || (Slot=atoi(sd->msg)) <= 0) {
p--;
- *p = ':';
- bsendmsg(ua, _("Invalid Slot number: %s\n"), sd->msg);
+ *p = ':';
+ bsendmsg(ua, _("Invalid Slot number: %s\n"), sd->msg);
continue;
}
} else {
}
if (!is_volume_name_legal(ua, p)) {
p--;
- *p = ':';
- bsendmsg(ua, _("Invalid Volume name: %s\n"), sd->msg);
+ *p = ':';
+ bsendmsg(ua, _("Invalid Volume name: %s\n"), sd->msg);
continue;
}
}
vl = (vol_list_t *)malloc(sizeof(vol_list_t));
vl->Slot = Slot;
if (p) {
- if (*p == ':') {
+ if (*p == ':') {
p++; /* skip separator */
}
vl->VolName = bstrdup(p);
/*
* Check if this is a cleaning tape by comparing the Volume name
- * with the Cleaning Prefix. If they match, this is a cleaning
+ * with the Cleaning Prefix. If they match, this is a cleaning
* tape.
*/
static bool is_cleaning_tape(UAContext *ua, MEDIA_DBR *mr, POOL_DBR *pr)
}
Dmsg4(100, "CLNprefix=%s: Vol=%s: len=%d strncmp=%d\n",
ua->jcr->pool->cleaning_prefix, mr->VolumeName,
- strlen(ua->jcr->pool->cleaning_prefix),
+ strlen(ua->jcr->pool->cleaning_prefix),
strncmp(mr->VolumeName, ua->jcr->pool->cleaning_prefix,
strlen(ua->jcr->pool->cleaning_prefix)));
return strncmp(mr->VolumeName, ua->jcr->pool->cleaning_prefix,
int autodisplay_cmd(UAContext *ua, const char *cmd)
{
static const char *kw[] = {
- N_("on"),
+ N_("on"),
N_("off"),
NULL};
bsendmsg(ua, _("ON or OFF keyword missing.\n"));
break;
}
- return 1;
+ return 1;
}
/*
int gui_cmd(UAContext *ua, const char *cmd)
{
static const char *kw[] = {
- N_("on"),
+ N_("on"),
N_("off"),
NULL};
bsendmsg(ua, _("ON or OFF keyword missing.\n"));
break;
}
- return 1;
+ return 1;
}
*/
int show_cmd(UAContext *ua, const char *cmd)
{
- int i, j, type, len;
+ int i, j, type, len;
int recurse;
char *res_name;
RES *res = NULL;
LockRes();
for (i=1; i<ua->argc; i++) {
type = 0;
- res_name = ua->argk[i];
+ res_name = ua->argk[i];
if (!ua->argv[i]) { /* was a name given? */
/* No name, dump all resources of specified type */
recurse = 1;
switch (type) {
case -1: /* all */
for (j=r_first; j<=r_last; j++) {
- dump_resource(j, res_head[j-r_first], bsendmsg, ua);
-// dump_resource(j, resources[j-r_first].res_head, bsendmsg, ua);
+ dump_resource(j, res_head[j-r_first], bsendmsg, ua);
+// dump_resource(j, resources[j-r_first].res_head, bsendmsg, ua);
}
break;
case -2:
- bsendmsg(ua, _("Keywords for the show command are:\n"));
+ bsendmsg(ua, _("Keywords for the show command are:\n"));
for (j=0; reses[j].res_name; j++) {
- bsendmsg(ua, "%s\n", _(reses[j].res_name));
+ bsendmsg(ua, "%s\n", _(reses[j].res_name));
}
goto bail_out;
case -3:
- bsendmsg(ua, _("%s resource %s not found.\n"), res_name, ua->argv[i]);
+ bsendmsg(ua, _("%s resource %s not found.\n"), res_name, ua->argv[i]);
goto bail_out;
case 0:
- bsendmsg(ua, _("Resource %s not found\n"), res_name);
+ bsendmsg(ua, _("Resource %s not found\n"), res_name);
goto bail_out;
default:
dump_resource(recurse?type:-type, res, bsendmsg, ua);
} else if (strcasecmp(ua->argk[i], _("files")) == 0) {
for (j=i+1; j<ua->argc; j++) {
- if (strcasecmp(ua->argk[j], _("job")) == 0 && ua->argv[j]) {
+ if (strcasecmp(ua->argk[j], _("job")) == 0 && ua->argv[j]) {
bstrncpy(jr.Job, ua->argv[j], MAX_NAME_LENGTH);
jr.JobId = 0;
db_get_job_record(ua->jcr, ua->db, &jr);
jobid = jr.JobId;
- } else if (strcasecmp(ua->argk[j], _("jobid")) == 0 && ua->argv[j]) {
+ } else if (strcasecmp(ua->argk[j], _("jobid")) == 0 && ua->argv[j]) {
jobid = atoi(ua->argv[j]);
} else {
continue;
db_list_files_for_job(ua->jcr, ua->db, jobid, prtit, ua);
}
}
-
+
/* List JOBMEDIA */
} else if (strcasecmp(ua->argk[i], _("jobmedia")) == 0) {
int done = FALSE;
for (j=i+1; j<ua->argc; j++) {
- if (strcasecmp(ua->argk[j], _("job")) == 0 && ua->argv[j]) {
+ if (strcasecmp(ua->argk[j], _("job")) == 0 && ua->argv[j]) {
bstrncpy(jr.Job, ua->argv[j], MAX_NAME_LENGTH);
jr.JobId = 0;
db_get_job_record(ua->jcr, ua->db, &jr);
jobid = jr.JobId;
- } else if (strcasecmp(ua->argk[j], _("jobid")) == 0 && ua->argv[j]) {
+ } else if (strcasecmp(ua->argk[j], _("jobid")) == 0 && ua->argv[j]) {
jobid = atoi(ua->argv[j]);
} else {
continue;
/* List MEDIA or VOLUMES */
} else if (strcasecmp(ua->argk[i], _("media")) == 0 ||
- strcasecmp(ua->argk[i], _("volumes")) == 0) {
+ strcasecmp(ua->argk[i], _("volumes")) == 0) {
bool done = false;
for (j=i+1; j<ua->argc; j++) {
- if (strcasecmp(ua->argk[j], _("job")) == 0 && ua->argv[j]) {
+ if (strcasecmp(ua->argk[j], _("job")) == 0 && ua->argv[j]) {
bstrncpy(jr.Job, ua->argv[j], MAX_NAME_LENGTH);
jr.JobId = 0;
db_get_job_record(ua->jcr, ua->db, &jr);
jobid = jr.JobId;
- } else if (strcasecmp(ua->argk[j], _("jobid")) == 0 && ua->argv[j]) {
+ } else if (strcasecmp(ua->argk[j], _("jobid")) == 0 && ua->argv[j]) {
jobid = atoi(ua->argv[j]);
} else {
continue;
}
VolumeName = get_pool_memory(PM_FNAME);
n = db_get_job_volume_names(ua->jcr, ua->db, jobid, &VolumeName);
- bsendmsg(ua, _("Jobid %d used %d Volume(s): %s\n"), jobid, n, VolumeName);
+ bsendmsg(ua, _("Jobid %d used %d Volume(s): %s\n"), jobid, n, VolumeName);
free_pool_memory(VolumeName);
done = true;
}
uint32_t *ids;
/* Is a specific pool wanted? */
for (i=1; i<ua->argc; i++) {
- if (strcasecmp(ua->argk[i], _("pool")) == 0) {
+ if (strcasecmp(ua->argk[i], _("pool")) == 0) {
if (!get_pool_dbr(ua, &pr)) {
- bsendmsg(ua, _("No Pool specified.\n"));
+ bsendmsg(ua, _("No Pool specified.\n"));
return 1;
}
mr.PoolId = pr.PoolId;
}
/* List Volumes in all pools */
if (!db_get_pool_ids(ua->jcr, ua->db, &num_pools, &ids)) {
- bsendmsg(ua, _("Error obtaining pool ids. ERR=%s\n"),
+ bsendmsg(ua, _("Error obtaining pool ids. ERR=%s\n"),
db_strerror(ua->db));
return 1;
}
for (i=0; i < num_pools; i++) {
pr.PoolId = ids[i];
if (db_get_pool_record(ua->jcr, ua->db, &pr)) {
- bsendmsg(ua, _("Pool: %s\n"), pr.Name);
+ bsendmsg(ua, _("Pool: %s\n"), pr.Name);
}
mr.PoolId = ids[i];
db_list_media_records(ua->jcr, ua->db, &mr, prtit, ua, llist);
/* List a specific volume */
} else if (strcasecmp(ua->argk[i], _("volume")) == 0) {
if (!ua->argv[i]) {
- bsendmsg(ua, _("No Volume Name specified.\n"));
+ bsendmsg(ua, _("No Volume Name specified.\n"));
return 1;
}
bstrncpy(mr.VolumeName, ua->argv[i], sizeof(mr.VolumeName));
db_list_media_records(ua->jcr, ua->db, &mr, prtit, ua, llist);
return 1;
/* List next volume */
- } else if (strcasecmp(ua->argk[i], _("nextvol")) == 0 ||
- strcasecmp(ua->argk[i], _("nextvolume")) == 0) {
+ } else if (strcasecmp(ua->argk[i], _("nextvol")) == 0 ||
+ strcasecmp(ua->argk[i], _("nextvolume")) == 0) {
list_nextvol(ua);
} else {
- bsendmsg(ua, _("Unknown list keyword: %s\n"), NPRT(ua->argk[i]));
+ bsendmsg(ua, _("Unknown list keyword: %s\n"), NPRT(ua->argk[i]));
}
}
return 1;
} else {
job = (JOB *)GetResWithName(R_JOB, ua->argv[i]);
if (!job) {
- Jmsg(jcr, M_ERROR, 0, _("%s is not a job name.\n"), ua->argv[i]);
+ Jmsg(jcr, M_ERROR, 0, _("%s is not a job name.\n"), ua->argv[i]);
if ((job = select_job_resource(ua)) == NULL) {
return false;
}
if (!complete_jcr_for_job(jcr, job, pool)) {
return false;
}
-
+
if (!find_next_volume_for_append(jcr, &mr, 0)) {
- bsendmsg(ua, _("Could not find next Volume.\n"));
+ bsendmsg(ua, _("Could not find next Volume.\n"));
} else {
- bsendmsg(ua, _("The next Volume to be used by Job \"%s\" will be %s\n"),
+ bsendmsg(ua, _("The next Volume to be used by Job \"%s\" will be %s\n"),
job->hdr.name, mr.VolumeName);
found = true;
}
}
-/*
+/*
* For a given job, we examine all his run records
* to see if it is scheduled today or tomorrow.
*/
if (sched == NULL) { /* scheduled? */
return NULL; /* no nothing to report */
}
- /* Break down current time into components */
+ /* Break down current time into components */
now = time(NULL);
localtime_r(&now, &tm);
mday = tm.tm_mday - 1;
run = run->next;
}
for ( ; run; run=run->next) {
- /*
+ /*
* Find runs in next 24 hours
*/
- tod = bit_is_set(mday, run->mday) && bit_is_set(wday, run->wday) &&
+ tod = bit_is_set(mday, run->mday) && bit_is_set(wday, run->wday) &&
bit_is_set(month, run->month) && bit_is_set(wom, run->wom) &&
bit_is_set(woy, run->woy);
if (tod) { /* Jobs scheduled today (next 24 hours) */
#ifdef xxx
char buf[300], num[10];
- bsnprintf(buf, sizeof(buf), "tm.hour=%d hour=", tm.tm_hour);
+ bsnprintf(buf, sizeof(buf), "tm.hour=%d hour=", tm.tm_hour);
for (i=0; i<24; i++) {
if (bit_is_set(i, run->hour)) {
- bsnprintf(num, sizeof(num), "%d ", i);
+ bsnprintf(num, sizeof(num), "%d ", i);
bstrncat(buf, num, sizeof(buf));
}
}
- bstrncat(buf, "\n", sizeof(buf));
- Dmsg1(000, "%s", buf);
-#endif
+ bstrncat(buf, "\n", sizeof(buf));
+ Dmsg1(000, "%s", buf);
+#endif
/* find time (time_t) job is to be run */
localtime_r(&now, &tm);
for (i=tm.tm_hour; i < 24; i++) {
tm.tm_min = run->minute;
tm.tm_sec = 0;
runtime = mktime(&tm);
- Dmsg2(200, "now=%d runtime=%d\n", now, runtime);
+ Dmsg2(200, "now=%d runtime=%d\n", now, runtime);
if (runtime > now) {
- Dmsg2(200, "Found it level=%d %c\n", run->level, run->level);
+ Dmsg2(200, "Found it level=%d %c\n", run->level, run->level);
return run; /* found it, return run resource */
}
}
tm.tm_min = run->minute;
tm.tm_sec = 0;
runtime = mktime(&tm);
- Dmsg2(200, "now=%d runtime=%d\n", now, runtime);
+ Dmsg2(200, "now=%d runtime=%d\n", now, runtime);
if (runtime < tomorrow) {
- Dmsg2(200, "Found it level=%d %c\n", run->level, run->level);
+ Dmsg2(200, "Found it level=%d %c\n", run->level, run->level);
return run; /* found it, return run resource */
}
}
}
}
- } /* end for loop over runs */
+ } /* end for loop over runs */
/* Nothing found */
return NULL;
}
-/*
+/*
* Fill in the remaining fields of the jcr as if it
* is going to run the job.
*/
{
POOL_DBR pr;
- memset(&pr, 0, sizeof(POOL_DBR));
+ memset(&pr, 0, sizeof(POOL_DBR));
set_jcr_defaults(jcr, job);
if (pool) {
jcr->pool = pool; /* override */
}
jcr->db = jcr->db=db_init_database(jcr, jcr->catalog->db_name, jcr->catalog->db_user,
jcr->catalog->db_password, jcr->catalog->db_address,
- jcr->catalog->db_port, jcr->catalog->db_socket,
+ jcr->catalog->db_port, jcr->catalog->db_socket,
jcr->catalog->mult_db_connections);
if (!jcr->db || !db_open_database(jcr, jcr->db)) {
Jmsg(jcr, M_FATAL, 0, _("Could not open database \"%s\".\n"),
jcr->catalog->db_name);
if (jcr->db) {
- Jmsg(jcr, M_FATAL, 0, "%s", db_strerror(jcr->db));
+ Jmsg(jcr, M_FATAL, 0, "%s", db_strerror(jcr->db));
}
return 0;
}
while (!db_get_pool_record(jcr, jcr->db, &pr)) { /* get by Name */
/* Try to create the pool */
if (create_pool(jcr, jcr->db, jcr->pool, POOL_OP_CREATE) < 0) {
- Jmsg(jcr, M_FATAL, 0, _("Pool %s not in database. %s"), pr.Name,
+ Jmsg(jcr, M_FATAL, 0, _("Pool %s not in database. %s"), pr.Name,
db_strerror(jcr->db));
if (jcr->db) {
db_close_database(jcr, jcr->db);
}
return 0;
} else {
- Jmsg(jcr, M_INFO, 0, _("Pool %s created in database.\n"), pr.Name);
+ Jmsg(jcr, M_INFO, 0, _("Pool %s created in database.\n"), pr.Name);
}
}
- jcr->PoolId = pr.PoolId;
+ jcr->PoolId = pr.PoolId;
jcr->jr.PoolId = pr.PoolId;
return 1;
}
void do_messages(UAContext *ua, const char *cmd)
{
char msg[2000];
- int mlen;
+ int mlen;
int do_truncate = FALSE;
Pw(con_lock);
void prtit(void *ctx, const char *msg)
{
UAContext *ua = (UAContext *)ctx;
-
+
bnet_fsend(ua->UA_sock, "%s", msg);
}
-/*
- * Format message and send to other end.
+/*
+ * Format message and send to other end.
* If the UA_sock is NULL, it means that there is no user
* agent, so we are being called from Bacula core. In
/*
- * Called here to count entries to be deleted
+ * Called here to count entries to be deleted
*/
static int count_handler(void *ctx, int num_fields, char **row)
{
{
struct s_job_del_ctx *del = (struct s_job_del_ctx *)ctx;
- if (del->num_ids == MAX_DEL_LIST_LEN) {
+ if (del->num_ids == MAX_DEL_LIST_LEN) {
return 1;
}
if (del->num_ids == del->max_ids) {
{
struct s_file_del_ctx *del = (struct s_file_del_ctx *)ctx;
- if (del->num_ids == MAX_DEL_LIST_LEN) {
+ if (del->num_ids == MAX_DEL_LIST_LEN) {
return 1;
}
if (del->num_ids == del->max_ids) {
*
* prune files (from) client=xxx
* prune jobs (from) client=xxx
- * prune volume=xxx
+ * prune volume=xxx
*/
int prunecmd(UAContext *ua, const char *cmd)
{
}
/* First search args */
- kw = find_arg_keyword(ua, keywords);
+ kw = find_arg_keyword(ua, keywords);
if (kw < 0 || kw > 2) {
/* no args, so ask user */
- kw = do_keyword_prompt(ua, _("Choose item to prune"), keywords);
- }
-
+ kw = do_keyword_prompt(ua, _("Choose item to prune"), keywords);
+ }
+
switch (kw) {
case 0: /* prune files */
client = get_client_resource(ua);
period = client->FileRetention;
now = (utime_t)time(NULL);
-
+
/* Select Jobs -- for counting */
Mmsg(query, select_job, edit_uint64(now - period, ed1), cr.ClientId);
Dmsg1(050, "select sql=%s\n", query);
if (!db_sql_query(ua->db, query, file_count_handler, (void *)&del)) {
if (ua->verbose) {
- bsendmsg(ua, "%s", db_strerror(ua->db));
+ bsendmsg(ua, "%s", db_strerror(ua->db));
}
Dmsg0(050, "Count failed\n");
goto bail_out;
}
-
+
if (del.tot_ids == 0) {
if (ua->verbose) {
- bsendmsg(ua, _("No Files found to prune.\n"));
+ bsendmsg(ua, _("No Files found to prune.\n"));
}
goto bail_out;
}
if (del.tot_ids < MAX_DEL_LIST_LEN) {
del.max_ids = del.tot_ids + 1;
} else {
- del.max_ids = MAX_DEL_LIST_LEN;
+ del.max_ids = MAX_DEL_LIST_LEN;
}
del.tot_ids = 0;
del.tot_ids += cnt.count;
Mmsg(query, del_File, del.JobId[i]);
db_sql_query(ua->db, query, NULL, (void *)NULL);
- /*
+ /*
* Now mark Job as having files purged. This is necessary to
* avoid having too many Jobs to process in future prunings. If
* we don't do this, the number of JobId's in our in memory list
}
edit_uint64_with_commas(del.tot_ids, ed1);
edit_uint64_with_commas(del.num_ids, ed2);
- bsendmsg(ua, _("Pruned %s Files from %s Jobs for client %s from catalog.\n"),
+ bsendmsg(ua, _("Pruned %s Files from %s Jobs for client %s from catalog.\n"),
ed1, ed2, client->hdr.name);
-
+
bail_out:
db_unlock(ua->db);
if (del.JobId) {
}
-static void drop_temp_tables(UAContext *ua)
+static void drop_temp_tables(UAContext *ua)
{
int i;
for (i=0; drop_deltabs[i]; i++) {
}
}
-static int create_temp_tables(UAContext *ua)
+static int create_temp_tables(UAContext *ua)
{
int i;
/* Create temp tables and indicies */
for (i=0; create_deltabs[i]; i++) {
if (!db_sql_query(ua->db, create_deltabs[i], NULL, (void *)NULL)) {
- bsendmsg(ua, "%s", db_strerror(ua->db));
- Dmsg0(050, "create DelTables table failed\n");
+ bsendmsg(ua, "%s", db_strerror(ua->db));
+ Dmsg0(050, "create DelTables table failed\n");
return 0;
}
}
goto bail_out;
}
- /*
+ /*
* Select all files that are older than the JobRetention period
* and stuff them into the "DeletionCandidates" table.
*/
Mmsg(query, insert_delcand, (char)JobType, ed1, cr.ClientId);
if (!db_sql_query(ua->db, query, NULL, (void *)NULL)) {
if (ua->verbose) {
- bsendmsg(ua, "%s", db_strerror(ua->db));
+ bsendmsg(ua, "%s", db_strerror(ua->db));
}
Dmsg0(050, "insert delcand failed\n");
goto bail_out;
Dmsg0(050, "Count failed\n");
goto bail_out;
}
-
+
if (cnt.count == 0) {
if (ua->verbose) {
- bsendmsg(ua, _("No Jobs found to prune.\n"));
+ bsendmsg(ua, _("No Jobs found to prune.\n"));
}
goto bail_out;
}
if (cnt.count < MAX_DEL_LIST_LEN) {
del.max_ids = cnt.count + 1;
} else {
- del.max_ids = MAX_DEL_LIST_LEN;
+ del.max_ids = MAX_DEL_LIST_LEN;
}
del.JobId = (JobId_t *)malloc(sizeof(JobId_t) * del.max_ids);
del.PurgedFiles = (char *)malloc(del.max_ids);
bsendmsg(ua, "%s", db_strerror(ua->db));
}
- /*
+ /*
* OK, now we have the list of JobId's to be pruned, first check
* if the Files have been purged, if not, purge (delete) them.
* Then delete the Job entry, and finally and JobMedia records.
if (!del.PurgedFiles[i]) {
Mmsg(query, del_File, del.JobId[i]);
if (!db_sql_query(ua->db, query, NULL, (void *)NULL)) {
- bsendmsg(ua, "%s", db_strerror(ua->db));
+ bsendmsg(ua, "%s", db_strerror(ua->db));
}
- Dmsg1(050, "Del sql=%s\n", query);
+ Dmsg1(050, "Del sql=%s\n", query);
}
Mmsg(query, del_Job, del.JobId[i]);
if (!db_sql_query(ua->db, query, NULL, (void *)NULL)) {
- bsendmsg(ua, "%s", db_strerror(ua->db));
+ bsendmsg(ua, "%s", db_strerror(ua->db));
}
Dmsg1(050, "Del sql=%s\n", query);
Mmsg(query, del_JobMedia, del.JobId[i]);
if (!db_sql_query(ua->db, query, NULL, (void *)NULL)) {
- bsendmsg(ua, "%s", db_strerror(ua->db));
+ bsendmsg(ua, "%s", db_strerror(ua->db));
}
Dmsg1(050, "Del sql=%s\n", query);
}
bsendmsg(ua, _("Pruned %d %s for client %s from catalog.\n"), del.num_ids,
del.num_ids==1?_("Job"):_("Jobs"), client->hdr.name);
-
+
bail_out:
drop_temp_tables(ua);
db_unlock(ua->db);
memset(&del, 0, sizeof(del));
/*
- * Find out how many Jobs remain on this Volume by
+ * Find out how many Jobs remain on this Volume by
* counting the JobMedia records.
*/
cnt.count = 0;
Dmsg0(050, "Count failed\n");
goto bail_out;
}
-
+
if (cnt.count == 0) {
if (strcmp(mr->VolStatus, "Purged") != 0 && verbose) {
- bsendmsg(ua, "There are no Jobs associated with Volume \"%s\". Marking it purged.\n",
+ bsendmsg(ua, "There are no Jobs associated with Volume \"%s\". Marking it purged.\n",
mr->VolumeName);
}
stat = mark_media_purged(ua, mr);
if (cnt.count < MAX_DEL_LIST_LEN) {
del.max_ids = cnt.count + 1;
} else {
- del.max_ids = MAX_DEL_LIST_LEN;
+ del.max_ids = MAX_DEL_LIST_LEN;
}
- /*
+ /*
* Now get a list of JobIds for Jobs written to this Volume
* Could optimize here by adding JobTDate > (now - period).
*/
Mmsg(query, sel_JobMedia, mr->MediaId);
if (!db_sql_query(ua->db, query, file_delete_handler, (void *)&del)) {
if (ua->verbose) {
- bsendmsg(ua, "%s", db_strerror(ua->db));
+ bsendmsg(ua, "%s", db_strerror(ua->db));
}
Dmsg0(050, "Count failed\n");
goto bail_out;
}
if (ua->verbose && del.num_del != 0) {
bsendmsg(ua, _("Pruned %d %s on Volume \"%s\" from catalog.\n"), del.num_del,
- del.num_del == 1 ? "Job" : "Jobs", mr->VolumeName);
+ del.num_del == 1 ? "Job" : "Jobs", mr->VolumeName);
}
/* If purged, mark it so */
};
/*
- * Called here to count entries to be deleted
+ * Called here to count entries to be deleted
*/
static int count_handler(void *ctx, int num_fields, char **row)
{
}
/*
- * Called here to count entries to be deleted
+ * Called here to count entries to be deleted
*/
static int file_count_handler(void *ctx, int num_fields, char **row)
{
{
struct s_job_del_ctx *del = (struct s_job_del_ctx *)ctx;
- if (del->num_ids == MAX_DEL_LIST_LEN) {
+ if (del->num_ids == MAX_DEL_LIST_LEN) {
return 1;
}
if (del->num_ids == del->max_ids) {
{
struct s_file_del_ctx *del = (struct s_file_del_ctx *)ctx;
- if (del->num_ids == MAX_DEL_LIST_LEN) {
+ if (del->num_ids == MAX_DEL_LIST_LEN) {
return 1;
}
if (del->num_ids == del->max_ids) {
N_("Client"),
N_("Volume"),
NULL};
-
+
bsendmsg(ua, _(
"\nThis command is can be DANGEROUS!!!\n\n"
"It purges (deletes) all Files from a Job,\n"
"JobId, Client or Volume; or it purges (deletes)\n"
"all Jobs from a Client or Volume without regard\n"
- "for retention periods. Normally you should use the\n"
+ "for retention periods. Normally you should use the\n"
"PRUNE command, which respects retention periods.\n"));
if (!open_db(ua)) {
purge_jobs_from_volume(ua, &mr);
}
*ua->argk[i] = 0; /* zap keyword already seen */
- bsendmsg(ua, "\n");
+ bsendmsg(ua, "\n");
}
return 1;
default:
Mmsg(query, select_jobsfiles_from_client, cr.ClientId);
Dmsg1(050, "select sql=%s\n", query);
-
+
if (!db_sql_query(ua->db, query, file_count_handler, (void *)&del)) {
bsendmsg(ua, "%s", db_strerror(ua->db));
Dmsg0(050, "Count failed\n");
goto bail_out;
}
-
+
if (del.tot_ids == 0) {
bsendmsg(ua, _("No Files found for client %s to purge from %s catalog.\n"),
client->hdr.name, client->catalog->hdr.name);
if (del.tot_ids < MAX_DEL_LIST_LEN) {
del.max_ids = del.tot_ids + 1;
} else {
- del.max_ids = MAX_DEL_LIST_LEN;
+ del.max_ids = MAX_DEL_LIST_LEN;
}
del.tot_ids = 0;
Dmsg1(050, "Delete JobId=%d\n", del.JobId[i]);
Mmsg(query, "DELETE FROM File WHERE JobId=%d", del.JobId[i]);
db_sql_query(ua->db, query, NULL, (void *)NULL);
- /*
+ /*
* Now mark Job as having files purged. This is necessary to
* avoid having too many Jobs to process in future prunings. If
* we don't do this, the number of JobId's in our in memory list
}
bsendmsg(ua, _("%d Files for client \"%s\" purged from %s catalog.\n"), del.num_ids,
client->hdr.name, client->catalog->hdr.name);
-
+
bail_out:
if (del.JobId) {
free(del.JobId);
Mmsg(query, select_jobs_from_client, cr.ClientId);
Dmsg1(050, "select sql=%s\n", query);
-
+
if (!db_sql_query(ua->db, query, job_count_handler, (void *)&del)) {
bsendmsg(ua, "%s", db_strerror(ua->db));
Dmsg0(050, "Count failed\n");
if (del.tot_ids < MAX_DEL_LIST_LEN) {
del.max_ids = del.tot_ids + 1;
} else {
- del.max_ids = MAX_DEL_LIST_LEN;
+ del.max_ids = MAX_DEL_LIST_LEN;
}
del.tot_ids = 0;
db_sql_query(ua->db, query, job_delete_handler, (void *)&del);
- /*
+ /*
* OK, now we have the list of JobId's to be purged, first check
* if the Files have been purged, if not, purge (delete) them.
* Then delete the Job entry, and finally and JobMedia records.
for (i=0; i < del.num_ids; i++) {
Dmsg1(050, "Delete JobId=%d\n", del.JobId[i]);
if (!del.PurgedFiles[i]) {
- Mmsg(query, "DELETE FROM File WHERE JobId=%d", del.JobId[i]);
+ Mmsg(query, "DELETE FROM File WHERE JobId=%d", del.JobId[i]);
db_sql_query(ua->db, query, NULL, (void *)NULL);
- Dmsg1(050, "Del sql=%s\n", query);
+ Dmsg1(050, "Del sql=%s\n", query);
}
Mmsg(query, "DELETE FROM Job WHERE JobId=%d", del.JobId[i]);
}
bsendmsg(ua, _("%d Jobs for client %s purged from %s catalog.\n"), del.num_ids,
client->hdr.name, client->catalog->hdr.name);
-
+
bail_out:
if (del.JobId) {
free(del.JobId);
void purge_files_from_job(UAContext *ua, JOB_DBR *jr)
{
char *query = (char *)get_pool_memory(PM_MESSAGE);
-
+
Mmsg(query, "DELETE FROM File WHERE JobId=%u", jr->JobId);
db_sql_query(ua->db, query, NULL, (void *)NULL);
free_pool_memory(query);
}
-void purge_files_from_volume(UAContext *ua, MEDIA_DBR *mr )
+void purge_files_from_volume(UAContext *ua, MEDIA_DBR *mr )
{} /* ***FIXME*** implement */
/*
* Returns: 1 if Volume purged
* 0 if Volume not purged
*/
-int purge_jobs_from_volume(UAContext *ua, MEDIA_DBR *mr)
+int purge_jobs_from_volume(UAContext *ua, MEDIA_DBR *mr)
{
char *query = (char *)get_pool_memory(PM_MESSAGE);
struct s_count_ctx cnt;
int i, stat = 0;
JOB_DBR jr;
- stat = strcmp(mr->VolStatus, "Append") == 0 ||
- strcmp(mr->VolStatus, "Full") == 0 ||
- strcmp(mr->VolStatus, "Used") == 0 ||
- strcmp(mr->VolStatus, "Error") == 0;
+ stat = strcmp(mr->VolStatus, "Append") == 0 ||
+ strcmp(mr->VolStatus, "Full") == 0 ||
+ strcmp(mr->VolStatus, "Used") == 0 ||
+ strcmp(mr->VolStatus, "Error") == 0;
if (!stat) {
bsendmsg(ua, "\n");
bsendmsg(ua, _("Volume \"%s\" has VolStatus \"%s\" and cannot be purged.\n"
- "The VolStatus must be: Append, Full, Used, or Error to be purged.\n"),
+ "The VolStatus must be: Append, Full, Used, or Error to be purged.\n"),
mr->VolumeName, mr->VolStatus);
goto bail_out;
}
-
+
memset(&jr, 0, sizeof(jr));
memset(&del, 0, sizeof(del));
cnt.count = 0;
Dmsg0(050, "Count failed\n");
goto bail_out;
}
-
+
if (cnt.count == 0) {
bsendmsg(ua, "There are no Jobs associated with Volume \"%s\". Marking it purged.\n",
mr->VolumeName);
if (!mark_media_purged(ua, mr)) {
- bsendmsg(ua, "%s", db_strerror(ua->db));
+ bsendmsg(ua, "%s", db_strerror(ua->db));
goto bail_out;
}
goto bail_out;
if (cnt.count < MAX_DEL_LIST_LEN) {
del.max_ids = cnt.count + 1;
} else {
- del.max_ids = MAX_DEL_LIST_LEN;
+ del.max_ids = MAX_DEL_LIST_LEN;
}
/*
- * Check if he wants to purge a single jobid
+ * Check if he wants to purge a single jobid
*/
i = find_arg_with_value(ua, "jobid");
if (i >= 0) {
del.num_ids = 1;
del.JobId[0] = str_to_int64(ua->argv[i]);
} else {
- /*
- * Purge ALL JobIds
+ /*
+ * Purge ALL JobIds
*/
del.JobId = (JobId_t *)malloc(sizeof(JobId_t) * del.max_ids);
Mmsg(query, "SELECT JobId FROM JobMedia WHERE MediaId=%d", mr->MediaId);
if (!db_sql_query(ua->db, query, file_delete_handler, (void *)&del)) {
- bsendmsg(ua, "%s", db_strerror(ua->db));
- Dmsg0(050, "Count failed\n");
+ bsendmsg(ua, "%s", db_strerror(ua->db));
+ Dmsg0(050, "Count failed\n");
goto bail_out;
}
}
Dmsg0(050, "Count failed\n");
goto bail_out;
}
-
+
if (cnt.count == 0) {
bsendmsg(ua, "There are no more Jobs associated with Volume \"%s\". Marking it purged.\n",
mr->VolumeName);
if (!(stat = mark_media_purged(ua, mr))) {
- bsendmsg(ua, "%s", db_strerror(ua->db));
+ bsendmsg(ua, "%s", db_strerror(ua->db));
goto bail_out;
}
}
-bail_out:
+bail_out:
free_pool_memory(query);
return stat;
}
*/
int mark_media_purged(UAContext *ua, MEDIA_DBR *mr)
{
- if (strcmp(mr->VolStatus, "Append") == 0 ||
+ if (strcmp(mr->VolStatus, "Append") == 0 ||
strcmp(mr->VolStatus, "Full") == 0 ||
- strcmp(mr->VolStatus, "Used") == 0 ||
+ strcmp(mr->VolStatus, "Used") == 0 ||
strcmp(mr->VolStatus, "Error") == 0) {
bstrncpy(mr->VolStatus, "Purged", sizeof(mr->VolStatus));
if (!db_update_media_record(ua->jcr, ua->db, mr)) {
extern DIRRES *director;
-static POOLMEM *substitute_prompts(UAContext *ua,
+static POOLMEM *substitute_prompts(UAContext *ua,
POOLMEM *query, char **prompt, int nprompt);
/*
char *prompt[9];
int nprompt = 0;;
char *query_file = director->query_file;
-
+
if (!open_db(ua)) {
goto bail_out;
}
len = strlen(line);
if (line[0] == '*') { /* prompt */
if (nprompt >= 9) {
- bsendmsg(ua, _("Too many prompts in query, max is 9.\n"));
+ bsendmsg(ua, _("Too many prompts in query, max is 9.\n"));
} else {
- line[len++] = ' ';
+ line[len++] = ' ';
line[len] = 0;
prompt[nprompt++] = bstrdup(line+1);
continue;
}
- }
+ }
if (*query != 0) {
- pm_strcat(query, " ");
+ pm_strcat(query, " ");
}
pm_strcat(query, line);
if (line[len-1] != ';') {
line[len-1] = 0; /* zap ; */
if (query[0] != 0) {
query = substitute_prompts(ua, query, prompt, nprompt);
- Dmsg1(100, "Query2=%s\n", query);
- if (query[0] == '!') {
+ Dmsg1(100, "Query2=%s\n", query);
+ if (query[0] == '!') {
db_list_sql_query(ua->jcr, ua->db, query+1, prtit, ua, 0, VERT_LIST);
} else if (!db_list_sql_query(ua->jcr, ua->db, query, prtit, ua, 1, HORZ_LIST)) {
- bsendmsg(ua, "%s\n", query);
+ bsendmsg(ua, "%s\n", query);
}
query[0] = 0;
}
if (query[0] != 0) {
query = substitute_prompts(ua, query, prompt, nprompt);
Dmsg1(100, "Query2=%s\n", query);
- if (query[0] == '!') {
+ if (query[0] == '!') {
db_list_sql_query(ua->jcr, ua->db, query+1, prtit, ua, 0, VERT_LIST);
} else if (!db_list_sql_query(ua->jcr, ua->db, query, prtit, ua, 1, HORZ_LIST)) {
- bsendmsg(ua, "%s\n", query);
+ bsendmsg(ua, "%s\n", query);
}
}
return 1;
}
-static POOLMEM *substitute_prompts(UAContext *ua,
+static POOLMEM *substitute_prompts(UAContext *ua,
POOLMEM *query, char **prompt, int nprompt)
{
char *p, *q, *o;
}
p++;
switch (*p) {
- case '1':
- case '2':
- case '3':
- case '4':
- case '5':
- case '6':
- case '7':
- case '8':
- case '9':
- n = (int)(*p) - (int)'1';
+ case '1':
+ case '2':
+ case '3':
+ case '4':
+ case '5':
+ case '6':
+ case '7':
+ case '8':
+ case '9':
+ n = (int)(*p) - (int)'1';
if (prompt[n]) {
if (!subst[n]) {
if (!get_cmd(ua, prompt[n])) {
*o++ = *p++;
}
} else {
- bsendmsg(ua, _("Warning prompt %d missing.\n"), n+1);
+ bsendmsg(ua, _("Warning prompt %d missing.\n"), n+1);
}
q += 2;
break;
- case '%':
- *o++ = '%';
+ case '%':
+ *o++ = '%';
q += 2;
break;
default:
- *o++ = '%';
+ *o++ = '%';
q++;
break;
}
}
*query = 0;
- bsendmsg(ua, _("Entering SQL query mode.\n\
-Terminate each query with a semicolon.\n\
-Terminate query mode with a blank line.\n"));
+ bsendmsg(ua, _("Entering SQL query mode.\n"
+"Terminate each query with a semicolon.\n"
+"Terminate query mode with a blank line.\n"));
msg = "Enter SQL query: ";
while (get_cmd(ua, msg)) {
len = strlen(ua->cmd);
}
query = check_pool_memory_size(query, len + 1);
if (*query != 0) {
- strcat(query, " ");
+ strcat(query, " ");
}
strcat(query, ua->cmd);
if (ua->cmd[len-1] == ';') {
/* Submit query */
db_list_sql_query(ua->jcr, ua->db, query, prtit, ua, 1, HORZ_LIST);
*query = 0; /* start new query */
- msg = _("Enter SQL query: ");
+ msg = _("Enter SQL query: ");
} else {
- msg = _("Add to SQL query: ");
+ msg = _("Add to SQL query: ");
}
}
free_pool_memory(query);
bsendmsg(ua, _("End query mode.\n"));
- return 1;
+ return 1;
}
UnlockRes();
if (!rx.restore_jobs) {
bsendmsg(ua, _(
- "No Restore Job Resource found. You must create at least\n"
- "one before running this command.\n"));
+ "No Restore Job Resource found. You must create at least\n"
+ "one before running this command.\n"));
goto bail_out;
}
- /*
+ /*
* Request user to select JobIds or files by various different methods
* last 20 jobs, where File saved, most recent backup, ...
* In the end, a list of files are pumped into
goto bail_out;
case 1: /* select by jobid */
if (!build_directory_tree(ua, &rx)) {
- bsendmsg(ua, _("Restore not done.\n"));
+ bsendmsg(ua, _("Restore not done.\n"));
goto bail_out;
}
break;
if (rx.bsr->JobId) {
if (!complete_bsr(ua, rx.bsr)) { /* find Vol, SessId, SessTime from JobIds */
- bsendmsg(ua, _("Unable to construct a valid BSR. Cannot continue.\n"));
+ bsendmsg(ua, _("Unable to construct a valid BSR. Cannot continue.\n"));
goto bail_out;
}
if (!write_bsr_file(ua, rx.bsr)) {
goto bail_out;
}
bsendmsg(ua, _("\n%u file%s selected to be restored.\n\n"), rx.selected_files,
- rx.selected_files==1?"":"s");
+ rx.selected_files==1?"":"s");
} else {
bsendmsg(ua, _("No files selected to be restored.\n"));
goto bail_out;
/* Build run command */
if (rx.where) {
- Mmsg(ua->cmd,
- "run job=\"%s\" client=\"%s\" storage=\"%s\" bootstrap=\"%s/restore.bsr\""
- " where=\"%s\" files=%d catalog=\"%s\"",
- job->hdr.name, rx.ClientName, rx.store?rx.store->hdr.name:"",
+ Mmsg(ua->cmd,
+ "run job=\"%s\" client=\"%s\" storage=\"%s\" bootstrap=\"%s/restore.bsr\""
+ " where=\"%s\" files=%d catalog=\"%s\"",
+ job->hdr.name, rx.ClientName, rx.store?rx.store->hdr.name:"",
working_directory, rx.where, rx.selected_files, ua->catalog->hdr.name);
} else {
- Mmsg(ua->cmd,
- "run job=\"%s\" client=\"%s\" storage=\"%s\" bootstrap=\"%s/restore.bsr\""
- " files=%d catalog=\"%s\"",
- job->hdr.name, rx.ClientName, rx.store?rx.store->hdr.name:"",
+ Mmsg(ua->cmd,
+ "run job=\"%s\" client=\"%s\" storage=\"%s\" bootstrap=\"%s/restore.bsr\""
+ " files=%d catalog=\"%s\"",
+ job->hdr.name, rx.ClientName, rx.store?rx.store->hdr.name:"",
working_directory, rx.selected_files, ua->catalog->hdr.name);
}
if (find_arg(ua, _("yes")) > 0) {
}
-static void free_rx(RESTORE_CTX *rx)
+static void free_rx(RESTORE_CTX *rx)
{
free_bsr(rx->bsr);
rx->bsr = NULL;
}
/*
- * The first step in the restore process is for the user to
+ * The first step in the restore process is for the user to
* select a list of JobIds from which he will subsequently
* select which files are to be restored.
*/
JOB_DBR jr;
bool done = false;
int i, j;
- const char *list[] = {
+ const char *list[] = {
"List last 20 Jobs run",
"List Jobs where a given File is saved",
"Enter list of comma separated JobIds to select",
- "Enter SQL list command",
+ "Enter SQL list command",
"Select the most recent backup for a client",
"Select backup for a client before a specified time",
"Enter a list of files to restore",
}
}
if (!found_kw) {
- bsendmsg(ua, _("Unknown keyword: %s\n"), ua->argk[i]);
+ bsendmsg(ua, _("Unknown keyword: %s\n"), ua->argk[i]);
return 0;
}
/* Found keyword in kw[] list, process it */
switch (j) {
case 0: /* jobid */
if (*rx->JobIds != 0) {
- pm_strcat(rx->JobIds, ",");
+ pm_strcat(rx->JobIds, ",");
}
pm_strcat(rx->JobIds, ua->argv[i]);
done = true;
break;
case 2: /* before */
if (str_to_utime(ua->argv[i]) == 0) {
- bsendmsg(ua, _("Improper date format: %s\n"), ua->argv[i]);
+ bsendmsg(ua, _("Improper date format: %s\n"), ua->argv[i]);
return 0;
}
bstrncpy(date, ua->argv[i], sizeof(date));
case 5: /* pool specified */
rx->pool = (POOL *)GetResWithName(R_POOL, ua->argv[i]);
if (!rx->pool) {
- bsendmsg(ua, _("Error: Pool resource \"%s\" does not exist.\n"), ua->argv[i]);
+ bsendmsg(ua, _("Error: Pool resource \"%s\" does not exist.\n"), ua->argv[i]);
return 0;
}
if (!acl_access_ok(ua, Pool_ACL, ua->argv[i])) {
rx->pool = NULL;
- bsendmsg(ua, _("Error: Pool resource \"%s\" access not allowed.\n"), ua->argv[i]);
+ bsendmsg(ua, _("Error: Pool resource \"%s\" access not allowed.\n"), ua->argv[i]);
return 0;
}
break;
case 6: /* all specified */
rx->all = true;
break;
- /*
+ /*
* All keywords 7 or greater are ignored or handled by a select prompt
*/
default:
if (rx->name_list.num_ids) {
return 2; /* filename list made */
}
-
+
if (!done) {
bsendmsg(ua, _("\nFirst you select one or more JobIds that contain files\n"
- "to be restored. You will be presented several methods\n"
- "of specifying the JobIds. Then you will be allowed to\n"
- "select which files from those JobIds are to be restored.\n\n"));
+ "to be restored. You will be presented several methods\n"
+ "of specifying the JobIds. Then you will be allowed to\n"
+ "select which files from those JobIds are to be restored.\n\n"));
}
/* If choice not already made above, prompt */
done = false;
break;
case 1: /* list where a file is saved */
- if (!get_cmd(ua, _("Enter Filename (no path):"))) {
+ if (!get_cmd(ua, _("Enter Filename (no path):"))) {
return 0;
}
len = strlen(ua->cmd);
done = false;
break;
case 2: /* enter a list of JobIds */
- if (!get_cmd(ua, _("Enter JobId(s), comma separated, to restore: "))) {
+ if (!get_cmd(ua, _("Enter JobId(s), comma separated, to restore: "))) {
return 0;
}
pm_strcpy(rx->JobIds, ua->cmd);
break;
case 3: /* Enter an SQL list command */
- if (!get_cmd(ua, _("Enter SQL list command: "))) {
+ if (!get_cmd(ua, _("Enter SQL list command: "))) {
return 0;
}
gui_save = ua->jcr->gui;
if (!get_client_name(ua, rx)) {
return 0;
}
- bsendmsg(ua, _("Enter file names with paths, or < to enter a filename\n"
- "containg a list of file names with paths, and terminate\n"
- "them with a blank line.\n"));
+ bsendmsg(ua, _("Enter file names with paths, or < to enter a filename\n"
+ "containg a list of file names with paths, and terminate\n"
+ "them with a blank line.\n"));
for ( ;; ) {
- if (!get_cmd(ua, _("Enter full filename: "))) {
+ if (!get_cmd(ua, _("Enter full filename: "))) {
return 0;
}
len = strlen(ua->cmd);
if (!get_client_name(ua, rx)) {
return 0;
}
- bsendmsg(ua, _("Enter file names with paths, or < to enter a filename\n"
- "containg a list of file names with paths, and terminate\n"
- "them with a blank line.\n"));
+ bsendmsg(ua, _("Enter file names with paths, or < to enter a filename\n"
+ "containg a list of file names with paths, and terminate\n"
+ "them with a blank line.\n"));
for ( ;; ) {
- if (!get_cmd(ua, _("Enter full filename: "))) {
+ if (!get_cmd(ua, _("Enter full filename: "))) {
return 0;
}
len = strlen(ua->cmd);
}
return 2;
-
+
case 8: /* Cancel or quit */
return 0;
}
bsendmsg(ua, _("No Jobs selected.\n"));
return 0;
}
- bsendmsg(ua, _("You have selected the following JobId%s: %s\n"),
+ bsendmsg(ua, _("You have selected the following JobId%s: %s\n"),
strchr(rx->JobIds,',')?"s":"",rx->JobIds);
memset(&jr, 0, sizeof(JOB_DBR));
for (p=rx->JobIds; ; ) {
int stat = get_next_jobid_from_list(&p, &JobId);
if (stat < 0) {
- bsendmsg(ua, _("Invalid JobId in list.\n"));
+ bsendmsg(ua, _("Invalid JobId in list.\n"));
return 0;
}
if (stat == 0) {
}
jr.JobId = JobId;
if (!db_get_job_record(ua->jcr, ua->db, &jr)) {
- bsendmsg(ua, _("Unable to get Job record for JobId=%u: ERR=%s\n"),
+ bsendmsg(ua, _("Unable to get Job record for JobId=%u: ERR=%s\n"),
JobId, db_strerror(ua->db));
return 0;
}
if (!acl_access_ok(ua, Job_ACL, jr.Name)) {
- bsendmsg(ua, _("No authorization. Job \"%s\" not selected.\n"),
+ bsendmsg(ua, _("No authorization. Job \"%s\" not selected.\n"),
jr.Name);
- continue;
+ continue;
}
rx->TotalFiles += jr.JobFiles;
}
return 1;
}
-/*
+/*
* Get date from user
*/
static int get_date(UAContext *ua, char *date, int date_len)
{
bsendmsg(ua, _("The restored files will the most current backup\n"
- "BEFORE the date you specify below.\n\n"));
+ "BEFORE the date you specify below.\n\n"));
for ( ;; ) {
if (!get_cmd(ua, _("Enter date as YYYY-MM-DD HH:MM:SS :"))) {
return 0;
break;
}
bsendmsg(ua, _("Improper date format.\n"));
- }
+ }
bstrncpy(date, ua->cmd, date_len);
return 1;
}
/*
- * Insert a single file, or read a list of files from a file
+ * Insert a single file, or read a list of files from a file
*/
static void insert_one_file(UAContext *ua, RESTORE_CTX *rx, char *date)
{
char file[5000];
char *p = ua->cmd;
int line = 0;
-
+
switch (*p) {
case '<':
p++;
if ((ffd = fopen(p, "r")) == NULL) {
- bsendmsg(ua, _("Cannot open file %s: ERR=%s\n"),
+ bsendmsg(ua, _("Cannot open file %s: ERR=%s\n"),
p, strerror(errno));
break;
}
while (fgets(file, sizeof(file), ffd)) {
line++;
if (!insert_file_into_findex_list(ua, rx, file, date)) {
- bsendmsg(ua, _("Error occurred on line %d of %s\n"), line, p);
+ bsendmsg(ua, _("Error occurred on line %d of %s\n"), line, p);
}
}
fclose(ffd);
* lookup the most recent backup in the catalog to get the JobId
* and FileIndex, then insert them into the findex list.
*/
-static int insert_file_into_findex_list(UAContext *ua, RESTORE_CTX *rx, char *file,
+static int insert_file_into_findex_list(UAContext *ua, RESTORE_CTX *rx, char *file,
char *date)
{
strip_trailing_junk(file);
if (*rx->JobIds == 0) {
Mmsg(rx->query, uar_jobid_fileindex, date, rx->path, rx->fname, rx->ClientName);
} else {
- Mmsg(rx->query, uar_jobids_fileindex, rx->JobIds, date,
+ Mmsg(rx->query, uar_jobids_fileindex, rx->JobIds, date,
rx->path, rx->fname, rx->ClientName);
}
rx->found = false;
/* Find and insert jobid and File Index */
if (!db_sql_query(ua->db, rx->query, jobid_fileindex_handler, (void *)rx)) {
- bsendmsg(ua, _("Query failed: %s. ERR=%s\n"),
+ bsendmsg(ua, _("Query failed: %s. ERR=%s\n"),
rx->query, db_strerror(ua->db));
}
if (!rx->found) {
{
char *p, *f;
- /* Find path without the filename.
+ /* Find path without the filename.
* I.e. everything after the last / is a "filename".
* OK, maybe it is a directory name, but we treat it like
* a filename. If we don't find a / then the whole name
}
/* If filename doesn't exist (i.e. root directory), we
- * simply create a blank name consisting of a single
+ * simply create a blank name consisting of a single
* space. This makes handling zero length filenames
* easier.
*/
rx->fnl = 0;
}
- rx->pnl = f - name;
+ rx->pnl = f - name;
if (rx->pnl > 0) {
rx->path = check_pool_memory_size(rx->path, rx->pnl+1);
memcpy(rx->path, name, rx->pnl);
bool OK = true;
memset(&tree, 0, sizeof(TREE_CTX));
- /*
+ /*
* Build the directory tree containing JobIds user selected
*/
tree.root = new_tree(rx->TotalFiles);
/* Use first JobId as estimate of the number of files to restore */
Mmsg(rx->query, uar_count_files, JobId);
if (!db_sql_query(ua->db, rx->query, count_handler, (void *)rx)) {
- bsendmsg(ua, "%s\n", db_strerror(ua->db));
+ bsendmsg(ua, "%s\n", db_strerror(ua->db));
}
if (rx->found) {
/* Add about 25% more than this job for over estimate */
}
for (p=rx->JobIds; get_next_jobid_from_list(&p, &JobId) > 0; ) {
- if (JobId == last_JobId) {
+ if (JobId == last_JobId) {
continue; /* eliminate duplicate JobIds */
}
last_JobId = JobId;
*/
Mmsg(rx->query, uar_sel_files, JobId);
if (!db_sql_query(ua->db, rx->query, insert_tree_handler, (void *)&tree)) {
- bsendmsg(ua, "%s", db_strerror(ua->db));
+ bsendmsg(ua, "%s", db_strerror(ua->db));
}
/*
* Find the MediaTypes for this JobId and add to the name_list
*/
Mmsg(rx->query, uar_mediatype, JobId);
if (!db_sql_query(ua->db, rx->query, unique_name_list_handler, (void *)&rx->name_list)) {
- bsendmsg(ua, "%s", db_strerror(ua->db));
+ bsendmsg(ua, "%s", db_strerror(ua->db));
}
}
char ec1[50];
- bsendmsg(ua, "\n%d Job%s, %s files inserted into the tree%s.\n",
+ bsendmsg(ua, "\n%d Job%s, %s files inserted into the tree%s.\n",
items, items==1?"":"s", edit_uint64_with_commas(tree.FileCount, ec1),
tree.all?" and marked for extraction":"");
}
/*
- * Walk down through the tree finding all files marked to be
+ * Walk down through the tree finding all files marked to be
* extracted making a bootstrap file.
*/
if (OK) {
for (TREE_NODE *node=first_tree_node(tree.root); node; node=next_tree_node(node)) {
- Dmsg2(400, "FI=%d node=0x%x\n", node->FileIndex, node);
+ Dmsg2(400, "FI=%d node=0x%x\n", node->FileIndex, node);
if (node->extract || node->extract_dir) {
- Dmsg2(400, "type=%d FI=%d\n", node->type, node->FileIndex);
+ Dmsg2(400, "type=%d FI=%d\n", node->type, node->FileIndex);
add_findex(rx->bsr, node->JobId, node->FileIndex);
if (node->extract && node->type != TN_NEWDIR) {
rx->selected_files++; /* count only saved files */
bstrncpy(rx->ClientName, cr.Name, sizeof(rx->ClientName));
/*
- * Get FileSet
+ * Get FileSet
*/
memset(&fsr, 0, sizeof(fsr));
- i = find_arg_with_value(ua, "FileSet");
+ i = find_arg_with_value(ua, "FileSet");
if (i >= 0) {
bstrncpy(fsr.FileSet, ua->argv[i], sizeof(fsr.FileSet));
if (!db_get_fileset_record(ua->jcr, ua->db, &fsr)) {
- bsendmsg(ua, _("Error getting FileSet \"%s\": ERR=%s\n"), fsr.FileSet,
+ bsendmsg(ua, _("Error getting FileSet \"%s\": ERR=%s\n"), fsr.FileSet,
db_strerror(ua->db));
i = -1;
}
Mmsg(rx->query, uar_sel_fileset, cr.ClientId, cr.ClientId);
start_prompt(ua, _("The defined FileSet resources are:\n"));
if (!db_sql_query(ua->db, rx->query, fileset_handler, (void *)ua)) {
- bsendmsg(ua, "%s\n", db_strerror(ua->db));
+ bsendmsg(ua, "%s\n", db_strerror(ua->db));
}
- if (do_prompt(ua, _("FileSet"), _("Select FileSet resource"),
+ if (do_prompt(ua, _("FileSet"), _("Select FileSet resource"),
fileset_name, sizeof(fileset_name)) < 0) {
goto bail_out;
}
bstrncpy(fsr.FileSet, fileset_name, sizeof(fsr.FileSet));
if (!db_get_fileset_record(ua->jcr, ua->db, &fsr)) {
- bsendmsg(ua, _("Error getting FileSet record: %s\n"), db_strerror(ua->db));
- bsendmsg(ua, _("This probably means you modified the FileSet.\n"
- "Continuing anyway.\n"));
+ bsendmsg(ua, _("Error getting FileSet record: %s\n"), db_strerror(ua->db));
+ bsendmsg(ua, _("This probably means you modified the FileSet.\n"
+ "Continuing anyway.\n"));
}
}
memset(&pr, 0, sizeof(pr));
bstrncpy(pr.Name, rx->pool->hdr.name, sizeof(pr.Name));
if (db_get_pool_record(ua->jcr, ua->db, &pr)) {
- bsnprintf(pool_select, sizeof(pool_select), "AND Media.PoolId=%u ", pr.PoolId);
+ bsnprintf(pool_select, sizeof(pool_select), "AND Media.PoolId=%u ", pr.PoolId);
} else {
- bsendmsg(ua, _("Pool \"%s\" not found, using any pool.\n"), pr.Name);
+ bsendmsg(ua, _("Pool \"%s\" not found, using any pool.\n"), pr.Name);
}
}
/* Display a list of Jobs selected for this restore */
db_list_sql_query(ua->jcr, ua->db, uar_list_temp, prtit, ua, 1, HORZ_LIST);
} else {
- bsendmsg(ua, _("No jobs found.\n"));
+ bsendmsg(ua, _("No jobs found.\n"));
}
stat = 1;
-
+
bail_out:
db_sql_query(ua->db, uar_del_temp, NULL, NULL);
db_sql_query(ua->db, uar_del_temp1, NULL, NULL);
{
RESTORE_CTX *rx = (RESTORE_CTX *)ctx;
- if (strcmp(rx->last_jobid, row[0]) == 0) {
+ if (strcmp(rx->last_jobid, row[0]) == 0) {
return 0; /* duplicate id */
}
bstrncpy(rx->last_jobid, row[0], sizeof(rx->last_jobid));
{
RESTORE_CTX *rx = (RESTORE_CTX *)ctx;
- rx->JobTDate = str_to_int64(row[1]);
+ rx->JobTDate = str_to_int64(row[1]);
return 0;
}
{
NAME_LIST *name = (NAME_LIST *)ctx;
- if (name->num_ids == MAX_ID_LIST_LEN) {
+ if (name->num_ids == MAX_ID_LIST_LEN) {
return 1;
}
if (name->num_ids == name->max_ids) {
* Print names in the list
*/
static void print_name_list(UAContext *ua, NAME_LIST *name_list)
-{
+{
for (int i=0; i < name_list->num_ids; i++) {
bsendmsg(ua, "%s\n", name_list->name[i]);
}
* Free names in the list
*/
static void free_name_list(NAME_LIST *name_list)
-{
+{
for (int i=0; i < name_list->num_ids; i++) {
free(name_list->name[i]);
}
if (name_list->num_ids > 1) {
bsendmsg(ua, _("Warning, the JobIds that you selected refer to more than one MediaType.\n"
- "Restore is not possible. The MediaTypes used are:\n"));
+ "Restore is not possible. The MediaTypes used are:\n"));
print_name_list(ua, name_list);
rx->store = select_storage_resource(ua);
return;
return;
}
/*
- * We have a single MediaType, look it up in our Storage resource
+ * We have a single MediaType, look it up in our Storage resource
*/
LockRes();
foreach_res(store, R_STORAGE) {
if (rx->store) {
/* Check if an explicit storage resource is given */
store = NULL;
- int i = find_arg_with_value(ua, "storage");
+ int i = find_arg_with_value(ua, "storage");
if (i > 0) {
store = (STORE *)GetResWithName(R_STORAGE, ua->argv[i]);
if (store && !acl_access_ok(ua, Storage_ACL, store->hdr.name)) {
}
}
if (store && (store != rx->store)) {
- bsendmsg(ua, _("Warning default storage overridden by %s on command line.\n"),
+ bsendmsg(ua, _("Warning default storage overridden by %s on command line.\n"),
store->hdr.name);
rx->store = store;
}
if (!rx->store) {
bsendmsg(ua, _("\nWarning. Unable to find Storage resource for\n"
- "MediaType \"%s\", needed by the Jobs you selected.\n"
- "You will be allowed to select a Storage device later.\n"),
- name_list->name[0]);
+ "MediaType \"%s\", needed by the Jobs you selected.\n"
+ "You will be allowed to select a Storage device later.\n"),
+ name_list->name[0]);
}
}
N_("job"), /* Used in a switch() */
N_("jobid"), /* 1 */
N_("client"), /* 2 */
- N_("fd"),
+ N_("fd"),
N_("fileset"), /* 4 */
N_("level"), /* 5 */
N_("storage"), /* 6 */
for (j=0; !kw_ok && kw[j]; j++) {
if (strcasecmp(ua->argk[i], _(kw[j])) == 0) {
/* Note, yes and run have no value, so do not err */
- if (!ua->argv[i] && j != YES_POS /*yes*/) {
+ if (!ua->argv[i] && j != YES_POS /*yes*/) {
bsendmsg(ua, _("Value missing for keyword %s\n"), ua->argk[i]);
return 1;
}
break;
case 1: /* JobId */
if (jid) {
- bsendmsg(ua, _("JobId specified twice.\n"));
+ bsendmsg(ua, _("JobId specified twice.\n"));
return 0;
}
jid = ua->argv[i];
case 2: /* client */
case 3: /* fd */
if (client_name) {
- bsendmsg(ua, _("Client specified twice.\n"));
+ bsendmsg(ua, _("Client specified twice.\n"));
return 0;
}
client_name = ua->argv[i];
break;
case 4: /* fileset */
if (fileset_name) {
- bsendmsg(ua, _("FileSet specified twice.\n"));
+ bsendmsg(ua, _("FileSet specified twice.\n"));
return 0;
}
fileset_name = ua->argv[i];
break;
case 5: /* level */
if (level_name) {
- bsendmsg(ua, _("Level specified twice.\n"));
+ bsendmsg(ua, _("Level specified twice.\n"));
return 0;
}
level_name = ua->argv[i];
case 6: /* storage */
case 7: /* sd */
if (store_name) {
- bsendmsg(ua, _("Storage specified twice.\n"));
+ bsendmsg(ua, _("Storage specified twice.\n"));
return 0;
}
store_name = ua->argv[i];
break;
case 8: /* pool */
if (pool_name) {
- bsendmsg(ua, _("Pool specified twice.\n"));
+ bsendmsg(ua, _("Pool specified twice.\n"));
return 0;
}
pool_name = ua->argv[i];
break;
case 9: /* where */
if (where) {
- bsendmsg(ua, _("Where specified twice.\n"));
+ bsendmsg(ua, _("Where specified twice.\n"));
return 0;
}
where = ua->argv[i];
break;
case 10: /* bootstrap */
if (bootstrap) {
- bsendmsg(ua, _("Bootstrap specified twice.\n"));
+ bsendmsg(ua, _("Bootstrap specified twice.\n"));
return 0;
}
bootstrap = ua->argv[i];
break;
case 11: /* replace */
if (replace) {
- bsendmsg(ua, _("Replace specified twice.\n"));
+ bsendmsg(ua, _("Replace specified twice.\n"));
return 0;
}
replace = ua->argv[i];
break;
case 12: /* When */
if (when) {
- bsendmsg(ua, _("When specified twice.\n"));
+ bsendmsg(ua, _("When specified twice.\n"));
return 0;
}
when = ua->argv[i];
break;
case 13: /* Priority */
if (Priority) {
- bsendmsg(ua, _("Priority specified twice.\n"));
+ bsendmsg(ua, _("Priority specified twice.\n"));
return 0;
}
Priority = atoi(ua->argv[i]);
if (Priority <= 0) {
- bsendmsg(ua, _("Priority must be positive nonzero setting it to 10.\n"));
+ bsendmsg(ua, _("Priority must be positive nonzero setting it to 10.\n"));
Priority = 10;
}
kw_ok = true;
break;
case 15: /* Verify Job */
if (verify_job_name) {
- bsendmsg(ua, _("Verify Job specified twice.\n"));
+ bsendmsg(ua, _("Verify Job specified twice.\n"));
return 0;
}
verify_job_name = ua->argv[i];
* End of keyword for loop -- if not found, we got a bogus keyword
*/
if (!kw_ok) {
- Dmsg1(200, "%s not found\n", ua->argk[i]);
+ Dmsg1(200, "%s not found\n", ua->argk[i]);
/*
* Special case for Job Name, it can be the first
* keyword that has no value.
*/
if (!job_name && !ua->argv[i]) {
job_name = ua->argk[i]; /* use keyword as job name */
- Dmsg1(200, "Set jobname=%s\n", job_name);
+ Dmsg1(200, "Set jobname=%s\n", job_name);
} else {
- bsendmsg(ua, _("Invalid keyword: %s\n"), ua->argk[i]);
+ bsendmsg(ua, _("Invalid keyword: %s\n"), ua->argk[i]);
return 0;
}
}
if (catalog_name != NULL) {
catalog = (CAT *)GetResWithName(R_CATALOG, catalog_name);
if (catalog == NULL) {
- bsendmsg(ua, _("Catalog \"%s\" not found\n"), catalog_name);
+ bsendmsg(ua, _("Catalog \"%s\" not found\n"), catalog_name);
return 0;
}
}
job = (JOB *)GetResWithName(R_JOB, job_name);
if (!job) {
if (*job_name != 0) {
- bsendmsg(ua, _("Job \"%s\" not found\n"), job_name);
+ bsendmsg(ua, _("Job \"%s\" not found\n"), job_name);
}
job = select_job_resource(ua);
} else {
- Dmsg1(200, "Found job=%s\n", job_name);
+ Dmsg1(200, "Found job=%s\n", job_name);
}
} else {
bsendmsg(ua, _("A job name must be specified.\n"));
store = (STORE *)GetResWithName(R_STORAGE, store_name);
if (!store) {
if (*store_name != 0) {
- bsendmsg(ua, _("Storage \"%s\" not found.\n"), store_name);
+ bsendmsg(ua, _("Storage \"%s\" not found.\n"), store_name);
}
store = select_storage_resource(ua);
}
pool = (POOL *)GetResWithName(R_POOL, pool_name);
if (!pool) {
if (*pool_name != 0) {
- bsendmsg(ua, _("Pool \"%s\" not found.\n"), pool_name);
+ bsendmsg(ua, _("Pool \"%s\" not found.\n"), pool_name);
}
pool = select_pool_resource(ua);
}
client = (CLIENT *)GetResWithName(R_CLIENT, client_name);
if (!client) {
if (*client_name != 0) {
- bsendmsg(ua, _("Client \"%s\" not found.\n"), client_name);
+ bsendmsg(ua, _("Client \"%s\" not found.\n"), client_name);
}
client = select_client_resource(ua);
}
if (fileset_name) {
fileset = (FILESET *)GetResWithName(R_FILESET, fileset_name);
if (!fileset) {
- bsendmsg(ua, _("FileSet \"%s\" not found.\n"), fileset_name);
+ bsendmsg(ua, _("FileSet \"%s\" not found.\n"), fileset_name);
fileset = select_fileset_resource(ua);
}
} else {
if (verify_job_name) {
verify_job = (JOB *)GetResWithName(R_JOB, verify_job_name);
if (!verify_job) {
- bsendmsg(ua, _("Verify Job \"%s\" not found.\n"), verify_job_name);
+ bsendmsg(ua, _("Verify Job \"%s\" not found.\n"), verify_job_name);
verify_job = select_job_resource(ua);
}
} else {
if (when) {
jcr->sched_time = str_to_utime(when);
if (jcr->sched_time == 0) {
- bsendmsg(ua, _("Invalid time, using current time.\n"));
+ bsendmsg(ua, _("Invalid time, using current time.\n"));
jcr->sched_time = time(NULL);
}
}
-
+
if (bootstrap) {
if (jcr->RestoreBootstrap) {
free(jcr->RestoreBootstrap);
}
}
if (!jcr->replace) {
- bsendmsg(ua, _("Invalid replace option: %s\n"), replace);
+ bsendmsg(ua, _("Invalid replace option: %s\n"), replace);
goto bail_out;
}
} else if (job->replace) {
if (Priority) {
jcr->JobPriority = Priority;
}
-
+
if (find_arg(ua, _("fdcalled")) > 0) {
jcr->file_bsock = dup_bsock(ua->UA_sock);
ua->quit = true;
}
if (level_name) {
if (!get_level_from_name(jcr, level_name)) {
- bsendmsg(ua, _("Level %s not valid.\n"), level_name);
+ bsendmsg(ua, _("Level %s not valid.\n"), level_name);
goto bail_out;
}
}
goto start_job;
}
- /*
+ /*
* Prompt User to see if all run job parameters are correct, and
* allow him to modify them.
*/
char ec1[30];
char dt[MAX_TIME_LENGTH];
case JT_ADMIN:
- bsendmsg(ua, _("Run %s job\n\
-JobName: %s\n\
-FileSet: %s\n\
-Client: %s\n\
-Storage: %s\n\
-When: %s\n\
-Priority: %d\n"),
- _("Admin"),
+ bsendmsg(ua, _("Run %s job\n"
+"JobName: %s\n"
+"FileSet: %s\n"
+"Client: %s\n"
+"Storage: %s\n"
+"When: %s\n"
+"Priority: %d\n"),
+ _("Admin"),
job->hdr.name,
jcr->fileset->hdr.name,
NPRT(jcr->client->hdr.name),
- NPRT(jcr->store->hdr.name),
- bstrutime(dt, sizeof(dt), jcr->sched_time),
+ NPRT(jcr->store->hdr.name),
+ bstrutime(dt, sizeof(dt), jcr->sched_time),
jcr->JobPriority);
jcr->JobLevel = L_FULL;
break;
case JT_BACKUP:
case JT_VERIFY:
if (jcr->JobType == JT_BACKUP) {
- bsendmsg(ua, _("Run %s job\n\
-JobName: %s\n\
-FileSet: %s\n\
-Level: %s\n\
-Client: %s\n\
-Storage: %s\n\
-Pool: %s\n\
-When: %s\n\
-Priority: %d\n"),
- _("Backup"),
+ bsendmsg(ua, _("Run %s job\n"
+"JobName: %s\n"
+"FileSet: %s\n"
+"Level: %s\n"
+"Client: %s\n"
+"Storage: %s\n"
+"Pool: %s\n"
+"When: %s\n"
+"Priority: %d\n"),
+ _("Backup"),
job->hdr.name,
jcr->fileset->hdr.name,
level_to_str(jcr->JobLevel),
jcr->client->hdr.name,
jcr->store->hdr.name,
- NPRT(jcr->pool->hdr.name),
+ NPRT(jcr->pool->hdr.name),
bstrutime(dt, sizeof(dt), jcr->sched_time),
jcr->JobPriority);
} else { /* JT_VERIFY */
if (jcr->verify_job) {
Name = jcr->verify_job->hdr.name;
} else {
- Name = "";
+ Name = "";
}
- bsendmsg(ua, _("Run %s job\n\
-JobName: %s\n\
-FileSet: %s\n\
-Level: %s\n\
-Client: %s\n\
-Storage: %s\n\
-Pool: %s\n\
-Verify Job: %s\n\
-When: %s\n\
-Priority: %d\n"),
- _("Verify"),
+ bsendmsg(ua, _("Run %s job\n"
+"JobName: %s\n"
+"FileSet: %s\n"
+"Level: %s\n"
+"Client: %s\n"
+"Storage: %s\n"
+"Pool: %s\n"
+"Verify Job: %s\n"
+"When: %s\n"
+"Priority: %d\n"),
+ _("Verify"),
job->hdr.name,
jcr->fileset->hdr.name,
level_to_str(jcr->JobLevel),
jcr->client->hdr.name,
jcr->store->hdr.name,
- NPRT(jcr->pool->hdr.name),
- Name,
+ NPRT(jcr->pool->hdr.name),
+ Name,
bstrutime(dt, sizeof(dt), jcr->sched_time),
jcr->JobPriority);
}
if (jid) {
jcr->RestoreJobId = atoi(jid);
} else {
- if (!get_pint(ua, _("Please enter a JobId for restore: "))) {
+ if (!get_pint(ua, _("Please enter a JobId for restore: "))) {
goto bail_out;
- }
+ }
jcr->RestoreJobId = ua->pint32_val;
}
}
jcr->JobLevel = L_FULL; /* default level */
Dmsg1(20, "JobId to restore=%d\n", jcr->RestoreJobId);
if (jcr->RestoreJobId == 0) {
- bsendmsg(ua, _("Run Restore job\n"
- "JobName: %s\n"
- "Bootstrap: %s\n"
- "Where: %s\n"
- "Replace: %s\n"
- "FileSet: %s\n"
- "Client: %s\n"
- "Storage: %s\n"
- "When: %s\n"
- "Catalog: %s\n"
- "Priority: %d\n"),
+ bsendmsg(ua, _("Run Restore job\n"
+ "JobName: %s\n"
+ "Bootstrap: %s\n"
+ "Where: %s\n"
+ "Replace: %s\n"
+ "FileSet: %s\n"
+ "Client: %s\n"
+ "Storage: %s\n"
+ "When: %s\n"
+ "Catalog: %s\n"
+ "Priority: %d\n"),
job->hdr.name,
NPRT(jcr->RestoreBootstrap),
jcr->where?jcr->where:NPRT(job->RestoreWhere),
replace,
jcr->fileset->hdr.name,
jcr->client->hdr.name,
- jcr->store->hdr.name,
+ jcr->store->hdr.name,
bstrutime(dt, sizeof(dt), jcr->sched_time),
jcr->catalog->hdr.name,
jcr->JobPriority);
} else {
- bsendmsg(ua, _("Run Restore job\n"
- "JobName: %s\n"
- "Bootstrap: %s\n"
- "Where: %s\n"
- "Replace: %s\n"
- "Client: %s\n"
- "Storage: %s\n"
- "JobId: %s\n"
- "When: %s\n"
- "Catalog: %s\n"
- "Priority: %d\n"),
+ bsendmsg(ua, _("Run Restore job\n"
+ "JobName: %s\n"
+ "Bootstrap: %s\n"
+ "Where: %s\n"
+ "Replace: %s\n"
+ "Client: %s\n"
+ "Storage: %s\n"
+ "JobId: %s\n"
+ "When: %s\n"
+ "Catalog: %s\n"
+ "Priority: %d\n"),
job->hdr.name,
NPRT(jcr->RestoreBootstrap),
jcr->where?jcr->where:NPRT(job->RestoreWhere),
replace,
jcr->client->hdr.name,
- jcr->store->hdr.name,
- jcr->RestoreJobId==0?"*None*":edit_uint64(jcr->RestoreJobId, ec1),
+ jcr->store->hdr.name,
+ jcr->RestoreJobId==0?"*None*":edit_uint64(jcr->RestoreJobId, ec1),
bstrutime(dt, sizeof(dt), jcr->sched_time),
jcr->catalog->hdr.name,
jcr->JobPriority);
add_prompt(ua, _("Priority")); /* 6 */
if (jcr->JobType == JT_BACKUP ||
jcr->JobType == JT_VERIFY) {
- add_prompt(ua, _("Pool")); /* 7 */
+ add_prompt(ua, _("Pool")); /* 7 */
if (jcr->JobType == JT_VERIFY) {
- add_prompt(ua, _("Verify Job")); /* 8 */
+ add_prompt(ua, _("Verify Job")); /* 8 */
}
} else if (jcr->JobType == JT_RESTORE) {
- add_prompt(ua, _("Bootstrap")); /* 7 */
- add_prompt(ua, _("Where")); /* 8 */
- add_prompt(ua, _("Replace")); /* 9 */
- add_prompt(ua, _("JobId")); /* 10 */
+ add_prompt(ua, _("Bootstrap")); /* 7 */
+ add_prompt(ua, _("Where")); /* 8 */
+ add_prompt(ua, _("Replace")); /* 9 */
+ add_prompt(ua, _("JobId")); /* 10 */
}
switch (do_prompt(ua, "", _("Select parameter to modify"), NULL, 0)) {
case 0:
/* Level */
if (jcr->JobType == JT_BACKUP) {
- start_prompt(ua, _("Levels:\n"));
- add_prompt(ua, _("Base"));
- add_prompt(ua, _("Full"));
- add_prompt(ua, _("Incremental"));
- add_prompt(ua, _("Differential"));
- add_prompt(ua, _("Since"));
- switch (do_prompt(ua, "", _("Select level"), NULL, 0)) {
+ start_prompt(ua, _("Levels:\n"));
+ add_prompt(ua, _("Base"));
+ add_prompt(ua, _("Full"));
+ add_prompt(ua, _("Incremental"));
+ add_prompt(ua, _("Differential"));
+ add_prompt(ua, _("Since"));
+ switch (do_prompt(ua, "", _("Select level"), NULL, 0)) {
case 0:
jcr->JobLevel = L_BASE;
break;
}
goto try_again;
} else if (jcr->JobType == JT_VERIFY) {
- start_prompt(ua, _("Levels:\n"));
- add_prompt(ua, _("Initialize Catalog"));
- add_prompt(ua, _("Verify Catalog"));
- add_prompt(ua, _("Verify Volume to Catalog"));
- add_prompt(ua, _("Verify Disk to Catalog"));
- add_prompt(ua, _("Verify Volume Data (not yet implemented)"));
- switch (do_prompt(ua, "", _("Select level"), NULL, 0)) {
+ start_prompt(ua, _("Levels:\n"));
+ add_prompt(ua, _("Initialize Catalog"));
+ add_prompt(ua, _("Verify Catalog"));
+ add_prompt(ua, _("Verify Volume to Catalog"));
+ add_prompt(ua, _("Verify Disk to Catalog"));
+ add_prompt(ua, _("Verify Volume Data (not yet implemented)"));
+ switch (do_prompt(ua, "", _("Select level"), NULL, 0)) {
case 0:
jcr->JobLevel = L_VERIFY_INIT;
break;
}
goto try_again;
} else {
- bsendmsg(ua, _("Level not appropriate for this Job. Cannot be changed.\n"));
+ bsendmsg(ua, _("Level not appropriate for this Job. Cannot be changed.\n"));
}
goto try_again;
case 1:
if (fileset) {
jcr->fileset = fileset;
goto try_again;
- }
+ }
break;
case 4:
/* Client */
break;
case 5:
/* When */
- if (!get_cmd(ua, _("Please enter desired start time as YYYY-MM-DD HH:MM:SS (return for now): "))) {
+ if (!get_cmd(ua, _("Please enter desired start time as YYYY-MM-DD HH:MM:SS (return for now): "))) {
break;
}
if (ua->cmd[0] == 0) {
} else {
jcr->sched_time = str_to_utime(ua->cmd);
if (jcr->sched_time == 0) {
- bsendmsg(ua, _("Invalid time, using current time.\n"));
+ bsendmsg(ua, _("Invalid time, using current time.\n"));
jcr->sched_time = time(NULL);
}
}
goto try_again;
case 6:
/* Priority */
- if (!get_pint(ua, _("Enter new Priority: "))) {
+ if (!get_pint(ua, _("Enter new Priority: "))) {
break;
}
if (ua->pint32_val == 0) {
- bsendmsg(ua, _("Priority must be a positive integer.\n"));
+ bsendmsg(ua, _("Priority must be a positive integer.\n"));
} else {
jcr->JobPriority = ua->pint32_val;
}
}
/* Bootstrap */
- if (!get_cmd(ua, _("Please enter the Bootstrap file name: "))) {
+ if (!get_cmd(ua, _("Please enter the Bootstrap file name: "))) {
break;
}
if (jcr->RestoreBootstrap) {
}
if (ua->cmd[0] != 0) {
jcr->RestoreBootstrap = bstrdup(ua->cmd);
- fd = fopen(jcr->RestoreBootstrap, "r");
+ fd = fopen(jcr->RestoreBootstrap, "r");
if (!fd) {
- bsendmsg(ua, _("Warning cannot open %s: ERR=%s\n"),
+ bsendmsg(ua, _("Warning cannot open %s: ERR=%s\n"),
jcr->RestoreBootstrap, strerror(errno));
free(jcr->RestoreBootstrap);
jcr->RestoreBootstrap = NULL;
goto try_again;
}
/* Where */
- if (!get_cmd(ua, _("Please enter path prefix for restore (/ for none): "))) {
+ if (!get_cmd(ua, _("Please enter path prefix for restore (/ for none): "))) {
break;
}
if (jcr->where) {
free(jcr->where);
jcr->where = NULL;
}
- if (ua->cmd[0] == '/' && ua->cmd[1] == 0) {
+ if (ua->cmd[0] == '/' && ua->cmd[1] == 0) {
ua->cmd[0] = 0;
}
jcr->where = bstrdup(ua->cmd);
goto try_again;
case 9:
/* Replace */
- start_prompt(ua, _("Replace:\n"));
+ start_prompt(ua, _("Replace:\n"));
for (i=0; ReplaceOptions[i].name; i++) {
add_prompt(ua, ReplaceOptions[i].name);
}
- opt = do_prompt(ua, "", _("Select replace option"), NULL, 0);
+ opt = do_prompt(ua, "", _("Select replace option"), NULL, 0);
if (opt >= 0) {
jcr->replace = ReplaceOptions[opt].token;
}
jid = NULL; /* force reprompt */
jcr->RestoreJobId = 0;
if (jcr->RestoreBootstrap) {
- bsendmsg(ua, _("You must set the bootstrap file to NULL to be able to specify a JobId.\n"));
+ bsendmsg(ua, _("You must set the bootstrap file to NULL to be able to specify a JobId.\n"));
}
goto try_again;
- default:
+ default:
goto try_again;
}
goto bail_out;
JobId = run_job(jcr);
free_jcr(jcr); /* release jcr */
if (JobId == 0) {
- bsendmsg(ua, _("Job failed.\n"));
+ bsendmsg(ua, _("Job failed.\n"));
} else {
- bsendmsg(ua, _("Job started. JobId=%u\n"), JobId);
+ bsendmsg(ua, _("Job started. JobId=%u\n"), JobId);
}
return JobId;
}
char ed1[100];
for ( ;; ) {
- bsendmsg(ua, _("The current %s retention period is: %s\n"),
+ bsendmsg(ua, _("The current %s retention period is: %s\n"),
msg, edit_utime(*ret, ed1, sizeof(ed1)));
if (!get_cmd(ua, _("Continue? (yes/mod/no): "))) {
return 0;
}
if (strcasecmp(ua->cmd, _("mod")) == 0) {
- if (!get_cmd(ua, _("Enter new retention period: "))) {
+ if (!get_cmd(ua, _("Enter new retention period: "))) {
return 0;
}
if (!duration_to_utime(ua->cmd, ret)) {
- bsendmsg(ua, _("Invalid period.\n"));
+ bsendmsg(ua, _("Invalid period.\n"));
continue;
}
continue;
return 1;
}
-/*
+/*
* Given a list of keywords, find the first one
* that is in the argument list.
* Returns: -1 if not found
return -1;
}
-/*
+/*
* Given one keyword, find the first one that
* is in the argument list.
* Returns: argk index (always gt 0)
return -1;
}
-/*
+/*
* Given a single keyword, find it in the argument list, but
* it must have a value
* Returns: -1 if not found or no value
return -1;
}
-/*
- * Given a list of keywords, prompt the user
+/*
+ * Given a list of keywords, prompt the user
* to choose one.
*
* Returns: -1 on failure
}
-/*
+/*
* Select a Storage resource from prompt list
*/
STORE *select_storage_resource(UAContext *ua)
{
- char name[MAX_NAME_LENGTH];
+ char name[MAX_NAME_LENGTH];
STORE *store;
start_prompt(ua, _("The defined Storage resources are:\n"));
return store;
}
-/*
+/*
* Select a FileSet resource from prompt list
*/
FILESET *select_fileset_resource(UAContext *ua)
{
- char name[MAX_NAME_LENGTH];
+ char name[MAX_NAME_LENGTH];
FILESET *fs;
start_prompt(ua, _("The defined FileSet resources are:\n"));
}
-/*
+/*
* Get a catalog resource from prompt list
*/
CAT *get_catalog_resource(UAContext *ua)
{
- char name[MAX_NAME_LENGTH];
+ char name[MAX_NAME_LENGTH];
CAT *catalog = NULL;
int i;
}
-/*
+/*
* Select a Job resource from prompt list
*/
JOB *select_job_resource(UAContext *ua)
{
- char name[MAX_NAME_LENGTH];
+ char name[MAX_NAME_LENGTH];
JOB *job;
start_prompt(ua, _("The defined Job resources are:\n"));
return job;
}
-/*
+/*
* Select a Restore Job resource from prompt list
*/
JOB *select_restore_job_resource(UAContext *ua)
{
- char name[MAX_NAME_LENGTH];
+ char name[MAX_NAME_LENGTH];
JOB *job;
start_prompt(ua, _("The defined Restore Job resources are:\n"));
-/*
+/*
* Select a client resource from prompt list
*/
CLIENT *select_client_resource(UAContext *ua)
{
- char name[MAX_NAME_LENGTH];
+ char name[MAX_NAME_LENGTH];
CLIENT *client;
start_prompt(ua, _("The defined Client resources are:\n"));
{
CLIENT *client = NULL;
int i;
-
+
for (i=1; i<ua->argc; i++) {
if ((strcasecmp(ua->argk[i], _("client")) == 0 ||
- strcasecmp(ua->argk[i], _("fd")) == 0) && ua->argv[i]) {
+ strcasecmp(ua->argk[i], _("fd")) == 0) && ua->argv[i]) {
if (!acl_access_ok(ua, Client_ACL, ua->argv[i])) {
break;
}
if (client) {
return client;
}
- bsendmsg(ua, _("Error: Client resource %s does not exist.\n"), ua->argv[i]);
+ bsendmsg(ua, _("Error: Client resource %s does not exist.\n"), ua->argv[i]);
break;
}
}
}
/* Scan what the user has entered looking for:
- *
+ *
* client=<client-name>
*
* if error or not found, put up a list of client DBRs
bsendmsg(ua, _("Could not find Client %s: ERR=%s"), cr->Name, db_strerror(ua->db));
}
for (i=1; i<ua->argc; i++) {
- if ((strcasecmp(ua->argk[i], _("client")) == 0 ||
- strcasecmp(ua->argk[i], _("fd")) == 0) && ua->argv[i]) {
+ if ((strcasecmp(ua->argk[i], _("client")) == 0 ||
+ strcasecmp(ua->argk[i], _("fd")) == 0) && ua->argv[i]) {
if (!acl_access_ok(ua, Client_ACL, ua->argv[i])) {
break;
}
bstrncpy(cr->Name, ua->argv[i], sizeof(cr->Name));
if (!db_get_client_record(ua->jcr, ua->db, cr)) {
- bsendmsg(ua, _("Could not find Client \"%s\": ERR=%s"), ua->argv[i],
+ bsendmsg(ua, _("Could not find Client \"%s\": ERR=%s"), ua->argv[i],
db_strerror(ua->db));
cr->ClientId = 0;
break;
CLIENT_DBR ocr;
char name[MAX_NAME_LENGTH];
int num_clients, i;
- uint32_t *ids;
+ uint32_t *ids;
cr->ClientId = 0;
bsendmsg(ua, _("No clients defined. You must run a job before using this command.\n"));
return 0;
}
-
+
start_prompt(ua, _("Defined Clients:\n"));
for (i=0; i < num_clients; i++) {
ocr.ClientId = ids[i];
/* Scan what the user has entered looking for:
- *
- * pool=<pool-name>
+ *
+ * pool=<pool-name>
*
* if error or not found, put up a list of pool DBRs
* to choose from.
{
if (pr->Name[0]) { /* If name already supplied */
if (db_get_pool_record(ua->jcr, ua->db, pr) &&
- acl_access_ok(ua, Pool_ACL, pr->Name)) {
+ acl_access_ok(ua, Pool_ACL, pr->Name)) {
return true;
}
bsendmsg(ua, _("Could not find Pool \"%s\": ERR=%s"), pr->Name, db_strerror(ua->db));
POOL_DBR opr;
char name[MAX_NAME_LENGTH];
int num_pools, i;
- uint32_t *ids;
+ uint32_t *ids;
for (i=1; i<ua->argc; i++) {
if (strcasecmp(ua->argk[i], _("pool")) == 0 && ua->argv[i] &&
acl_access_ok(ua, Pool_ACL, ua->argv[i])) {
bstrncpy(pr->Name, ua->argv[i], sizeof(pr->Name));
if (!db_get_pool_record(ua->jcr, ua->db, pr)) {
- bsendmsg(ua, _("Could not find Pool \"%s\": ERR=%s"), ua->argv[i],
+ bsendmsg(ua, _("Could not find Pool \"%s\": ERR=%s"), ua->argv[i],
db_strerror(ua->db));
pr->PoolId = 0;
break;
bsendmsg(ua, _("No pools defined. Use the \"create\" command to create one.\n"));
return false;
}
-
+
start_prompt(ua, _("Defined Pools:\n"));
for (i=0; i < num_pools; i++) {
opr.PoolId = ids[i];
}
-/*
+/*
* Select a pool resource from prompt list
*/
POOL *select_pool_resource(UAContext *ua)
{
- char name[MAX_NAME_LENGTH];
+ char name[MAX_NAME_LENGTH];
POOL *pool;
start_prompt(ua, _("The defined Pool resources are:\n"));
/*
* If you are thinking about using it, you
- * probably want to use select_pool_dbr()
+ * probably want to use select_pool_dbr()
* or get_pool_dbr() above.
*/
POOL *get_pool_resource(UAContext *ua)
{
POOL *pool = NULL;
int i;
-
+
i = find_arg_with_value(ua, "pool");
if (i >= 0 && acl_access_ok(ua, Pool_ACL, ua->argv[i])) {
pool = (POOL *)GetResWithName(R_POOL, ua->argv[i]);
/* Scan what the user has entered looking for:
- *
+ *
* jobid=nn
*
* if error or not found, put up a list of Jobs
continue;
}
if (!db_get_job_record(ua->jcr, ua->db, jr)) {
- bsendmsg(ua, _("Could not find Job \"%s\": ERR=%s"), ua->argv[i],
+ bsendmsg(ua, _("Could not find Job \"%s\": ERR=%s"), ua->argv[i],
db_strerror(ua->db));
jr->JobId = 0;
break;
}
/*
- * Implement unique set of prompts
+ * Implement unique set of prompts
*/
void start_prompt(UAContext *ua, const char *msg)
{
}
/*
- * Add to prompts -- keeping them unique
+ * Add to prompts -- keeping them unique
*/
void add_prompt(UAContext *ua, const char *prompt)
{
for ( ;; ) {
/* First item is the prompt string, not the items */
- if (ua->num_prompts == 1) {
- bsendmsg(ua, _("Selection is empty!\n"));
+ if (ua->num_prompts == 1) {
+ bsendmsg(ua, _("Selection is empty!\n"));
item = 0; /* list is empty ! */
break;
}
if (ua->num_prompts == 2) {
item = 1;
- bsendmsg(ua, _("Item 1 selected automatically.\n"));
+ bsendmsg(ua, _("Item 1 selected automatically.\n"));
if (prompt) {
bstrncpy(prompt, ua->prompt[1], max_prompt);
}
break;
} else {
- sprintf(pmsg, "%s (1-%d): ", msg, ua->num_prompts-1);
+ sprintf(pmsg, "%s (1-%d): ", msg, ua->num_prompts-1);
}
/* Either a . or an @ will get you out of the loop */
if (!get_pint(ua, pmsg)) {
item = -1; /* error */
- bsendmsg(ua, _("Selection aborted, nothing done.\n"));
+ bsendmsg(ua, _("Selection aborted, nothing done.\n"));
break;
}
item = ua->pint32_val;
if (item < 1 || item >= ua->num_prompts) {
- bsendmsg(ua, _("Please enter a number between 1 and %d\n"), ua->num_prompts-1);
+ bsendmsg(ua, _("Please enter a number between 1 and %d\n"), ua->num_prompts-1);
continue;
}
if (prompt) {
}
break;
}
-
+
done:
for (i=0; i < ua->num_prompts; i++) {
free(ua->prompt[i]);
int jobid;
JCR *jcr;
int i;
-
+
for (i=1; i<ua->argc; i++) {
if (use_default && !ua->argv[i]) {
/* Ignore slots, scan and barcode(s) keywords */
- if (strncasecmp("scan", ua->argk[i], 4) == 0 ||
- strncasecmp("barcode", ua->argk[i], 7) == 0 ||
- strncasecmp("slots", ua->argk[i], 5) == 0) {
+ if (strncasecmp("scan", ua->argk[i], 4) == 0 ||
+ strncasecmp("barcode", ua->argk[i], 7) == 0 ||
+ strncasecmp("slots", ua->argk[i], 5) == 0) {
continue;
}
/* Default argument is storage */
if (store_name) {
- bsendmsg(ua, _("Storage name given twice.\n"));
+ bsendmsg(ua, _("Storage name given twice.\n"));
return NULL;
}
store_name = ua->argk[i];
- if (*store_name == '?') {
+ if (*store_name == '?') {
*store_name = 0;
break;
}
} else {
- if (strcasecmp(ua->argk[i], _("storage")) == 0 ||
- strcasecmp(ua->argk[i], _("sd")) == 0) {
+ if (strcasecmp(ua->argk[i], _("storage")) == 0 ||
+ strcasecmp(ua->argk[i], _("sd")) == 0) {
store_name = ua->argv[i];
break;
- } else if (strcasecmp(ua->argk[i], _("jobid")) == 0) {
+ } else if (strcasecmp(ua->argk[i], _("jobid")) == 0) {
jobid = str_to_int64(ua->argv[i]);
if (jobid <= 0) {
- bsendmsg(ua, _("Expecting jobid=nn command, got: %s\n"), ua->argk[i]);
+ bsendmsg(ua, _("Expecting jobid=nn command, got: %s\n"), ua->argk[i]);
return NULL;
}
if (!(jcr=get_jcr_by_id(jobid))) {
- bsendmsg(ua, _("JobId %d is not running.\n"), jobid);
+ bsendmsg(ua, _("JobId %d is not running.\n"), jobid);
return NULL;
}
store = jcr->store;
free_jcr(jcr);
break;
- } else if (strcasecmp(ua->argk[i], _("job")) == 0) {
+ } else if (strcasecmp(ua->argk[i], _("job")) == 0) {
if (!ua->argv[i]) {
- bsendmsg(ua, _("Expecting job=xxx, got: %s.\n"), ua->argk[i]);
+ bsendmsg(ua, _("Expecting job=xxx, got: %s.\n"), ua->argk[i]);
return NULL;
}
if (!(jcr=get_jcr_by_partial_name(ua->argv[i]))) {
- bsendmsg(ua, _("Job \"%s\" is not running.\n"), ua->argv[i]);
+ bsendmsg(ua, _("Job \"%s\" is not running.\n"), ua->argv[i]);
return NULL;
}
store = jcr->store;
if (store && !acl_access_ok(ua, Storage_ACL, store->hdr.name)) {
store = NULL;
}
-
+
if (!store && store_name) {
store = (STORE *)GetResWithName(R_STORAGE, store_name);
if (!store) {
- bsendmsg(ua, "Storage resource \"%s\": not found\n", store_name);
+ bsendmsg(ua, "Storage resource \"%s\": not found\n", store_name);
}
}
if (store && !acl_access_ok(ua, Storage_ACL, store->hdr.name)) {
/*
- * Scan looking for mediatype=
+ * Scan looking for mediatype=
*
* if not found or error, put up selection list
*
return;
}
-extern "C"
+extern "C"
void *connect_thread(void *arg)
{
pthread_detach(pthread_self());
}
/*
- * Handle Director User Agent commands
+ * Handle Director User Agent commands
*
*/
static void *handle_UA_client_request(void *arg)
if (stat >= 0) {
pm_strcpy(ua->cmd, ua->UA_sock->msg);
parse_ua_args(ua);
- if (ua->argc > 0 && ua->argk[0][0] == '.') {
+ if (ua->argc > 0 && ua->argk[0][0] == '.') {
do_a_dot_command(ua, ua->cmd);
} else {
do_a_command(ua, ua->cmd);
}
if (!ua->quit) {
if (ua->auto_display_messages) {
- strcpy(ua->cmd, "messages");
+ strcpy(ua->cmd, "messages");
qmessagescmd(ua, ua->cmd);
ua->user_notified_msg_pending = FALSE;
} else if (!ua->user_notified_msg_pending && console_msg_pending) {
- bsendmsg(ua, _("You have messages.\n"));
+ bsendmsg(ua, _("You have messages.\n"));
ua->user_notified_msg_pending = TRUE;
}
bnet_sig(ua->UA_sock, BNET_EOD); /* send end of command */
/*
* Create a UAContext for a Job that is running so that
- * it can the User Agent routines and
+ * it can the User Agent routines and
* to ensure that the Job gets the proper output.
* This is a sort of mini-kludge, and should be
* unified at some point.
/*
- * Called from main Bacula thread
+ * Called from main Bacula thread
*/
void term_ua_server()
{
{
JCR* njcr;
s_last_job* job;
-
+
if (!open_db(ua)) {
return 1;
}
bsendmsg(ua, "1900 Bad .status command, missing arguments.\n");
return 1;
}
-
+
if (strcasecmp(ua->argk[2], "current") == 0) {
bsendmsg(ua, OKqstatus, ua->argk[2]);
lock_jcr_chain();
bsendmsg(ua, "1900 Bad .status command, wrong argument.\n");
return 1;
}
-
+
return 1;
}
do_all_status(ua);
return 1;
} else if (strcasecmp(ua->argk[i], _("dir")) == 0 ||
- strcasecmp(ua->argk[i], _("director")) == 0) {
+ strcasecmp(ua->argk[i], _("director")) == 0) {
do_director_status(ua);
return 1;
} else if (strcasecmp(ua->argk[i], _("client")) == 0) {
}
}
/* If no args, ask for status type */
- if (ua->argc == 1) {
- char prmt[MAX_NAME_LENGTH];
-
+ if (ua->argc == 1) {
+ char prmt[MAX_NAME_LENGTH];
+
start_prompt(ua, _("Status available for:\n"));
add_prompt(ua, _("Director"));
add_prompt(ua, _("Storage"));
return 1;
}
Dmsg1(20, "item=%d\n", item);
- switch (item) {
+ switch (item) {
case 0: /* Director */
do_director_status(ua);
break;
i++;
}
unique_store = (STORE **) malloc(i * sizeof(STORE));
- /* Find Unique Storage address/port */
+ /* Find Unique Storage address/port */
i = 0;
foreach_res(store, R_STORAGE) {
found = false;
}
if (!found) {
unique_store[i++] = store;
- Dmsg2(40, "Stuffing: %s:%d\n", store->address, store->SDport);
+ Dmsg2(40, "Stuffing: %s:%d\n", store->address, store->SDport);
}
}
UnlockRes();
i++;
}
unique_client = (CLIENT **)malloc(i * sizeof(CLIENT));
- /* Find Unique Client address/port */
+ /* Find Unique Client address/port */
i = 0;
foreach_res(client, R_CLIENT) {
found = false;
}
if (!found) {
unique_client[i++] = client;
- Dmsg2(40, "Stuffing: %s:%d\n", client->address, client->FDport);
+ Dmsg2(40, "Stuffing: %s:%d\n", client->address, client->FDport);
}
}
UnlockRes();
do_client_status(ua, unique_client[j]);
}
free(unique_client);
-
+
}
static void do_director_status(UAContext *ua)
bsendmsg(ua, "%s Version: " VERSION " (" BDATE ") %s %s %s\n", my_name,
HOST_OS, DISTNAME, DISTVER);
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");
+ bsendmsg(ua, _("Daemon started %s, %d Job%s run since started.\n"),
+ dt, num_jobs_run, num_jobs_run == 1 ? "" : "s");
if (debug_level > 0) {
char b1[35], b2[35], b3[35], b4[35];
bsendmsg(ua, _(" Heap: bytes=%s max_bytes=%s bufs=%s max_bufs=%s\n"),
*/
list_scheduled_jobs(ua);
- /*
+ /*
* List running jobs
*/
list_running_jobs(ua);
- /*
+ /*
* List terminated jobs
*/
list_terminated_jobs(ua);
set_storage(ua->jcr, store);
/* Try connecting for up to 15 seconds */
- bsendmsg(ua, _("Connecting to Storage daemon %s at %s:%d\n"),
+ bsendmsg(ua, _("Connecting to Storage daemon %s at %s:%d\n"),
store->hdr.name, store->address, store->SDport);
if (!connect_to_storage_daemon(ua->jcr, 1, 15, 0)) {
bsendmsg(ua, _("\nFailed to connect to Storage daemon %s.\n====\n"),
if (ua->jcr->store_bsock) {
bnet_close(ua->jcr->store_bsock);
ua->jcr->store_bsock = NULL;
- }
+ }
return;
}
Dmsg0(20, _("Connected to storage daemon\n"));
bnet_sig(sd, BNET_TERMINATE);
bnet_close(sd);
ua->jcr->store_bsock = NULL;
- return;
+ return;
}
-
+
static void do_client_status(UAContext *ua, CLIENT *client)
{
BSOCK *fd;
ua->jcr->sd_auth_key = bstrdup("dummy");
/* Try to connect for 15 seconds */
- bsendmsg(ua, _("Connecting to Client %s at %s:%d\n"),
+ bsendmsg(ua, _("Connecting to Client %s at %s:%d\n"),
client->hdr.name, client->address, client->FDport);
if (!connect_to_file_daemon(ua->jcr, 1, 15, 0)) {
bsendmsg(ua, _("Failed to connect to Client %s.\n====\n"),
if (ua->jcr->file_bsock) {
bnet_close(ua->jcr->file_bsock);
ua->jcr->file_bsock = NULL;
- }
+ }
return;
}
Dmsg0(20, _("Connected to file daemon\n"));
bnet_close(fd);
ua->jcr->file_bsock = NULL;
- return;
+ return;
}
static void prt_runhdr(UAContext *ua)
static void prt_runtime(UAContext *ua, sched_pkt *sp)
{
- char dt[MAX_TIME_LENGTH];
+ char dt[MAX_TIME_LENGTH];
const char *level_ptr;
bool ok = false;
bool close_db = false;
ok = find_next_volume_for_append(jcr, &mr, 0);
}
if (!ok) {
- bstrncpy(mr.VolumeName, "*unknown*", sizeof(mr.VolumeName));
+ bstrncpy(mr.VolumeName, "*unknown*", sizeof(mr.VolumeName));
}
}
bstrftime_nc(dt, sizeof(dt), sp->runtime);
level_ptr = level_to_str(sp->level);
break;
}
- bsendmsg(ua, _("%-14s %-8s %3d %-18s %-18s %s\n"),
- level_ptr, job_type_to_str(sp->job->JobType), sp->priority, dt,
+ bsendmsg(ua, _("%-14s %-8s %3d %-18s %-18s %s\n"),
+ level_ptr, job_type_to_str(sp->job->JobType), sp->priority, dt,
sp->job->hdr.name, mr.VolumeName);
if (close_db) {
db_close_database(jcr, jcr->db);
return -1;
} else if (p1->runtime > p2->runtime) {
return 1;
- }
+ }
if (p1->priority < p2->priority) {
return -1;
} else if (p1->priority > p2->priority) {
return 0;
}
-/*
+/*
* Find all jobs to be run in roughly the
* next 24 hours.
*/
if (run->level) {
level = run->level;
}
- priority = job->Priority;
+ priority = job->Priority;
if (run->Priority) {
priority = run->Priority;
}
}
if (num_jobs == 0) {
bsendmsg(ua, _("No Scheduled Jobs.\n"));
- }
+ }
bsendmsg(ua, "====\n");
Dmsg0(200, "Leave list_sched_jobs_runs()\n");
}
*/
if (jcr->JobType == JT_CONSOLE) {
bstrftime_nc(dt, sizeof(dt), jcr->start_time);
- bsendmsg(ua, _("Console connected at %s\n"), dt);
+ bsendmsg(ua, _("Console connected at %s\n"), dt);
}
njobs--;
}
njobs++;
switch (jcr->JobStatus) {
case JS_Created:
- msg = _("is waiting execution");
+ msg = _("is waiting execution");
break;
case JS_Running:
- msg = _("is running");
+ msg = _("is running");
break;
case JS_Blocked:
- msg = _("is blocked");
+ msg = _("is blocked");
break;
case JS_Terminated:
- msg = _("has terminated");
+ msg = _("has terminated");
break;
case JS_ErrorTerminated:
- msg = _("has erred");
+ msg = _("has erred");
break;
case JS_Error:
- msg = _("has errors");
+ msg = _("has errors");
break;
case JS_FatalError:
- msg = _("has a fatal error");
+ msg = _("has a fatal error");
break;
case JS_Differences:
- msg = _("has verify differences");
+ msg = _("has verify differences");
break;
case JS_Canceled:
- msg = _("has been canceled");
+ msg = _("has been canceled");
break;
case JS_WaitFD:
emsg = (char *) get_pool_memory(PM_FNAME);
- Mmsg(emsg, _("is waiting on Client %s"), jcr->client->hdr.name);
+ Mmsg(emsg, _("is waiting on Client %s"), jcr->client->hdr.name);
pool_mem = true;
msg = emsg;
break;
case JS_WaitSD:
emsg = (char *) get_pool_memory(PM_FNAME);
- Mmsg(emsg, _("is waiting on Storage %s"), jcr->store->hdr.name);
+ Mmsg(emsg, _("is waiting on Storage %s"), jcr->store->hdr.name);
pool_mem = true;
msg = emsg;
break;
case JS_WaitStoreRes:
- msg = _("is waiting on max Storage jobs");
+ msg = _("is waiting on max Storage jobs");
break;
case JS_WaitClientRes:
- msg = _("is waiting on max Client jobs");
+ msg = _("is waiting on max Client jobs");
break;
case JS_WaitJobRes:
- msg = _("is waiting on max Job jobs");
+ msg = _("is waiting on max Job jobs");
break;
case JS_WaitMaxJobs:
- msg = _("is waiting on max total jobs");
+ msg = _("is waiting on max total jobs");
break;
case JS_WaitStartTime:
- msg = _("is waiting for its start time");
+ msg = _("is waiting for its start time");
break;
case JS_WaitPriority:
- msg = _("is waiting for higher priority jobs to finish");
+ msg = _("is waiting for higher priority jobs to finish");
break;
default:
emsg = (char *) get_pool_memory(PM_FNAME);
- Mmsg(emsg, _("is in unknown state %c"), jcr->JobStatus);
+ Mmsg(emsg, _("is in unknown state %c"), jcr->JobStatus);
pool_mem = true;
msg = emsg;
break;
}
- /*
- * Now report Storage daemon status code
+ /*
+ * Now report Storage daemon status code
*/
switch (jcr->SDJobStatus) {
case JS_WaitMount:
free_pool_memory(emsg);
pool_mem = false;
}
- msg = _("is waiting for a mount request");
+ msg = _("is waiting for a mount request");
break;
case JS_WaitMedia:
if (pool_mem) {
free_pool_memory(emsg);
pool_mem = false;
}
- msg = _("is waiting for an appendable Volume");
+ msg = _("is waiting for an appendable Volume");
break;
case JS_WaitFD:
if (!pool_mem) {
emsg = (char *) get_pool_memory(PM_FNAME);
pool_mem = true;
}
- Mmsg(emsg, _("is waiting for Client %s to connect to Storage %s"),
+ Mmsg(emsg, _("is waiting for Client %s to connect to Storage %s"),
jcr->client->hdr.name, jcr->store->hdr.name);
msg = emsg;
break;
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));
break;
}
- bsendmsg(ua, _("%6d %-6s %-20s %s\n"),
+ bsendmsg(ua, _("%6d %-6s %-20s %s\n"),
jcr->JobId,
- level,
+ level,
jcr->Job,
msg);
switch (je->JobType) {
case JT_ADMIN:
case JT_RESTORE:
- bstrncpy(level, " ", sizeof(level));
+ bstrncpy(level, " ", sizeof(level));
break;
default:
bstrncpy(level, level_to_str(je->JobLevel), sizeof(level));
}
switch (je->JobStatus) {
case JS_Created:
- termstat = "Created";
+ termstat = "Created";
break;
case JS_FatalError:
case JS_ErrorTerminated:
- termstat = "Error";
+ termstat = "Error";
break;
case JS_Differences:
- termstat = "Diffs";
+ termstat = "Diffs";
break;
case JS_Canceled:
- termstat = "Cancel";
+ termstat = "Cancel";
break;
case JS_Terminated:
- termstat = "OK";
+ termstat = "OK";
break;
default:
- termstat = "Other";
+ termstat = "Other";
break;
}
bstrncpy(JobName, je->Job, sizeof(JobName));
/* There are three periods after the Job name */
char *p;
for (int i=0; i<3; i++) {
- if ((p=strrchr(JobName, '.')) != NULL) {
+ if ((p=strrchr(JobName, '.')) != NULL) {
*p = 0;
}
}
- bsendmsg(ua, _("%6d %-6s %8s %14s %-7s %-8s %s\n"),
+ bsendmsg(ua, _("%6d %-6s %8s %14s %-7s %-8s %s\n"),
je->JobId,
- level,
+ level,
edit_uint64_with_commas(je->JobFiles, b1),
- edit_uint64_with_commas(je->JobBytes, b2),
+ edit_uint64_with_commas(je->JobBytes, b2),
termstat,
dt, JobName);
}
static int donecmd(UAContext *ua, TREE_CTX *tree);
-struct cmdstruct { const char *key; int (*func)(UAContext *ua, TREE_CTX *tree); const char *help; };
+struct cmdstruct { const char *key; int (*func)(UAContext *ua, TREE_CTX *tree); const char *help; };
static struct cmdstruct commands[] = {
{ N_("cd"), cdcmd, _("change current directory")},
{ N_("count"), countcmd, _("count marked files in and below the cd")},
- { N_("dir"), dircmd, _("list current directory")},
+ { N_("dir"), dircmd, _("list current directory")},
{ N_("done"), donecmd, _("leave file selection mode")},
{ N_("estimate"), estimatecmd, _("estimate restore size")},
{ N_("exit"), donecmd, _("exit = done")},
{ N_("find"), findcmd, _("find files -- wildcards allowed")},
{ N_("help"), helpcmd, _("print help")},
- { N_("ls"), lscmd, _("list current directory -- wildcards allowed")},
- { N_("lsmark"), lsmarkcmd, _("list the marked files in and below the cd")},
+ { N_("ls"), lscmd, _("list current directory -- wildcards allowed")},
+ { N_("lsmark"), lsmarkcmd, _("list the marked files in and below the cd")},
{ N_("mark"), markcmd, _("mark dir/file to be restored -- recursively in dirs")},
{ N_("markdir"), markdircmd, _("mark directory name to be restored (no files)")},
{ N_("pwd"), pwdcmd, _("print current working directory")},
{ N_("unmark"), unmarkcmd, _("unmark dir/file to be restored -- recursively in dir")},
{ N_("unmarkdir"), unmarkdircmd, _("unmark directory name only -- no recursion")},
{ N_("quit"), quitcmd, _("quit")},
- { N_("?"), helpcmd, _("print help")},
+ { N_("?"), helpcmd, _("print help")},
};
#define comsize (sizeof(commands)/sizeof(struct cmdstruct))
UAContext *ua = new_ua_context(tree->ua->jcr);
ua->UA_sock = tree->ua->UA_sock; /* patch in UA socket */
- bsendmsg(tree->ua, _(
+ bsendmsg(tree->ua, _(
"\nYou are now entering file selection mode where you add (mark) and\n"
"remove (unmark) files to be restored. No files are initially added, unless\n"
"you used the \"all\" keyword on the command line.\n"
tree->node = (TREE_NODE *)tree->root;
tree_getpath(tree->node, cwd, sizeof(cwd));
bsendmsg(tree->ua, _("cwd is: %s\n"), cwd);
- for ( ;; ) {
+ for ( ;; ) {
int found, len, i;
if (!get_cmd(ua, "$ ")) {
break;
break;
}
if (!found) {
- bsendmsg(tree->ua, _("Illegal command. Enter \"done\" to exit.\n"));
+ bsendmsg(tree->ua, _("Illegal command. Enter \"done\" to exit.\n"));
continue;
}
if (!stat) {
if (node->inserted) {
tree->FileCount++;
if (tree->DeltaCount > 0 && (tree->FileCount-tree->LastCount) > tree->DeltaCount) {
- bsendmsg(tree->ua, "+");
+ bsendmsg(tree->ua, "+");
tree->LastCount = tree->FileCount;
}
}
/*
* Set extract to value passed. We recursively walk
- * down the tree setting all children if the
+ * down the tree setting all children if the
* node is a directory.
*/
static int set_extract(UAContext *ua, TREE_NODE *node, TREE_CTX *tree, bool extract)
}
/*
- * Recursively mark the current directory to be restored as
+ * Recursively mark the current directory to be restored as
* well as all directories and files below it.
*/
static int markcmd(UAContext *ua, TREE_CTX *tree)
if (count == 0) {
bsendmsg(ua, _("No files marked.\n"));
} else {
- bsendmsg(ua, _("%s file%s marked.\n"),
- edit_uint64_with_commas(count, ec1), count==0?"":"s");
+ bsendmsg(ua, _("%s file%s marked.\n"),
+ edit_uint64_with_commas(count, ec1), count==0?"":"s");
}
return 1;
}
if (count == 0) {
bsendmsg(ua, _("No directories marked.\n"));
} else {
- bsendmsg(ua, _("%s director%s marked.\n"),
- edit_uint64_with_commas(count, ec1), count==1?"y":"ies");
+ bsendmsg(ua, _("%s director%s marked.\n"),
+ edit_uint64_with_commas(count, ec1), count==1?"y":"ies");
}
return 1;
}
}
}
}
- bsendmsg(ua, "%s total files/dirs. %s marked to be restored.\n",
- edit_uint64_with_commas(total, ec1),
+ bsendmsg(ua, "%s total files/dirs. %s marked to be restored.\n",
+ edit_uint64_with_commas(total, ec1),
edit_uint64_with_commas(num_extract, ec2));
return 1;
}
bsendmsg(ua, _("No file specification given.\n"));
return 0;
}
-
+
for (int i=1; i < ua->argc; i++) {
for (TREE_NODE *node=first_tree_node(tree->root); node; node=next_tree_node(node)) {
if (fnmatch(ua->argk[i], node->fname, 0) == 0) {
const char *tag;
tree_getpath(node, cwd, sizeof(cwd));
if (node->extract) {
- tag = "*";
+ tag = "*";
} else if (node->extract_dir) {
- tag = "+";
+ tag = "+";
} else {
- tag = "";
+ tag = "";
}
- bsendmsg(ua, "%s%s\n", tag, cwd);
+ bsendmsg(ua, "%s%s\n", tag, cwd);
}
}
}
{
TREE_NODE *node;
- if (!tree_node_has_child(tree->node)) {
+ if (!tree_node_has_child(tree->node)) {
return 1;
}
foreach_child(node, tree->node) {
if (ua->argc == 1 || fnmatch(ua->argk[1], node->fname, 0) == 0) {
const char *tag;
if (node->extract) {
- tag = "*";
+ tag = "*";
} else if (node->extract_dir) {
- tag = "+";
+ tag = "+";
} else {
- tag = "";
+ tag = "";
}
- bsendmsg(ua, "%s%s%s\n", tag, node->fname, tree_node_has_child(node)?"/":"");
+ bsendmsg(ua, "%s%s%s\n", tag, node->fname, tree_node_has_child(node)?"/":"");
}
}
return 1;
/*
* Ls command that lists only the marked files
*/
-static void rlsmark(UAContext *ua, TREE_NODE *tnode)
+static void rlsmark(UAContext *ua, TREE_NODE *tnode)
{
TREE_NODE *node;
- if (!tree_node_has_child(tnode)) {
+ if (!tree_node_has_child(tnode)) {
return;
}
foreach_child(node, tnode) {
(node->extract || node->extract_dir)) {
const char *tag;
if (node->extract) {
- tag = "*";
+ tag = "*";
} else if (node->extract_dir) {
- tag = "+";
+ tag = "+";
} else {
- tag = "";
+ tag = "";
}
- bsendmsg(ua, "%s%s%s\n", tag, node->fname, tree_node_has_child(node)?"/":"");
+ bsendmsg(ua, "%s%s%s\n", tag, node->fname, tree_node_has_child(node)?"/":"");
if (tree_node_has_child(node)) {
rlsmark(ua, node);
}
char buf[1100];
char cwd[1100], *pcwd;
- if (!tree_node_has_child(tree->node)) {
+ if (!tree_node_has_child(tree->node)) {
bsendmsg(ua, "Node %s has no children.\n", tree->node->fname);
return 1;
}
const char *tag;
if (ua->argc == 1 || fnmatch(ua->argk[1], node->fname, 0) == 0) {
if (node->extract) {
- tag = "*";
+ tag = "*";
} else if (node->extract_dir) {
- tag = "+";
+ tag = "+";
} else {
- tag = " ";
+ tag = " ";
}
tree_getpath(node, cwd, sizeof(cwd));
fdbr.FileId = 0;
memset(&statp, 0, sizeof(statp));
}
ls_output(buf, cwd, tag, &statp);
- bsendmsg(ua, "%s\n", buf);
+ bsendmsg(ua, "%s\n", buf);
}
}
return 1;
}
}
}
- bsendmsg(ua, "%d total files; %d marked to be restored; %s bytes.\n",
+ bsendmsg(ua, "%d total files; %d marked to be restored; %s bytes.\n",
total, num_extract, edit_uint64_with_commas(total_bytes, ec1));
return 1;
}
-static int helpcmd(UAContext *ua, TREE_CTX *tree)
+static int helpcmd(UAContext *ua, TREE_CTX *tree)
{
unsigned int i;
* we assume it is a Win32 absolute cd rather than relative and
* try a second time with /x: ... Win32 kludge.
*/
-static int cdcmd(UAContext *ua, TREE_CTX *tree)
+static int cdcmd(UAContext *ua, TREE_CTX *tree)
{
TREE_NODE *node;
char cwd[2000];
if (!node) {
/* Try once more if Win32 drive -- make absolute */
if (ua->argk[1][1] == ':') { /* win32 drive */
- bstrncpy(cwd, "/", sizeof(cwd));
+ bstrncpy(cwd, "/", sizeof(cwd));
bstrncat(cwd, ua->argk[1], sizeof(cwd));
node = tree_cwd(cwd, tree->root, tree->node);
}
if (!node) {
- bsendmsg(ua, _("Invalid path given.\n"));
+ bsendmsg(ua, _("Invalid path given.\n"));
} else {
tree->node = node;
}
return 1;
}
-static int pwdcmd(UAContext *ua, TREE_CTX *tree)
+static int pwdcmd(UAContext *ua, TREE_CTX *tree)
{
char cwd[2000];
tree_getpath(tree->node, cwd, sizeof(cwd));
TREE_NODE *node;
int count = 0;
- if (ua->argc < 2 || !tree_node_has_child(tree->node)) {
+ if (ua->argc < 2 || !tree_node_has_child(tree->node)) {
bsendmsg(ua, _("No files unmarked.\n"));
return 1;
}
}
-static int donecmd(UAContext *ua, TREE_CTX *tree)
+static int donecmd(UAContext *ua, TREE_CTX *tree)
{
return 0;
}
-static int quitcmd(UAContext *ua, TREE_CTX *tree)
+static int quitcmd(UAContext *ua, TREE_CTX *tree)
{
ua->quit = true;
return 0;
/* Commands sent to File daemon */
static char verifycmd[] = "verify level=%s\n";
static char storaddr[] = "storage address=%s port=%d ssl=0\n";
-static char sessioncmd[] = "session %s %ld %ld %ld %ld %ld %ld\n";
+static char sessioncmd[] = "session %s %ld %ld %ld %ld %ld %ld\n";
/* Responses received from File daemon */
static char OKverify[] = "2000 OK verify\n";
static void prt_fname(JCR *jcr);
static int missing_handler(void *ctx, int num_fields, char **row);
-/*
+/*
* Do a verification of the specified files against the Catlaog
- *
+ *
* Returns: false on failure
* true on success
*/
-bool do_verify(JCR *jcr)
+bool do_verify(JCR *jcr)
{
const char *level, *Name;
BSOCK *fd;
Dmsg1(9, "bdird: created client %s record\n", jcr->client->hdr.name);
/*
- * Find JobId of last job that ran. E.g.
+ * Find JobId of last job that ran. E.g.
* for VERIFY_CATALOG we want the JobId of the last INIT.
- * for VERIFY_VOLUME_TO_CATALOG, we want the JobId of the
+ * for VERIFY_VOLUME_TO_CATALOG, we want the JobId of the
* last backup Job.
*/
- if (jcr->JobLevel == L_VERIFY_CATALOG ||
+ if (jcr->JobLevel == L_VERIFY_CATALOG ||
jcr->JobLevel == L_VERIFY_VOLUME_TO_CATALOG ||
jcr->JobLevel == L_VERIFY_DISK_TO_CATALOG) {
memcpy(&jr, &jcr->jr, sizeof(jr));
if (!db_find_last_jobid(jcr, jcr->db, Name, &jr)) {
if (jcr->JobLevel == L_VERIFY_CATALOG) {
Jmsg(jcr, M_FATAL, 0, _(
- "Unable to find JobId of previous InitCatalog Job.\n"
- "Please run a Verify with Level=InitCatalog before\n"
- "running the current Job.\n"));
+ "Unable to find JobId of previous InitCatalog Job.\n"
+ "Please run a Verify with Level=InitCatalog before\n"
+ "running the current Job.\n"));
} else {
Jmsg(jcr, M_FATAL, 0, _(
- "Unable to find JobId of previous Job for this client.\n"));
- }
+ "Unable to find JobId of previous Job for this client.\n"));
+ }
goto bail_out;
}
verify_jobid = jr.JobId;
Dmsg1(100, "Last full jobid=%d\n", verify_jobid);
- }
+ }
if (!db_update_job_start_record(jcr, jcr->db, &jcr->jr)) {
Jmsg(jcr, M_FATAL, 0, "%s", db_strerror(jcr->db));
* Now get the job record for the previous backup that interests
* us. We use the verify_jobid that we found above.
*/
- if (jcr->JobLevel == L_VERIFY_CATALOG ||
+ if (jcr->JobLevel == L_VERIFY_CATALOG ||
jcr->JobLevel == L_VERIFY_VOLUME_TO_CATALOG ||
jcr->JobLevel == L_VERIFY_DISK_TO_CATALOG) {
verify_jr.JobId = verify_jobid;
if (!db_get_job_record(jcr, jcr->db, &verify_jr)) {
- Jmsg(jcr, M_FATAL, 0, _("Could not get job record for previous Job. ERR=%s"),
+ Jmsg(jcr, M_FATAL, 0, _("Could not get job record for previous Job. ERR=%s"),
db_strerror(jcr->db));
goto bail_out;
}
if (verify_jr.JobStatus != 'T') {
- Jmsg(jcr, M_FATAL, 0, _("Last Job %d did not terminate normally. JobStatus=%c\n"),
+ Jmsg(jcr, M_FATAL, 0, _("Last Job %d did not terminate normally. JobStatus=%c\n"),
verify_jobid, verify_jr.JobStatus);
goto bail_out;
}
Jmsg(jcr, M_INFO, 0, _("Verifying against JobId=%d Job=%s\n"),
- verify_jr.JobId, verify_jr.Job);
+ verify_jr.JobId, verify_jr.Job);
}
- /*
+ /*
* If we are verifying a Volume, we need the Storage
* daemon, so open a connection, otherwise, just
* create a dummy authorization key (passed to
free_pool_memory(fname);
/*
- * Start conversation with Storage daemon
+ * Start conversation with Storage daemon
*/
set_jcr_job_status(jcr, JS_Blocked);
if (!connect_to_storage_daemon(jcr, 10, SDConnectTimeout, 1)) {
goto bail_out;
}
- /*
+ /*
* Send Level command to File daemon, as well
* as the Storage address if appropriate.
*/
level = "catalog";
break;
case L_VERIFY_VOLUME_TO_CATALOG:
- /*
+ /*
* send Storage daemon address to the File daemon
*/
if (jcr->store->SDDport == 0) {
goto bail_out;
}
- /*
+ /*
* Send the bootstrap file -- what Volumes/files to restore
*/
if (!send_bootstrap_file(jcr)) {
goto bail_out;
}
- /*
- * The following code is deprecated
+ /*
+ * The following code is deprecated
*/
if (!jcr->RestoreBootstrap) {
/*
* Pass the VolSessionId, VolSessionTime, Start and
* end File and Blocks on the session command.
*/
- bnet_fsend(fd, sessioncmd,
+ bnet_fsend(fd, sessioncmd,
jcr->VolumeName,
- jr.VolSessionId, jr.VolSessionTime,
- jr.StartFile, jr.EndFile, jr.StartBlock,
+ jr.VolSessionId, jr.VolSessionTime,
+ jr.StartFile, jr.EndFile, jr.StartBlock,
jr.EndBlock);
- if (!response(jcr, fd, OKsession, "Session", DISPLAY_ERROR)) {
+ if (!response(jcr, fd, OKsession, "Session", DISPLAY_ERROR)) {
goto bail_out;
}
}
goto bail_out;
}
- /*
+ /*
* Send verify command/level to File daemon
*/
bnet_fsend(fd, verifycmd, level);
* catalog depending on the run type.
*/
/* Compare to catalog */
- switch (jcr->JobLevel) {
+ switch (jcr->JobLevel) {
case L_VERIFY_CATALOG:
Dmsg0(10, "Verify level=catalog\n");
jcr->sd_msg_thread_done = true; /* no SD msg thread, so it is done */
break;
case JS_FatalError:
case JS_ErrorTerminated:
- term_msg = _("*** Verify Error ***");
+ term_msg = _("*** Verify Error ***");
msg_type = M_ERROR; /* Generate error message */
break;
case JS_Error:
break;
default:
term_msg = term_code;
- bsnprintf(term_code, sizeof(term_code),
- _("Inappropriate term code: %d %c\n"), TermCode, TermCode);
+ bsnprintf(term_code, sizeof(term_code),
+ _("Inappropriate term code: %d %c\n"), TermCode, TermCode);
break;
}
bstrftimes(sdt, sizeof(sdt), jcr->jr.StartTime);
jobstatus_to_ascii(jcr->FDJobStatus, fd_term_msg, sizeof(fd_term_msg));
if (jcr->JobLevel == L_VERIFY_VOLUME_TO_CATALOG) {
jobstatus_to_ascii(jcr->SDJobStatus, sd_term_msg, sizeof(sd_term_msg));
- Jmsg(jcr, msg_type, 0, _("Bacula " VERSION " (" LSMDATE "): %s\n\
- JobId: %d\n\
- Job: %s\n\
- FileSet: %s\n\
- Verify Level: %s\n\
- Client: %s\n\
- Verify JobId: %d\n\
- Verify Job: %s\n\
- Start time: %s\n\
- End time: %s\n\
- Files Expected: %s\n\
- Files Examined: %s\n\
- Non-fatal FD errors: %d\n\
- FD termination status: %s\n\
- SD termination status: %s\n\
- Termination: %s\n\n"),
+ Jmsg(jcr, msg_type, 0, _("Bacula " VERSION " (" LSMDATE "): %s\n"
+" JobId: %d\n"
+" Job: %s\n"
+" FileSet: %s\n"
+" Verify Level: %s\n"
+" Client: %s\n"
+" Verify JobId: %d\n"
+" Verify Job: %s\n"
+" Start time: %s\n"
+" End time: %s\n"
+" Files Expected: %s\n"
+" Files Examined: %s\n"
+" Non-fatal FD errors: %d\n"
+" FD termination status: %s\n"
+" SD termination status: %s\n"
+" Termination: %s\n\n"),
edt,
jcr->jr.JobId,
jcr->jr.Job,
sd_term_msg,
term_msg);
} else {
- Jmsg(jcr, msg_type, 0, _("Bacula " VERSION " (" LSMDATE "): %s\n\
- JobId: %d\n\
- Job: %s\n\
- FileSet: %s\n\
- Verify Level: %s\n\
- Client: %s\n\
- Verify JobId: %d\n\
- Verify Job: %s\n\
- Start time: %s\n\
- End time: %s\n\
- Files Examined: %s\n\
- Non-fatal FD errors: %d\n\
- FD termination status: %s\n\
- Termination: %s\n\n"),
+ Jmsg(jcr, msg_type, 0, _("Bacula " VERSION " (" LSMDATE "): %s\n"
+" JobId: %d\n"
+" Job: %s\n"
+" FileSet: %s\n"
+" Verify Level: %s\n"
+" Client: %s\n"
+" Verify JobId: %d\n"
+" Verify Job: %s\n"
+" Start time: %s\n"
+" End time: %s\n"
+" Files Examined: %s\n"
+" Non-fatal FD errors: %d\n"
+" FD termination status: %s\n"
+" Termination: %s\n\n"),
edt,
jcr->jr.JobId,
jcr->jr.Job,
fd = jcr->file_bsock;
fdbr.JobId = JobId;
jcr->FileIndex = 0;
-
+
Dmsg0(20, "bdird: waiting to receive file attributes\n");
/*
* Get Attributes and Signature from File daemon
fname = check_pool_memory_size(fname, fd->msglen);
jcr->fname = check_pool_memory_size(jcr->fname, fd->msglen);
Dmsg1(200, "Atts+SIG=%s\n", fd->msg);
- if ((len = sscanf(fd->msg, "%ld %d %100s", &file_index, &stream,
+ if ((len = sscanf(fd->msg, "%ld %d %100s", &file_index, &stream,
fname)) != 3) {
- Jmsg3(jcr, M_FATAL, 0, _("bird<filed: bad attributes, expected 3 fields got %d\n\
- mslen=%d msg=%s\n"), len, fd->msglen, fd->msg);
+ Jmsg3(jcr, M_FATAL, 0, _("bird<filed: bad attributes, expected 3 fields got %d\n"
+" mslen=%d msg=%s\n"), len, fd->msglen, fd->msg);
goto bail_out;
}
/*
- * We read the Options or Signature into fname
+ * We read the Options or Signature into fname
* to prevent overrun, now copy it to proper location.
*/
bstrncpy(Opts_SIG, fname, sizeof(Opts_SIG));
skip_spaces(&p);
skip_nonspaces(&p); /* skip Stream */
skip_spaces(&p);
- skip_nonspaces(&p); /* skip Opts_SIG */
+ skip_nonspaces(&p); /* skip Opts_SIG */
p++; /* skip space */
fn = fname;
while (*p != 0) {
*/
if (stream == STREAM_UNIX_ATTRIBUTES || stream == STREAM_UNIX_ATTRIBUTES_EX) {
int32_t LinkFIf, LinkFIc;
- Dmsg2(400, "file_index=%d attr=%s\n", file_index, attr);
+ Dmsg2(400, "file_index=%d attr=%s\n", file_index, attr);
jcr->JobFiles++;
jcr->FileIndex = file_index; /* remember attribute file_index */
decode_stat(attr, &statf, &LinkFIf); /* decode file stat packet */
jcr->fn_printed = false;
pm_strcpy(jcr->fname, fname); /* move filename into JCR */
- Dmsg2(040, "dird<filed: stream=%d %s\n", stream, jcr->fname);
- Dmsg1(020, "dird<filed: attr=%s\n", attr);
+ Dmsg2(040, "dird<filed: stream=%d %s\n", stream, jcr->fname);
+ Dmsg1(020, "dird<filed: attr=%s\n", attr);
- /*
- * Find equivalent record in the database
+ /*
+ * Find equivalent record in the database
*/
fdbr.FileId = 0;
- if (!db_get_file_attributes_record(jcr, jcr->db, jcr->fname,
+ if (!db_get_file_attributes_record(jcr, jcr->db, jcr->fname,
jcr->verify_jr, &fdbr)) {
- Jmsg(jcr, M_INFO, 0, _("New file: %s\n"), jcr->fname);
- Dmsg1(020, _("File not in catalog: %s\n"), jcr->fname);
+ Jmsg(jcr, M_INFO, 0, _("New file: %s\n"), jcr->fname);
+ Dmsg1(020, _("File not in catalog: %s\n"), jcr->fname);
stat = JS_Differences;
continue;
} else {
- /*
+ /*
* mark file record as visited by stuffing the
* current JobId, which is unique, into the MarkId field.
*/
db_mark_file_record(jcr, jcr->db, fdbr.FileId, jcr->JobId);
}
- Dmsg3(400, "Found %s in catalog. inx=%d Opts=%s\n", jcr->fname,
+ Dmsg3(400, "Found %s in catalog. inx=%d Opts=%s\n", jcr->fname,
file_index, Opts_SIG);
decode_stat(fdbr.LStat, &statc, &LinkFIc); /* decode catalog stat */
/*
for (p=Opts_SIG; *p; p++) {
char ed1[30], ed2[30];
switch (*p) {
- case 'i': /* compare INODEs */
+ case 'i': /* compare INODEs */
if (statc.st_ino != statf.st_ino) {
prt_fname(jcr);
- Jmsg(jcr, M_INFO, 0, _(" st_ino differ. Cat: %s File: %s\n"),
+ Jmsg(jcr, M_INFO, 0, _(" st_ino differ. Cat: %s File: %s\n"),
edit_uint64((uint64_t)statc.st_ino, ed1),
edit_uint64((uint64_t)statf.st_ino, ed2));
stat = JS_Differences;
}
break;
- case 'p': /* permissions bits */
+ case 'p': /* permissions bits */
if (statc.st_mode != statf.st_mode) {
prt_fname(jcr);
- Jmsg(jcr, M_INFO, 0, _(" st_mode differ. Cat: %x File: %x\n"),
+ Jmsg(jcr, M_INFO, 0, _(" st_mode differ. Cat: %x File: %x\n"),
(uint32_t)statc.st_mode, (uint32_t)statf.st_mode);
stat = JS_Differences;
}
break;
- case 'n': /* number of links */
+ case 'n': /* number of links */
if (statc.st_nlink != statf.st_nlink) {
prt_fname(jcr);
- Jmsg(jcr, M_INFO, 0, _(" st_nlink differ. Cat: %d File: %d\n"),
+ Jmsg(jcr, M_INFO, 0, _(" st_nlink differ. Cat: %d File: %d\n"),
(uint32_t)statc.st_nlink, (uint32_t)statf.st_nlink);
stat = JS_Differences;
}
break;
- case 'u': /* user id */
+ case 'u': /* user id */
if (statc.st_uid != statf.st_uid) {
prt_fname(jcr);
- Jmsg(jcr, M_INFO, 0, _(" st_uid differ. Cat: %u File: %u\n"),
+ Jmsg(jcr, M_INFO, 0, _(" st_uid differ. Cat: %u File: %u\n"),
(uint32_t)statc.st_uid, (uint32_t)statf.st_uid);
stat = JS_Differences;
}
break;
- case 'g': /* group id */
+ case 'g': /* group id */
if (statc.st_gid != statf.st_gid) {
prt_fname(jcr);
- Jmsg(jcr, M_INFO, 0, _(" st_gid differ. Cat: %u File: %u\n"),
+ Jmsg(jcr, M_INFO, 0, _(" st_gid differ. Cat: %u File: %u\n"),
(uint32_t)statc.st_gid, (uint32_t)statf.st_gid);
stat = JS_Differences;
}
break;
- case 's': /* size */
+ case 's': /* size */
if (statc.st_size != statf.st_size) {
prt_fname(jcr);
- Jmsg(jcr, M_INFO, 0, _(" st_size differ. Cat: %s File: %s\n"),
+ Jmsg(jcr, M_INFO, 0, _(" st_size differ. Cat: %s File: %s\n"),
edit_uint64((uint64_t)statc.st_size, ed1),
edit_uint64((uint64_t)statf.st_size, ed2));
stat = JS_Differences;
}
break;
- case 'a': /* access time */
+ case 'a': /* access time */
if (statc.st_atime != statf.st_atime) {
prt_fname(jcr);
- Jmsg(jcr, M_INFO, 0, _(" st_atime differs\n"));
+ Jmsg(jcr, M_INFO, 0, _(" st_atime differs\n"));
stat = JS_Differences;
}
break;
- case 'm':
+ case 'm':
if (statc.st_mtime != statf.st_mtime) {
prt_fname(jcr);
- Jmsg(jcr, M_INFO, 0, _(" st_mtime differs\n"));
+ Jmsg(jcr, M_INFO, 0, _(" st_mtime differs\n"));
stat = JS_Differences;
}
break;
- case 'c': /* ctime */
+ case 'c': /* ctime */
if (statc.st_ctime != statf.st_ctime) {
prt_fname(jcr);
- Jmsg(jcr, M_INFO, 0, _(" st_ctime differs\n"));
+ Jmsg(jcr, M_INFO, 0, _(" st_ctime differs\n"));
stat = JS_Differences;
}
break;
- case 'd': /* file size decrease */
+ case 'd': /* file size decrease */
if (statc.st_size > statf.st_size) {
prt_fname(jcr);
- Jmsg(jcr, M_INFO, 0, _(" st_size decrease. Cat: %s File: %s\n"),
+ Jmsg(jcr, M_INFO, 0, _(" st_size decrease. Cat: %s File: %s\n"),
edit_uint64((uint64_t)statc.st_size, ed1),
edit_uint64((uint64_t)statf.st_size, ed2));
stat = JS_Differences;
}
break;
- case '5': /* compare MD5 */
- Dmsg1(500, "set Do_MD5 for %s\n", jcr->fname);
+ case '5': /* compare MD5 */
+ Dmsg1(500, "set Do_MD5 for %s\n", jcr->fname);
do_SIG = MD5_SIG;
break;
- case '1': /* compare SHA1 */
+ case '1': /* compare SHA1 */
do_SIG = SHA1_SIG;
break;
- case ':':
- case 'V':
+ case ':':
+ case 'V':
default:
break;
}
* It came across in the Opts_SIG field.
*/
} else if (stream == STREAM_MD5_SIGNATURE || stream == STREAM_SHA1_SIGNATURE) {
- Dmsg2(400, "stream=SIG inx=%d SIG=%s\n", file_index, Opts_SIG);
- /*
+ Dmsg2(400, "stream=SIG inx=%d SIG=%s\n", file_index, Opts_SIG);
+ /*
* When ever we get a signature is MUST have been
* preceded by an attributes record, which sets attr_file_index
*/
if (jcr->FileIndex != (uint32_t)file_index) {
- Jmsg2(jcr, M_FATAL, 0, _("MD5/SHA1 index %d not same as attributes %d\n"),
+ Jmsg2(jcr, M_FATAL, 0, _("MD5/SHA1 index %d not same as attributes %d\n"),
file_index, jcr->FileIndex);
goto bail_out;
- }
+ }
if (do_SIG) {
db_escape_string(buf, Opts_SIG, strlen(Opts_SIG));
if (strcmp(buf, fdbr.SIG) != 0) {
prt_fname(jcr);
if (debug_level >= 10) {
- Jmsg(jcr, M_INFO, 0, _(" %s not same. File=%s Cat=%s\n"),
- stream==STREAM_MD5_SIGNATURE?"MD5":"SHA1", buf, fdbr.SIG);
+ Jmsg(jcr, M_INFO, 0, _(" %s not same. File=%s Cat=%s\n"),
+ stream==STREAM_MD5_SIGNATURE?"MD5":"SHA1", buf, fdbr.SIG);
} else {
- Jmsg(jcr, M_INFO, 0, _(" %s differs.\n"),
- stream==STREAM_MD5_SIGNATURE?"MD5":"SHA1");
+ Jmsg(jcr, M_INFO, 0, _(" %s differs.\n"),
+ stream==STREAM_MD5_SIGNATURE?"MD5":"SHA1");
}
stat = JS_Differences;
}
}
}
jcr->JobFiles = file_index;
- }
+ }
if (is_bnet_error(fd)) {
Jmsg2(jcr, M_FATAL, 0, _("bdird<filed: bad attributes from filed n=%d : %s\n"),
n, strerror(errno));
* the database where the MarkedId != current JobId
*/
jcr->fn_printed = false;
- sprintf(buf,
+ sprintf(buf,
"SELECT Path.Path,Filename.Name FROM File,Path,Filename "
"WHERE File.JobId=%d "
"AND File.MarkedId!=%d AND File.PathId=Path.PathId "
-"AND File.FilenameId=Filename.FilenameId",
+"AND File.FilenameId=Filename.FilenameId",
JobId, jcr->JobId);
/* missing_handler is called for each file found */
db_sql_query(jcr->db, buf, missing_handler, (void *)jcr);
free_pool_memory(fname);
set_jcr_job_status(jcr, stat);
return 1;
-
+
bail_out:
free_pool_memory(fname);
set_jcr_job_status(jcr, JS_ErrorTerminated);
}
-/*
+/*
* Print filename for verify
*/
static void prt_fname(JCR *jcr)
* Kern Sibbald, October 2000
*
* Version $Id$
- *
+ *
*/
/*
Copyright (C) 2000-2004 Kern Sibbald and John Walker
MA 02111-1307, USA.
*/
-
+
#include "bacula.h"
#include "filed.h"
static char Dir_sorry[] = "2999 No go\n";
-/*********************************************************************
+/*********************************************************************
*
*/
static int authenticate(int rcode, BSOCK *bs, JCR* jcr)
return 0;
}
if (bs->msglen < 25 || bs->msglen > 200) {
- Dmsg2(50, _("Bad Hello command from Director at %s. Len=%d.\n"),
+ Dmsg2(50, _("Bad Hello command from Director at %s. Len=%d.\n"),
bs->who, bs->msglen);
- Emsg2(M_FATAL, 0, _("Bad Hello command from Director at %s. Len=%d.\n"),
+ Emsg2(M_FATAL, 0, _("Bad Hello command from Director at %s. Len=%d.\n"),
bs->who, bs->msglen);
return 0;
}
if (sscanf(bs->msg, "Hello Director %s calling\n", dirname) != 1) {
free_pool_memory(dirname);
bs->msg[100] = 0;
- Dmsg2(50, _("Bad Hello command from Director at %s: %s\n"),
+ Dmsg2(50, _("Bad Hello command from Director at %s: %s\n"),
bs->who, bs->msg);
- Emsg2(M_FATAL, 0, _("Bad Hello command from Director at %s: %s\n"),
+ Emsg2(M_FATAL, 0, _("Bad Hello command from Director at %s: %s\n"),
bs->who, bs->msg);
return 0;
}
if (!director) {
Dmsg2(50, _("Connection from unknown Director %s at %s rejected.\n"),
dirname, bs->who);
- Emsg2(M_FATAL, 0, _("Connection from unknown Director %s at %s rejected.\n"
- "Please see http://www.bacula.org/html-manual/faq.html#AuthorizationErrors for help.\n"),
+ Emsg2(M_FATAL, 0, _("Connection from unknown Director %s at %s rejected.\n"
+ "Please see http://www.bacula.org/html-manual/faq.html#AuthorizationErrors for help.\n"),
dirname, bs->who);
free_pool_memory(dirname);
return 0;
}
btimer_t *tid = start_bsock_timer(bs, AUTH_TIMEOUT);
- auth = cram_md5_auth(bs, director->password, ssl_need);
+ auth = cram_md5_auth(bs, director->password, ssl_need);
if (auth) {
- get_auth = cram_md5_get_auth(bs, director->password, ssl_need);
+ get_auth = cram_md5_get_auth(bs, director->password, ssl_need);
if (!get_auth) {
- Dmsg1(50, "cram_get_auth failed for %s\n", bs->who);
+ Dmsg1(50, "cram_get_auth failed for %s\n", bs->who);
}
} else {
Dmsg1(50, "cram_auth failed for %s\n", bs->who);
}
if (!auth || !get_auth) {
- Emsg1(M_FATAL, 0, _("Incorrect password given by Director at %s.\n"
- "Please see http://www.bacula.org/html-manual/faq.html#AuthorizationErrors for help.\n"),
+ Emsg1(M_FATAL, 0, _("Incorrect password given by Director at %s.\n"
+ "Please see http://www.bacula.org/html-manual/faq.html#AuthorizationErrors for help.\n"),
bs->who);
director = NULL;
}
/*
* Inititiate the communications with the Director.
* He has made a connection to our server.
- *
+ *
* Basic tasks done here:
* We read Director's initial message and authorize him.
*
bool get_auth, auth = false;
btimer_t *tid = start_bsock_timer(sd, AUTH_TIMEOUT);
- get_auth = cram_md5_get_auth(sd, jcr->sd_auth_key, ssl_need);
+ get_auth = cram_md5_get_auth(sd, jcr->sd_auth_key, ssl_need);
if (!get_auth) {
Dmsg1(50, "cram_get_auth failed for %s\n", sd->who);
} else {
auth = cram_md5_auth(sd, jcr->sd_auth_key, ssl_need);
if (!auth) {
- Dmsg1(50, "cram_auth failed for %s\n", sd->who);
+ Dmsg1(50, "cram_auth failed for %s\n", sd->who);
}
}
stop_bsock_timer(tid);
memset(jcr->sd_auth_key, 0, strlen(jcr->sd_auth_key));
if (!get_auth || !auth) {
- Jmsg(jcr, M_FATAL, 0, _("Authorization key rejected by Storage daemon.\n"
+ Jmsg(jcr, M_FATAL, 0, _("Authorization key rejected by Storage daemon.\n"
"Please see http://www.bacula.org/html-manual/faq.html#AuthorizationErrors for help.\n"));
}
return get_auth && auth;
static int save_file(FF_PKT *ff_pkt, void *pkt);
static int send_data(int stream, FF_PKT *ff_pkt, BSOCK *sd, JCR *jcr, struct CHKSUM *chksum);
-/*
+/*
* Find all the requested files and send them
- * to the Storage daemon.
+ * to the Storage daemon.
*
* Note, we normally carry on a one-way
* conversation from this point on with the SD, simply blasting
* also run a "heartbeat" monitor which reads the socket and
* reacts accordingly (at the moment it has nothing to do
* except echo the heartbeat to the Director).
- *
+ *
*/
-bool blast_data_to_storage_daemon(JCR *jcr, char *addr)
+bool blast_data_to_storage_daemon(JCR *jcr, char *addr)
{
BSOCK *sd;
bool ok = true;
return false;
}
- jcr->buf_size = sd->msglen;
+ jcr->buf_size = sd->msglen;
/* Adjust for compression so that output buffer is
* 12 bytes + 0.1% larger than input buffer plus 18 bytes.
* This gives a bit extra plus room for the sparse addr if any.
}
Dmsg1(300, "end blast_data stat=%d\n", ok);
return ok;
-}
+}
-/*
+/*
* Called here by find() for each file included.
*
* *****FIXME***** add FSMs File System Modules
case FT_INVALIDFS:
case FT_DIREND:
if (ff_pkt->type == FT_NORECURSE) {
- Jmsg(jcr, M_INFO, 1, _(" Recursion turned off. Will not descend into %s\n"),
+ Jmsg(jcr, M_INFO, 1, _(" Recursion turned off. Will not descend into %s\n"),
ff_pkt->fname);
} else if (ff_pkt->type == FT_NOFSCHG) {
- Jmsg(jcr, M_INFO, 1, _(" File system change prohibited. Will not descend into %s\n"),
+ Jmsg(jcr, M_INFO, 1, _(" File system change prohibited. Will not descend into %s\n"),
ff_pkt->fname);
} else if (ff_pkt->type == FT_INVALIDFS) {
- Jmsg(jcr, M_INFO, 1, _(" Disallowed filesystem. Will not descend into %s\n"),
+ Jmsg(jcr, M_INFO, 1, _(" Disallowed filesystem. Will not descend into %s\n"),
ff_pkt->fname);
}
ff_pkt->type = FT_DIREND; /* value is used below */
case FT_NOACCESS: {
berrno be;
be.set_errno(ff_pkt->ff_errno);
- Jmsg(jcr, M_NOTSAVED, 0, _(" Could not access %s: ERR=%s\n"), ff_pkt->fname,
+ Jmsg(jcr, M_NOTSAVED, 0, _(" Could not access %s: ERR=%s\n"), ff_pkt->fname,
be.strerror());
jcr->Errors++;
return 1;
case FT_NOFOLLOW: {
berrno be;
be.set_errno(ff_pkt->ff_errno);
- Jmsg(jcr, M_NOTSAVED, 0, _(" Could not follow link %s: ERR=%s\n"), ff_pkt->fname,
+ Jmsg(jcr, M_NOTSAVED, 0, _(" Could not follow link %s: ERR=%s\n"), ff_pkt->fname,
be.strerror());
jcr->Errors++;
return 1;
case FT_NOSTAT: {
berrno be;
be.set_errno(ff_pkt->ff_errno);
- Jmsg(jcr, M_NOTSAVED, 0, _(" Could not stat %s: ERR=%s\n"), ff_pkt->fname,
+ Jmsg(jcr, M_NOTSAVED, 0, _(" Could not stat %s: ERR=%s\n"), ff_pkt->fname,
be.strerror());
jcr->Errors++;
return 1;
case FT_NOOPEN: {
berrno be;
be.set_errno(ff_pkt->ff_errno);
- Jmsg(jcr, M_NOTSAVED, 0, _(" Could not open directory %s: ERR=%s\n"), ff_pkt->fname,
+ Jmsg(jcr, M_NOTSAVED, 0, _(" Could not open directory %s: ERR=%s\n"), ff_pkt->fname,
be.strerror());
jcr->Errors++;
return 1;
attr_stream = encode_attribsEx(jcr, attribsEx, ff_pkt);
Dmsg3(300, "File %s\nattribs=%s\nattribsEx=%s\n", ff_pkt->fname, attribs, attribsEx);
-
+
P(jcr->mutex);
jcr->JobFiles++; /* increment number of files sent */
ff_pkt->FileIndex = jcr->JobFiles; /* return FileIndex */
pm_strcpy(jcr->last_fname, ff_pkt->fname);
V(jcr->mutex);
-
+
/*
* Send Attributes header to Storage daemon
* <file-index> <stream> <info>
*/
if (ff_pkt->type == FT_LNK || ff_pkt->type == FT_LNKSAVED) {
Dmsg2(300, "Link %s to %s\n", ff_pkt->fname, ff_pkt->link);
- stat = bnet_fsend(sd, "%ld %d %s%c%s%c%s%c%s%c", jcr->JobFiles,
+ stat = bnet_fsend(sd, "%ld %d %s%c%s%c%s%c%s%c", jcr->JobFiles,
ff_pkt->type, ff_pkt->fname, 0, attribs, 0, ff_pkt->link, 0,
attribsEx, 0);
} else if (ff_pkt->type == FT_DIREND) {
/* Here link is the canonical filename (i.e. with trailing slash) */
- stat = bnet_fsend(sd, "%ld %d %s%c%s%c%c%s%c", jcr->JobFiles,
+ stat = bnet_fsend(sd, "%ld %d %s%c%s%c%c%s%c", jcr->JobFiles,
ff_pkt->type, ff_pkt->link, 0, attribs, 0, 0, attribsEx, 0);
} else {
- stat = bnet_fsend(sd, "%ld %d %s%c%s%c%c%s%c", jcr->JobFiles,
+ stat = bnet_fsend(sd, "%ld %d %s%c%s%c%c%s%c", jcr->JobFiles,
ff_pkt->type, ff_pkt->fname, 0, attribs, 0, 0, attribsEx, 0);
}
set_prog(&ff_pkt->bfd, ff_pkt->reader, jcr);
}
- /*
+ /*
* Open any file with data that we intend to save, then save it.
*
* Note, if is_win32_backup, we must open the Directory so that
* the BackupRead will save its permissions and ownership streams.
*/
- if (ff_pkt->type != FT_LNKSAVED && (S_ISREG(ff_pkt->statp.st_mode) &&
- ff_pkt->statp.st_size > 0) ||
+ if (ff_pkt->type != FT_LNKSAVED && (S_ISREG(ff_pkt->statp.st_mode) &&
+ ff_pkt->statp.st_size > 0) ||
ff_pkt->type == FT_RAW || ff_pkt->type == FT_FIFO ||
(!is_portable_backup(&ff_pkt->bfd) && ff_pkt->type == FT_DIREND)) {
- btimer_t *tid;
+ btimer_t *tid;
if (ff_pkt->type == FT_FIFO) {
tid = start_thread_timer(pthread_self(), 60);
} else {
if (bopen(&ff_pkt->bfd, ff_pkt->fname, O_RDONLY | O_BINARY, 0) < 0) {
ff_pkt->ff_errno = errno;
berrno be;
- Jmsg(jcr, M_NOTSAVED, 0, _(" Cannot open %s: ERR=%s.\n"), ff_pkt->fname,
+ Jmsg(jcr, M_NOTSAVED, 0, _(" Cannot open %s: ERR=%s.\n"), ff_pkt->fname,
be.strerror());
jcr->Errors++;
if (tid) {
if (!bopen_rsrc(&ff_pkt->bfd, ff_pkt->fname, O_RDONLY | O_BINARY, 0) < 0) {
ff_pkt->ff_errno = errno;
berrno be;
- Jmsg(jcr, M_NOTSAVED, -1, _(" Cannot open resource fork for %s: ERR=%s.\n"), ff_pkt->fname,
+ Jmsg(jcr, M_NOTSAVED, -1, _(" Cannot open resource fork for %s: ERR=%s.\n"), ff_pkt->fname,
be.strerror());
jcr->Errors++;
if (is_bopen(&ff_pkt->bfd)) {
if (ff_pkt->flags & FO_ACL) {
char *acl_text = NULL;
char *aclDef_text = NULL;
-
+
/* Read ACLs for files, dirs and links */
if (ff_pkt->type == FT_DIREND) {
/* Directory: Check for default ACL*/
acl_t myDefAcl = acl_get_file(ff_pkt->fname, ACL_TYPE_DEFAULT);
- /* Check for Access ACL */
- acl_t myAccAcl = acl_get_file(ff_pkt->fname, ACL_TYPE_ACCESS);
- if (!myDefAcl || !myAccAcl) {
- Jmsg1(jcr, M_WARNING, 0, "Error while trying to get ACL of directory: %s!\n", ff_pkt->fname);
- }
- if(myDefAcl){
- aclDef_text = acl_to_any_text(myDefAcl, NULL, ',', TEXT_ABBREVIATE);
- acl_free(myDefAcl);
- }
- if(myAccAcl){
- acl_text = acl_to_any_text(myAccAcl, NULL, ',', TEXT_ABBREVIATE);
- acl_free(myAccAcl);
- }
+ /* Check for Access ACL */
+ acl_t myAccAcl = acl_get_file(ff_pkt->fname, ACL_TYPE_ACCESS);
+ if (!myDefAcl || !myAccAcl) {
+ Jmsg1(jcr, M_WARNING, 0, "Error while trying to get ACL of directory: %s!\n", ff_pkt->fname);
+ }
+ if(myDefAcl){
+ aclDef_text = acl_to_any_text(myDefAcl, NULL, ',', TEXT_ABBREVIATE);
+ acl_free(myDefAcl);
+ }
+ if(myAccAcl){
+ acl_text = acl_to_any_text(myAccAcl, NULL, ',', TEXT_ABBREVIATE);
+ acl_free(myAccAcl);
+ }
} else {
/* Files or links */
- acl_t myAcl = acl_get_file(ff_pkt->fname, ACL_TYPE_ACCESS);
+ acl_t myAcl = acl_get_file(ff_pkt->fname, ACL_TYPE_ACCESS);
if (!myAcl) {
- Jmsg1(jcr, M_WARNING, 0, "Error while trying to get ACL of file: %s!\n", ff_pkt->fname);
+ Jmsg1(jcr, M_WARNING, 0, "Error while trying to get ACL of file: %s!\n", ff_pkt->fname);
acl_free(myAcl);
}
- acl_text = acl_to_any_text(myAcl, NULL, ',', TEXT_ABBREVIATE);
+ acl_text = acl_to_any_text(myAcl, NULL, ',', TEXT_ABBREVIATE);
acl_free(myAcl);
}
-
+
POOLMEM *msgsave;
-
+
/* If there is an ACL, send it to the Storage daemon */
if (acl_text != NULL) {
sd = jcr->store_bsock;
pm_strcpy(&jcr->last_fname, ff_pkt->fname);
-
-
+
+
// Send ACL header
- if (!bnet_fsend(sd, "%ld %d 0", jcr->JobFiles, STREAM_UNIX_ATTRIBUTES_ACCESS_ACL)) {
+ if (!bnet_fsend(sd, "%ld %d 0", jcr->JobFiles, STREAM_UNIX_ATTRIBUTES_ACCESS_ACL)) {
berrno be;
- Jmsg1(jcr, M_FATAL, 0, _("Network send error to SD. ERR=%s\n"),
+ Jmsg1(jcr, M_FATAL, 0, _("Network send error to SD. ERR=%s\n"),
bnet_strerror(sd));
return 0;
}
-
+
/* Send the buffer to the storage deamon */
msgsave = sd->msg;
sd->msg = acl_text;
berrno be;
sd->msg = msgsave;
sd->msglen = 0;
- Jmsg1(jcr, M_FATAL, 0, _("Network send error to SD. ERR=%s\n"),
+ Jmsg1(jcr, M_FATAL, 0, _("Network send error to SD. ERR=%s\n"),
bnet_strerror(sd));
} else {
jcr->JobBytes += sd->msglen;
sd->msg = msgsave;
if (!bnet_sig(sd, BNET_EOD)) {
berrno be;
- Jmsg1(jcr, M_FATAL, 0, _("Network send error to SD. ERR=%s\n"),
+ Jmsg1(jcr, M_FATAL, 0, _("Network send error to SD. ERR=%s\n"),
bnet_strerror(sd));
} else {
- Dmsg1(200, "ACL of file: %s successfully backed up!\n", ff_pkt->fname);
+ Dmsg1(200, "ACL of file: %s successfully backed up!\n", ff_pkt->fname);
}
- }
+ }
}
/* If there is an Default ACL, send it to the Storage daemon */
if (aclDef_text != NULL) {
sd = jcr->store_bsock;
pm_strcpy(&jcr->last_fname, ff_pkt->fname);
-
-
+
+
// Send ACL header
if (!bnet_fsend(sd, "%ld %d 0", jcr->JobFiles, STREAM_UNIX_ATTRIBUTES_DEFAULT_ACL)) {
berrno be;
- Jmsg1(jcr, M_FATAL, 0, _("Network send error to SD. ERR=%s\n"),
+ Jmsg1(jcr, M_FATAL, 0, _("Network send error to SD. ERR=%s\n"),
bnet_strerror(sd));
return 0;
}
-
+
// Send the buffer to the storage deamon
msgsave = sd->msg;
sd->msg = aclDef_text;
berrno be;
sd->msg = msgsave;
sd->msglen = 0;
- Jmsg1(jcr, M_FATAL, 0, _("Network send error to SD. ERR=%s\n"),
+ Jmsg1(jcr, M_FATAL, 0, _("Network send error to SD. ERR=%s\n"),
bnet_strerror(sd));
} else {
jcr->JobBytes += sd->msglen;
sd->msg = msgsave;
if (!bnet_sig(sd, BNET_EOD)) {
berrno be;
- Jmsg1(jcr, M_FATAL, 0, _("Network send error to SD. ERR=%s\n"),
+ Jmsg1(jcr, M_FATAL, 0, _("Network send error to SD. ERR=%s\n"),
bnet_strerror(sd));
} else {
- Dmsg1(200, "ACL of file: %s successfully backed up!\n", ff_pkt->fname);
+ Dmsg1(200, "ACL of file: %s successfully backed up!\n", ff_pkt->fname);
}
- }
+ }
}
- }
+ }
#endif
/* Terminate any signature and send it to Storage daemon and the Director */
} else if (chksum.type == CHKSUM_SHA1) {
stream = STREAM_SHA1_SIGNATURE;
} else {
- Jmsg1(jcr, M_WARNING, 0, _("Unknown signature type %i."), chksum.type);
+ Jmsg1(jcr, M_WARNING, 0, _("Unknown signature type %i."), chksum.type);
}
if (stream != 0) {
- bnet_fsend(sd, "%ld %d 0", jcr->JobFiles, stream);
- Dmsg1(300, "bfiled>stored:header %s\n", sd->msg);
+ bnet_fsend(sd, "%ld %d 0", jcr->JobFiles, stream);
+ Dmsg1(300, "bfiled>stored:header %s\n", sd->msg);
memcpy(sd->msg, chksum.signature, chksum.length);
sd->msglen = chksum.length;
bnet_send(sd);
POOLMEM *msgsave;
msgsave = sd->msg;
- rbuf = sd->msg; /* read buffer */
+ rbuf = sd->msg; /* read buffer */
wbuf = sd->msg; /* write buffer */
/*
* Make space at beginning of buffer for fileAddr because this
- * same buffer will be used for writing if compression if off.
+ * same buffer will be used for writing if compression if off.
*/
if (ff_pkt->flags & FO_SPARSE) {
rbuf += SPARSE_FADDR_SIZE;
rsize -= SPARSE_FADDR_SIZE;
#ifdef HAVE_FREEBSD_OS
- /*
+ /*
* To read FreeBSD partitions, the read size must be
* a multiple of 512.
*/
#endif
}
- /*
+ /*
* Read the file data
*/
while ((sd->msglen=(uint32_t)bread(&ff_pkt->bfd, rbuf, rsize)) > 0) {
/* Check for sparse blocks */
if (ff_pkt->flags & FO_SPARSE) {
ser_declare;
- if (sd->msglen == rsize &&
+ if (sd->msglen == rsize &&
(fileAddr+sd->msglen < (uint64_t)ff_pkt->statp.st_size)) {
sparseBlock = is_buf_zero(rbuf, rsize);
}
-
+
ser_begin(wbuf, SPARSE_FADDR_SIZE);
ser_uint64(fileAddr); /* store fileAddr in begin of buffer */
- }
+ }
jcr->ReadBytes += sd->msglen; /* count bytes read */
fileAddr += sd->msglen;
if (!sparseBlock && ff_pkt->flags & FO_GZIP) {
int zstat;
compress_len = max_compress_len;
- Dmsg4(400, "cbuf=0x%x len=%u rbuf=0x%x len=%u\n", cbuf, compress_len,
+ Dmsg4(400, "cbuf=0x%x len=%u rbuf=0x%x len=%u\n", cbuf, compress_len,
rbuf, sd->msglen);
/* NOTE! This call modifies compress_len !!! */
- if ((zstat=compress2((Bytef *)cbuf, &compress_len,
+ if ((zstat=compress2((Bytef *)cbuf, &compress_len,
(const Bytef *)rbuf, (uLong)sd->msglen,
ff_pkt->GZIP_level)) != Z_OK) {
- Jmsg(jcr, M_FATAL, 0, _("Compression error: %d\n"), zstat);
+ Jmsg(jcr, M_FATAL, 0, _("Compression error: %d\n"), zstat);
sd->msg = msgsave;
sd->msglen = 0;
set_jcr_job_status(jcr, JS_ErrorTerminated);
return 0;
}
- Dmsg2(400, "compressed len=%d uncompressed len=%d\n",
+ Dmsg2(400, "compressed len=%d uncompressed len=%d\n",
compress_len, sd->msglen);
sd->msglen = compress_len; /* set compressed length */
sd->msg = wbuf; /* set correct write buffer */
if (!bnet_send(sd)) {
berrno be;
- Jmsg2(jcr, M_FATAL, 0, _("Network send error %d to SD. ERR=%s\n"),
+ Jmsg2(jcr, M_FATAL, 0, _("Network send error %d to SD. ERR=%s\n"),
sd->msglen, bnet_strerror(sd));
sd->msg = msgsave; /* restore bnet buffer */
sd->msglen = 0;
status = SHA1Init(&chksum->context.sha1);
if (status == 0) {
chksum->type = CHKSUM_SHA1;
- bstrncpy(chksum->name, "SHA1", sizeof(chksum->name));
+ bstrncpy(chksum->name, "SHA1", sizeof(chksum->name));
}
}
return status;
/*
- * Bacula File Daemon estimate.c
+ * Bacula File Daemon estimate.c
* Make and estimate of the number of files and size to be saved.
*
* Kern Sibbald, September MMI
static int tally_file(FF_PKT *ff_pkt, void *pkt);
-/*
+/*
* Find all the requested files and count them.
*/
int make_estimate(JCR *jcr)
stat = find_files(jcr, (FF_PKT *)jcr->ff, tally_file, (void *)jcr);
return stat;
-}
+}
-/*
+/*
* Called here by find() for each file included.
*
*/
if (ff_pkt->type != FT_LNKSAVED && S_ISREG(ff_pkt->statp.st_mode)) {
if (ff_pkt->statp.st_size > 0) {
- jcr->JobBytes += ff_pkt->statp.st_size;
+ jcr->JobBytes += ff_pkt->statp.st_size;
}
#ifdef HAVE_DARWIN_OS
if (ff_pkt->flags & FO_HFSPLUS) {
- if (ff_pkt->hfsinfo.rsrclength > 0) {
- jcr->JobBytes += ff_pkt->hfsinfo.rsrclength;
- }
- jcr->JobBytes += 32; /* Finder info */
+ if (ff_pkt->hfsinfo.rsrclength > 0) {
+ jcr->JobBytes += ff_pkt->hfsinfo.rsrclength;
+ }
+ jcr->JobBytes += 32; /* Finder info */
}
#endif
}
fprintf(stderr, _(
"Copyright (C) 2000-2004 Kern Sibbald and John Walker\n"
"\nVersion: " VERSION " (" BDATE ")\n\n"
-"Usage: bacula-fd [-f -s] [-c config_file] [-d debug_level]\n"
+"Usage: bacula-fd [-f -s] [-c config_file] [-d debug_level]\n"
" -c <file> use <file> as configuration file\n"
" -dnn set debug level to nn\n"
" -f run in foreground (for debugging)\n"
" -u userid\n"
" -v verbose user messages\n"
" -? print this message.\n"
-"\n"));
+"\n"));
exit(1);
}
-/*********************************************************************
+/*********************************************************************
*
- * Main Bacula Unix Client Program
+ * Main Bacula Unix Client Program
*
*/
#if defined(HAVE_CYGWIN) || defined(HAVE_WIN32)
case 'd': /* debug level */
debug_level = atoi(optarg);
if (debug_level <= 0) {
- debug_level = 1;
+ debug_level = 1;
}
break;
default:
usage();
- }
+ }
}
argc -= optind;
argv += optind;
if (configfile != NULL)
free(configfile);
configfile = bstrdup(*argv);
- argc--;
+ argc--;
argv++;
}
if (argc) {
me = (CLIENT *)GetNextRes(R_CLIENT, NULL);
UnlockRes();
if (!me) {
- Emsg1(M_ABORT, 0, _("No File daemon resource defined in %s\n\
-Without that I don't know who I am :-(\n"), configfile);
+ Emsg1(M_ABORT, 0, _("No File daemon resource defined in %s\n"
+"Without that I don't know who I am :-(\n"), configfile);
} else {
my_name_is(0, NULL, me->hdr.name);
if (!me->messages) {
me->messages = (MSGS *)GetNextRes(R_MSGS, NULL);
UnlockRes();
if (!me->messages) {
- Emsg1(M_ABORT, 0, _("No Messages resource defined in %s\n"), configfile);
+ Emsg1(M_ABORT, 0, _("No Messages resource defined in %s\n"), configfile);
}
}
close_msg(NULL); /* close temp message handler */
server_tid = pthread_self();
if (inetd_request) {
- /* Socket is on fd 0 */
+ /* Socket is on fd 0 */
struct sockaddr client_addr;
int port = -1;
socklen_t client_addr_len = sizeof(client_addr);
/* Become server, and handle requests */
IPADDR *p;
foreach_dlist(p, me->FDaddrs) {
- Dmsg1(10, "filed: listening on port %d\n", p->get_port_host_order());
+ Dmsg1(10, "filed: listening on port %d\n", p->get_port_host_order());
}
bnet_thread_server(me->FDaddrs, me->MaxConcurrentJobs, &dir_workq, handle_client_request);
}
free(configfile);
}
if (debug_level > 5) {
- print_memory_pool_stats();
+ print_memory_pool_stats();
}
free_config_resources();
term_msg();
/*
* Bacula File Daemon specific configuration and defines
*
- * Kern Sibbald, Jan MMI
+ * Kern Sibbald, Jan MMI
*
* Version $Id$
*/
*
* 1. The generic lexical scanner in lib/lex.c and lib/lex.h
*
- * 2. The generic config scanner in lib/parse_config.c and
+ * 2. The generic config scanner in lib/parse_config.c and
* lib/parse_config.h.
* These files contain the parser code, some utility
* routines, and the common store routines (name, int,
#endif
/* Definition of records permitted within each
- * resource with the routine to process the record
+ * resource with the routine to process the record
* information.
- */
+ */
/* Client or File daemon "Global" resources */
static RES_ITEM cli_items[] = {
{"fdaddress", store_addresses_address, ITEM(res_client.FDaddrs), 0, ITEM_DEFAULT, 9102},
{"fdaddresses", store_addresses, ITEM(res_client.FDaddrs), 0, ITEM_DEFAULT, 9102},
- {"workingdirectory", store_dir, ITEM(res_client.working_directory), 0, ITEM_REQUIRED, 0},
- {"piddirectory", store_dir, ITEM(res_client.pid_directory), 0, ITEM_REQUIRED, 0},
- {"subsysdirectory", store_dir, ITEM(res_client.subsys_directory), 0, 0, 0},
+ {"workingdirectory", store_dir, ITEM(res_client.working_directory), 0, ITEM_REQUIRED, 0},
+ {"piddirectory", store_dir, ITEM(res_client.pid_directory), 0, ITEM_REQUIRED, 0},
+ {"subsysdirectory", store_dir, ITEM(res_client.subsys_directory), 0, 0, 0},
{"requiressl", store_yesno, ITEM(res_client.require_ssl), 1, ITEM_DEFAULT, 0},
{"maximumconcurrentjobs", store_pint, ITEM(res_client.MaxConcurrentJobs), 0, ITEM_DEFAULT, 10},
{"messages", store_res, ITEM(res_client.messages), R_MSGS, 0, 0},
{"heartbeatinterval", store_time, ITEM(res_client.heartbeat_interval), 0, ITEM_DEFAULT, 0},
{"sdconnecttimeout", store_time,ITEM(res_client.SDConnectTimeout), 0, ITEM_DEFAULT, 60 * 30},
{"maximumnetworkbuffersize", store_pint, ITEM(res_client.max_network_buffer_size), 0, 0, 0},
- {NULL, NULL, NULL, 0, 0, 0}
+ {NULL, NULL, NULL, 0, 0, 0}
};
/* Directors that can use our services */
{"address", store_str, ITEM(res_dir.address), 0, 0, 0},
{"enablessl", store_yesno, ITEM(res_dir.enable_ssl),1, ITEM_DEFAULT, 0},
{"monitor", store_yesno, ITEM(res_dir.monitor), 1, ITEM_DEFAULT, 0},
- {NULL, NULL, NULL, 0, 0, 0}
+ {NULL, NULL, NULL, 0, 0, 0}
};
/* Message resource */
extern RES_ITEM msgs_items[];
-/*
- * This is the master resource definition.
+/*
+ * This is the master resource definition.
* It must have one item for each of the resources.
*/
RES_TABLE resources[] = {
}
switch (type) {
case R_DIRECTOR:
- sendit(sock, "Director: name=%s password=%s\n", reshdr->name,
+ sendit(sock, "Director: name=%s password=%s\n", reshdr->name,
res->res_dir.password);
break;
case R_CLIENT:
- sendit(sock, "Client: name=%s FDport=%d\n", reshdr->name,
+ sendit(sock, "Client: name=%s FDport=%d\n", reshdr->name,
get_first_port_host_order(res->res_client.FDaddrs));
break;
case R_MSGS:
- sendit(sock, "Messages: name=%s\n", res->res_msgs.hdr.name);
- if (res->res_msgs.mail_cmd)
- sendit(sock, " mailcmd=%s\n", res->res_msgs.mail_cmd);
- if (res->res_msgs.operator_cmd)
- sendit(sock, " opcmd=%s\n", res->res_msgs.operator_cmd);
+ sendit(sock, "Messages: name=%s\n", res->res_msgs.hdr.name);
+ if (res->res_msgs.mail_cmd)
+ sendit(sock, " mailcmd=%s\n", res->res_msgs.mail_cmd);
+ if (res->res_msgs.operator_cmd)
+ sendit(sock, " opcmd=%s\n", res->res_msgs.operator_cmd);
break;
default:
- sendit(sock, "Unknown resource type %d\n", type);
+ sendit(sock, "Unknown resource type %d\n", type);
}
if (recurse && res->res_dir.hdr.next)
dump_resource(type, res->res_dir.hdr.next, sendit, sock);
}
-/*
- * Free memory of resource.
+/*
+ * Free memory of resource.
* NB, we don't need to worry about freeing any references
- * to other resources as they will be freed when that
+ * to other resources as they will be freed when that
* resource chain is traversed. Mainly we worry about freeing
* allocated strings (names).
*/
int i, size;
int error = 0;
- /*
+ /*
* Ensure that all required items are present
*/
for (i=0; items[i].name; i++) {
if (items[i].flags & ITEM_REQUIRED) {
- if (!bit_is_set(i, res_all.res_dir.hdr.item_present)) {
- Emsg2(M_ABORT, 0, _("%s item is required in %s resource, but not found.\n"),
+ if (!bit_is_set(i, res_all.res_dir.hdr.item_present)) {
+ Emsg2(M_ABORT, 0, _("%s item is required in %s resource, but not found.\n"),
items[i].name, resources[rindex]);
}
}
/* Resources containing another resource */
case R_CLIENT:
if ((res = (URES *)GetResWithName(R_CLIENT, res_all.res_dir.hdr.name)) == NULL) {
- Emsg1(M_ABORT, 0, "Cannot find Client resource %s\n", res_all.res_dir.hdr.name);
+ Emsg1(M_ABORT, 0, "Cannot find Client resource %s\n", res_all.res_dir.hdr.name);
}
res->res_client.messages = res_all.res_client.messages;
break;
default:
- Emsg1(M_ERROR, 0, _("Unknown resource type %d\n"), type);
+ Emsg1(M_ERROR, 0, _("Unknown resource type %d\n"), type);
error = 1;
break;
}
size = sizeof(MSGS);
break;
default:
- printf(_("Unknown resource type %d\n"), type);
+ printf(_("Unknown resource type %d\n"), type);
error = 1;
size = 1;
break;
for (next=res_head[rindex]; next->next; next=next->next) {
if (strcmp(next->name, res->res_dir.hdr.name) == 0) {
Emsg2(M_ERROR_TERM, 0,
- _("Attempt to define second %s resource named \"%s\" is not permitted.\n"),
+ _("Attempt to define second %s resource named \"%s\" is not permitted.\n"),
resources[rindex].name, res->res_dir.hdr.name);
}
}
next->next = (RES *)res;
- Dmsg2(90, "Inserting %s res: %s\n", res_to_str(type),
+ Dmsg2(90, "Inserting %s res: %s\n", res_to_str(type),
res->res_dir.hdr.name);
}
}
*/
/*
- * Resource codes -- they must be sequential for indexing
+ * Resource codes -- they must be sequential for indexing
*/
#define R_FIRST 1001
#define pthread_kill(x, y)
/* Use shorter wait interval on Cygwin because no kill */
#define WAIT_INTERVAL 10
-
+
#else /* Unix systems */
#define WAIT_INTERVAL 60
#endif
extern "C" void *dir_heartbeat_thread(void *arg);
extern bool no_signals;
-/*
+/*
* Listen on the SD socket for heartbeat signals.
* Send heartbeats to the Director every HB_TIME
* seconds.
if (n == 1) { /* input waiting */
bnet_recv(sd); /* read it -- probably heartbeat from sd */
if (sd->msglen <= 0) {
- Dmsg1(100, "Got BNET_SIG %d from SD\n", sd->msglen);
+ Dmsg1(100, "Got BNET_SIG %d from SD\n", sd->msglen);
} else {
- Dmsg2(100, "Got %d bytes from SD. MSG=%s\n", sd->msglen, sd->msg);
+ Dmsg2(100, "Got %d bytes from SD. MSG=%s\n", sd->msglen, sd->msg);
}
}
}
/* Startup the heartbeat thread -- see above */
void start_heartbeat_monitor(JCR *jcr)
{
- /*
+ /*
* If no signals are set, do not start the heartbeat because
* it gives a constant stream of TIMEOUT_SIGNAL signals that
* make debugging impossible.
}
/* Terminate the heartbeat thread. Used for both SD and DIR */
-void stop_heartbeat_monitor(JCR *jcr)
+void stop_heartbeat_monitor(JCR *jcr)
{
int cnt = 0;
if (no_signals) {
extern char my_name[];
extern CLIENT *me; /* our client resource */
-
+
/* Imported functions */
extern int status_cmd(JCR *jcr);
extern int qstatus_cmd(JCR *jcr);
int monitoraccess; /* specify if monitors have access to this function */
};
-/*
- * The following are the recognized commands from the Director.
+/*
+ * The following are the recognized commands from the Director.
*/
static struct s_cmds cmds[] = {
{"backup", backup_cmd, 0},
static char read_data[] = "read data %d\n";
static char read_close[] = "read close session %d\n";
-/*
+/*
* Accept requests from a Director
*
* NOTE! We are running as a separate thread
*/
void *handle_client_request(void *dirp)
{
- int i;
+ int i;
bool found, quit;
JCR *jcr;
BSOCK *dir = (BSOCK *)dirp;
break;
}
if ((jcr->authenticated) && (!cmds[i].monitoraccess) && (jcr->director->monitor)) {
- Dmsg1(100, "Command %s illegal.\n", cmds[i].cmd);
+ Dmsg1(100, "Command %s illegal.\n", cmds[i].cmd);
bnet_fsend(dir, illegal_cmd);
bnet_sig(dir, BNET_EOD);
break;
}
- Dmsg1(100, "Executing %s command.\n", cmds[i].cmd);
+ Dmsg1(100, "Executing %s command.\n", cmds[i].cmd);
if (!cmds[i].func(jcr)) { /* do command */
quit = true; /* error or fully terminated, get out */
- Dmsg0(20, "Quit command loop due to command error or Job done.\n");
+ Dmsg0(20, "Quit command loop due to command error or Job done.\n");
}
break;
}
}
/*
- * Hello from Director he must identify himself and provide his
+ * Hello from Director he must identify himself and provide his
* password.
*/
static int hello_cmd(JCR *jcr)
if (sscanf(dir->msg, "cancel Job=%127s", Job) == 1) {
if (!(cjcr=get_jcr_by_full_name(Job))) {
- bnet_fsend(dir, "2901 Job %s not found.\n", Job);
+ bnet_fsend(dir, "2901 Job %s not found.\n", Job);
} else {
if (cjcr->store_bsock) {
P(cjcr->mutex);
cjcr->store_bsock->timed_out = 1;
cjcr->store_bsock->terminated = 1;
-/*
+/*
* #if !defined(HAVE_CYGWIN) && !defined(HAVE_WIN32)
*/
#if !defined(HAVE_CYGWIN)
}
set_jcr_job_status(cjcr, JS_Canceled);
free_jcr(cjcr);
- bnet_fsend(dir, _("2001 Job %s marked to be canceled.\n"), Job);
+ bnet_fsend(dir, _("2001 Job %s marked to be canceled.\n"), Job);
}
} else {
bnet_fsend(dir, _("2902 Error scanning cancel command.\n"));
if (sscanf(dir->msg, "setdebug=%d trace=%d", &level, &trace_flag) != 2 || level < 0) {
pm_strcpy(jcr->errmsg, dir->msg);
bnet_fsend(dir, "2991 Bad setdebug command: %s\n", jcr->errmsg);
- return 0;
+ return 0;
}
debug_level = level;
set_trace(trace_flag);
return 0;
}
make_estimate(jcr);
- bnet_fsend(dir, OKest, jcr->num_files_examined,
+ bnet_fsend(dir, OKest, jcr->num_files_examined,
edit_uint64_with_commas(jcr->JobBytes, ed2));
bnet_sig(dir, BNET_EOD);
return 1;
POOLMEM *sd_auth_key;
sd_auth_key = get_memory(dir->msglen);
- if (sscanf(dir->msg, jobcmd, &jcr->JobId, jcr->Job,
+ if (sscanf(dir->msg, jobcmd, &jcr->JobId, jcr->Job,
&jcr->VolSessionId, &jcr->VolSessionTime,
sd_auth_key) != 5) {
pm_strcpy(jcr->errmsg, dir->msg);
int status;
BPIPE *bpipe;
char line[MAXSTRING];
-
+
ecmd = edit_job_codes(jcr, ecmd, cmd, "");
bpipe = open_bpipe(ecmd, 0, "r");
free_pool_memory(ecmd);
bpipe = open_bpipe(fn, 0, "r");
free_pool_memory(fn);
if (!bpipe) {
- Jmsg(jcr, M_FATAL, 0, _("Cannot run program: %s. ERR=%s\n"),
+ Jmsg(jcr, M_FATAL, 0, _("Cannot run program: %s. ERR=%s\n"),
p, strerror(errno));
return;
}
if (list == INC_LIST) {
*q = 0; /* terminate options */
strcpy(buf, fname);
- strcat(buf, " ");
+ strcat(buf, " ");
optlen = strlen(buf);
} else {
optlen = 0;
}
}
if ((stat=close_bpipe(bpipe)) != 0) {
- Jmsg(jcr, M_FATAL, 0, _("Error running program: %s. RtnStat=%d ERR=%s\n"),
+ Jmsg(jcr, M_FATAL, 0, _("Error running program: %s. RtnStat=%d ERR=%s\n"),
p, stat, strerror(errno));
return;
}
p++; /* skip over < */
if ((ffd = fopen(p, "r")) == NULL) {
berrno be;
- Jmsg(jcr, M_FATAL, 0, _("Cannot open %s file: %s. ERR=%s\n"),
- list==INC_LIST?"included":"excluded", p, be.strerror());
+ Jmsg(jcr, M_FATAL, 0, _("Cannot open %s file: %s. ERR=%s\n"),
+ list==INC_LIST?"included":"excluded", p, be.strerror());
return;
}
/* Copy File options */
if (list == INC_LIST) {
*q = 0; /* terminate options */
strcpy(buf, fname);
- strcat(buf, " ");
+ strcat(buf, " ");
optlen = strlen(buf);
} else {
optlen = 0;
}
}
-/*
- *
+/*
+ *
* Get list of files/directories to include from Director
*
*/
return bnet_fsend(dir, OKinc);
}
-static bool init_fileset(JCR *jcr)
+static bool init_fileset(JCR *jcr)
{
FF_PKT *ff;
findFILESET *fileset;
- if (!jcr->ff) {
+ if (!jcr->ff) {
return false;
}
ff = (FF_PKT *)jcr->ff;
bpipe = open_bpipe(fn, 0, "r");
free_pool_memory(fn);
if (!bpipe) {
- Jmsg(jcr, M_FATAL, 0, _("Cannot run program: %s. ERR=%s\n"),
+ Jmsg(jcr, M_FATAL, 0, _("Cannot run program: %s. ERR=%s\n"),
p, strerror(errno));
return;
}
fileset->incexe->name_list.append(bstrdup(buf));
}
if ((stat=close_bpipe(bpipe)) != 0) {
- Jmsg(jcr, M_FATAL, 0, _("Error running program: %s. RtnStat=%d ERR=%s\n"),
+ Jmsg(jcr, M_FATAL, 0, _("Error running program: %s. RtnStat=%d ERR=%s\n"),
p, stat, strerror(errno));
return;
}
p++; /* skip over < */
if ((ffd = fopen(p, "r")) == NULL) {
berrno be;
- Jmsg(jcr, M_FATAL, 0, _("Cannot open FileSet input file: %s. ERR=%s\n"),
+ Jmsg(jcr, M_FATAL, 0, _("Cannot open FileSet input file: %s. ERR=%s\n"),
p, be.strerror());
return;
}
}
}
-
+
static void add_fileset(JCR *jcr, const char *item)
{
FF_PKT *ff = (FF_PKT *)jcr->ff;
char prbuf[500];
preg = (regex_t *)malloc(sizeof(regex_t));
if (current_opts->flags & FO_IGNORECASE) {
- rc = regcomp(preg, item, REG_EXTENDED|REG_ICASE);
+ rc = regcomp(preg, item, REG_EXTENDED|REG_ICASE);
} else {
- rc = regcomp(preg, item, REG_EXTENDED);
+ rc = regcomp(preg, item, REG_EXTENDED);
}
if (rc != 0) {
regerror(rc, preg, prbuf, sizeof(prbuf));
regfree(preg);
free(preg);
- Jmsg(jcr, M_FATAL, 0, "REGEX %s compile error. ERR=%s\n", item, prbuf);
+ Jmsg(jcr, M_FATAL, 0, "REGEX %s compile error. ERR=%s\n", item, prbuf);
state = state_error;
break;
}
current_opts->wild.append(bstrdup(item));
state = state_options;
break;
- case 'O':
+ case 'O':
current_opts = start_options(ff);
set_options(current_opts, item);
state = state_options;
for (j=0; j<incexe->opts_list.size(); j++) {
findFOPTS *fo = (findFOPTS *)incexe->opts_list.get(j);
for (k=0; k<fo->regex.size(); k++) {
- Dmsg1(400, "R %s\n", (char *)fo->regex.get(k));
+ Dmsg1(400, "R %s\n", (char *)fo->regex.get(k));
}
for (k=0; k<fo->wild.size(); k++) {
- Dmsg1(400, "W %s\n", (char *)fo->wild.get(k));
+ Dmsg1(400, "W %s\n", (char *)fo->wild.get(k));
}
for (k=0; k<fo->base.size(); k++) {
- Dmsg1(400, "B %s\n", (char *)fo->base.get(k));
+ Dmsg1(400, "B %s\n", (char *)fo->base.get(k));
}
for (k=0; k<fo->fstype.size(); k++) {
- Dmsg1(400, "X %s\n", (char *)fo->fstype.get(k));
+ Dmsg1(400, "X %s\n", (char *)fo->fstype.get(k));
}
if (fo->reader) {
- Dmsg1(400, "D %s\n", fo->reader);
+ Dmsg1(400, "D %s\n", fo->reader);
}
if (fo->writer) {
- Dmsg1(400, "T %s\n", fo->writer);
+ Dmsg1(400, "T %s\n", fo->writer);
}
}
for (j=0; j<incexe->name_list.size(); j++) {
- Dmsg1(400, "F %s\n", (char *)incexe->name_list.get(j));
+ Dmsg1(400, "F %s\n", (char *)incexe->name_list.get(j));
}
}
for (i=0; i<fileset->exclude_list.size(); i++) {
for (j=0; j<incexe->opts_list.size(); j++) {
findFOPTS *fo = (findFOPTS *)incexe->opts_list.get(j);
for (k=0; k<fo->regex.size(); k++) {
- Dmsg1(400, "R %s\n", (char *)fo->regex.get(k));
+ Dmsg1(400, "R %s\n", (char *)fo->regex.get(k));
}
for (k=0; k<fo->wild.size(); k++) {
- Dmsg1(400, "W %s\n", (char *)fo->wild.get(k));
+ Dmsg1(400, "W %s\n", (char *)fo->wild.get(k));
}
for (k=0; k<fo->base.size(); k++) {
- Dmsg1(400, "B %s\n", (char *)fo->base.get(k));
+ Dmsg1(400, "B %s\n", (char *)fo->base.get(k));
}
for (k=0; k<fo->fstype.size(); k++) {
- Dmsg1(400, "X %s\n", (char *)fo->fstype.get(k));
+ Dmsg1(400, "X %s\n", (char *)fo->fstype.get(k));
}
}
for (j=0; j<incexe->name_list.size(); j++) {
- Dmsg1(400, "F %s\n", (char *)incexe->name_list.get(j));
+ Dmsg1(400, "F %s\n", (char *)incexe->name_list.get(j));
}
}
return ff->fileset->state != state_error;
break;
case 'V': /* verify options */
/* Copy Verify Options */
- for (j=0; *p && *p != ':'; p++) {
+ for (j=0; *p && *p != ':'; p++) {
fo->VerifyOpts[j] = *p;
if (j < (int)sizeof(fo->VerifyOpts) - 1) {
j++;
break;
case 'Z': /* gzip compression */
fo->flags |= FO_GZIP;
- fo->GZIP_level = *++p - '0';
- Dmsg1(200, "Compression level=%d\n", fo->GZIP_level);
+ fo->GZIP_level = *++p - '0';
+ Dmsg1(200, "Compression level=%d\n", fo->GZIP_level);
break;
default:
- Emsg1(M_ERROR, 0, "Unknown include/exclude option: %c\n", *p);
+ Emsg1(M_ERROR, 0, "Unknown include/exclude option: %c\n", *p);
break;
}
}
-}
+}
/*
- * Director is passing his Fileset
+ * Director is passing his Fileset
*/
static int fileset_cmd(JCR *jcr)
{
bs = fopen(fname, "a+"); /* create file */
if (!bs) {
berrno be;
- /*
+ /*
* Suck up what he is sending to us so that he will then
* read our error message.
*/
/* Base backup requested? */
if (strcmp(level, "base") == 0) {
jcr->JobLevel = L_BASE;
- /* Full backup requested? */
+ /* Full backup requested? */
} else if (strcmp(level, "full") == 0) {
jcr->JobLevel = L_FULL;
- /*
+ /*
* Backup requested since <date> <time>
* This form is also used for incremental and differential
* This code is deprecated. See since_utime for new code.
*/
} else if (strcmp(level, "since") == 0) {
jcr->JobLevel = L_SINCE;
- if (sscanf(dir->msg, "level = since %d-%d-%d %d:%d:%d mtime_only=%d",
+ if (sscanf(dir->msg, "level = since %d-%d-%d %d:%d:%d mtime_only=%d",
&tm.tm_year, &tm.tm_mon, &tm.tm_mday,
&tm.tm_hour, &tm.tm_min, &tm.tm_sec, &mtime_only) != 7) {
goto bail_out;
}
tm.tm_year -= 1900;
tm.tm_mon -= 1;
- tm.tm_wday = tm.tm_yday = 0;
+ tm.tm_wday = tm.tm_yday = 0;
tm.tm_isdst = -1;
mtime = mktime(&tm);
Dmsg2(100, "Got since time: %s mtime_only=%d\n", ctime(&mtime), mtime_only);
utime_t since_time, adj;
btime_t his_time, bt_start, rt=0, bt_adj=0;
jcr->JobLevel = L_SINCE;
- if (sscanf(dir->msg, "level = since_utime %s mtime_only=%d",
- buf, &mtime_only) != 2) {
+ if (sscanf(dir->msg, "level = since_utime %s mtime_only=%d",
+ buf, &mtime_only) != 2) {
goto bail_out;
}
since_time = str_to_uint64(buf); /* this is the since time */
char ed1[50], ed2[50];
- /*
- * Sync clocks by polling him for the time. We take
+ /*
+ * Sync clocks by polling him for the time. We take
* 10 samples of his time throwing out the first two.
*/
for (int i=0; i<10; i++) {
if (bnet_recv(dir) <= 0) { /* get response */
goto bail_out;
}
- if (sscanf(dir->msg, "btime %s", buf) != 1) {
+ if (sscanf(dir->msg, "btime %s", buf) != 1) {
goto bail_out;
}
if (i < 2) { /* toss first two results */
his_time = str_to_uint64(buf);
rt = get_current_btime() - bt_start; /* compute round trip time */
bt_adj -= his_time - bt_start - rt/2;
- Dmsg2(200, "rt=%s adj=%s\n", edit_uint64(rt, ed1), edit_uint64(bt_adj, ed2));
+ Dmsg2(200, "rt=%s adj=%s\n", edit_uint64(rt, ed1), edit_uint64(bt_adj, ed2));
}
bt_adj = bt_adj / 8; /* compute average time */
adj = btime_to_utime(bt_adj);
since_time += adj; /* adjust for clock difference */
if (adj != 0) {
- Jmsg(jcr, M_INFO, 0, _("Since time adjusted by %d seconds.\n"), adj);
+ Jmsg(jcr, M_INFO, 0, _("Since time adjusted by %d seconds.\n"), adj);
}
bnet_sig(dir, BNET_EOD);
Dmsg1(100, "SessionCmd: %s", dir->msg);
if (sscanf(dir->msg, sessioncmd, jcr->VolumeName,
&jcr->VolSessionId, &jcr->VolSessionTime,
- &jcr->StartFile, &jcr->EndFile,
+ &jcr->StartFile, &jcr->EndFile,
&jcr->StartBlock, &jcr->EndBlock) != 7) {
pm_strcpy(jcr->errmsg, dir->msg);
Jmsg(jcr, M_FATAL, 0, "Bad session command: %s", jcr->errmsg);
Dmsg3(110, "Open storage: %s:%d ssl=%d\n", jcr->stored_addr, stored_port, enable_ssl);
/* Open command communications with Storage daemon */
/* Try to connect for 1 hour at 10 second intervals */
- sd = bnet_connect(jcr, 10, (int)me->SDConnectTimeout, _("Storage daemon"),
+ sd = bnet_connect(jcr, 10, (int)me->SDConnectTimeout, _("Storage daemon"),
jcr->stored_addr, NULL, stored_port, 1);
if (sd == NULL) {
Jmsg(jcr, M_FATAL, 0, _("Failed to connect to Storage daemon: %s:%d\n"),
}
-/*
+/*
* Do a backup. For now, we handle only Full and Incremental.
*/
static int backup_cmd(JCR *jcr)
-{
+{
BSOCK *dir = jcr->dir_bsock;
BSOCK *sd = jcr->store_bsock;
int ok = 0;
bnet_fsend(dir, OKbackup);
Dmsg1(110, "bfiled>dird: %s", dir->msg);
- /*
+ /*
* Send Append Open Session to Storage daemon
*/
bnet_fsend(sd, append_open);
Dmsg1(110, ">stored: %s", sd->msg);
- /*
+ /*
* Expect to receive back the Ticket number
*/
if (bget_msg(sd) >= 0) {
Dmsg1(110, "<stored: %s", sd->msg);
if (sscanf(sd->msg, OK_open, &jcr->Ticket) != 1) {
- Jmsg(jcr, M_FATAL, 0, _("Bad response to append open: %s\n"), sd->msg);
+ Jmsg(jcr, M_FATAL, 0, _("Bad response to append open: %s\n"), sd->msg);
goto cleanup;
}
Dmsg1(110, "Got Ticket=%d\n", jcr->Ticket);
goto cleanup;
}
- /*
+ /*
* Send Append data command to Storage daemon
*/
bnet_fsend(sd, append_data, jcr->Ticket);
Dmsg1(110, ">stored: %s", sd->msg);
- /*
- * Expect to get OK data
+ /*
+ * Expect to get OK data
*/
Dmsg1(110, "<stored: %s", sd->msg);
if (!response(jcr, sd, OK_data, "Append Data")) {
goto cleanup;
}
-
+
/*
* Send Files to Storage daemon
*/
bnet_suppress_error_messages(sd, 1);
goto cleanup; /* bail out now */
}
- /*
+ /*
* Expect to get response to append_data from Storage daemon
*/
if (!response(jcr, sd, OK_append, "Append Data")) {
set_jcr_job_status(jcr, JS_ErrorTerminated);
goto cleanup;
}
-
- /*
+
+ /*
* Send Append End Data to Storage daemon
*/
bnet_fsend(sd, append_end, jcr->Ticket);
while (bget_msg(sd) >= 0) { /* stop on signal or error */
if (sscanf(sd->msg, OK_close, &SDJobStatus) == 1) {
ok = 1;
- Dmsg2(200, "SDJobStatus = %d %c\n", SDJobStatus, (char)SDJobStatus);
+ Dmsg2(200, "SDJobStatus = %d %c\n", SDJobStatus, (char)SDJobStatus);
}
}
if (!ok) {
- Jmsg(jcr, M_FATAL, 0, _("Append Close with SD failed.\n"));
+ Jmsg(jcr, M_FATAL, 0, _("Append Close with SD failed.\n"));
goto cleanup;
}
if (SDJobStatus != JS_Terminated) {
- Jmsg(jcr, M_FATAL, 0, _("Bad status %d returned from Storage Daemon.\n"),
+ Jmsg(jcr, M_FATAL, 0, _("Bad status %d returned from Storage Daemon.\n"),
SDJobStatus);
}
}
cleanup:
- bnet_fsend(dir, EndJob, jcr->JobStatus, jcr->JobFiles,
- edit_uint64(jcr->ReadBytes, ed1),
- edit_uint64(jcr->JobBytes, ed2), jcr->Errors);
+ bnet_fsend(dir, EndJob, jcr->JobStatus, jcr->JobFiles,
+ edit_uint64(jcr->ReadBytes, ed1),
+ edit_uint64(jcr->JobBytes, ed2), jcr->Errors);
Dmsg1(110, "End FD msg: %s\n", dir->msg);
return 0; /* return and stop command loop */
}
-/*
+/*
* Do a Verify for Director
*
*/
static int verify_cmd(JCR *jcr)
-{
+{
BSOCK *dir = jcr->dir_bsock;
BSOCK *sd = jcr->store_bsock;
char level[100], ed1[50], ed2[50];
jcr->JobType = JT_VERIFY;
if (sscanf(dir->msg, verifycmd, level) != 1) {
bnet_fsend(dir, "2994 Bad verify command: %s\n", dir->msg);
- return 0;
+ return 0;
}
if (strcasecmp(level, "init") == 0) {
jcr->JobLevel = L_VERIFY_INIT;
jcr->JobLevel = L_VERIFY_DATA;
} else if (strcasecmp(level, "disk_to_catalog") == 0) {
jcr->JobLevel = L_VERIFY_DISK_TO_CATALOG;
- } else {
+ } else {
bnet_fsend(dir, "2994 Bad verify level: %s\n", dir->msg);
- return 0;
+ return 0;
}
bnet_fsend(dir, OKverify);
start_dir_heartbeat(jcr);
do_verify_volume(jcr);
stop_dir_heartbeat(jcr);
- /*
+ /*
* Send Close session command to Storage daemon
*/
bnet_fsend(sd, read_close, jcr->Ticket);
break;
default:
bnet_fsend(dir, "2994 Bad verify level: %s\n", dir->msg);
- return 0;
+ return 0;
}
bnet_sig(dir, BNET_EOD);
/* Send termination status back to Dir */
- bnet_fsend(dir, EndJob, jcr->JobStatus, jcr->JobFiles,
- edit_uint64(jcr->ReadBytes, ed1),
- edit_uint64(jcr->JobBytes, ed2), jcr->Errors);
+ bnet_fsend(dir, EndJob, jcr->JobStatus, jcr->JobFiles,
+ edit_uint64(jcr->ReadBytes, ed1),
+ edit_uint64(jcr->JobBytes, ed2), jcr->Errors);
/* Inform Director that we are done */
bnet_sig(dir, BNET_TERMINATE);
return 0; /* return and terminate command loop */
}
-/*
+/*
* Do a Restore for Director
*
*/
static int restore_cmd(JCR *jcr)
-{
+{
BSOCK *dir = jcr->dir_bsock;
BSOCK *sd = jcr->store_bsock;
POOLMEM *where;
if (sscanf(dir->msg, restorecmd, &replace, &prefix_links, where) != 3) {
if (sscanf(dir->msg, restorecmd1, &replace, &prefix_links) != 2) {
pm_strcpy(jcr->errmsg, dir->msg);
- Jmsg(jcr, M_FATAL, 0, _("Bad replace command. CMD=%s\n"), jcr->errmsg);
+ Jmsg(jcr, M_FATAL, 0, _("Bad replace command. CMD=%s\n"), jcr->errmsg);
return 0;
}
*where = 0;
if (where[0] == '/' && where[1] == 0) {
where[0] = 0;
}
-
+
Dmsg2(150, "Got replace %c, where=%s\n", replace, where);
unbash_spaces(where);
jcr->where = bstrdup(where);
set_jcr_job_status(jcr, JS_Running);
- /*
+ /*
* Do restore of files and data
*/
start_dir_heartbeat(jcr);
do_restore(jcr);
stop_dir_heartbeat(jcr);
-
+
set_jcr_job_status(jcr, JS_Terminated);
if (jcr->JobStatus != JS_Terminated) {
bnet_suppress_error_messages(sd, 1);
}
- /*
+ /*
* Send Close session command to Storage daemon
*/
bnet_fsend(sd, read_close, jcr->Ticket);
set_jcr_job_status(jcr, JS_ErrorTerminated);
}
/* Send termination status back to Dir */
- bnet_fsend(dir, EndJob, jcr->JobStatus, jcr->JobFiles,
- edit_uint64(jcr->ReadBytes, ed1),
- edit_uint64(jcr->JobBytes, ed2), jcr->Errors);
+ bnet_fsend(dir, EndJob, jcr->JobStatus, jcr->JobFiles,
+ edit_uint64(jcr->ReadBytes, ed1),
+ edit_uint64(jcr->JobBytes, ed2), jcr->Errors);
/* Inform Director that we are done */
bnet_sig(dir, BNET_TERMINATE);
Dmsg4(120, "VolSessId=%ld VolsessT=%ld SF=%ld EF=%ld\n",
jcr->VolSessionId, jcr->VolSessionTime, jcr->StartFile, jcr->EndFile);
Dmsg2(120, "JobId=%d vol=%s\n", jcr->JobId, "DummyVolume");
- /*
+ /*
* Open Read Session with Storage daemon
*/
bnet_fsend(sd, read_open, jcr->VolumeName,
- jcr->VolSessionId, jcr->VolSessionTime, jcr->StartFile, jcr->EndFile,
+ jcr->VolSessionId, jcr->VolSessionTime, jcr->StartFile, jcr->EndFile,
jcr->StartBlock, jcr->EndBlock);
Dmsg1(110, ">stored: %s", sd->msg);
- /*
+ /*
* Get ticket number
*/
if (bget_msg(sd) >= 0) {
Dmsg1(110, "bfiled<stored: %s", sd->msg);
if (sscanf(sd->msg, OK_open, &jcr->Ticket) != 1) {
- Jmsg(jcr, M_FATAL, 0, _("Bad response to SD read open: %s\n"), sd->msg);
+ Jmsg(jcr, M_FATAL, 0, _("Bad response to SD read open: %s\n"), sd->msg);
return 0;
}
Dmsg1(110, "bfiled: got Ticket=%d\n", jcr->Ticket);
return 0;
}
- /*
+ /*
* Start read of data with Storage daemon
*/
bnet_fsend(sd, read_data, jcr->Ticket);
Dmsg1(110, ">stored: %s", sd->msg);
- /*
+ /*
* Get OK data
*/
if (!response(jcr, sd, OK_data, "Read Data")) {
return 1;
}
-/*
+/*
* Destroy the Job Control Record and associated
* resources (sockets).
*/
-static void filed_free_jcr(JCR *jcr)
+static void filed_free_jcr(JCR *jcr)
{
if (jcr->store_bsock) {
bnet_close(jcr->store_bsock);
free_pool_memory(jcr->RunAfterJob);
}
-
+
return;
}
if (strcmp(sd->msg, resp) == 0) {
return 1;
}
- }
+ }
if (job_canceled(jcr)) {
return 0; /* if canceled avoid useless error messages */
}
bs = fopen(jcr->RestoreBootstrap, "r");
if (!bs) {
berrno be;
- Jmsg(jcr, M_FATAL, 0, _("Could not open bootstrap file %s: ERR=%s\n"),
+ Jmsg(jcr, M_FATAL, 0, _("Could not open bootstrap file %s: ERR=%s\n"),
jcr->RestoreBootstrap, be.strerror());
set_jcr_job_status(jcr, JS_ErrorTerminated);
goto bail_out;
}
- sd->msglen = pm_strcpy(sd->msg, bootstrap);
+ sd->msglen = pm_strcpy(sd->msg, bootstrap);
bnet_send(sd);
while (fgets(buf, sizeof(buf), bs)) {
sd->msglen = Mmsg(sd->msg, "%s", buf);
- bnet_send(sd);
+ bnet_send(sd);
}
bnet_sig(sd, BNET_EOD);
fclose(bs);
bclose(bfd); /* first close file */
if (fsize > 0 && fsize != osize) {
Jmsg3(jcr, M_ERROR, 0, _("File size of resource fork for restored file %s not correct. Original %s, restored %s.\n"),
- jcr->last_fname, edit_uint64(osize, ec1),
- edit_uint64(fsize, ec2));
+ jcr->last_fname, edit_uint64(osize, ec1),
+ edit_uint64(fsize, ec2));
return -1;
}
return 0;
}
#endif
-/*
+/*
* Restore the requested files.
- *
+ *
*/
void do_restore(JCR *jcr)
{
jcr->compress_buf = (char *)bmalloc(compress_buf_size);
#endif
- /*
- * Get a record from the Storage daemon. We are guaranteed to
+ /*
+ * Get a record from the Storage daemon. We are guaranteed to
* receive records in the following order:
* 1. Stream record header
* 2. Stream data
*/
while (bget_msg(sd) >= 0 && !job_canceled(jcr)) {
/*
- * First we expect a Stream Record Header
+ * First we expect a Stream Record Header
*/
if (sscanf(sd->msg, rec_header, &VolSessionId, &VolSessionTime, &file_index,
&stream, &size) != 5) {
- Jmsg1(jcr, M_FATAL, 0, _("Record header scan error: %s\n"), sd->msg);
+ Jmsg1(jcr, M_FATAL, 0, _("Record header scan error: %s\n"), sd->msg);
goto bail_out;
}
Dmsg2(30, "Got hdr: FilInx=%d Stream=%d.\n", file_index, stream);
- /*
+ /*
* Now we expect the Stream Data
*/
if (bget_msg(sd) < 0) {
- Jmsg1(jcr, M_FATAL, 0, _("Data record error. ERR=%s\n"), bnet_strerror(sd));
+ Jmsg1(jcr, M_FATAL, 0, _("Data record error. ERR=%s\n"), bnet_strerror(sd));
goto bail_out;
}
if (size != (uint32_t)sd->msglen) {
- Jmsg2(jcr, M_FATAL, 0, _("Actual data size %d not same as header %d\n"), sd->msglen, size);
+ Jmsg2(jcr, M_FATAL, 0, _("Actual data size %d not same as header %d\n"), sd->msglen, size);
goto bail_out;
}
Dmsg1(30, "Got stream data, len=%d\n", sd->msglen);
switch (stream) {
case STREAM_UNIX_ATTRIBUTES:
case STREAM_UNIX_ATTRIBUTES_EX:
- Dmsg1(30, "Stream=Unix Attributes. extract=%d\n", extract);
+ Dmsg1(30, "Stream=Unix Attributes. extract=%d\n", extract);
/* If extracting, it was from previous stream, so
* close the output file.
*/
if (extract) {
if (!is_bopen(&bfd) && !is_bopen(&rsrc_bfd)) {
- Jmsg0(jcr, M_ERROR, 0, _("Logic error output file should be open\n"));
+ Jmsg0(jcr, M_ERROR, 0, _("Logic error output file should be open\n"));
}
#ifdef HAVE_DARWIN_OS
- if (is_bopen(&rsrc_bfd)) {
- bclose_chksize(jcr, &rsrc_bfd, rsrc_len);
- }
+ if (is_bopen(&rsrc_bfd)) {
+ bclose_chksize(jcr, &rsrc_bfd, rsrc_len);
+ }
#endif
- if (is_bopen(&bfd)) {
- set_attributes(jcr, attr, &bfd);
- }
+ if (is_bopen(&bfd)) {
+ set_attributes(jcr, attr, &bfd);
+ }
extract = false;
- Dmsg0(30, "Stop extracting.\n");
+ Dmsg0(30, "Stop extracting.\n");
}
goto bail_out;
}
if (file_index != attr->file_index) {
- Jmsg(jcr, M_FATAL, 0, _("Record header file index %ld not equal record index %ld\n"),
+ Jmsg(jcr, M_FATAL, 0, _("Record header file index %ld not equal record index %ld\n"),
file_index, attr->file_index);
- Dmsg0(100, "File index error\n");
+ Dmsg0(100, "File index error\n");
goto bail_out;
}
-
- Dmsg3(200, "File %s\nattrib=%s\nattribsEx=%s\n", attr->fname,
+
+ Dmsg3(200, "File %s\nattrib=%s\nattribsEx=%s\n", attr->fname,
attr->attr, attr->attrEx);
attr->data_stream = decode_stat(attr->attr, &attr->statp, &attr->LinkFI);
if (!is_stream_supported(attr->data_stream)) {
if (!non_support_data++) {
- Jmsg(jcr, M_ERROR, 0, _("%s stream not supported on this Client.\n"),
+ Jmsg(jcr, M_ERROR, 0, _("%s stream not supported on this Client.\n"),
stream_to_ascii(attr->data_stream));
}
continue;
build_attr_output_fnames(jcr, attr);
#ifdef HAVE_DARWIN_OS
- from_base64(&rsrc_len, attr->attrEx);
+ from_base64(&rsrc_len, attr->attrEx);
#endif
jcr->num_files_examined++;
- Dmsg1(30, "Outfile=%s\n", attr->ofname);
+ Dmsg1(30, "Outfile=%s\n", attr->ofname);
extract = false;
stat = create_file(jcr, attr, &bfd, jcr->replace);
switch (stat) {
jcr->JobFiles++;
fileAddr = 0;
print_ls_output(jcr, attr);
- if (!extract) {
- /* set attributes now because file will not be extracted */
- set_attributes(jcr, attr, &bfd);
- }
+ if (!extract) {
+ /* set attributes now because file will not be extracted */
+ set_attributes(jcr, attr, &bfd);
+ }
#ifdef HAVE_DARWIN_OS
- if (rsrc_len > 0) {
+ if (rsrc_len > 0) {
rsrcAddr = 0;
if (bopen_rsrc(&rsrc_bfd, jcr->last_fname, O_WRONLY | O_TRUNC | O_BINARY, 0) < 0) {
Jmsg(jcr, M_ERROR, 0, _(" Cannot open resource fork for %s"), jcr->last_fname);
}
#endif
break;
- }
+ }
break;
/* Data stream */
case STREAM_FILE_DATA:
- case STREAM_SPARSE_DATA:
- case STREAM_WIN32_DATA:
+ case STREAM_SPARSE_DATA:
+ case STREAM_WIN32_DATA:
if (extract) {
if (stream == STREAM_SPARSE_DATA) {
ser_declare;
if (blseek(&bfd, (off_t)fileAddr, SEEK_SET) < 0) {
berrno be;
be.set_errno(bfd.berrno);
- Jmsg3(jcr, M_ERROR, 0, _("Seek to %s error on %s: ERR=%s\n"),
+ Jmsg3(jcr, M_ERROR, 0, _("Seek to %s error on %s: ERR=%s\n"),
edit_uint64(fileAddr, ec1), attr->ofname, be.strerror());
extract = false;
bclose(&bfd);
wbuf = sd->msg;
wsize = sd->msglen;
}
- Dmsg2(30, "Write %u bytes, total before write=%u\n", wsize, total);
+ Dmsg2(30, "Write %u bytes, total before write=%u\n", wsize, total);
if ((uint32_t)bwrite(&bfd, wbuf, wsize) != wsize) {
- Dmsg0(0, "===Write error===\n");
+ Dmsg0(0, "===Write error===\n");
berrno be;
be.set_errno(bfd.berrno);
- Jmsg2(jcr, M_ERROR, 0, _("Write error on %s: ERR=%s\n"), attr->ofname,
+ Jmsg2(jcr, M_ERROR, 0, _("Write error on %s: ERR=%s\n"), attr->ofname,
be.strerror());
extract = false;
bclose(&bfd);
bclose(&rsrc_bfd);
}
continue;
- }
+ }
total += wsize;
jcr->JobBytes += wsize;
jcr->ReadBytes += wsize;
/* GZIP data stream */
case STREAM_GZIP_DATA:
- case STREAM_SPARSE_GZIP_DATA:
- case STREAM_WIN32_GZIP_DATA:
+ case STREAM_SPARSE_GZIP_DATA:
+ case STREAM_WIN32_GZIP_DATA:
#ifdef HAVE_LIBZ
if (extract) {
uLong compress_len;
if (blseek(&bfd, (off_t)fileAddr, SEEK_SET) < 0) {
berrno be;
be.set_errno(bfd.berrno);
- Jmsg3(jcr, M_ERROR, 0, _("Seek to %s error on %s: ERR=%s\n"),
+ Jmsg3(jcr, M_ERROR, 0, _("Seek to %s error on %s: ERR=%s\n"),
edit_uint64(fileAddr, ec1), attr->ofname, be.strerror());
extract = false;
bclose(&bfd);
wsize = sd->msglen;
}
compress_len = compress_buf_size;
- Dmsg2(100, "Comp_len=%d msglen=%d\n", compress_len, wsize);
- if ((stat=uncompress((Byte *)jcr->compress_buf, &compress_len,
+ Dmsg2(100, "Comp_len=%d msglen=%d\n", compress_len, wsize);
+ if ((stat=uncompress((Byte *)jcr->compress_buf, &compress_len,
(const Byte *)wbuf, (uLong)wsize)) != Z_OK) {
- Jmsg(jcr, M_ERROR, 0, _("Uncompression error on file %s. ERR=%s\n"),
+ Jmsg(jcr, M_ERROR, 0, _("Uncompression error on file %s. ERR=%s\n"),
attr->ofname, zlib_strerror(stat));
extract = false;
bclose(&bfd);
continue;
}
- Dmsg2(100, "Write uncompressed %d bytes, total before write=%d\n", compress_len, total);
+ Dmsg2(100, "Write uncompressed %d bytes, total before write=%d\n", compress_len, total);
if ((uLong)bwrite(&bfd, jcr->compress_buf, compress_len) != compress_len) {
- Dmsg0(0, "===Write error===\n");
+ Dmsg0(0, "===Write error===\n");
berrno be;
be.set_errno(bfd.berrno);
- Jmsg2(jcr, M_ERROR, 0, _("Write error on %s: %s\n"), attr->ofname, be.strerror());
+ Jmsg2(jcr, M_ERROR, 0, _("Write error on %s: %s\n"), attr->ofname, be.strerror());
extract = false;
bclose(&bfd);
if (is_bopen(&rsrc_bfd)) {
}
#else
if (extract) {
- Jmsg(jcr, M_ERROR, 0, _("GZIP data stream found, but GZIP not configured!\n"));
+ Jmsg(jcr, M_ERROR, 0, _("GZIP data stream found, but GZIP not configured!\n"));
extract = false;
bclose(&bfd);
if (is_bopen(&rsrc_bfd)) {
/* Silently ignore if we cannot write - we already reported that */
case STREAM_MACOS_FORK_DATA:
#ifdef HAVE_DARWIN_OS
- if (is_bopen(&rsrc_bfd) && sd->msglen) {
- Dmsg2(30, "Write %u bytes, total before write=%u\n", sd->msglen, total);
- if (bwrite(&rsrc_bfd, sd->msg, sd->msglen) != sd->msglen) {
- Dmsg0(0, "===Write error===\n");
- berrno be;
- be.set_errno(rsrc_bfd.berrno);
- Jmsg2(jcr, M_ERROR, 0, _("Write error on resource fork of %s: ERR=%s\n"), jcr->last_fname,
- be.strerror());
- extract = false;
+ if (is_bopen(&rsrc_bfd) && sd->msglen) {
+ Dmsg2(30, "Write %u bytes, total before write=%u\n", sd->msglen, total);
+ if (bwrite(&rsrc_bfd, sd->msg, sd->msglen) != sd->msglen) {
+ Dmsg0(0, "===Write error===\n");
+ berrno be;
+ be.set_errno(rsrc_bfd.berrno);
+ Jmsg2(jcr, M_ERROR, 0, _("Write error on resource fork of %s: ERR=%s\n"), jcr->last_fname,
+ be.strerror());
+ extract = false;
if (is_bopen(&bfd)) {
bclose(&bfd);
}
- bclose(&rsrc_bfd);
- continue;
- }
- total += sd->msglen;
- jcr->JobBytes += sd->msglen;
- jcr->ReadBytes += sd->msglen;
- rsrcAddr += sd->msglen;
- }
+ bclose(&rsrc_bfd);
+ continue;
+ }
+ total += sd->msglen;
+ jcr->JobBytes += sd->msglen;
+ jcr->ReadBytes += sd->msglen;
+ rsrcAddr += sd->msglen;
+ }
break;
#else
- non_support_rsrc++;
+ non_support_rsrc++;
#endif
case STREAM_HFSPLUS_ATTRIBUTES:
#ifdef HAVE_DARWIN_OS
- Dmsg0(30, "Restoring Finder Info");
- if (sd->msglen != 32) {
- Jmsg(jcr, M_ERROR, 0, _(" Invalid length of Finder Info (got %d, not 32)"), sd->msglen);
- continue;
- }
- if (setattrlist(jcr->last_fname, &attrList, sd->msg, sd->msglen, 0) != 0) {
- Jmsg(jcr, M_ERROR, 0, _(" Could not set Finder Info on %s"), jcr->last_fname);
- continue;
- }
- break;
+ Dmsg0(30, "Restoring Finder Info");
+ if (sd->msglen != 32) {
+ Jmsg(jcr, M_ERROR, 0, _(" Invalid length of Finder Info (got %d, not 32)"), sd->msglen);
+ continue;
+ }
+ if (setattrlist(jcr->last_fname, &attrList, sd->msg, sd->msglen, 0) != 0) {
+ Jmsg(jcr, M_ERROR, 0, _(" Could not set Finder Info on %s"), jcr->last_fname);
+ continue;
+ }
+ break;
#else
- non_support_finfo++;
+ non_support_finfo++;
#endif
/*** FIXME ***/
-case STREAM_UNIX_ATTRIBUTES_ACCESS_ACL:
+case STREAM_UNIX_ATTRIBUTES_ACCESS_ACL:
#ifdef HAVE_ACL
/* Recover Acess ACL from stream and check it */
acl = acl_from_text(sd->msg);
if (acl_valid(acl) != 0) {
- Jmsg1(jcr, M_WARNING, 0, "Failure in the ACL of %s! FD is not able to restore it!\n", jcr->last_fname);
+ Jmsg1(jcr, M_WARNING, 0, "Failure in the ACL of %s! FD is not able to restore it!\n", jcr->last_fname);
acl_free(acl);
}
-
+
/* Try to restore ACL */
if (attr->type == FT_DIREND) {
/* Directory */
if (acl_set_file(jcr->last_fname, ACL_TYPE_ACCESS, acl) != 0) {
- Jmsg1(jcr, M_WARNING, 0, "Error! Can't restore ACL of directory: %s! Maybe system does not support ACLs!\n", jcr->last_fname);
+ Jmsg1(jcr, M_WARNING, 0, "Error! Can't restore ACL of directory: %s! Maybe system does not support ACLs!\n", jcr->last_fname);
}
/* File or Link */
} else if (acl_set_file(jcr->last_fname, ACL_TYPE_ACCESS, acl) != 0) {
- Jmsg1(jcr, M_WARNING, 0, "Error! Can't restore ACL of file: %s! Maybe system does not support ACLs!\n", jcr->last_fname);
+ Jmsg1(jcr, M_WARNING, 0, "Error! Can't restore ACL of file: %s! Maybe system does not support ACLs!\n", jcr->last_fname);
}
acl_free(acl);
- Dmsg1(200, "ACL of file: %s successfully restored!", jcr->last_fname);
+ Dmsg1(200, "ACL of file: %s successfully restored!", jcr->last_fname);
break;
-#else
+#else
non_support_acl++;
break; /* unconfigured, ignore */
#endif
/* Recover Default ACL from stream and check it */
acl = acl_from_text(sd->msg);
if (acl_valid(acl) != 0) {
- Jmsg1(jcr, M_WARNING, 0, "Failure in the Default ACL of %s! FD is not able to restore it!\n", jcr->last_fname);
+ Jmsg1(jcr, M_WARNING, 0, "Failure in the Default ACL of %s! FD is not able to restore it!\n", jcr->last_fname);
acl_free(acl);
}
-
+
/* Try to restore ACL */
if (attr->type == FT_DIREND) {
/* Directory */
if (acl_set_file(jcr->last_fname, ACL_TYPE_DEFAULT, acl) != 0) {
- Jmsg1(jcr, M_WARNING, 0, "Error! Can't restore Default ACL of directory: %s! Maybe system does not support ACLs!\n", jcr->last_fname);
+ Jmsg1(jcr, M_WARNING, 0, "Error! Can't restore Default ACL of directory: %s! Maybe system does not support ACLs!\n", jcr->last_fname);
}
- }
+ }
acl_free(acl);
- Dmsg1(200, "Default ACL of file: %s successfully restored!", jcr->last_fname);
+ Dmsg1(200, "Default ACL of file: %s successfully restored!", jcr->last_fname);
break;
-#else
+#else
non_support_acl++;
break; /* unconfigured, ignore */
#endif
/*** FIXME ***/
-
+
case STREAM_MD5_SIGNATURE:
case STREAM_SHA1_SIGNATURE:
break;
case STREAM_PROGRAM_NAMES:
case STREAM_PROGRAM_DATA:
if (!prog_name_msg) {
- Pmsg0(000, "Got Program Name or Data Stream. Ignored.\n");
+ Pmsg0(000, "Got Program Name or Data Stream. Ignored.\n");
prog_name_msg++;
}
break;
default:
/* If extracting, wierd stream (not 1 or 2), close output file anyway */
if (extract) {
- Dmsg1(30, "Found wierd stream %d\n", stream);
+ Dmsg1(30, "Found wierd stream %d\n", stream);
if (!is_bopen(&bfd)) {
- Jmsg0(jcr, M_ERROR, 0, _("Logic error output file should be open but is not.\n"));
+ Jmsg0(jcr, M_ERROR, 0, _("Logic error output file should be open but is not.\n"));
}
set_attributes(jcr, attr, &bfd);
extract = false;
}
- Jmsg(jcr, M_ERROR, 0, _("Unknown stream=%d ignored. This shouldn't happen!\n"), stream);
- Dmsg2(0, "None of above!!! stream=%d data=%s\n", stream,sd->msg);
+ Jmsg(jcr, M_ERROR, 0, _("Unknown stream=%d ignored. This shouldn't happen!\n"), stream);
+ Dmsg2(0, "None of above!!! stream=%d data=%s\n", stream,sd->msg);
break;
} /* end switch(stream) */
} /* end while get_msg() */
/* If output file is still open, it was the last one in the
- * archive since we just hit an end of file, so close the file.
+ * archive since we just hit an end of file, so close the file.
*/
if (is_bopen(&bfd)) {
set_attributes(jcr, attr, &bfd);
Jmsg(jcr, M_INFO, 0, _("%d non-supported acl streams ignored.\n"), non_support_acl);
}
-}
+}
#ifdef HAVE_LIBZ
/*
/*
* General status generator
*/
-static void do_status(void sendit(const char *msg, int len, void *sarg), void *arg)
+static void do_status(void sendit(const char *msg, int len, void *sarg), void *arg)
{
int sec, bps;
char *msg, b1[32], b2[32], b3[32], b4[32];
HOST_OS, DISTNAME, DISTVER);
sendit(msg, len, arg);
bstrftime_nc(dt, sizeof(dt), daemon_start_time);
- len = Mmsg(msg, _("Daemon started %s, %d Job%s run since started.\n"),
- dt, num_jobs_run, num_jobs_run == 1 ? "" : "s");
+ len = Mmsg(msg, _("Daemon started %s, %d Job%s run since started.\n"),
+ dt, num_jobs_run, num_jobs_run == 1 ? "" : "s");
sendit(msg, len, arg);
#if defined(HAVE_CYGWIN) || defined(HAVE_WIN32)
if (debug_level > 0) {
if (!privs) {
privs = enable_backup_privileges(NULL, 1);
}
- len = Mmsg(msg,
- _(" Priv 0x%x APIs=%sOPT,%sATP,%sLPV,%sGFAE,%sBR,%sBW,%sSPSP\n"), privs,
- p_OpenProcessToken?"":"!",
- p_AdjustTokenPrivileges?"":"!",
- p_LookupPrivilegeValue?"":"!",
- p_GetFileAttributesEx?"":"!",
- p_BackupRead?"":"!",
- p_BackupWrite?"":"!",
- p_SetProcessShutdownParameters?"":"!");
+ len = Mmsg(msg,
+ _(" Priv 0x%x APIs=%sOPT,%sATP,%sLPV,%sGFAE,%sBR,%sBW,%sSPSP\n"), privs,
+ p_OpenProcessToken?"":"!",
+ p_AdjustTokenPrivileges?"":"!",
+ p_LookupPrivilegeValue?"":"!",
+ p_GetFileAttributesEx?"":"!",
+ p_BackupRead?"":"!",
+ p_BackupWrite?"":"!",
+ p_SetProcessShutdownParameters?"":"!");
sendit(msg, len, arg);
}
#endif
edit_uint64_with_commas(sm_buffers, b3),
edit_uint64_with_commas(sm_max_buffers, b4));
sendit(msg, len, arg);
- len = Mmsg(msg, _(" Sizeof: off_t=%d size_t=%d debug=%d trace=%d\n"),
+ len = Mmsg(msg, _(" Sizeof: off_t=%d size_t=%d debug=%d trace=%d\n"),
sizeof(off_t), sizeof(size_t), debug_level, get_trace());
sendit(msg, len, arg);
}
list_terminated_jobs(sendit, arg);
/*
- * List running jobs
+ * List running jobs
*/
Dmsg0(1000, "Begin status jcr loop.\n");
len = Mmsg(msg, _("Running Jobs:\n"));
foreach_jcr(njcr) {
bstrftime_nc(dt, sizeof(dt), njcr->start_time);
if (njcr->JobId == 0) {
- len = Mmsg(msg, _("Director connected at: %s\n"), dt);
+ len = Mmsg(msg, _("Director connected at: %s\n"), dt);
} else {
- len = Mmsg(msg, _("JobId %d Job %s is running.\n"),
+ len = Mmsg(msg, _("JobId %d Job %s is running.\n"),
njcr->JobId, njcr->Job);
sendit(msg, len, arg);
- len = Mmsg(msg, _(" %s Job started: %s\n"),
+ len = Mmsg(msg, _(" %s Job started: %s\n"),
job_type_to_str(njcr->JobType), dt);
}
sendit(msg, len, arg);
sec = 1;
}
bps = (int)(njcr->JobBytes / sec);
- len = Mmsg(msg, _(" Files=%s Bytes=%s Bytes/sec=%s\n"),
+ len = Mmsg(msg, _(" Files=%s Bytes=%s Bytes/sec=%s\n"),
edit_uint64_with_commas(njcr->JobFiles, b1),
edit_uint64_with_commas(njcr->JobBytes, b2),
edit_uint64_with_commas(bps, b3));
sendit(msg, len, arg);
- len = Mmsg(msg, _(" Files Examined=%s\n"),
+ len = Mmsg(msg, _(" Files Examined=%s\n"),
edit_uint64_with_commas(njcr->num_files_examined, b1));
sendit(msg, len, arg);
if (njcr->JobFiles > 0) {
P(njcr->mutex);
- len = Mmsg(msg, _(" Processing file: %s\n"), njcr->last_fname);
+ len = Mmsg(msg, _(" Processing file: %s\n"), njcr->last_fname);
V(njcr->mutex);
sendit(msg, len, arg);
}
found = 1;
if (njcr->store_bsock) {
- len = Mmsg(msg, " SDReadSeqNo=%" lld " fd=%d\n",
+ len = Mmsg(msg, " SDReadSeqNo=%" lld " fd=%d\n",
njcr->store_bsock->read_seqno, njcr->store_bsock->fd);
sendit(msg, len, arg);
} else {
- len = Mmsg(msg, _(" SDSocket closed.\n"));
+ len = Mmsg(msg, _(" SDSocket closed.\n"));
sendit(msg, len, arg);
}
free_locked_jcr(njcr);
free_pool_memory(msg);
}
-static void list_terminated_jobs(void sendit(const char *msg, int len, void *sarg), void *arg)
+static void list_terminated_jobs(void sendit(const char *msg, int len, void *sarg), void *arg)
{
char dt[MAX_TIME_LENGTH], b1[30], b2[30];
char level[10];
const char *msg;
if (last_jobs->size() == 0) {
- msg = _("No Terminated Jobs.\n");
+ msg = _("No Terminated Jobs.\n");
sendit(msg, strlen(msg), arg);
return;
}
lock_last_jobs_list();
sendit("\n", 1, arg); /* send separately */
- msg = _("Terminated Jobs:\n");
+ msg = _("Terminated Jobs:\n");
sendit(msg, strlen(msg), arg);
msg = _(" JobId Level Files Bytes Status Finished Name \n");
sendit(msg, strlen(msg), arg);
- msg = _("======================================================================\n");
+ msg = _("======================================================================\n");
sendit(msg, strlen(msg), arg);
foreach_dlist(je, last_jobs) {
char JobName[MAX_NAME_LENGTH];
switch (je->JobType) {
case JT_ADMIN:
case JT_RESTORE:
- bstrncpy(level, " ", sizeof(level));
+ bstrncpy(level, " ", sizeof(level));
break;
default:
bstrncpy(level, level_to_str(je->JobLevel), sizeof(level));
}
switch (je->JobStatus) {
case JS_Created:
- termstat = "Created";
+ termstat = "Created";
break;
case JS_FatalError:
case JS_ErrorTerminated:
- termstat = "Error";
+ termstat = "Error";
break;
case JS_Differences:
- termstat = "Diffs";
+ termstat = "Diffs";
break;
case JS_Canceled:
- termstat = "Cancel";
+ termstat = "Cancel";
break;
case JS_Terminated:
- termstat = "OK";
+ termstat = "OK";
break;
default:
- termstat = "Other";
+ termstat = "Other";
break;
}
bstrncpy(JobName, je->Job, sizeof(JobName));
/* There are three periods after the Job name */
char *p;
for (int i=0; i<3; i++) {
- if ((p=strrchr(JobName, '.')) != NULL) {
+ if ((p=strrchr(JobName, '.')) != NULL) {
*p = 0;
}
}
- bsnprintf(buf, sizeof(buf), _("%6d %-6s %8s %14s %-7s %-8s %s\n"),
+ bsnprintf(buf, sizeof(buf), _("%6d %-6s %8s %14s %-7s %-8s %s\n"),
je->JobId,
- level,
+ level,
edit_uint64_with_commas(je->JobFiles, b1),
- edit_uint64_with_commas(je->JobBytes, b2),
+ edit_uint64_with_commas(je->JobBytes, b2),
termstat,
dt, JobName);
sendit(buf, strlen(buf), arg);
user->msglen = len+1;
bnet_send(user);
}
-
+
/*
* Status command from Director
*/
s_last_job* job;
time = get_memory(dir->msglen+1);
-
+
if (sscanf(dir->msg, qstatus, time) != 1) {
pm_strcpy(&jcr->errmsg, dir->msg);
Jmsg1(jcr, M_FATAL, 0, _("Bad .status command: %s\n"), jcr->errmsg);
return 0;
}
unbash_spaces(time);
-
+
if (strcmp(time, "current") == 0) {
bnet_fsend(dir, OKqstatus, time);
lock_jcr_chain();
free_memory(time);
return 0;
}
-
+
bnet_sig(dir, BNET_EOD);
free_memory(time);
return 1;
/*
* Convert Job Level into a string
*/
-static const char *level_to_str(int level)
+static const char *level_to_str(int level)
{
const char *str;
struct s_win32_arg *arg = (struct s_win32_arg *)marg;
if (len > 0 && msg[len-1] == '\n') {
- // when compiling with visual studio some strings are read-only
+ // when compiling with visual studio some strings are read-only
// and cause access violations. So we creat a tmp copy.
char *_msg = (char *)alloca(len);
bstrncpy(_msg, msg, len);
msg = _msg;
}
SendDlgItemMessage(arg->hwnd, arg->idlist, LB_ADDSTRING, 0, (LONG)msg);
-
+
}
void FillStatusBox(HWND hwnd, int idlist)
foreach_jcr(njcr) {
if (njcr->JobId != 0) {
stat = JS_Running;
- termstat = _("Bacula Running");
+ termstat = _("Bacula Running");
free_locked_jcr(njcr);
break;
}
stat = job->JobStatus;
switch (job->JobStatus) {
case JS_Canceled:
- termstat = _("Last Job Canceled");
+ termstat = _("Last Job Canceled");
break;
case JS_ErrorTerminated:
- case JS_FatalError:
- termstat = _("Last Job Failed");
+ case JS_FatalError:
+ termstat = _("Last Job Failed");
break;
default:
if (job->Errors) {
- termstat = _("Last Job had Warnings");
+ termstat = _("Last Job had Warnings");
}
break;
}
static int verify_file(FF_PKT *ff_pkt, void *my_pkt);
static int read_chksum(BFILE *bfd, CHKSUM *chksum, JCR *jcr, char *fname);
-/*
+/*
* Find all the requested files and send attributes
* to the Director.
- *
+ *
*/
void do_verify(JCR *jcr)
{
set_jcr_job_status(jcr, JS_Running);
jcr->buf_size = DEFAULT_NETWORK_BUFFER_SIZE;
if ((jcr->big_buf = (char *) malloc(jcr->buf_size)) == NULL) {
- Jmsg1(jcr, M_ABORT, 0, _("Cannot malloc %d network read buffer\n"),
+ Jmsg1(jcr, M_ABORT, 0, _("Cannot malloc %d network read buffer\n"),
DEFAULT_NETWORK_BUFFER_SIZE);
}
set_find_options((FF_PKT *)jcr->ff, jcr->incremental, jcr->mtime);
Dmsg0(10, "Start find files\n");
/* Subroutine verify_file() is called for each file */
- find_files(jcr, (FF_PKT *)jcr->ff, verify_file, (void *)jcr);
+ find_files(jcr, (FF_PKT *)jcr->ff, verify_file, (void *)jcr);
Dmsg0(10, "End find files\n");
if (jcr->big_buf) {
jcr->big_buf = NULL;
}
set_jcr_job_status(jcr, JS_Terminated);
-}
+}
-/*
+/*
* Called here by find() for each file.
*
* Find the file, compute the MD5 or SHA1 and send it back to the Director
*/
-static int verify_file(FF_PKT *ff_pkt, void *pkt)
+static int verify_file(FF_PKT *ff_pkt, void *pkt)
{
char attribs[MAXSTRING];
char attribsEx[MAXSTRING];
if (job_canceled(jcr)) {
return 0;
}
-
+
dir = jcr->dir_bsock;
jcr->num_files_examined++; /* bump total file count */
pm_strcpy(jcr->last_fname, ff_pkt->fname);
V(jcr->mutex);
- /*
+ /*
* Send file attributes to Director
* File_index
* Stream
Dmsg2(400, "send ATTR inx=%d fname=%s\n", jcr->JobFiles, ff_pkt->fname);
if (ff_pkt->type == FT_LNK || ff_pkt->type == FT_LNKSAVED) {
stat = bnet_fsend(dir, "%d %d %s %s%c%s%c%s%c", jcr->JobFiles,
- STREAM_UNIX_ATTRIBUTES, ff_pkt->VerifyOpts, ff_pkt->fname,
+ STREAM_UNIX_ATTRIBUTES, ff_pkt->VerifyOpts, ff_pkt->fname,
0, attribs, 0, ff_pkt->link, 0);
} else if (ff_pkt->type == FT_DIREND) {
/* Here link is the canonical filename (i.e. with trailing slash) */
- stat = bnet_fsend(dir,"%d %d %s %s%c%s%c%c", jcr->JobFiles,
- STREAM_UNIX_ATTRIBUTES, ff_pkt->VerifyOpts, ff_pkt->link,
+ stat = bnet_fsend(dir,"%d %d %s %s%c%s%c%c", jcr->JobFiles,
+ STREAM_UNIX_ATTRIBUTES, ff_pkt->VerifyOpts, ff_pkt->link,
0, attribs, 0, 0);
} else {
stat = bnet_fsend(dir,"%d %d %s %s%c%s%c%c", jcr->JobFiles,
- STREAM_UNIX_ATTRIBUTES, ff_pkt->VerifyOpts, ff_pkt->fname,
+ STREAM_UNIX_ATTRIBUTES, ff_pkt->VerifyOpts, ff_pkt->fname,
0, attribs, 0, 0);
}
Dmsg2(20, "bfiled>bdird: attribs len=%d: msg=%s\n", dir->msglen, dir->msg);
* The remainder of the function is all about getting the checksum.
* First we initialise, then we read files, other streams and Finder Info.
*/
- if (ff_pkt->type != FT_LNKSAVED && (S_ISREG(ff_pkt->statp.st_mode) &&
+ if (ff_pkt->type != FT_LNKSAVED && (S_ISREG(ff_pkt->statp.st_mode) &&
ff_pkt->flags & (FO_MD5|FO_SHA1))) {
chksum_init(&chksum, ff_pkt->flags);
binit(&bfd);
ff_pkt->ff_errno = errno;
berrno be;
be.set_errno(bfd.berrno);
- Jmsg(jcr, M_NOTSAVED, 1, _(" Cannot open %s: ERR=%s.\n"),
+ Jmsg(jcr, M_NOTSAVED, 1, _(" Cannot open %s: ERR=%s.\n"),
ff_pkt->fname, be.strerror());
jcr->Errors++;
return 1;
if (bopen_rsrc(&bfd, ff_pkt->fname, O_RDONLY | O_BINARY, 0) < 0) {
ff_pkt->ff_errno = errno;
berrno be;
- Jmsg(jcr, M_NOTSAVED, -1, _(" Cannot open resource fork for %s: ERR=%s\n"),
+ Jmsg(jcr, M_NOTSAVED, -1, _(" Cannot open resource fork for %s: ERR=%s\n"),
ff_pkt->fname, be.strerror());
jcr->Errors++;
if (is_bopen(&ff_pkt->bfd)) {
stream = STREAM_SHA1_SIGNATURE;
}
bin_to_base64(chksumbuf, (char *)chksum.signature, chksum.length);
- Dmsg3(400, "send inx=%d %s=%s\n", jcr->JobFiles, chksum.name, chksumbuf);
- bnet_fsend(dir, "%d %d %s *%s-%d*", jcr->JobFiles, stream, chksumbuf,
+ Dmsg3(400, "send inx=%d %s=%s\n", jcr->JobFiles, chksum.name, chksumbuf);
+ bnet_fsend(dir, "%d %d %s *%s-%d*", jcr->JobFiles, stream, chksumbuf,
chksum.name, jcr->JobFiles);
- Dmsg3(20, "bfiled>bdird: %s len=%d: msg=%s\n", chksum.name,
+ Dmsg3(20, "bfiled>bdird: %s len=%d: msg=%s\n", chksum.name,
dir->msglen, dir->msg);
}
}
if (n < 0) {
berrno be;
be.set_errno(bfd->berrno);
- Jmsg(jcr, M_ERROR, 1, _("Error reading file %s: ERR=%s\n"),
+ Jmsg(jcr, M_ERROR, 1, _("Error reading file %s: ERR=%s\n"),
fname, be.strerror());
jcr->Errors++;
return -1;
/* Forward referenced functions */
-/*
+/*
* Verify attributes of the requested files on the Volume
- *
+ *
*/
void do_verify_volume(JCR *jcr)
{
uint32_t VolSessionId, VolSessionTime, file_index;
uint32_t record_file_index;
int type, stat;
-
+
sd = jcr->store_bsock;
if (!sd) {
Jmsg(jcr, M_FATAL, 0, _("Storage command not issued before Verify.\n"));
fname = get_pool_memory(PM_FNAME);
lname = get_pool_memory(PM_FNAME);
- /*
+ /*
* Get a record from the Storage daemon
*/
while (bget_msg(sd) >= 0 && !job_canceled(jcr)) {
/*
- * First we expect a Stream Record Header
+ * First we expect a Stream Record Header
*/
if (sscanf(sd->msg, rec_header, &VolSessionId, &VolSessionTime, &file_index,
&stream, &size) != 5) {
- Jmsg1(jcr, M_FATAL, 0, _("Record header scan error: %s\n"), sd->msg);
+ Jmsg1(jcr, M_FATAL, 0, _("Record header scan error: %s\n"), sd->msg);
goto bail_out;
}
Dmsg2(30, "Got hdr: FilInx=%d Stream=%d.\n", file_index, stream);
- /*
+ /*
* Now we expect the Stream Data
*/
if (bget_msg(sd) < 0) {
- Jmsg1(jcr, M_FATAL, 0, _("Data record error. ERR=%s\n"), bnet_strerror(sd));
+ Jmsg1(jcr, M_FATAL, 0, _("Data record error. ERR=%s\n"), bnet_strerror(sd));
goto bail_out;
}
if (size != ((uint32_t)sd->msglen)) {
- Jmsg2(jcr, M_FATAL, 0, _("Actual data size %d not same as header %d\n"), sd->msglen, size);
+ Jmsg2(jcr, M_FATAL, 0, _("Actual data size %d not same as header %d\n"), sd->msglen, size);
goto bail_out;
}
Dmsg1(30, "Got stream data, len=%d\n", sd->msglen);
case STREAM_UNIX_ATTRIBUTES_EX:
char *ap, *lp, *fp;
- Dmsg0(400, "Stream=Unix Attributes.\n");
+ Dmsg0(400, "Stream=Unix Attributes.\n");
if ((int)sizeof_pool_memory(fname) < sd->msglen) {
fname = realloc_pool_memory(fname, sd->msglen + 1);
*fname = 0;
*lname = 0;
- /*
+ /*
* An Attributes record consists of:
* File_index
* Type (FT_types)
* Link name (if file linked i.e. FT_LNK)
* Extended Attributes (if Win32)
*/
- if (sscanf(sd->msg, "%d %d", &record_file_index, &type) != 2) {
- Jmsg(jcr, M_FATAL, 0, _("Error scanning record header: %s\n"), sd->msg);
- Dmsg0(0, "\nError scanning header\n");
+ if (sscanf(sd->msg, "%d %d", &record_file_index, &type) != 2) {
+ Jmsg(jcr, M_FATAL, 0, _("Error scanning record header: %s\n"), sd->msg);
+ Dmsg0(0, "\nError scanning header\n");
goto bail_out;
}
- Dmsg2(30, "Got Attr: FilInx=%d type=%d\n", record_file_index, type);
+ Dmsg2(30, "Got Attr: FilInx=%d type=%d\n", record_file_index, type);
if (record_file_index != file_index) {
- Jmsg(jcr, M_FATAL, 0, _("Record header file index %ld not equal record index %ld\n"),
+ Jmsg(jcr, M_FATAL, 0, _("Record header file index %ld not equal record index %ld\n"),
file_index, record_file_index);
- Dmsg0(0, "File index error\n");
+ Dmsg0(0, "File index error\n");
goto bail_out;
}
ap = sd->msg;
- while (*ap++ != ' ') /* skip record file index */
+ while (*ap++ != ' ') /* skip record file index */
;
- while (*ap++ != ' ') /* skip type */
+ while (*ap++ != ' ') /* skip type */
;
/* Save filename and position to attributes */
- fp = fname;
+ fp = fname;
while (*ap != 0) {
*fp++ = *ap++; /* copy filename to fname */
}
*fp = *ap++; /* terminate filename & point to attribs */
- Dmsg1(200, "Attr=%s\n", ap);
+ Dmsg1(200, "Attr=%s\n", ap);
/* Skip to Link name */
if (type == FT_LNK || type == FT_LNKSAVED) {
lp = ap;
while (*lp++ != 0) {
;
}
- strcat(lname, lp); /* "save" link name */
+ strcat(lname, lp); /* "save" link name */
} else {
*lname = 0;
}
pm_strcpy(&jcr->last_fname, fname); /* last file examined */
V(jcr->mutex);
- /*
+ /*
* Send file attributes to Director
* File_index
* Stream
* slash. For a linked file, link is the link.
*/
/* Send file attributes to Director */
- Dmsg2(200, "send ATTR inx=%d fname=%s\n", jcr->JobFiles, fname);
+ Dmsg2(200, "send ATTR inx=%d fname=%s\n", jcr->JobFiles, fname);
if (type == FT_LNK || type == FT_LNKSAVED) {
- stat = bnet_fsend(dir, "%d %d %s %s%c%s%c%s%c", jcr->JobFiles,
- STREAM_UNIX_ATTRIBUTES, "pinsug5", fname,
+ stat = bnet_fsend(dir, "%d %d %s %s%c%s%c%s%c", jcr->JobFiles,
+ STREAM_UNIX_ATTRIBUTES, "pinsug5", fname,
0, ap, 0, lname, 0);
} else {
- stat = bnet_fsend(dir,"%d %d %s %s%c%s%c%c", jcr->JobFiles,
- STREAM_UNIX_ATTRIBUTES, "pinsug5", fname,
+ stat = bnet_fsend(dir,"%d %d %s %s%c%s%c%c", jcr->JobFiles,
+ STREAM_UNIX_ATTRIBUTES, "pinsug5", fname,
0, ap, 0, 0);
}
- Dmsg2(200, "bfiled>bdird: attribs len=%d: msg=%s\n", dir->msglen, dir->msg);
+ Dmsg2(200, "bfiled>bdird: attribs len=%d: msg=%s\n", dir->msglen, dir->msg);
if (!stat) {
- Jmsg(jcr, M_FATAL, 0, _("Network error in send to Director: ERR=%s\n"), bnet_strerror(dir));
+ Jmsg(jcr, M_FATAL, 0, _("Network error in send to Director: ERR=%s\n"), bnet_strerror(dir));
goto bail_out;
}
break;
case STREAM_MD5_SIGNATURE:
char MD5buf[30];
bin_to_base64(MD5buf, (char *)sd->msg, 16); /* encode 16 bytes */
- Dmsg2(400, "send inx=%d MD5=%s\n", jcr->JobFiles, MD5buf);
- bnet_fsend(dir, "%d %d %s *MD5-%d*", jcr->JobFiles, STREAM_MD5_SIGNATURE, MD5buf,
+ Dmsg2(400, "send inx=%d MD5=%s\n", jcr->JobFiles, MD5buf);
+ bnet_fsend(dir, "%d %d %s *MD5-%d*", jcr->JobFiles, STREAM_MD5_SIGNATURE, MD5buf,
jcr->JobFiles);
- Dmsg2(20, "bfiled>bdird: MD5 len=%d: msg=%s\n", dir->msglen, dir->msg);
+ Dmsg2(20, "bfiled>bdird: MD5 len=%d: msg=%s\n", dir->msglen, dir->msg);
break;
-
+
case STREAM_SHA1_SIGNATURE:
char SHA1buf[30];
bin_to_base64(SHA1buf, (char *)sd->msg, 20); /* encode 20 bytes */
- Dmsg2(400, "send inx=%d SHA1=%s\n", jcr->JobFiles, SHA1buf);
- bnet_fsend(dir, "%d %d %s *SHA1-%d*", jcr->JobFiles, STREAM_SHA1_SIGNATURE,
+ Dmsg2(400, "send inx=%d SHA1=%s\n", jcr->JobFiles, SHA1buf);
+ bnet_fsend(dir, "%d %d %s *SHA1-%d*", jcr->JobFiles, STREAM_SHA1_SIGNATURE,
SHA1buf, jcr->JobFiles);
- Dmsg2(20, "bfiled>bdird: SHA1 len=%d: msg=%s\n", dir->msglen, dir->msg);
+ Dmsg2(20, "bfiled>bdird: SHA1 len=%d: msg=%s\n", dir->msglen, dir->msg);
break;
default:
- Pmsg2(0, "None of above!!! stream=%d data=%s\n", stream,sd->msg);
+ Pmsg2(0, "None of above!!! stream=%d data=%s\n", stream,sd->msg);
break;
} /* end switch */
} /* end while bnet_get */
free_pool_memory(lname);
Dmsg2(050, "End Verify-Vol. Files=%d Bytes=%" lld "\n", jcr->JobFiles,
jcr->JobBytes);
-}
+}
-/*
+/*
* Dumb Windows program to put up a message box
* containing the command line. Any leading and
* trailing quotes are stripped.
- *
+ *
* Kern E. Sibbald
- * July MM
+ * July MM
*/
#include "windows.h"
-int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
+int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
int len = strlen(szCmdLine);
MA 02111-1307, USA.
This file was inspired by the VNC Win32 code by ATT
-
+
Kern E. Sibbald, 2000
*/
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
// USA.
//
-// If the source code for the ups system is not available from the place
+// If the source code for the ups system is not available from the place
// whence you received this file, check http://www.uk.research.att.com/vnc or contact
// the authors on ups@uk.research.att.com for information on obtaining it.
//
class bacService
{
public:
- bacService();
+ bacService();
// SERVICE INSTALL & START FUNCTIONS
class bacStatus;
-#ifndef _WINSTAT_H_
+#ifndef _WINSTAT_H_
#define _WINSTAT_H_
class bacStatus
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
// USA.
//
-// If the source code for the VNC system is not available from the place
+// If the source code for the VNC system is not available from the place
// whence you received this file, check http://www.uk.research.att.com/vnc or contact
// the authors on vnc@uk.research.att.com for information on obtaining it.
//
/*=============================================================*/
/*
- * Return the data stream that will be used
+ * Return the data stream that will be used
*/
int select_data_stream(FF_PKT *ff_pkt)
{
}
-/*
- * Encode a stat structure into a base64 character string
+/*
+ * Encode a stat structure into a base64 character string
* All systems must create such a structure.
* In addition, we tack on the LinkFI, which is non-zero in
* the case of a hard linked file that has no data. This
/* Decode a stat packet from base64 characters */
-int decode_stat(char *buf, struct stat *statp, int32_t *LinkFI)
+int decode_stat(char *buf, struct stat *statp, int32_t *LinkFI)
{
char *p = buf;
int64_t val;
statp->st_flags = 0;
#endif
}
-
+
/* Look for data stream id */
if (*p == ' ' || (*p != 0 && *(p+1) == ' ')) {
p++;
/*
* Set file modes, permissions and times
*
- * fname is the original filename
+ * fname is the original filename
* ofile is the output filename (may be in a different directory)
*
* Returns: true on success
*/
bool set_attributes(JCR *jcr, ATTR *attr, BFILE *ofd)
{
- struct utimbuf ut;
+ struct utimbuf ut;
mode_t old_mask;
bool ok = true;
off_t fsize;
if (attr->stream == STREAM_UNIX_ATTRIBUTES_EX &&
set_win32_attributes(jcr, attr, ofd)) {
if (is_bopen(ofd)) {
- bclose(ofd);
+ bclose(ofd);
}
pm_strcpy(attr->ofname, "*none*");
return true;
if (attr->data_stream == STREAM_WIN32_DATA ||
attr->data_stream == STREAM_WIN32_GZIP_DATA) {
if (is_bopen(ofd)) {
- bclose(ofd);
+ bclose(ofd);
}
pm_strcpy(attr->ofname, "*none*");
return true;
/*
* If Windows stuff failed, e.g. attempt to restore Unix file
- * to Windows, simply fall through and we will do it the
+ * to Windows, simply fall through and we will do it the
* universal way.
*/
#endif
fsize = blseek(ofd, 0, SEEK_CUR);
bclose(ofd); /* first close file */
if (fsize > 0 && fsize != attr->statp.st_size) {
- Jmsg3(jcr, M_ERROR, 0, _("File size of restored file %s not correct. Original %s, restored %s.\n"),
+ Jmsg3(jcr, M_ERROR, 0, _("File size of restored file %s not correct. Original %s, restored %s.\n"),
attr->ofname, edit_uint64(attr->statp.st_size, ec1),
edit_uint64(fsize, ec2));
}
ut.modtime = attr->statp.st_mtime;
/* ***FIXME**** optimize -- don't do if already correct */
- /*
+ /*
* For link, change owner of link using lchown, but don't
* try to do a chmod as that will update the file behind it.
*/
/* Change owner of link, not of real file */
if (lchown(attr->ofname, attr->statp.st_uid, attr->statp.st_gid) < 0) {
berrno be;
- Jmsg2(jcr, M_ERROR, 0, _("Unable to set file owner %s: ERR=%s\n"),
+ Jmsg2(jcr, M_ERROR, 0, _("Unable to set file owner %s: ERR=%s\n"),
attr->ofname, be.strerror());
ok = false;
}
} else {
if (chown(attr->ofname, attr->statp.st_uid, attr->statp.st_gid) < 0) {
berrno be;
- Jmsg2(jcr, M_ERROR, 0, _("Unable to set file owner %s: ERR=%s\n"),
+ Jmsg2(jcr, M_ERROR, 0, _("Unable to set file owner %s: ERR=%s\n"),
attr->ofname, be.strerror());
ok = false;
}
if (chmod(attr->ofname, attr->statp.st_mode) < 0) {
berrno be;
- Jmsg2(jcr, M_ERROR, 0, _("Unable to set file modes %s: ERR=%s\n"),
+ Jmsg2(jcr, M_ERROR, 0, _("Unable to set file modes %s: ERR=%s\n"),
attr->ofname, be.strerror());
ok = false;
}
*/
if (utime(attr->ofname, &ut) < 0) {
berrno be;
- Jmsg2(jcr, M_ERROR, 0, _("Unable to set file times %s: ERR=%s\n"),
+ Jmsg2(jcr, M_ERROR, 0, _("Unable to set file times %s: ERR=%s\n"),
attr->ofname, be.strerror());
ok = false;
}
*/
if (chflags(attr->ofname, attr->statp.st_flags) < 0) {
berrno be;
- Jmsg2(jcr, M_ERROR, 0, _("Unable to set file flags %s: ERR=%s\n"),
+ Jmsg2(jcr, M_ERROR, 0, _("Unable to set file flags %s: ERR=%s\n"),
attr->ofname, be.strerror());
ok = false;
}
/*=============================================================*/
#if !defined(HAVE_CYGWIN) && !defined(HAVE_WIN32)
-
+
/*
* It is possible to piggyback additional data e.g. ACLs on
* the encode_stat() data by returning the extended attributes
attribsEx[0] = 0; /* no extended attributes */
- if (!p_GetFileAttributesEx) {
+ if (!p_GetFileAttributesEx) {
return STREAM_UNIX_ATTRIBUTES;
}
/* Define attributes that are legal to set with SetFileAttributes() */
#define SET_ATTRS ( \
- FILE_ATTRIBUTE_ARCHIVE| \
- FILE_ATTRIBUTE_HIDDEN| \
- FILE_ATTRIBUTE_NORMAL| \
- FILE_ATTRIBUTE_NOT_CONTENT_INDEXED| \
- FILE_ATTRIBUTE_OFFLINE| \
- FILE_ATTRIBUTE_READONLY| \
- FILE_ATTRIBUTE_SYSTEM| \
+ FILE_ATTRIBUTE_ARCHIVE| \
+ FILE_ATTRIBUTE_HIDDEN| \
+ FILE_ATTRIBUTE_NORMAL| \
+ FILE_ATTRIBUTE_NOT_CONTENT_INDEXED| \
+ FILE_ATTRIBUTE_OFFLINE| \
+ FILE_ATTRIBUTE_READONLY| \
+ FILE_ATTRIBUTE_SYSTEM| \
FILE_ATTRIBUTE_TEMPORARY)
/*
* Set Extended File Attributes for Win32
*
- * fname is the original filename
+ * fname is the original filename
* ofile is the output filename (may be in a different directory)
*
* Returns: true on success
ULARGE_INTEGER li;
POOLMEM *win32_ofile;
- if (!p_GetFileAttributesEx) {
+ if (!p_GetFileAttributesEx) {
return false;
}
li.QuadPart = val;
atts.ftLastWriteTime.dwLowDateTime = li.LowPart;
atts.ftLastWriteTime.dwHighDateTime = li.HighPart;
- p++;
+ p++;
p += from_base64(&val, p);
plug(atts.nFileSizeHigh, val);
p++;
&atts.ftCreationTime,
&atts.ftLastAccessTime,
&atts.ftLastWriteTime)) {
- win_error(jcr, "SetFileTime:", win32_ofile);
+ win_error(jcr, "SetFileTime:", win32_ofile);
}
bclose(ofd);
}
Dmsg1(100, "SetFileAtts %s\n", attr->ofname);
if (!(atts.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
if (!SetFileAttributes(win32_ofile, atts.dwFileAttributes & SET_ATTRS)) {
- win_error(jcr, "SetFileAttributes:", win32_ofile);
+ win_error(jcr, "SetFileAttributes:", win32_ofile);
}
}
free_pool_memory(win32_ofile);
#endif
/* ===============================================================
- *
+ *
* U N I X AND W I N D O W S
*
* ===============================================================
/* ===============================================================
- *
+ *
* W I N D O W S
*
* ===============================================================
* Returns 1 if function worked
* Returns 0 if failed (i.e. do not have Backup API on this machine)
*/
-int set_win32_backup(BFILE *bfd)
+int set_win32_backup(BFILE *bfd)
{
/* We enable if possible here */
bfd->use_backup_api = have_win32_api();
}
/*
- * Return 1 if we are NOT using Win32 BackupWrite()
+ * Return 1 if we are NOT using Win32 BackupWrite()
* return 0 if are
*/
-int is_portable_backup(BFILE *bfd)
+int is_portable_backup(BFILE *bfd)
{
return !bfd->use_backup_api;
}
if (flags & O_CREAT) { /* Create */
if (bfd->use_backup_api) {
- dwaccess = GENERIC_WRITE|FILE_ALL_ACCESS|WRITE_OWNER|WRITE_DAC|ACCESS_SYSTEM_SECURITY;
+ dwaccess = GENERIC_WRITE|FILE_ALL_ACCESS|WRITE_OWNER|WRITE_DAC|ACCESS_SYSTEM_SECURITY;
dwflags = FILE_FLAG_BACKUP_SEMANTICS;
} else {
dwaccess = GENERIC_WRITE;
return bfd->mode == BF_CLOSED ? -1 : 1;
}
-/*
+/*
* Returns 0 on success
* -1 on error
*/
int bclose(BFILE *bfd)
-{
+{
int stat = 0;
if (bfd->errmsg) {
}
if (bfd->use_backup_api && bfd->mode == BF_READ) {
BYTE buf[10];
- if (!bfd->lpContext && !p_BackupRead(bfd->fh,
+ if (!bfd->lpContext && !p_BackupRead(bfd->fh,
buf, /* buffer */
(DWORD)0, /* bytes to read */
&bfd->rw_bytes, /* bytes read */
&bfd->lpContext)) { /* Read context */
errno = b_errno_win32;
stat = -1;
- }
+ }
} else if (bfd->use_backup_api && bfd->mode == BF_WRITE) {
BYTE buf[10];
- if (!bfd->lpContext && !p_BackupWrite(bfd->fh,
+ if (!bfd->lpContext && !p_BackupWrite(bfd->fh,
buf, /* buffer */
(DWORD)0, /* bytes to read */
&bfd->rw_bytes, /* bytes written */
&bfd->lpContext)) { /* Write context */
errno = b_errno_win32;
stat = -1;
- }
+ }
}
if (!CloseHandle(bfd->fh)) {
stat = -1;
#else /* Unix systems */
/* ===============================================================
- *
+ *
* U N I X
*
* ===============================================================
}
int have_win32_api()
-{
+{
return 0; /* no can do */
-}
+}
/*
* Enables using the Backup API (win32_data).
* Returns 1 if function worked
* Returns 0 if failed (i.e. do not have Backup API on this machine)
*/
-int set_win32_backup(BFILE *bfd)
+int set_win32_backup(BFILE *bfd)
{
return 0; /* no can do */
}
* Return 1 if we are writing in portable format
* return 0 if not
*/
-int is_portable_backup(BFILE *bfd)
+int is_portable_backup(BFILE *bfd)
{
return 1; /* portable by definition */
}
ecmd = edit_job_codes(bfd->jcr, ecmd, bfd->prog, fname);
const char *pmode;
if (flags & O_RDONLY) {
- pmode = "r";
+ pmode = "r";
} else {
- pmode = "w";
+ pmode = "w";
}
bfd->bpipe = open_bpipe(ecmd, 0, pmode);
if (bfd->bpipe == NULL) {
#endif
int bclose(BFILE *bfd)
-{
- int stat;
+{
+ int stat;
Dmsg1(400, "Close file %d\n", bfd->fid);
if (bfd->fid == -1) {
return 0;
bfd->bpipe = NULL;
return stat;
}
-
+
/* Close normal file */
stat = close(bfd->fid);
bfd->berrno = errno;
/* =======================================================
*
- * W I N D O W S
+ * W I N D O W S
*
* =======================================================
*/
char *prog; /* reader/writer program if any */
BPIPE *bpipe; /* pipe for reader */
JCR *jcr; /* jcr for editing job codes */
-};
+};
HANDLE bget_handle(BFILE *bfd);
/* =======================================================
*
- * U N I X
+ * U N I X
*
* =======================================================
*/
char *prog; /* reader/writer program if any */
BPIPE *bpipe; /* pipe for reader */
JCR *jcr; /* jcr for editing job codes */
-};
+};
#endif
/*
* Create the file, or the directory
*
- * fname is the original filename
+ * fname is the original filename
* ofile is the output filename (may be in a different directory)
*
* Returns: CF_SKIP if file should be skipped
* CF_ERROR on error
- * CF_EXTRACT file created and data to restore
+ * CF_EXTRACT file created and data to restore
* CF_CREATED file created no data to restore
*
* Note, we create the file here, except for special files,
- * we do not set the attributes because we want to first
+ * we do not set the attributes because we want to first
* write the file, then when the writing is done, set the
* attributes.
- * So, we return with the file descriptor open for normal
+ * So, we return with the file descriptor open for normal
* files.
*
*/
bool exists = false;
struct stat mstatp;
- if (is_win32_stream(attr->data_stream)) {
+ if (is_win32_stream(attr->data_stream)) {
set_win32_backup(bfd);
} else {
set_portable_backup(bfd);
switch (replace) {
case REPLACE_IFNEWER:
if (attr->statp.st_mtime <= mstatp.st_mtime) {
- Jmsg(jcr, M_SKIPPED, 0, _("File skipped. Not newer: %s\n"), attr->ofname);
+ Jmsg(jcr, M_SKIPPED, 0, _("File skipped. Not newer: %s\n"), attr->ofname);
return CF_SKIP;
}
break;
case REPLACE_IFOLDER:
if (attr->statp.st_mtime >= mstatp.st_mtime) {
- Jmsg(jcr, M_SKIPPED, 0, _("File skipped. Not older: %s\n"), attr->ofname);
+ Jmsg(jcr, M_SKIPPED, 0, _("File skipped. Not older: %s\n"), attr->ofname);
return CF_SKIP;
}
break;
case REPLACE_NEVER:
- Jmsg(jcr, M_SKIPPED, 0, _("File skipped. Already exists: %s\n"), attr->ofname);
+ Jmsg(jcr, M_SKIPPED, 0, _("File skipped. Already exists: %s\n"), attr->ofname);
return CF_SKIP;
case REPLACE_ALWAYS:
/* Get rid of old copy */
if (unlink(attr->ofname) == -1) {
berrno be;
- Jmsg(jcr, M_ERROR, 0, _("File %s already exists and could not be replaced. ERR=%s.\n"),
+ Jmsg(jcr, M_ERROR, 0, _("File %s already exists and could not be replaced. ERR=%s.\n"),
attr->ofname, be.strerror());
/* Continue despite error */
}
}
- /*
+ /*
* Here we do some preliminary work for all the above
* types to create the path to the file if it does
* not already exist. Below, we will split to
attr->ofname[pnl] = 0; /* terminate path */
if (!path_already_seen(jcr, attr->ofname, pnl)) {
- Dmsg1(50, "Make path %s\n", attr->ofname);
+ Dmsg1(50, "Make path %s\n", attr->ofname);
/*
* If we need to make the directory, ensure that it is with
* execute bit set (i.e. parent_mode), and preserve what already
* exists. Normally, this should do nothing.
*/
if (make_path(jcr, attr->ofname, parent_mode, parent_mode, uid, gid, 1, NULL) != 0) {
- Dmsg1(10, "Could not make path. %s\n", attr->ofname);
+ Dmsg1(10, "Could not make path. %s\n", attr->ofname);
attr->ofname[pnl] = savechr; /* restore full name */
return CF_ERROR;
}
switch(attr->type) {
case FT_REGE:
case FT_REG:
- Dmsg1(100, "Create file %s\n", attr->ofname);
+ Dmsg1(100, "Create file %s\n", attr->ofname);
mode = O_WRONLY | O_CREAT | O_TRUNC | O_BINARY; /* O_NOFOLLOW; */
if (IS_CTG(attr->statp.st_mode)) {
mode |= O_CTG; /* set contiguous bit if needed */
}
- Dmsg1(50, "Create file: %s\n", attr->ofname);
+ Dmsg1(50, "Create file: %s\n", attr->ofname);
if (is_bopen(bfd)) {
- Jmsg1(jcr, M_ERROR, 0, "bpkt already open fid=%d\n", bfd->fid);
+ Jmsg1(jcr, M_ERROR, 0, "bpkt already open fid=%d\n", bfd->fid);
bclose(bfd);
}
if ((bopen(bfd, attr->ofname, mode, S_IRUSR | S_IWUSR)) < 0) {
berrno be;
be.set_errno(bfd->berrno);
- Jmsg2(jcr, M_ERROR, 0, _("Could not create %s: ERR=%s\n"),
+ Jmsg2(jcr, M_ERROR, 0, _("Could not create %s: ERR=%s\n"),
attr->ofname, be.strerror());
return CF_ERROR;
}
#ifndef HAVE_WIN32 // none of these exists on MS Windows
case FT_RAW: /* Bacula raw device e.g. /dev/sda1 */
case FT_FIFO: /* Bacula fifo to save data */
- case FT_SPEC:
+ case FT_SPEC:
if (S_ISFIFO(attr->statp.st_mode)) {
- Dmsg1(200, "Restore fifo: %s\n", attr->ofname);
+ Dmsg1(200, "Restore fifo: %s\n", attr->ofname);
if (mkfifo(attr->ofname, attr->statp.st_mode) != 0 && errno != EEXIST) {
berrno be;
- Jmsg2(jcr, M_ERROR, 0, _("Cannot make fifo %s: ERR=%s\n"),
+ Jmsg2(jcr, M_ERROR, 0, _("Cannot make fifo %s: ERR=%s\n"),
attr->ofname, be.strerror());
return CF_ERROR;
}
- } else {
- Dmsg1(200, "Restore node: %s\n", attr->ofname);
+ } else {
+ Dmsg1(200, "Restore node: %s\n", attr->ofname);
if (mknod(attr->ofname, attr->statp.st_mode, attr->statp.st_rdev) != 0 && errno != EEXIST) {
berrno be;
- Jmsg2(jcr, M_ERROR, 0, _("Cannot make node %s: ERR=%s\n"),
+ Jmsg2(jcr, M_ERROR, 0, _("Cannot make node %s: ERR=%s\n"),
attr->ofname, be.strerror());
return CF_ERROR;
}
- }
+ }
if (attr->type == FT_RAW || attr->type == FT_FIFO) {
btimer_t *tid;
- Dmsg1(200, "FT_RAW|FT_FIFO %s\n", attr->ofname);
+ Dmsg1(200, "FT_RAW|FT_FIFO %s\n", attr->ofname);
mode = O_WRONLY | O_BINARY;
/* Timeout open() in 60 seconds */
if (attr->type == FT_FIFO) {
tid = NULL;
}
if (is_bopen(bfd)) {
- Jmsg1(jcr, M_ERROR, 0, "bpkt already open fid=%d\n", bfd->fid);
+ Jmsg1(jcr, M_ERROR, 0, "bpkt already open fid=%d\n", bfd->fid);
}
if ((bopen(bfd, attr->ofname, mode, 0)) < 0) {
berrno be;
be.set_errno(bfd->berrno);
- Jmsg2(jcr, M_ERROR, 0, _("Could not open %s: ERR=%s\n"),
+ Jmsg2(jcr, M_ERROR, 0, _("Could not open %s: ERR=%s\n"),
attr->ofname, be.strerror());
stop_thread_timer(tid);
return CF_ERROR;
stop_thread_timer(tid);
return CF_EXTRACT;
}
- Dmsg1(200, "FT_SPEC %s\n", attr->ofname);
+ Dmsg1(200, "FT_SPEC %s\n", attr->ofname);
return CF_CREATED;
case FT_LNK:
- Dmsg2(130, "FT_LNK should restore: %s -> %s\n", attr->ofname, attr->olname);
+ Dmsg2(130, "FT_LNK should restore: %s -> %s\n", attr->ofname, attr->olname);
if (symlink(attr->olname, attr->ofname) != 0 && errno != EEXIST) {
berrno be;
- Jmsg3(jcr, M_ERROR, 0, _("Could not symlink %s -> %s: ERR=%s\n"),
+ Jmsg3(jcr, M_ERROR, 0, _("Could not symlink %s -> %s: ERR=%s\n"),
attr->ofname, attr->olname, be.strerror());
return CF_ERROR;
}
return CF_CREATED;
case FT_LNKSAVED: /* Hard linked, file already saved */
- Dmsg2(130, "Hard link %s => %s\n", attr->ofname, attr->olname);
+ Dmsg2(130, "Hard link %s => %s\n", attr->ofname, attr->olname);
if (link(attr->olname, attr->ofname) != 0) {
berrno be;
- Jmsg3(jcr, M_ERROR, 0, _("Could not hard link %s -> %s: ERR=%s\n"),
+ Jmsg3(jcr, M_ERROR, 0, _("Could not hard link %s -> %s: ERR=%s\n"),
attr->ofname, attr->olname, be.strerror());
return CF_ERROR;
}
*/
if (!is_portable_backup(bfd)) {
if (is_bopen(bfd)) {
- Jmsg1(jcr, M_ERROR, 0, "bpkt already open fid=%d\n", bfd->fid);
+ Jmsg1(jcr, M_ERROR, 0, "bpkt already open fid=%d\n", bfd->fid);
}
if ((bopen(bfd, attr->ofname, O_WRONLY|O_BINARY, 0)) < 0) {
berrno be;
be.set_errno(bfd->berrno);
- Jmsg2(jcr, M_ERROR, 0, _("Could not open %s: ERR=%s\n"),
+ Jmsg2(jcr, M_ERROR, 0, _("Could not open %s: ERR=%s\n"),
attr->ofname, be.strerror());
return CF_ERROR;
}
* Returns: > 0 index into path where last path char is.
* 0 no path
* -1 filename is zero length
- */
+ */
static int separate_path_and_file(JCR *jcr, char *fname, char *ofile)
{
char *f, *p;
Jmsg1(jcr, M_ERROR, 0, _("Zero length filename: %s\n"), fname);
return -1;
}
- pnl = f - ofile - 1;
+ pnl = f - ofile - 1;
return pnl;
}
-/*
- * Primitive caching of path to prevent recreating a pathname
+/*
+ * Primitive caching of path to prevent recreating a pathname
* each time as long as we remain in the same directory.
*/
static int path_already_seen(JCR *jcr, char *path, int pnl)
/*=============================================================*/
#if !defined(HAVE_CYGWIN) && !defined(HAVE_WIN32)
-
+
int enable_backup_privileges(JCR *jcr, int ignore_errors)
{ return 0; }
return 0; /* not avail on this OS */
}
- // Get the LUID for the security privilege.
+ // Get the LUID for the security privilege.
if (!p_LookupPrivilegeValue(NULL, name, &tkp.Privileges[0].Luid)) {
- if (!ignore_errors) {
- win_error(jcr, "LookupPrivilegeValue", GetLastError());
+ if (!ignore_errors) {
+ win_error(jcr, "LookupPrivilegeValue", GetLastError());
}
}
if (lerror != ERROR_SUCCESS) {
if (!ignore_errors) {
char buf[200];
- strcpy(buf, "AdjustTokenPrivileges set ");
+ strcpy(buf, "AdjustTokenPrivileges set ");
bstrncat(buf, name, sizeof(buf));
win_error(jcr, buf, lerror);
}
return 0;
- }
+ }
return 1;
}
hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, GetCurrentProcessId());
- // Get a token for this process.
+ // Get a token for this process.
if (!p_OpenProcessToken(hProcess,
TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) {
- if (!ignore_errors) {
- win_error(jcr, "OpenProcessToken", GetLastError());
+ if (!ignore_errors) {
+ win_error(jcr, "OpenProcessToken", GetLastError());
}
/* Forge on anyway */
- }
+ }
/* Return a bit map of permissions set. */
if (enable_priv(jcr, hToken, SE_SECURITY_NAME, ignore_errors)) {
#endif
-/*
+/*
* Initialize the find files "global" variables
*/
FF_PKT *init_find_files()
{
- FF_PKT *ff;
+ FF_PKT *ff;
ff = (FF_PKT *)bmalloc(sizeof(FF_PKT));
memset(ff, 0, sizeof(FF_PKT));
return ff;
}
-/*
+/*
* Set find_files options. For the moment, we only
* provide for full/incremental saves, and setting
* of save_time. For additional options, see above
}
-/*
+/*
* Find all specified files (determined by calls to name_add()
* This routine calls the (handle_file) subroutine with all
* sorts of good information for the final disposition of
* the file.
- *
+ *
* Call this subroutine with a callback subroutine as the first
* argument and a packet as the second argument, this packet
* will be passed back to the callback subroutine as the last
*
*/
int
-find_files(JCR *jcr, FF_PKT *ff, int callback(FF_PKT *ff_pkt, void *hpkt), void *his_pkt)
+find_files(JCR *jcr, FF_PKT *ff, int callback(FF_PKT *ff_pkt, void *hpkt), void *his_pkt)
{
ff->callback = callback;
ff->flags |= fo->flags;
ff->GZIP_level = fo->GZIP_level;
ff->fstypes = fo->fstype;
- bstrncat(ff->VerifyOpts, fo->VerifyOpts, sizeof(ff->VerifyOpts));
+ bstrncat(ff->VerifyOpts, fo->VerifyOpts, sizeof(ff->VerifyOpts));
}
for (j=0; j<incexe->name_list.size(); j++) {
- Dmsg1(100, "F %s\n", (char *)incexe->name_list.get(j));
+ Dmsg1(100, "F %s\n", (char *)incexe->name_list.get(j));
char *fname = (char *)incexe->name_list.get(j);
if (find_one_file(jcr, ff, our_callback, his_pkt, fname, (dev_t)-1, 1) == 0) {
return 0; /* error return */
/* This is the old deprecated way */
while (!job_canceled(jcr) && (inc = get_next_included_file(ff, inc))) {
/* Copy options for this file */
- bstrncat(ff->VerifyOpts, inc->VerifyOpts, sizeof(ff->VerifyOpts));
- Dmsg1(100, "find_files: file=%s\n", inc->fname);
+ bstrncat(ff->VerifyOpts, inc->VerifyOpts, sizeof(ff->VerifyOpts));
+ Dmsg1(100, "find_files: file=%s\n", inc->fname);
if (!file_is_excluded(ff, inc->fname)) {
if (find_one_file(jcr, ff, callback, his_pkt, inc->fname, (dev_t)-1, 1) ==0) {
return 0; /* error return */
for (k=0; k<fo->wild.size(); k++) {
if (fnmatch((char *)fo->wild.get(k), ff->fname, fnmode|ic) == 0) {
if (ff->flags & FO_EXCLUDE) {
- Dmsg2(100, "Exclude wild: %s file=%s\n", (char *)fo->wild.get(k),
+ Dmsg2(100, "Exclude wild: %s file=%s\n", (char *)fo->wild.get(k),
ff->fname);
return false; /* reject file */
}
ic = (fo->flags & FO_IGNORECASE) ? FNM_CASEFOLD : 0;
for (k=0; k<fo->wild.size(); k++) {
if (fnmatch((char *)fo->wild.get(k), ff->fname, fnmode|ic) == 0) {
- Dmsg1(100, "Reject wild1: %s\n", ff->fname);
+ Dmsg1(100, "Reject wild1: %s\n", ff->fname);
return false; /* reject file */
}
}
? FNM_CASEFOLD : 0;
for (j=0; j<incexe->name_list.size(); j++) {
if (fnmatch((char *)incexe->name_list.get(j), ff->fname, fnmode|ic) == 0) {
- Dmsg1(100, "Reject wild2: %s\n", ff->fname);
+ Dmsg1(100, "Reject wild2: %s\n", ff->fname);
return false; /* reject file */
}
}
/*
* The code comes here for each file examined.
* We filter the files, then call the user's callback if
- * the file is included.
+ * the file is included.
*/
static int our_callback(FF_PKT *ff, void *hpkt)
{
if (accept_file(ff)) {
return ff->callback(ff, hpkt);
} else {
- Dmsg1(100, "Skip file %s\n", ff->fname);
+ Dmsg1(100, "Skip file %s\n", ff->fname);
return -1; /* ignore this file */
}
/*
* Terminate find_files() and release
- * all allocated memory
+ * all allocated memory
*/
int
term_find_files(FF_PKT *ff)
* Kern Sibbald MIM
*/
/*
- Copyright (C) 2000-2004 Kern Sibbald
+ Copyright (C) 2000-2004 Kern Sibbald
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
#endif
-/*
+/*
* Status codes returned by create_file()
*/
enum {
/* Options saved int "options" of the include/exclude lists.
- * They are directly jammed ito "flag" of ff packet
+ * They are directly jammed ito "flag" of ff packet
*/
#define FO_MD5 (1<<1) /* Do MD5 checksum */
#define FO_GZIP (1<<2) /* Do Zlib compression */
* of the structure are passed by the Director to the
* File daemon and recompiled back into this structure
*/
-#undef MAX_FOPTS
+#undef MAX_FOPTS
#define MAX_FOPTS 30
enum {
alist name_list; /* filename list -- holds char * */
};
-/*
+/*
* FileSet Resource
*
*/
findFILESET *fileset;
int (*callback)(FF_PKT *, void *); /* User's callback */
- /* Values set by accept_file while processing Options */
+ /* Values set by accept_file while processing Options */
uint32_t flags; /* backup options */
int GZIP_level; /* compression level */
char *reader; /* reader program */
-/*
+/*
Copyright (C) 2000-2004 Kern Sibbald and John Walker
This program is free software; you can redistribute it and/or
extern int32_t path_max; /* path name max length */
/*
- * Structure for keeping track of hard linked files, we
+ * Structure for keeping track of hard linked files, we
* keep an entry for each hardlinked file that we save,
* which is the first one found. For all the other files that
* are linked to this one, we save only the directory
accept = false;
fs = fstype(ff->fname);
if (fs == NULL) {
- Dmsg1(50, "Cannot determine file system type for \"%s\"\n", ff->fname);
+ Dmsg1(50, "Cannot determine file system type for \"%s\"\n", ff->fname);
} else {
for (i = 0; i < ff->fstypes.size(); ++i) {
if (strcmp(fs, (char *)ff->fstypes.get(i)) == 0) {
- Dmsg2(100, "Accepting fstype %s for \"%s\"\n", fs, ff->fname);
+ Dmsg2(100, "Accepting fstype %s for \"%s\"\n", fs, ff->fname);
accept = true;
break;
}
- Dmsg3(200, "fstype %s for \"%s\" does not match %s\n", fs,
+ Dmsg3(200, "fstype %s for \"%s\" does not match %s\n", fs,
ff->fname, ff->fstypes.get(i));
}
free(fs);
}
/*
- * Find a single file.
+ * Find a single file.
* handle_file is the callback for handling the file.
* p is the filename
- * parent_device is the device we are currently on
- * top_level is 1 when not recursing or 0 when
+ * parent_device is the device we are currently on
+ * top_level is 1 when not recursing or 0 when
* descending into a directory.
*/
int
-find_one_file(JCR *jcr, FF_PKT *ff_pkt, int handle_file(FF_PKT *ff, void *hpkt),
+find_one_file(JCR *jcr, FF_PKT *ff_pkt, int handle_file(FF_PKT *ff, void *hpkt),
void *pkt, char *fname, dev_t parent_device, int top_level)
{
struct utimbuf restore_times;
return 1; /* Just ignore this error - or the whole backup is cancelled */
}
- /*
+ /*
* If this is an Incremental backup, see if file was modified
* since our last "save_time", presumably the last Full save
* or Incremental.
Dmsg1(300, "Non-directory incremental: %s\n", ff_pkt->fname);
/* Not a directory */
if (ff_pkt->statp.st_mtime < ff_pkt->save_time
- && ((ff_pkt->flags & FO_MTIMEONLY) ||
+ && ((ff_pkt->flags & FO_MTIMEONLY) ||
ff_pkt->statp.st_ctime < ff_pkt->save_time)) {
/* Incremental option, file not changed */
ff_pkt->type = FT_NOCHG;
}
#endif
ff_pkt->LinkFI = 0;
- /*
+ /*
* Handle hard linked files
*
* Maintain a list of hard linked files already backed up. This
- * allows us to ensure that the data of each file gets backed
+ * allows us to ensure that the data of each file gets backed
* up only once.
*/
if (!(ff_pkt->flags & FO_NO_HARDLINK)
/* Search link list of hard linked files */
for (lp = ff_pkt->linklist; lp; lp = lp->next)
- if (lp->ino == (ino_t)ff_pkt->statp.st_ino &&
+ if (lp->ino == (ino_t)ff_pkt->statp.st_ino &&
lp->dev == (dev_t)ff_pkt->statp.st_dev) {
- /* If we have already backed up the hard linked file don't do it again */
+ /* If we have already backed up the hard linked file don't do it again */
if (strcmp(lp->name, fname) == 0) {
- Jmsg1(jcr, M_WARNING, 0, _("Attempt to backup hard linked file %s twice ignored.\n"),
+ Jmsg1(jcr, M_WARNING, 0, _("Attempt to backup hard linked file %s twice ignored.\n"),
fname);
return 1; /* ignore */
}
size = readlink(fname, buffer, path_max + name_max + 101);
if (size < 0) {
- /* Could not follow link */
+ /* Could not follow link */
ff_pkt->type = FT_NOFOLLOW;
ff_pkt->ff_errno = errno;
rtn_stat = handle_file(ff_pkt, pkt);
struct dirent *entry, *result;
char *link;
int link_len;
- int len;
+ int len;
int status;
dev_t our_device = ff_pkt->statp.st_dev;
bool recurse = true;
- /*
+ /*
* If we are using Win32 (non-portable) backup API, don't check
* access as everything is more complicated, and
* in principle, we should be able to access everything.
} else {
ff_pkt->type = FT_DIRBEGIN;
}
- /*
+ /*
* Note, we return the directory to the calling program (handle_file)
- * when we first see the directory (FT_DIRBEGIN.
+ * when we first see the directory (FT_DIRBEGIN.
* This allows the program to apply matches and make a
* choice whether or not to accept it. If it is accepted, we
* do not immediately save it, but do so only after everything
dir_ff_pkt->excluded_paths_list = NULL;
dir_ff_pkt->linklist = NULL;
- /*
+ /*
* Do not descend into subdirectories (recurse) if the
* user has turned it off for this directory.
*
}
free(link);
free_dir_ff_pkt(dir_ff_pkt);
- ff_pkt->link = ff_pkt->fname; /* reset "link" */
+ ff_pkt->link = ff_pkt->fname; /* reset "link" */
if (ff_pkt->flags & FO_KEEPATIME) {
utime(fname, &restore_times);
}
ff_pkt->link = ff_pkt->fname; /* reset "link" */
- /*
+ /*
* Descend into or "recurse" into the directory to read
* all the files in it.
*/
}
ASSERT(name_max+1 > (int)sizeof(struct dirent) + (int)NAMELEN(entry));
p = entry->d_name;
- /* Skip `.', `..', and excluded file names. */
- if (p[0] == '\0' || (p[0] == '.' && (p[1] == '\0' ||
- (p[1] == '.' && p[2] == '\0')))) {
+ /* Skip `.', `..', and excluded file names. */
+ if (p[0] == '\0' || (p[0] == '.' && (p[1] == '\0' ||
+ (p[1] == '.' && p[2] == '\0')))) {
continue;
}
{
struct f_link *lp, *lc;
int count = 0;
-
+
/* Free up list of hard linked files */
for (lp = ff->linklist; lp;) {
lc = lp;
* Implement routines to determine file system types.
*
* Written by Preben 'Peppe' Guldberg, December MMIV
- *
+ *
* Version $Id$
*/
#include <stdlib.h>
#include <string.h>
#define SUPPORTEDOSES "HAVE_DARWIN_OS\n" \
- "HAVE_FREEBSD_OS\n" \
- "HAVE_HPUX_OS\n" \
- "HAVE_IRIX_OS\n" \
- "HAVE_LINUX_OS\n" \
- "HAVE_NETBSD_OS\n" \
- "HAVE_OPENBSD_OS\n" \
- "HAVE_SUN_OS\n"
+ "HAVE_FREEBSD_OS\n" \
+ "HAVE_HPUX_OS\n" \
+ "HAVE_IRIX_OS\n" \
+ "HAVE_LINUX_OS\n" \
+ "HAVE_NETBSD_OS\n" \
+ "HAVE_OPENBSD_OS\n" \
+ "HAVE_SUN_OS\n"
#define POOLMEM char
#define bstrdup strdup
#define Dmsg0(n,s) fprintf(stderr, s "\n");
struct statfs st;
if (statfs(fname, &st) == 0) {
/*
- * Values nicked from statfs(2), testing and
+ * Values nicked from statfs(2), testing and
*
* $ grep -r SUPER_MAGIC /usr/include/linux
*
#endif
default:
- Dmsg2(10, "Unknown file system type \"0x%x\" for \"%s\".", st.f_type,
+ Dmsg2(10, "Unknown file system type \"0x%x\" for \"%s\".", st.f_type,
fname);
return NULL;
}
if (argc < 2) {
p = (argc < 1) ? "fstype" : argv[0];
printf("usage:\t%s path ...\n"
- "\t%s prints the file system type and pathname of the paths.\n",
+ "\t%s prints the file system type and pathname of the paths.\n",
p, p);
return EXIT_FAILURE;
}
if ((p = fstype(*argv)) == NULL) {
status = EXIT_FAILURE;
} else {
- printf("%s\t%s\n", p, *argv);
+ printf("%s\t%s\n", p, *argv);
}
}
return status;
/* Written by David MacKenzie <djm@gnu.ai.mit.edu> and Jim Meyering. */
-/*
+/*
* Modified by Kern Sibbald for use in Bacula, December 2000
*
* Version $Id$
/* The mkdir and stat calls below may appear to be reversed.
They are not. It is important to call mkdir first and then to
call stat (to distinguish the three cases) only if mkdir fails.
- The alternative to this approach is to `stat' each directory,
- then to call mkdir if it doesn't exist. But if some other process
+ The alternative to this approach is to `stat' each directory,
+ then to call mkdir if it doesn't exist. But if some other process
were to create the directory between the stat & mkdir, the mkdir
would fail with EEXIST. */
if (stat(dir, &stats)) {
berrno be;
be.set_errno(save_errno);
- Jmsg(jcr, M_ERROR, 0, _("Cannot create directory %s: ERR=%s\n"),
+ Jmsg(jcr, M_ERROR, 0, _("Cannot create directory %s: ERR=%s\n"),
dirpath, be.strerror());
fail = 1;
} else if (!S_ISDIR(stats.st_mode)) {
- Jmsg(jcr, M_ERROR, 0, _("%s exists but is not a directory\n"), quote(dirpath));
+ Jmsg(jcr, M_ERROR, 0, _("%s exists but is not a directory\n"), quote(dirpath));
fail = 1;
} else {
/* DIR (aka DIRPATH) already exists and is a directory. */
return path[1] == ':' || *path == '/' || *path == '\\'; /* drivespec:/blah is absolute */
#else
return *path == '/';
-#endif
+#endif
}
-
+
/* Ensure that the directory ARGPATH exists.
Remove any trailing slashes from ARGPATH before calling this function.
Create any leading directories that don't already exist, with
permissions PARENT_MODE.
-
+
If the last element of ARGPATH does not exist, create it as
a new directory with permissions MODE.
cwd.do_chdir = !save_cwd(&cwd);
/* If we've saved the cwd and DIRPATH is an absolute pathname,
- we must chdir to `/' in order to enable the chdir optimization.
- So if chdir ("/") fails, turn off the optimization. */
+ we must chdir to `/' in order to enable the chdir optimization.
+ So if chdir ("/") fails, turn off the optimization. */
if (cwd.do_chdir && isAbsolute(dirpath) && (chdir("/") < 0)) {
cwd.do_chdir = 0;
}
/* slash points to the leftmost unprocessed component of dirpath. */
basename_dir = slash;
- slash = strchr (slash, '/');
+ slash = strchr (slash, '/');
if (slash == NULL) {
break;
}
- /* If we're *not* doing chdir before each mkdir, then we have to refer
+ /* If we're *not* doing chdir before each mkdir, then we have to refer
to the target using the full (multi-component) directory name. */
if (!cwd.do_chdir) {
basename_dir = dirpath;
}
- *slash = '\0';
+ *slash = '\0';
fail = make_dir(jcr, basename_dir, dirpath, tmp_mode, &newly_created_dir);
if (fail) {
umask(oldmask);
}
if (newly_created_dir) {
- Dmsg0(300, "newly_created_dir\n");
+ Dmsg0(300, "newly_created_dir\n");
if ((owner != (uid_t)-1 || group != (gid_t)-1)
&& chown(basename_dir, owner, group)
) {
/* Note, if we are restoring as NON-root, this may not be fatal */
berrno be;
- Jmsg(jcr, M_ERROR, 0, _("Cannot change owner and/or group of %s: ERR=%s\n"),
+ Jmsg(jcr, M_ERROR, 0, _("Cannot change owner and/or group of %s: ERR=%s\n"),
quote(dirpath), be.strerror());
}
- Dmsg0(300, "Chown done.\n");
+ Dmsg0(300, "Chown done.\n");
if (re_protect) {
struct ptr_list *pnew = (struct ptr_list *)
pnew->dirname_end = slash;
pnew->next = leading_dirs;
leading_dirs = pnew;
- Dmsg0(300, "re_protect\n");
+ Dmsg0(300, "re_protect\n");
}
}
stat and mkdir process O(n^2) file name components. */
if (cwd.do_chdir && chdir(basename_dir) < 0) {
berrno be;
- Jmsg(jcr, M_ERROR, 0, _("Cannot chdir to directory, %s: ERR=%s\n"),
+ Jmsg(jcr, M_ERROR, 0, _("Cannot chdir to directory, %s: ERR=%s\n"),
quote(dirpath), be.strerror());
umask(oldmask);
cleanup(&cwd);
return 1;
}
- *slash++ = '/';
+ *slash++ = '/';
- /* Avoid unnecessary calls to `stat' when given
+ /* Avoid unnecessary calls to `stat' when given
pathnames containing multiple adjacent slashes. */
- while (*slash == '/')
+ while (*slash == '/')
slash++;
} /* end while (1) */
)
{
berrno be;
- Jmsg(jcr, M_WARNING, 0, _("Cannot change owner and/or group of %s: ERR=%s\n"),
+ Jmsg(jcr, M_WARNING, 0, _("Cannot change owner and/or group of %s: ERR=%s\n"),
quote(dirpath), be.strerror());
}
}
/* The above chown may have turned off some permission bits in MODE.
Another reason we may have to use chmod here is that mkdir(2) is
required to honor only the file permission bits. In particular,
- it need not honor the `special' bits, so if MODE includes any
+ it need not honor the `special' bits, so if MODE includes any
special bits, set them here. */
if (mode & ~S_IRWXUGO) {
- Dmsg1(300, "Final chmod mode=%o\n", mode);
+ Dmsg1(300, "Final chmod mode=%o\n", mode);
}
if ((mode & ~S_IRWXUGO) && chmod(basename_dir, mode)) {
berrno be;
- Jmsg(jcr, M_WARNING, 0, _("Cannot change permissions of %s: ERR=%s\n"),
+ Jmsg(jcr, M_WARNING, 0, _("Cannot change permissions of %s: ERR=%s\n"),
quote(dirpath), be.strerror());
}
privileges, we have to reset their protections to the correct
value. */
for (p = leading_dirs; p != NULL; p = p->next) {
- *(p->dirname_end) = '\0';
- Dmsg2(300, "Reset parent mode=%o dir=%s\n", parent_mode, dirpath);
+ *(p->dirname_end) = '\0';
+ Dmsg2(300, "Reset parent mode=%o dir=%s\n", parent_mode, dirpath);
if (chmod(dirpath, parent_mode)) {
berrno be;
- Jmsg(jcr, M_WARNING, 0, _("Cannot change permissions of %s: ERR=%s\n"),
+ Jmsg(jcr, M_WARNING, 0, _("Cannot change permissions of %s: ERR=%s\n"),
quote(dirpath), be.strerror());
}
}
const char *dirpath = argpath;
if (!S_ISDIR(stats.st_mode)) {
- Jmsg(jcr, M_ERROR, 0, _("%s exists but is not a directory\n"), quote(dirpath));
+ Jmsg(jcr, M_ERROR, 0, _("%s exists but is not a directory\n"), quote(dirpath));
return 1;
}
if (!preserve_existing) {
- Dmsg0(300, "Do not preserve existing.\n");
+ Dmsg0(300, "Do not preserve existing.\n");
/* chown must precede chmod because on some systems,
chown clears the set[ug]id bits for non-superusers,
resulting in incorrect permissions.
On System V, users can give away files with chown and then not
- be able to chmod them. So don't give files away. */
+ be able to chmod them. So don't give files away. */
if ((owner != (uid_t)-1 || group != (gid_t)-1)
&& chown(dirpath, owner, group)
#endif
) {
berrno be;
- Jmsg(jcr, M_WARNING, 0, _("Cannot change owner and/or group of %s: ERR=%s\n"),
+ Jmsg(jcr, M_WARNING, 0, _("Cannot change owner and/or group of %s: ERR=%s\n"),
quote(dirpath), be.strerror());
}
if (chmod(dirpath, mode)) {
berrno be;
- Jmsg(jcr, M_WARNING, 0, _("Cannot change permissions of %s: ERR=%s\n"),
+ Jmsg(jcr, M_WARNING, 0, _("Cannot change permissions of %s: ERR=%s\n"),
quote(dirpath), be.strerror());
}
- Dmsg2(300, "pathexists chmod mode=%o dir=%s\n", mode, dirpath);
+ Dmsg2(300, "pathexists chmod mode=%o dir=%s\n", mode, dirpath);
}
}
return retval;
* filename/pathname patterns.
*
* Note, this file is used for the old style include and
- * excludes, so is deprecated. The new style code is
+ * excludes, so is deprecated. The new style code is
* found in find.c
*
* Kern E. Sibbald, December MMI
#define bmalloc(x) sm_malloc(__FILE__, __LINE__, x)
extern const int win32_client;
-
+
/*
* Initialize structures for filename matching
*/
}
/*
- * Done doing filename matching, release all
+ * Done doing filename matching, release all
* resources used.
*/
void term_include_exclude_files(FF_PKT *ff)
free(exc);
exc = next_exc;
}
-
+
}
/*
inc =(struct s_included_file *)bmalloc(sizeof(struct s_included_file) + len + 1);
inc->options = 0;
- inc->VerifyOpts[0] = 'V';
+ inc->VerifyOpts[0] = 'V';
inc->VerifyOpts[1] = ':';
inc->VerifyOpts[2] = 0;
if (prefixed) {
for (rp=fname; *rp && *rp != ' '; rp++) {
switch (*rp) {
- case 'a': /* alway replace */
- case '0': /* no option */
+ case 'a': /* alway replace */
+ case '0': /* no option */
break;
- case 'f':
+ case 'f':
inc->options |= FO_MULTIFS;
break;
- case 'h': /* no recursion */
+ case 'h': /* no recursion */
inc->options |= FO_NO_RECURSION;
break;
- case 'M': /* MD5 */
+ case 'M': /* MD5 */
inc->options |= FO_MD5;
break;
- case 'n':
+ case 'n':
inc->options |= FO_NOREPLACE;
break;
- case 'p': /* use portable data format */
+ case 'p': /* use portable data format */
inc->options |= FO_PORTABLE;
break;
- case 'r': /* read fifo */
+ case 'r': /* read fifo */
inc->options |= FO_READFIFO;
break;
- case 'S':
+ case 'S':
inc->options |= FO_SHA1;
break;
- case 's':
+ case 's':
inc->options |= FO_SPARSE;
break;
- case 'm':
+ case 'm':
inc->options |= FO_MTIMEONLY;
break;
- case 'k':
+ case 'k':
inc->options |= FO_KEEPATIME;
break;
- case 'V': /* verify options */
+ case 'V': /* verify options */
/* Copy Verify Options */
- for (j=0; *rp && *rp != ':'; rp++) {
+ for (j=0; *rp && *rp != ':'; rp++) {
inc->VerifyOpts[j] = *rp;
if (j < (int)sizeof(inc->VerifyOpts) - 1) {
j++;
}
inc->VerifyOpts[j] = 0;
break;
- case 'w':
+ case 'w':
inc->options |= FO_IF_NEWER;
break;
- case 'A':
+ case 'A':
inc->options |= FO_ACL;
break;
- case 'Z': /* gzip compression */
+ case 'Z': /* gzip compression */
inc->options |= FO_GZIP;
- inc->level = *++rp - '0';
- Dmsg1(200, "Compression level=%d\n", inc->level);
+ inc->level = *++rp - '0';
+ Dmsg1(200, "Compression level=%d\n", inc->level);
break;
default:
- Emsg1(M_ERROR, 0, "Unknown include/exclude option: %c\n", *rp);
+ Emsg1(M_ERROR, 0, "Unknown include/exclude option: %c\n", *rp);
break;
}
}
rp = fname;
}
- strcpy(inc->fname, rp);
+ strcpy(inc->fname, rp);
p = inc->fname;
len = strlen(p);
/* Zap trailing slashes. */
/* Convert any \'s into /'s */
for (p=inc->fname; *p; p++) {
if (*p == '\\') {
- *p = '/';
+ *p = '/';
}
}
#endif
for (next=ff->included_files_list; next->next; next=next->next)
{ }
next->next = inc;
- }
+ }
Dmsg1(50, "add_fname_to_include fname=%s\n", inc->fname);
}
} else {
list = &ff->excluded_files_list;
}
-
+
len = strlen(fname);
exc = (struct s_excluded_file *)bmalloc(sizeof(struct s_excluded_file) + len + 1);
exc->next = *list;
exc->len = len;
- strcpy(exc->fname, fname);
+ strcpy(exc->fname, fname);
#if defined(HAVE_CYGWIN) || defined(HAVE_WIN32)
/* Convert any \'s into /'s */
for (char *p=exc->fname; *p; p++) {
if (*p == '\\') {
- *p = '/';
+ *p = '/';
}
}
#endif
{
struct s_included_file *inc;
- if (ainc == NULL) {
+ if (ainc == NULL) {
inc = ff->included_files_list;
} else {
inc = ainc->next;
return 1;
}
continue;
- }
+ }
/*
* No wild cards. We accept a match to the
* end of any component.
if (inc->len == len && strcmp(inc->fname, file) == 0) {
return 1;
}
- if (inc->len < len && file[inc->len] == '/' &&
+ if (inc->len < len && file[inc->len] == '/' &&
strncmp(inc->fname, file, inc->len) == 0) {
return 1;
}
}
for ( ; exc; exc=exc->next ) {
if (fnmatch(exc->fname, file, fnmode|FNM_PATHNAME) == 0) {
- Dmsg2(900, "Match exc pat=%s: file=%s:\n", exc->fname, file);
+ Dmsg2(900, "Match exc pat=%s: file=%s:\n", exc->fname, file);
return 1;
}
Dmsg2(900, "No match exc pat=%s: file=%s:\n", exc->fname, file);
{
const char *p;
- /*
+ /*
* ***NB*** this removes the drive from the exclude
* rule. Why?????
*/
/* Match from the beginning of a component only */
if ((p == file || (*p != '/' && *(p-1) == '/'))
&& file_in_excluded_list(ff->excluded_files_list, p)) {
- return 1;
+ return 1;
}
}
return 0;
void add_fname_to_exclude_list(FF_PKT *ff, const char *fname);
int file_is_excluded(FF_PKT *ff, const char *file);
int file_is_included(FF_PKT *ff, const char *file);
-struct s_included_file *get_next_included_file(FF_PKT *ff,
+struct s_included_file *get_next_included_file(FF_PKT *ff,
struct s_included_file *inc);
/* From find_one.c */
-int find_one_file(JCR *jcr, FF_PKT *ff, int handle_file(FF_PKT *ff_pkt, void *hpkt),
+int find_one_file(JCR *jcr, FF_PKT *ff, int handle_file(FF_PKT *ff_pkt, void *hpkt),
void *pkt, char *p, dev_t parent_device, int top_level);
int term_find_one(FF_PKT *ff);
cwd->desc = open(".", O_RDONLY);
if (cwd->desc < 0) {
berrno be;
- Emsg1(M_ERROR, 0, "Cannot open current directory: %s\n", be.strerror());
+ Emsg1(M_ERROR, 0, "Cannot open current directory: %s\n", be.strerror());
return 1;
}
have_working_fchdir = 0;
} else {
berrno be;
- Emsg1(M_ERROR, 0, "Current directory: %s\n", be.strerror());
+ Emsg1(M_ERROR, 0, "Current directory: %s\n", be.strerror());
close(cwd->desc);
cwd->desc = -1;
return 1;
cwd->name = (POOLMEM *)getcwd(buf, sizeof_pool_memory(buf));
if (cwd->name == NULL) {
berrno be;
- Emsg1(M_ERROR, 0, "Cannot get current directory: %s\n", be.strerror());
+ Emsg1(M_ERROR, 0, "Cannot get current directory: %s\n", be.strerror());
free_pool_memory(buf);
return 1;
}
if (cwd->desc >= 0) {
if (fchdir(cwd->desc)) {
berrno be;
- Emsg4(M_ERROR, 0, "Cannot return to %s%s%s: %s\n",
- (dest ? dest : "saved working directory"),
- (from ? " from " : ""),
- (from ? from : ""), be.strerror());
+ Emsg4(M_ERROR, 0, "Cannot return to %s%s%s: %s\n",
+ (dest ? dest : "saved working directory"),
+ (from ? " from " : ""),
+ (from ? from : ""), be.strerror());
fail = 1;
}
} else if (chdir(cwd->name) < 0) {
int save_cwd(struct saved_cwd *cwd);
int restore_cwd(const struct saved_cwd *cwd, const char *dest,
- const char *from);
+ const char *from);
void free_cwd(struct saved_cwd *cwd);
#endif
/*
* Windows APIs that are different for each system.
- * We use pointers to the entry points so that a
+ * We use pointers to the entry points so that a
* single binary will run on all Windows systems.
*
* Kern Sibbald MMIII
#ifndef __WINAPI_H
#define __WINAPI_H
#if defined(HAVE_WIN32)
-/* Commented out native.h include statement, which is not distributed with the
+/* Commented out native.h include statement, which is not distributed with the
* free version of VC++, and which is not used in bacula. */
/*#if !defined(HAVE_MINGW) // native.h not present on mingw
#include <native.h>
typedef BOOL (WINAPI * t_OpenProcessToken)(HANDLE, DWORD, PHANDLE);
typedef BOOL (WINAPI * t_AdjustTokenPrivileges)(HANDLE, BOOL,
- PTOKEN_PRIVILEGES, DWORD, PTOKEN_PRIVILEGES, PDWORD);
+ PTOKEN_PRIVILEGES, DWORD, PTOKEN_PRIVILEGES, PDWORD);
typedef BOOL (WINAPI * t_LookupPrivilegeValue)(LPCTSTR, LPCTSTR, PLUID);
extern t_OpenProcessToken p_OpenProcessToken;
MA 02111-1307, USA.
*/
-
+
#ifndef __JCR_H_
#define __JCR_H_ 1
jcr->JobStatus == JS_FatalError)
#define foreach_jcr(jcr) \
- for ((jcr)=NULL; ((jcr)=get_next_jcr(jcr)); )
+ for ((jcr)=NULL; ((jcr)=get_next_jcr(jcr)); )
uint64_t JobBytes; /* Number of bytes processed this job */
uint64_t ReadBytes; /* Bytes read -- before compression */
uint32_t Errors; /* Number of non-fatal errors */
- volatile int JobStatus; /* ready, running, blocked, terminated */
+ volatile int JobStatus; /* ready, running, blocked, terminated */
int JobType; /* backup, restore, verify ... */
int JobLevel; /* Job level */
int JobPriority; /* Job priority */
JOB_DBR jr; /* Job DB record for current job */
JOB_DBR *verify_jr; /* Pointer to target job */
uint32_t RestoreJobId; /* Id specified by UA */
- POOLMEM *client_uname; /* client uname */
+ POOLMEM *client_uname; /* client uname */
int replace; /* Replace option */
int saveMaxConcurrentJobs; /* save for restore jobs */
int NumVols; /* Number of Volume used in pool */
bool spool_data; /* set to spool data */
int CurVol; /* Current Volume count */
DIRRES* director; /* Director resource */
-
+
uint32_t FileId; /* Last file id inserted */
/* Parmaters for Open Read Session */
#endif /* STORAGE_DAEMON */
-};
+};
-/*
+/*
* Structure for all daemons that keeps some summary
* info on the last job run.
*/
char Job[MAX_NAME_LENGTH];
};
-extern struct s_last_job last_job;
+extern struct s_last_job last_job;
extern dlist *last_jobs;
{
memcpy(&saddrbuf, &src.saddrbuf, sizeof(saddrbuf));
saddr = &saddrbuf.dontuse;
- saddr4 = &saddrbuf.dontuse4;
+ saddr4 = &saddrbuf.dontuse4;
#ifdef HAVE_IPV6
saddr6 = &saddrbuf.dontuse6;
#endif
}
#endif
saddr = &saddrbuf.dontuse;
- saddr4 = &saddrbuf.dontuse4;
+ saddr4 = &saddrbuf.dontuse4;
#ifdef HAVE_IPV6
saddr6 = &saddrbuf.dontuse6;
#endif
saddr->sa_len = sizeof(sockaddr_in);
#endif
#endif
- set_addr_any();
-}
+ set_addr_any();
+}
void IPADDR::set_type(i_type o)
{
int IPADDR::get_family() const
{
return saddr->sa_family;
-}
+}
struct sockaddr *IPADDR::get_sockaddr()
{
saddr6->sin6_addr = src->saddr6->sin6_addr;
}
#endif
-}
+}
void IPADDR::set_addr_any()
{
}
void IPADDR::set_addr4(struct in_addr *ip4)
-{
+{
if (saddr->sa_family != AF_INET) {
Emsg1(M_ERROR_TERM, 0, _("It was tried to assign a ipv6 address to a ipv4(%d)\n"), saddr->sa_family);
}
#ifdef HAVE_IPV6
void IPADDR::set_addr6(struct in6_addr *ip6)
-{
+{
if (saddr->sa_family != AF_INET6) {
Emsg1(M_ERROR_TERM, 0, _("It was tried to assign a ipv4 address to a ipv6(%d)\n"), saddr->sa_family);
}
return outputbuf;
}
-const char *IPADDR::build_address_str(char *buf, int blen)
+const char *IPADDR::build_address_str(char *buf, int blen)
{
char tmp[1024];
bsnprintf(buf, blen, "host[%s:%s:%hu] ",
- get_family() == AF_INET ? "ipv4" : "ipv6",
+ get_family() == AF_INET ? "ipv4" : "ipv6",
get_address(tmp, sizeof(tmp) - 1), get_port_host_order());
return buf;
}
-const char *build_addresses_str(dlist *addrs, char *buf, int blen)
+const char *build_addresses_str(dlist *addrs, char *buf, int blen)
{
if (addrs->size() == 0) {
bstrncpy(buf, "", blen);
int get_first_port_net_order(dlist * addrs)
{
- return ((IPADDR *)(addrs->first()))->get_port_net_order();
+ return ((IPADDR *)(addrs->first()))->get_port_net_order();
}
int get_first_port_host_order(dlist * addrs)
{
- return ((IPADDR *)(addrs->first()))->get_port_host_order();
+ return ((IPADDR *)(addrs->first()))->get_port_host_order();
}
void init_default_addresses(dlist **out, int port)
} else if (iaddr->get_type() != type) {
*errstr = (char *)malloc(1024);
bsnprintf(*errstr, 1023,
- "the old style addresses cannot be mixed with new style");
+ "the old style addresses cannot be mixed with new style");
return 0;
}
}
if (0 < pnum && pnum < 0xffff) {
port = htons(pnum);
} else {
- struct servent *s = getservbyname(port_str, "tcp");
+ struct servent *s = getservbyname(port_str, "tcp");
if (s) {
port = s->s_port;
} else {
*errstr = (char *)malloc(1024);
- bsnprintf(*errstr, 1023, "can't resolve service(%s)", port_str);
+ bsnprintf(*errstr, 1023, "can't resolve service(%s)", port_str);
return 0;
}
}
if (addrs->size()) {
addr = (IPADDR *)addrs->first();
} else {
- addr = New(IPADDR(family));
+ addr = New(IPADDR(family));
addr->set_type(type);
addr->set_port_net(defaultport);
addr->set_addr_any();
/* for duplicates */
foreach_dlist(jaddr, addrs) {
if (iaddr->get_sockaddr_len() == jaddr->get_sockaddr_len() &&
- !memcmp(iaddr->get_sockaddr(), jaddr->get_sockaddr(),
+ !memcmp(iaddr->get_sockaddr(), jaddr->get_sockaddr(),
iaddr->get_sockaddr_len()))
{
goto skip; /* no price */
}
}
- clone = New(IPADDR(*iaddr));
+ clone = New(IPADDR(*iaddr));
clone->set_type(type);
clone->set_port_net(port);
addrs->append(clone);
* my tests
* positiv
* = { ip = { addr = 1.2.3.4; port = 1205; } ipv4 = { addr = 1.2.3.4; port = http; } }
- * = { ip = {
- * addr = 1.2.3.4; port = 1205; }
- * ipv4 = {
- * addr = 1.2.3.4; port = http; }
- * ipv6 = {
- * addr = 1.2.3.4;
+ * = { ip = {
+ * addr = 1.2.3.4; port = 1205; }
+ * ipv4 = {
+ * addr = 1.2.3.4; port = http; }
+ * ipv6 = {
+ * addr = 1.2.3.4;
* port = 1205;
- * }
+ * }
* ip = {
* addr = 1.2.3.4
* port = 1205
- * }
+ * }
* ip = {
* addr = 1.2.3.4
- * }
+ * }
* ip = {
* addr = 2001:220:222::2
- * }
+ * }
* ip = {
* addr = bluedot.thun.net
- ( }
+ ( }
* }
* negativ
* = { ip = { } }
}
do {
if (!(token == T_UNQUOTED_STRING || token == T_IDENTIFIER)) {
- scan_err1(lc, _("Expected a string, got: %s"), lc->str);
+ scan_err1(lc, _("Expected a string, got: %s"), lc->str);
}
if (strcasecmp("ip", lc->str) == 0 || strcasecmp("ipv4", lc->str) == 0) {
family = AF_INET;
else if (strcasecmp("ipv6", lc->str) == 0) {
family = AF_INET6;
} else {
- scan_err1(lc, _("Expected a string [ip|ipv4|ipv6], got: %s"), lc->str);
+ scan_err1(lc, _("Expected a string [ip|ipv4|ipv6], got: %s"), lc->str);
}
#else
else {
- scan_err1(lc, _("Expected a string [ip|ipv4], got: %s"), lc->str);
+ scan_err1(lc, _("Expected a string [ip|ipv4], got: %s"), lc->str);
}
#endif
token = lex_get_token(lc, T_SKIP_EOL);
if (token != T_EQUALS) {
- scan_err1(lc, _("Expected a equal =, got: %s"), lc->str);
+ scan_err1(lc, _("Expected a equal =, got: %s"), lc->str);
}
token = lex_get_token(lc, T_SKIP_EOL);
if (token != T_BOB) {
- scan_err1(lc, _("Expected a block beginn { , got: %s"), lc->str);
+ scan_err1(lc, _("Expected a block beginn { , got: %s"), lc->str);
}
token = lex_get_token(lc, T_SKIP_EOL);
exist = EMPTYLINE;
port_str[0] = hostname_str[0] = '\0';
do {
if (token != T_IDENTIFIER) {
- scan_err1(lc, _("Expected a identifier [addr|port], got: %s"), lc->str);
+ scan_err1(lc, _("Expected a identifier [addr|port], got: %s"), lc->str);
}
- if (strcasecmp("port", lc->str) == 0) {
+ if (strcasecmp("port", lc->str) == 0) {
next_line = PORTLINE;
if (exist & PORTLINE) {
- scan_err0(lc, _("Only one port per address block"));
+ scan_err0(lc, _("Only one port per address block"));
}
exist |= PORTLINE;
- } else if (strcasecmp("addr", lc->str) == 0) {
+ } else if (strcasecmp("addr", lc->str) == 0) {
next_line = ADDRLINE;
if (exist & ADDRLINE) {
- scan_err0(lc, _("Only one addr per address block"));
+ scan_err0(lc, _("Only one addr per address block"));
}
exist |= ADDRLINE;
} else {
- scan_err1(lc, _("Expected a identifier [addr|port], got: %s"), lc->str);
+ scan_err1(lc, _("Expected a identifier [addr|port], got: %s"), lc->str);
}
token = lex_get_token(lc, T_SKIP_EOL);
if (token != T_EQUALS) {
- scan_err1(lc, _("Expected a equal =, got: %s"), lc->str);
+ scan_err1(lc, _("Expected a equal =, got: %s"), lc->str);
}
token = lex_get_token(lc, T_SKIP_EOL);
switch (next_line) {
if (!
(token == T_UNQUOTED_STRING || token == T_NUMBER
|| token == T_IDENTIFIER)) {
- scan_err1(lc, _("Expected a number or a string, got: %s"), lc->str);
+ scan_err1(lc, _("Expected a number or a string, got: %s"), lc->str);
}
bstrncpy(port_str, lc->str, sizeof(port_str));
break;
case ADDRLINE:
if (!(token == T_UNQUOTED_STRING || token == T_IDENTIFIER)) {
- scan_err1(lc, _("Expected an IP number or a hostname, got: %s"),
+ scan_err1(lc, _("Expected an IP number or a hostname, got: %s"),
lc->str);
}
bstrncpy(hostname_str, lc->str, sizeof(hostname_str));
break;
case EMPTYLINE:
- scan_err0(lc, _("State machine missmatch"));
+ scan_err0(lc, _("State machine missmatch"));
break;
}
token = lex_get_token(lc, T_SKIP_EOL);
} while (token == T_IDENTIFIER);
if (token != T_EOB) {
- scan_err1(lc, _("Expected a end of block }, got: %s"), lc->str);
+ scan_err1(lc, _("Expected a end of block }, got: %s"), lc->str);
}
char *errstr;
- if (pass == 1 && !add_address((dlist **)(item->value), IPADDR::R_MULTIPLE,
+ if (pass == 1 && !add_address((dlist **)(item->value), IPADDR::R_MULTIPLE,
htons(item->default_value), family, hostname_str, port_str, &errstr)) {
- scan_err3(lc, _("Can't add hostname(%s) and port(%s) to addrlist (%s)"),
+ scan_err3(lc, _("Can't add hostname(%s) and port(%s) to addrlist (%s)"),
hostname_str, port_str, errstr);
free(errstr);
}
IPADDR(int af);
IPADDR(const IPADDR & src);
private:
- IPADDR() { /* block this construction */ }
+ IPADDR() { /* block this construction */ }
i_type type;
union {
struct sockaddr dontuse;
/*
- * Bacula array list routines
+ * Bacula array list routines
*
* alist is a simple malloc'ed array of pointers. For the moment,
- * it simply malloc's a bigger array controlled by num_grow.
+ * it simply malloc's a bigger array controlled by num_grow.
* Default is to realloc the pointer array for each new member.
*
* Kern Sibbald, June MMIII
#include "bacula.h"
/*
- * Private grow list function. Used to insure that
+ * Private grow list function. Used to insure that
* at least one more "slot" is available.
*/
void alist::grow_list()
if (num_items == 0) {
return NULL;
} else {
- cur_item = num_items;
+ cur_item = num_items;
return items[num_items-1];
}
}
fileset->mylist.init();
printf("Manual allocation/destruction of list:\n");
-
+
for (int i=0; i<20; i++) {
sprintf(buf, "This is item %d", i);
fileset->mylist.append(bstrdup(buf));
- }
+ }
for (int i=0; i< fileset->mylist.size(); i++) {
- printf("Item %d = %s\n", i, (char *)fileset->mylist[i]);
+ printf("Item %d = %s\n", i, (char *)fileset->mylist[i]);
}
fileset->mylist.destroy();
free(fileset);
for (int i=0; i<20; i++) {
sprintf(buf, "This is item %d", i);
mlist->append(bstrdup(buf));
- }
+ }
for (int i=0; i< mlist->size(); i++) {
- printf("Item %d = %s\n", i, (char *)mlist->get(i));
+ printf("Item %d = %s\n", i, (char *)mlist->get(i));
}
delete mlist;
*/
-/*
+/*
* There is a lot of extra casting here to work around the fact
* that some compilers (Sun and Visual C++) do not accept
* (void *) as an lvalue on the left side of an equal.
#ifdef the_easy_way
#define foreach_alist(var, list) \
- for((void*(var))=(list)->first(); (var); (void *(var))=(list)->next(var)); )
+ for((void*(var))=(list)->first(); (var); (void *(var))=(list)->next(var)); )
#endif
not_owned_by_alist = false
};
-/*
+/*
* Array list -- much like a simplified STL vector
* array of pointers to inserted items
*/
return this ? num_items == 0 : true;
}
-/*
+/*
* This allows us to do explicit initialization,
* allowing us to mix C++ classes inside malloc'ed
* C structures. Define before called in constructor.
inline alist::~alist() {
destroy();
}
-
+
/* Current size of list */
-inline int alist::size() const
+inline int alist::size() const
{
/*
* Check for null pointer, which allows test
}
/* How much to grow by each time */
-inline void alist::grow(int num)
+inline void alist::grow(int num)
{
num_grow = num;
}
if ((buf = sm_malloc(fname, lineno, nbytes)) != NULL) {
return buf;
}
- V fprintf(stderr, "\nBoom!!! Memory capacity exceeded.\n");
- V fprintf(stderr, " Requested %u bytes at line %d of %s.\n",
+ V fprintf(stderr, "\nBoom!!! Memory capacity exceeded.\n");
+ V fprintf(stderr, " Requested %u bytes at line %d of %s.\n",
nbytes, lineno, fname);
abort();
/*NOTREACHED*/
if ((buf = malloc(nbytes)) != NULL) {
return buf;
}
- V fprintf(stderr, "\nBoom!!! Memory capacity exceeded.\n");
- V fprintf(stderr, " Requested %u bytes.\n", nbytes);
+ V fprintf(stderr, "\nBoom!!! Memory capacity exceeded.\n");
+ V fprintf(stderr, " Requested %u bytes.\n", nbytes);
abort();
/*NOTREACHED*/
}
/*
* attr.c Unpack an Attribute record returned from the tape
- *
+ *
* Kern Sibbald, June MMIII (code pulled from filed/restore.c and updated)
*
* Version $Id$
int unpack_attributes_record(JCR *jcr, int32_t stream, char *rec, ATTR *attr)
{
char *p;
- /*
+ /*
* An Attributes record consists of:
* File_index
* Type (FT_types)
{ }
while (*p++ != ' ') /* skip type */
{ }
-
+
attr->fname = p; /* set filname position */
while (*p++ != 0) /* skip filename */
{ }
/*
* Build attr->ofname from attr->fname and
- * attr->olname from attr->olname
+ * attr->olname from attr->olname
*/
void build_attr_output_fnames(JCR *jcr, ATTR *attr)
{
* a drive letter -- we simply change the drive
* from, for example, c: to c/ for
* every filename if a prefix is supplied.
- *
+ *
*/
if (jcr->where[0] == 0) {
pm_strcpy(attr->ofname, attr->fname);
int wherelen = strlen(jcr->where);
pm_strcpy(attr->ofname, jcr->where); /* copy prefix */
if (win32_client && attr->fname[1] == ':') {
- attr->fname[1] = '/'; /* convert : to / */
+ attr->fname[1] = '/'; /* convert : to / */
}
fn = attr->fname; /* take whole name */
/* Ensure where is terminated with a slash */
if (jcr->where[wherelen-1] != '/' && fn[0] != '/') {
- pm_strcat(attr->ofname, "/");
- }
+ pm_strcat(attr->ofname, "/");
+ }
pm_strcat(attr->ofname, fn); /* copy rest of name */
/*
* Fixup link name -- if it is an absolute path
/* Always add prefix to hard links (FT_LNKSAVED) and
* on user request to soft links
*/
- if (attr->lname[0] == '/' &&
+ if (attr->lname[0] == '/' &&
(attr->type == FT_LNKSAVED || jcr->prefix_links)) {
pm_strcpy(attr->olname, jcr->where);
add_link = true;
attr->olname[0] = 0;
add_link = false;
}
- if (win32_client && attr->lname[1] == ':') {
- attr->lname[1] = '/'; /* turn : into / */
+ if (win32_client && attr->lname[1] == ':') {
+ attr->lname[1] = '/'; /* turn : into / */
}
fn = attr->lname; /* take whole name */
/* Ensure where is terminated with a slash */
- if (add_link && jcr->where[wherelen-1] != '/' && fn[0] != '/') {
- pm_strcat(attr->olname, "/");
- }
+ if (add_link && jcr->where[wherelen-1] != '/' && fn[0] != '/') {
+ pm_strcat(attr->olname, "/");
+ }
pm_strcat(attr->olname, fn); /* copy rest of link */
}
}
*/
void print_ls_output(JCR *jcr, ATTR *attr)
{
- char buf[5000];
+ char buf[5000];
char ec1[30];
char en1[30], en2[30];
char *p, *f;
/*
* attr.h Definition of attributes packet for unpacking from tape
- *
+ *
* Kern Sibbald, June MMIII
*
* Version $Id$
POOLMEM *ofname; /* output filename */
POOLMEM *olname; /* output link name */
/*
- * Note the following three variables point into the
- * current BSOCK record, so they are invalid after
+ * Note the following three variables point into the
+ * current BSOCK record, so they are invalid after
* the next socket read!
*/
char *attr; /* attributes position */
-/*
+/*
* Generic base 64 input and output routines
*
* Written by Kern E. Sibbald, March MM.
static int base64_inited = 0;
static uint8_t base64_map[128];
-
+
/* Initialize the Base 64 conversion routines */
void
base64_init(void)
-{
- int i;
+{
+ int i;
memset(base64_map, 0, sizeof(base64_map));
for (i=0; i<64; i++)
base64_map[(uint8_t)base64_digits[i]] = i;
*/
int
from_base64(intmax_t *value, char *where)
-{
+{
uintmax_t val = 0;
int i, neg;
- if (!base64_inited)
+ if (!base64_inited)
base64_init();
/* Check if it is negative */
i = neg = 0;
val <<= 6;
val += base64_map[(uint8_t)where[i++]];
}
-
+
*value = neg ? -(intmax_t)val : (intmax_t)val;
return i;
}
* Test the base64 routines by encoding and decoding
* lstat() packets.
*/
-int main(int argc, char *argv[])
+int main(int argc, char *argv[])
{
char where[500];
int i;
time_t t = 1028712799;
if (argc > 1 && strcmp(argv[1], "-v") == 0)
- debug_level++;
+ debug_level++;
base64_init();
for (i=0; my_glob.gl_pathv[i]; i++) {
fname = my_glob.gl_pathv[i];
if (lstat(fname, &statp) < 0) {
- printf("Cannot stat %s: %s\n", fname, strerror(errno));
+ printf("Cannot stat %s: %s\n", fname, strerror(errno));
continue;
}
encode_stat(where, &statp);
printf("Encoded stat=%s\n", where);
-
+
#ifdef xxx
p = where;
p += to_base64((intmax_t)(statp.st_atime), p);
#endif
if (debug_level)
- printf("%s: len=%d val=%s\n", fname, strlen(where), where);
-
+ printf("%s: len=%d val=%s\n", fname, strlen(where), where);
+
decode_stat(where, &statn);
- if (statp.st_dev != statn.st_dev ||
+ if (statp.st_dev != statn.st_dev ||
statp.st_ino != statn.st_ino ||
statp.st_mode != statn.st_mode ||
statp.st_nlink != statn.st_nlink ||
statp.st_mtime != statn.st_mtime ||
statp.st_ctime != statn.st_ctime) {
- printf("%s: %s\n", fname, where);
+ printf("%s: %s\n", fname, where);
encode_stat(where, &statn);
- printf("%s: %s\n", fname, where);
- printf("NOT EQAL\n");
+ printf("%s: %s\n", fname, where);
+ printf("NOT EQAL\n");
}
}
printf("UINT32_MAX=%s\n", where);
return 0;
-}
+}
#endif
const char *berrno::strerror()
{
- int stat = 0;
+ int stat = 0;
#ifdef HAVE_WIN32
LPVOID msg;
if (berrno_ & b_errno_exit) {
stat = (berrno_ & ~b_errno_exit); /* remove bit */
if (stat == 0) {
- return "Child exited normally."; /* this really shouldn't happen */
+ return "Child exited normally."; /* this really shouldn't happen */
} else {
/* Maybe an execvp failure */
if (stat >= 200) {
if (stat < 200 + num_execvp_errors) {
berrno_ = execvp_errors[stat - 200];
} else {
- return "Unknown error during program execvp";
+ return "Unknown error during program execvp";
}
} else {
- Mmsg(&buf_, "Child exited with code %d", stat);
+ Mmsg(&buf_, "Child exited with code %d", stat);
return buf_;
}
/* If we drop out here, berrno_ is set to an execvp errno */
#endif
/* Normal errno */
if (bstrerror(berrno_, buf_, 1024) < 0) {
- return "Invalid errno. No error message possible.";
+ return "Invalid errno. No error message possible.";
}
return buf_;
}
* A more generalized way of handling errno that works with Unix, Windows,
* and with Bacula bpipes.
*
- * It works by picking up errno and creating a memory pool buffer
+ * It works by picking up errno and creating a memory pool buffer
* for editing the message. strerror() does the actual editing, and
* it is thread safe.
*
};
/* Constructor */
-inline berrno::berrno(int pool)
+inline berrno::berrno(int pool)
{
berrno_ = errno;
buf_ = get_pool_memory(pool);
}
-
+
inline berrno::~berrno()
-{
+{
free_pool_memory(buf_);
}
* Kern Sibbald, May MMI previously in src/stored/fdmsg.c
*
* Version $Id$
- *
+ *
*/
/*
Copyright (C) 2001-2004 Kern Sibbald and John Walker
#define msglvl 500
-/*
+/*
* This routine does a bnet_recv(), then if a signal was
* sent, it handles it. The return codes are the same as
* bne_recv() except the BNET_SIGNAL messages that can
* be handled are done so without returning.
*
* Returns number of bytes read (may return zero)
- * Returns -1 on signal (BNET_SIGNAL)
+ * Returns -1 on signal (BNET_SIGNAL)
* Returns -2 on hard end of file (BNET_HARDEOF)
* Returns -3 on error (BNET_ERROR)
*/
n = bnet_recv(sock);
if (n >= 0) { /* normal return */
return n;
- }
+ }
if (is_bnet_stop(sock)) { /* error return */
return n;
}
/* BNET_SIGNAL (-1) return from bnet_recv() => network signal */
switch (sock->msglen) {
case BNET_EOD: /* end of data */
- Dmsg0(msglvl, "Got BNET_EOD\n");
+ Dmsg0(msglvl, "Got BNET_EOD\n");
return n;
case BNET_EOD_POLL:
- Dmsg0(msglvl, "Got BNET_EOD_POLL\n");
+ Dmsg0(msglvl, "Got BNET_EOD_POLL\n");
if (sock->terminated) {
bnet_fsend(sock, TERM_msg);
} else {
}
return n; /* end of data */
case BNET_TERMINATE:
- Dmsg0(msglvl, "Got BNET_TERMINATE\n");
+ Dmsg0(msglvl, "Got BNET_TERMINATE\n");
sock->terminated = 1;
return n;
case BNET_POLL:
- Dmsg0(msglvl, "Got BNET_POLL\n");
+ Dmsg0(msglvl, "Got BNET_POLL\n");
if (sock->terminated) {
bnet_fsend(sock, TERM_msg);
} else {
break;
case BNET_STATUS:
/* *****FIXME***** Implement BNET_STATUS */
- Dmsg0(msglvl, "Got BNET_STATUS\n");
- bnet_fsend(sock, "Status OK\n");
+ Dmsg0(msglvl, "Got BNET_STATUS\n");
+ bnet_fsend(sock, "Status OK\n");
bnet_sig(sock, BNET_EOD);
break;
default:
- Emsg1(M_ERROR, 0, "bget_msg: unknown signal %d\n", sock->msglen);
+ Emsg1(M_ERROR, 0, "bget_msg: unknown signal %d\n", sock->msglen);
break;
}
}
#define __BITS_H_
/* number of bytes to hold n bits */
-#define nbytes_for_bits(n) ((((n)-1)>>3)+1)
+#define nbytes_for_bits(n) ((((n)-1)>>3)+1)
/* test if bit is set */
#define bit_is_set(b, var) (((var)[(b)>>3] & (1<<((b)&0x7))) != 0)
for (i=f; i<=l; i++) \
set_bit(i, var); \
}
-
+
/* clear range of bits */
#define clear_bits(f, l, var) { \
int i; \
*
* by Kern Sibbald
*
- * Adapted and enhanced for Bacula, originally written
+ * Adapted and enhanced for Bacula, originally written
* for inclusion in the Apcupsd package
*
* Version $Id$
if (nwritten != nbytes) {
berrno be;
bsock->b_errno = errno;
- Qmsg1(bsock->jcr, M_FATAL, 0, _("Attr spool write error. ERR=%s\n"),
+ Qmsg1(bsock->jcr, M_FATAL, 0, _("Attr spool write error. ERR=%s\n"),
be.strerror());
- Dmsg2(400, "nwritten=%d nbytes=%d.\n", nwritten, nbytes);
+ Dmsg2(400, "nwritten=%d nbytes=%d.\n", nwritten, nbytes);
errno = bsock->b_errno;
return -1;
}
return nbytes - nleft;
}
-/*
+/*
* Receive a message from the other end. Each message consists of
* two packets. The first is a header that contains the size
* of the data that follows in the second packet.
* Returns number of bytes read (may return zero)
- * Returns -1 on signal (BNET_SIGNAL)
+ * Returns -1 on signal (BNET_SIGNAL)
* Returns -2 on hard end of file (BNET_HARDEOF)
* Returns -3 on error (BNET_ERROR)
*
* four return types:
* 1. Normal data
* 2. Signal including end of data stream
- * 3. Hard end of file
+ * 3. Hard end of file
* 4. Error
* Using is_bnet_stop() and is_bnet_error() you can figure this all out.
*/
if (pktsiz < 0 || pktsiz > 1000000) {
if (pktsiz > 0) { /* if packet too big */
Qmsg3(bsock->jcr, M_FATAL, 0,
- _("Packet size too big from \"%s:%s:%d. Terminating connection.\n"),
+ _("Packet size too big from \"%s:%s:%d. Terminating connection.\n"),
bsock->who, bsock->host, bsock->port);
pktsiz = BNET_TERMINATE; /* hang up */
}
/*
- * Return 1 if there are errors on this bsock or it is closed,
+ * Return 1 if there are errors on this bsock or it is closed,
* i.e. stop communicating on this line.
*/
bool is_bnet_stop(BSOCK * bsock)
}
/*
- * Return number of errors on socket
+ * Return number of errors on socket
*/
int is_bnet_error(BSOCK * bsock)
{
nbytes = fread(bsock->msg, 1, bsock->msglen, bsock->spool_fd);
if (nbytes != (size_t) bsock->msglen) {
berrno be;
- Dmsg2(400, "nbytes=%d msglen=%d\n", nbytes, bsock->msglen);
- Qmsg1(bsock->jcr, M_FATAL, 0, _("fread attr spool error. ERR=%s\n"),
+ Dmsg2(400, "nbytes=%d msglen=%d\n", nbytes, bsock->msglen);
+ Qmsg1(bsock->jcr, M_FATAL, 0, _("fread attr spool error. ERR=%s\n"),
be.strerror());
update_attr_spool_size(tsize - last);
return 0;
if (rc < 0) {
if (!bsock->suppress_error_msgs && !bsock->timed_out) {
Qmsg4(bsock->jcr, M_ERROR, 0,
- _("Write error sending to %s:%s:%d: ERR=%s\n"), bsock->who,
+ _("Write error sending to %s:%s:%d: ERR=%s\n"), bsock->who,
bsock->host, bsock->port, bnet_strerror(bsock));
}
} else {
Qmsg5(bsock->jcr, M_ERROR, 0,
- _("Wrote %d bytes to %s:%s:%d, but only %d accepted.\n"), bsock->who,
+ _("Wrote %d bytes to %s:%s:%d, but only %d accepted.\n"), bsock->who,
bsock->host, bsock->port, bsock->msglen, rc);
}
return false;
if (rc < 0) {
if (!bsock->suppress_error_msgs) {
Qmsg4(bsock->jcr, M_ERROR, 0,
- _("Write error sending to %s:%s:%d: ERR=%s\n"), bsock->who,
+ _("Write error sending to %s:%s:%d: ERR=%s\n"), bsock->who,
bsock->host, bsock->port, bnet_strerror(bsock));
}
} else {
Qmsg5(bsock->jcr, M_ERROR, 0,
- _("Wrote %d bytes to %s:%s:%d, but only %d accepted.\n"),
+ _("Wrote %d bytes to %s:%s:%d, but only %d accepted.\n"),
bsock->msglen, bsock->who, bsock->host, bsock->port, rc);
}
return false;
}
/*
- * Establish an SSL connection -- server side
+ * Establish an SSL connection -- server side
* Codes that ssl_need and ssl_has can take
* BNET_SSL_NONE I cannot do ssl
* BNET_SSL_OK I can do ssl, but it is not required on my end
}
/*
- * Establish an SSL connection -- client side
+ * Establish an SSL connection -- client side
*/
int bnet_ssl_client(BSOCK * bsock, char *password, int ssl_need)
{
return addr_list;
}
-/*
+/*
* Open a TCP connection to the UPS network server
* Returns NULL
* Returns BSOCK * pointer on success
const char *errstr;
int save_errno = 0;
- /*
+ /*
* Fill in the structure serv_addr with the address of
* the server that we want to connect with.
*/
ipaddr->set_port_net(htons(port));
char allbuf[256 * 10];
char curbuf[256];
- Dmsg2(100, "Current %sAll %s\n",
- ipaddr->build_address_str(curbuf, sizeof(curbuf)),
+ Dmsg2(100, "Current %sAll %s\n",
+ ipaddr->build_address_str(curbuf, sizeof(curbuf)),
build_addresses_str(addr_list, allbuf, sizeof(allbuf)));
/* Open a TCP socket */
if ((sockfd = socket(ipaddr->get_family(), SOCK_STREAM, 0)) < 0) {
berrno be;
save_errno = errno;
*fatal = 1;
- Pmsg3(000, "Socket open error. proto=%d port=%d. ERR=%s\n",
+ Pmsg3(000, "Socket open error. proto=%d port=%d. ERR=%s\n",
ipaddr->get_family(), ipaddr->get_port_host_order(), be.strerror());
continue;
}
*/
if (setsockopt(sockfd, SOL_SOCKET, SO_KEEPALIVE, (sockopt_val_t)&turnon, sizeof(turnon)) < 0) {
berrno be;
- Qmsg1(jcr, M_WARNING, 0, _("Cannot set SO_KEEPALIVE on socket: %s\n"),
+ Qmsg1(jcr, M_WARNING, 0, _("Cannot set SO_KEEPALIVE on socket: %s\n"),
be.strerror());
}
/* connect to server */
if (i < 0) {
i = 60 * 5; /* complain again in 5 minutes */
if (verbose)
- Qmsg4(jcr, M_WARNING, 0, "Could not connect to %s on %s:%d. ERR=%s\n\
-Retrying ...\n", name, host, port, be.strerror());
+ Qmsg4(jcr, M_WARNING, 0, "Could not connect to %s on %s:%d. ERR=%s\n"
+"Retrying ...\n", name, host, port, be.strerror());
}
bmicrosleep(retry_interval, 0);
max_retry_time -= retry_interval;
if (max_retry_time <= 0) {
- Qmsg4(jcr, M_FATAL, 0, _("Unable to connect to %s on %s:%d. ERR=%s\n"),
+ Qmsg4(jcr, M_FATAL, 0, _("Unable to connect to %s on %s:%d. ERR=%s\n"),
name, host, port, be.strerror());
return NULL;
}
return bnet_send(bs);
}
-/*
+/*
* Set the network buffer size, suggested size is in size.
* Actual size obtained is returned in bs->msglen
*
return false;
}
if (rw & BNET_SETBUF_READ) {
- while ((dbuf_size > TAPE_BSIZE) && (setsockopt(bs->fd, SOL_SOCKET,
+ while ((dbuf_size > TAPE_BSIZE) && (setsockopt(bs->fd, SOL_SOCKET,
SO_RCVBUF, (sockopt_val_t) & dbuf_size, sizeof(dbuf_size)) < 0)) {
berrno be;
- Qmsg1(bs->jcr, M_ERROR, 0, _("sockopt error: %s\n"), be.strerror());
+ Qmsg1(bs->jcr, M_ERROR, 0, _("sockopt error: %s\n"), be.strerror());
dbuf_size -= TAPE_BSIZE;
}
Dmsg1(200, "set network buffer size=%d\n", dbuf_size);
if (dbuf_size != start_size) {
Qmsg1(bs->jcr, M_WARNING, 0,
- _("Warning network buffer = %d bytes not max size.\n"), dbuf_size);
+ _("Warning network buffer = %d bytes not max size.\n"), dbuf_size);
}
if (dbuf_size % TAPE_BSIZE != 0) {
Qmsg1(bs->jcr, M_ABORT, 0,
- _("Network buffer size %d not multiple of tape block size.\n"),
+ _("Network buffer size %d not multiple of tape block size.\n"),
dbuf_size);
}
}
}
start_size = dbuf_size;
if (rw & BNET_SETBUF_WRITE) {
- while ((dbuf_size > TAPE_BSIZE) && (setsockopt(bs->fd, SOL_SOCKET,
+ while ((dbuf_size > TAPE_BSIZE) && (setsockopt(bs->fd, SOL_SOCKET,
SO_SNDBUF, (sockopt_val_t) & dbuf_size, sizeof(dbuf_size)) < 0)) {
berrno be;
- Qmsg1(bs->jcr, M_ERROR, 0, _("sockopt error: %s\n"), be.strerror());
+ Qmsg1(bs->jcr, M_ERROR, 0, _("sockopt error: %s\n"), be.strerror());
dbuf_size -= TAPE_BSIZE;
}
Dmsg1(200, "set network buffer size=%d\n", dbuf_size);
if (dbuf_size != start_size) {
Qmsg1(bs->jcr, M_WARNING, 0,
- _("Warning network buffer = %d bytes not max size.\n"), dbuf_size);
+ _("Warning network buffer = %d bytes not max size.\n"), dbuf_size);
}
if (dbuf_size % TAPE_BSIZE != 0) {
Qmsg1(bs->jcr, M_ABORT, 0,
- _("Network buffer size %d not multiple of tape block size.\n"),
+ _("Network buffer size %d not multiple of tape block size.\n"),
dbuf_size);
}
}
}
/*
- * Send a network "signal" to the other end
+ * Send a network "signal" to the other end
* This consists of sending a negative packet length
*
* Returns: false on failure
}
-/* Initialize internal socket structure.
+/* Initialize internal socket structure.
* This probably should be done in net_open
*/
BSOCK *init_bsock(JCR * jcr, int sockfd, const char *who, const char *host, int port,
bsock->port = port;
memcpy(&bsock->client_addr, client_addr, sizeof(bsock->client_addr));
/*
- * ****FIXME**** reduce this to a few hours once
+ * ****FIXME**** reduce this to a few hours once
* heartbeats are implemented
*/
bsock->timeout = 60 * 60 * 6 * 24; /* 6 days timeout */
#include "bacula.h"
-/*
+/*
* Receive a message from the other end. Each message consists of
* two packets. The first is a header that contains the size
* of the data that follows in the second packet.
* Returns -1 on hard end of file (i.e. network connection close)
* Returns -2 on error
*/
-int32_t
+int32_t
bnet_recv_pkt(BSOCK *bsock, BPKT *pkt, int *version)
{
unser_declare;
unser_uint16(lversion);
*version = (int)lversion;
-
+
for ( ; pkt->type != BP_EOF; pkt++) {
if (pkt->id) {
ser_int8(BP_ID);
ser_bytes((char *)pkt->value, pkt->len);
break;
default:
- Emsg1(M_ABORT, 0, _("Unknown BPKT type: %d\n"), pkt->type);
+ Emsg1(M_ABORT, 0, _("Unknown BPKT type: %d\n"), pkt->type);
}
}
unser_end(bsock->msg, 0);
-
+
}
/*
ser_bytes((char *)pkt->value, pkt->len);
break;
default:
- Emsg1(M_ABORT, 0, _("Unknown BPKT type: %d\n"), pkt->type);
+ Emsg1(M_ABORT, 0, _("Unknown BPKT type: %d\n"), pkt->type);
}
}
ser_end(bsock->msg, 0);
MA 02111-1307, USA.
*/
- /*
+ /*
* Originally written by Kern Sibbald for inclusion in apcupsd,
* but heavily modified for Bacula
*
}
}
-/*
- Become Threaded Network Server
+/*
+ Become Threaded Network Server
This function is able to handle multiple server ips in
ipv4 and ipv6 style. The Addresse are give in a comma
seperated string in bind_addr
fd_ptr = (s_sockfd *)alloca(sizeof(s_sockfd));
fd_ptr->port = p->get_port_net_order();
/*
- * Open a TCP socket
+ * Open a TCP socket
*/
for (tlog= 60; (fd_ptr->fd=socket(p->get_family(), SOCK_STREAM, 0)) < 0; tlog -= 10) {
if (tlog <= 0) {
berrno be;
char curbuf[256];
- Emsg3(M_ABORT, 0, _("Cannot open stream socket. ERR=%s. Current %s All %s\n"),
+ Emsg3(M_ABORT, 0, _("Cannot open stream socket. ERR=%s. Current %s All %s\n"),
be.strerror(),
- p->build_address_str(curbuf, sizeof(curbuf)),
+ p->build_address_str(curbuf, sizeof(curbuf)),
build_addresses_str(addrs, allbuf, sizeof(allbuf)));
}
bmicrosleep(10, 0);
}
/*
- * Reuse old sockets
+ * Reuse old sockets
*/
if (setsockopt(fd_ptr->fd, SOL_SOCKET, SO_REUSEADDR, (sockopt_val_t)&turnon,
sizeof(turnon)) < 0) {
berrno be;
- Emsg1(M_WARNING, 0, _("Cannot set SO_REUSEADDR on socket: %s\n"),
+ Emsg1(M_WARNING, 0, _("Cannot set SO_REUSEADDR on socket: %s\n"),
be.strerror());
}
berrno be;
if (tlog <= 0) {
tlog = 2 * 60; /* Complain every 2 minutes */
- Emsg2(M_WARNING, 0, _("Cannot bind port %d: ERR=%s. Retrying ...\n"),
+ Emsg2(M_WARNING, 0, _("Cannot bind port %d: ERR=%s. Retrying ...\n"),
ntohs(fd_ptr->port), be.strerror());
}
bmicrosleep(5, 0);
if (--tmax <= 0) {
- Emsg2(M_ABORT, 0, _("Cannot bind port %d: ERR=%s.\n"), ntohs(fd_ptr->port),
+ Emsg2(M_ABORT, 0, _("Cannot bind port %d: ERR=%s.\n"), ntohs(fd_ptr->port),
be.strerror());
}
}
be.set_errno(stat);
Emsg1(M_ABORT, 0, _("Could not init client queue: ERR=%s\n"), be.strerror());
}
- /*
+ /*
* Wait for a connection from the client process.
*/
for (; !quit;) {
close(fd_ptr->fd);
free((void *)fd_ptr);
}
- Emsg1(M_FATAL, 0, _("Error in select: %s\n"), be.strerror());
+ Emsg1(M_FATAL, 0, _("Error in select: %s\n"), be.strerror());
break;
}
if (setsockopt(newsockfd, SOL_SOCKET, SO_KEEPALIVE, (sockopt_val_t)&turnon,
sizeof(turnon)) < 0) {
berrno be;
- Emsg1(M_WARNING, 0, _("Cannot set SO_KEEPALIVE on socket: %s\n"),
+ Emsg1(M_WARNING, 0, _("Cannot set SO_KEEPALIVE on socket: %s\n"),
be.strerror());
}
P(mutex);
sockaddr_to_ascii(&cli_addr, buf, sizeof(buf));
V(mutex);
- BSOCK *bs;
- bs = init_bsock(NULL, newsockfd, "client", buf, fd_ptr->port, &cli_addr);
+ BSOCK *bs;
+ bs = init_bsock(NULL, newsockfd, "client", buf, fd_ptr->port, &cli_addr);
if (bs == NULL) {
- Jmsg0(NULL, M_ABORT, 0, _("Could not create client BSOCK.\n"));
+ Jmsg0(NULL, M_ABORT, 0, _("Could not create client BSOCK.\n"));
}
/* Queue client to be served */
if ((stat = workq_add(client_wq, (void *)bs, NULL, 0)) != 0) {
berrno be;
be.set_errno(stat);
- Jmsg1(NULL, M_ABORT, 0, _("Could not add job to client queue: ERR=%s\n"),
+ Jmsg1(NULL, M_ABORT, 0, _("Could not add job to client queue: ERR=%s\n"),
be.strerror());
}
}
int turnon = 1;
/*
- * Open a TCP socket
+ * Open a TCP socket
*/
for (tlog = 0; (sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0; tlog -= 10) {
if (errno == EINTR || errno == EAGAIN) {
}
if (tlog <= 0) {
tlog = 2 * 60;
- Emsg1(M_ERROR, 0, _("Cannot open stream socket: %s\n"), strerror(errno));
+ Emsg1(M_ERROR, 0, _("Cannot open stream socket: %s\n"), strerror(errno));
}
bmicrosleep(60, 0);
}
/*
- * Reuse old sockets
+ * Reuse old sockets
*/
if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, (sockopt_val_t)&turnon, sizeof(turnon)) < 0) {
Emsg1(M_WARNING, 0, _("Cannot set SO_REUSEADDR on socket: %s\n"),
strerror(errno));
}
- /*
+ /*
* Bind our local address so that the client can send to us.
*/
bzero((char *)&serv_addr, sizeof(serv_addr));
}
if (tlog <= 0) {
tlog = 2 * 60;
- Emsg2(M_WARNING, 0, _("Cannot bind port %d: ERR=%s: retrying ...\n"), port,
+ Emsg2(M_WARNING, 0, _("Cannot bind port %d: ERR=%s: retrying ...\n"), port,
be.strerror());
}
bmicrosleep(5, 0);
}
/*
- * Accept a single connection
+ * Accept a single connection
*/
BSOCK *bnet_accept(BSOCK * bsock, char *who)
{
struct request_info request;
#endif
- /*
+ /*
* Wait for a connection from the client process.
*/
FD_ZERO(&sockset);
FD_SET((unsigned)bsock->fd, &sockset);
for (;;) {
- /*
+ /*
* Wait for a connection from a client process.
*/
ready = sockset;
errno = 0;
continue;
}
- Emsg1(M_FATAL, 0, _("Error in select: %s\n"), strerror(errno));
+ Emsg1(M_FATAL, 0, _("Error in select: %s\n"), strerror(errno));
newsockfd = -1;
break;
}
return NULL;
} else {
if (caller == NULL) {
- caller = "unknown";
+ caller = "unknown";
}
len = strlen(caller) + strlen(who) + 3;
buf = (char *)malloc(len);
/*
* bpipe.c bi-directional pipe
- *
+ *
* Kern Sibbald, November MMII
*
* Version $Id$
#include "bacula.h"
#include "jcr.h"
-int execvp_errors[] = {EACCES, ENOEXEC, EFAULT, EINTR, E2BIG,
+int execvp_errors[] = {EACCES, ENOEXEC, EFAULT, EINTR, E2BIG,
ENAMETOOLONG, ENOMEM, ETXTBSY, ENOENT};
int num_execvp_errors = (int)(sizeof(execvp_errors)/sizeof(int));
* Run an external program. Optionally wait a specified number
* of seconds. Program killed if wait exceeded. We open
* a bi-directional pipe so that the user can read from and
- * write to the program.
+ * write to the program.
*/
BPIPE *open_bpipe(char *prog, int wait, const char *mode)
{
return stat;
}
-/*
- * Close both pipes and free resources
+/*
+ * Close both pipes and free resources
*
* Returns: 0 on success
* berrno on failure
*/
-int close_bpipe(BPIPE *bpipe)
+int close_bpipe(BPIPE *bpipe)
{
int chldstatus = 0;
- int stat = 0;
+ int stat = 0;
int wait_option;
int remaining_wait;
pid_t wpid = 0;
} while (wpid == -1 && (errno == EINTR || errno == EAGAIN));
if (wpid == bpipe->worker_pid || wpid == -1) {
stat = errno;
- Dmsg3(200, "Got break wpid=%d status=%d ERR=%s\n", wpid, chldstatus,
- wpid==-1?strerror(errno):"none");
+ Dmsg3(200, "Got break wpid=%d status=%d ERR=%s\n", wpid, chldstatus,
+ wpid==-1?strerror(errno):"none");
break;
}
Dmsg3(200, "Got wpid=%d status=%d ERR=%s\n", wpid, chldstatus,
- wpid==-1?strerror(errno):"none");
+ wpid==-1?strerror(errno):"none");
if (remaining_wait > 0) {
bmicrosleep(1, 0); /* wait one second */
remaining_wait--;
} else {
stat = ETIME; /* set error status */
wpid = -1;
- break; /* don't wait any longer */
+ break; /* don't wait any longer */
}
}
if (wpid > 0) {
if (WIFEXITED(chldstatus)) { /* process exit()ed */
stat = WEXITSTATUS(chldstatus);
if (stat != 0) {
- Dmsg1(200, "Non-zero status %d returned from child.\n", stat);
+ Dmsg1(200, "Non-zero status %d returned from child.\n", stat);
stat |= b_errno_exit; /* exit status returned */
}
- Dmsg1(200, "child status=%d\n", stat & ~b_errno_exit);
+ Dmsg1(200, "child status=%d\n", stat & ~b_errno_exit);
} else if (WIFSIGNALED(chldstatus)) { /* process died */
stat = WTERMSIG(chldstatus);
- Dmsg1(200, "Child died from signale %d\n", stat);
+ Dmsg1(200, "Child died from signale %d\n", stat);
stat |= b_errno_signal; /* exit signal returned */
}
- }
+ }
if (bpipe->timer_id) {
stop_child_timer(bpipe->timer_id);
}
* of seconds. Program killed if wait exceeded. Optionally
* return the output from the program (normally a single line).
*
- * Contrary to my normal calling conventions, this program
+ * Contrary to my normal calling conventions, this program
*
* Returns: 0 on success
* non-zero on error == berrno status
}
if (results) {
results[0] = 0;
- fgets(results, sizeof_pool_memory(results), bpipe->rfd);
+ fgets(results, sizeof_pool_memory(results), bpipe->rfd);
if (feof(bpipe->rfd)) {
stat1 = 0;
} else {
stat1 = ferror(bpipe->rfd);
}
if (stat1 < 0) {
- Dmsg2(100, "Run program fgets stat=%d ERR=%s\n", stat1, strerror(errno));
+ Dmsg2(100, "Run program fgets stat=%d ERR=%s\n", stat1, strerror(errno));
} else if (stat1 != 0) {
- Dmsg1(100, "Run program fgets stat=%d\n", stat1);
+ Dmsg1(100, "Run program fgets stat=%d\n", stat1);
}
} else {
stat1 = 0;
*/
static void build_argc_argv(char *cmd, int *bargc, char *bargv[], int max_argv)
{
- int i;
+ int i;
char *p, *q, quote;
int argc = 0;
q++;
quote = 0;
} else {
- while (*q && *q != ' ')
+ while (*q && *q != ' ')
q++;
}
if (*q)
- *(q++) = '\0';
+ *(q++) = '\0';
bargv[argc++] = p;
p = q;
- while (*p && (*p == ' ' || *p == '\t'))
+ while (*p && (*p == ' ' || *p == '\t'))
p++;
- if (*p == '\"' || *p == '\'') {
+ if (*p == '\"' || *p == '\'') {
quote = *p;
p++;
}
-/*
+/*
* Bi-directional pipe structure
*
* Version $Id$
#define _LOCAL_SYS_QUEUE_H_
/*
- * This file defines five types of data structures: singly-linked lists,
+ * This file defines five types of data structures: singly-linked lists,
* lists, simple queues, tail queues, and circular queues.
*
*
*/
#define SLIST_HEAD(name, type) \
struct name { \
- struct type *slh_first; /* first element */ \
+ struct type *slh_first; /* first element */ \
}
-
+
#define SLIST_HEAD_INITIALIZER(head) \
- { NULL }
-
+ { NULL }
+
/* Conflicts with winnt.h */
#define bSLIST_ENTRY(type) \
struct { \
- struct type *sle_next; /* next element */ \
+ struct type *sle_next; /* next element */ \
}
-
+
/*
* Singly-linked List access methods.
*/
#define SLIST_NEXT(elm, field) ((elm)->field.sle_next)
#define SLIST_FOREACH(var, head, field) \
- for((var) = SLIST_FIRST(head); \
- (var) != SLIST_END(head); \
- (var) = SLIST_NEXT(var, field))
+ for((var) = SLIST_FIRST(head); \
+ (var) != SLIST_END(head); \
+ (var) = SLIST_NEXT(var, field))
#define SLIST_FOREACH_SAFE(var, head, field, tvar) \
- for((var) = SLIST_FIRST(head); \
- (var) != SLIST_END(head) && \
- ((tvar) = SLIST_NEXT(var, field), 1); \
- (var) = (tvar))
+ for((var) = SLIST_FIRST(head); \
+ (var) != SLIST_END(head) && \
+ ((tvar) = SLIST_NEXT(var, field), 1); \
+ (var) = (tvar))
/*
* Singly-linked List functions.
*/
#define SLIST_INIT(head) { \
- SLIST_FIRST(head) = SLIST_END(head); \
+ SLIST_FIRST(head) = SLIST_END(head); \
}
#define SLIST_INSERT_AFTER(slistelm, elm, field) do { \
- (elm)->field.sle_next = (slistelm)->field.sle_next; \
- (slistelm)->field.sle_next = (elm); \
+ (elm)->field.sle_next = (slistelm)->field.sle_next; \
+ (slistelm)->field.sle_next = (elm); \
} while (0)
#define SLIST_INSERT_HEAD(head, elm, field) do { \
- (elm)->field.sle_next = (head)->slh_first; \
- (head)->slh_first = (elm); \
+ (elm)->field.sle_next = (head)->slh_first; \
+ (head)->slh_first = (elm); \
} while (0)
#define SLIST_REMOVE_HEAD(head, field) do { \
- (head)->slh_first = (head)->slh_first->field.sle_next; \
+ (head)->slh_first = (head)->slh_first->field.sle_next; \
} while (0)
#define SLIST_REMOVE(head, elm, type, field) do { \
- if ((head)->slh_first == (elm)) { \
- SLIST_REMOVE_HEAD((head), field); \
- } \
- else { \
- struct type *curelm = (head)->slh_first; \
- while( curelm->field.sle_next != (elm) ) \
- curelm = curelm->field.sle_next; \
- curelm->field.sle_next = \
- curelm->field.sle_next->field.sle_next; \
- } \
+ if ((head)->slh_first == (elm)) { \
+ SLIST_REMOVE_HEAD((head), field); \
+ } \
+ else { \
+ struct type *curelm = (head)->slh_first; \
+ while( curelm->field.sle_next != (elm) ) \
+ curelm = curelm->field.sle_next; \
+ curelm->field.sle_next = \
+ curelm->field.sle_next->field.sle_next; \
+ } \
} while (0)
/*
*/
#define LIST_HEAD(name, type) \
struct name { \
- struct type *lh_first; /* first element */ \
+ struct type *lh_first; /* first element */ \
}
#define LIST_HEAD_INITIALIZER(head) \
- { NULL }
+ { NULL }
#define LIST_ENTRY(type) \
struct { \
- struct type *le_next; /* next element */ \
- struct type **le_prev; /* address of previous next element */ \
+ struct type *le_next; /* next element */ \
+ struct type **le_prev; /* address of previous next element */ \
}
/*
#define LIST_NEXT(elm, field) ((elm)->field.le_next)
#define LIST_FOREACH(var, head, field) \
- for((var) = LIST_FIRST(head); \
- (var)!= LIST_END(head); \
- (var) = LIST_NEXT(var, field))
+ for((var) = LIST_FIRST(head); \
+ (var)!= LIST_END(head); \
+ (var) = LIST_NEXT(var, field))
#define LIST_FOREACH_SAFE(var, head, field, tvar) \
- for((var) = LIST_FIRST(head); \
- (var)!= LIST_END(head) && \
- ((tvar) = LIST_NEXT(var, field), 1); \
- (var) = (tvar))
+ for((var) = LIST_FIRST(head); \
+ (var)!= LIST_END(head) && \
+ ((tvar) = LIST_NEXT(var, field), 1); \
+ (var) = (tvar))
/*
* List functions.
*/
#define LIST_INIT(head) do { \
- LIST_FIRST(head) = LIST_END(head); \
+ LIST_FIRST(head) = LIST_END(head); \
} while (0)
#define LIST_INSERT_AFTER(listelm, elm, field) do { \
- if (((elm)->field.le_next = (listelm)->field.le_next) != NULL) \
- (listelm)->field.le_next->field.le_prev = \
- &(elm)->field.le_next; \
- (listelm)->field.le_next = (elm); \
- (elm)->field.le_prev = &(listelm)->field.le_next; \
+ if (((elm)->field.le_next = (listelm)->field.le_next) != NULL) \
+ (listelm)->field.le_next->field.le_prev = \
+ &(elm)->field.le_next; \
+ (listelm)->field.le_next = (elm); \
+ (elm)->field.le_prev = &(listelm)->field.le_next; \
} while (0)
#define LIST_INSERT_BEFORE(listelm, elm, field) do { \
- (elm)->field.le_prev = (listelm)->field.le_prev; \
- (elm)->field.le_next = (listelm); \
- *(listelm)->field.le_prev = (elm); \
- (listelm)->field.le_prev = &(elm)->field.le_next; \
+ (elm)->field.le_prev = (listelm)->field.le_prev; \
+ (elm)->field.le_next = (listelm); \
+ *(listelm)->field.le_prev = (elm); \
+ (listelm)->field.le_prev = &(elm)->field.le_next; \
} while (0)
#define LIST_INSERT_HEAD(head, elm, field) do { \
- if (((elm)->field.le_next = (head)->lh_first) != NULL) \
- (head)->lh_first->field.le_prev = &(elm)->field.le_next;\
- (head)->lh_first = (elm); \
- (elm)->field.le_prev = &(head)->lh_first; \
+ if (((elm)->field.le_next = (head)->lh_first) != NULL) \
+ (head)->lh_first->field.le_prev = &(elm)->field.le_next;\
+ (head)->lh_first = (elm); \
+ (elm)->field.le_prev = &(head)->lh_first; \
} while (0)
#define LIST_REMOVE(elm, field) do { \
- if ((elm)->field.le_next != NULL) \
- (elm)->field.le_next->field.le_prev = \
- (elm)->field.le_prev; \
- *(elm)->field.le_prev = (elm)->field.le_next; \
+ if ((elm)->field.le_next != NULL) \
+ (elm)->field.le_next->field.le_prev = \
+ (elm)->field.le_prev; \
+ *(elm)->field.le_prev = (elm)->field.le_next; \
} while (0)
#define LIST_REPLACE(elm, elm2, field) do { \
- if (((elm2)->field.le_next = (elm)->field.le_next) != NULL) \
- (elm2)->field.le_next->field.le_prev = \
- &(elm2)->field.le_next; \
- (elm2)->field.le_prev = (elm)->field.le_prev; \
- *(elm2)->field.le_prev = (elm2); \
+ if (((elm2)->field.le_next = (elm)->field.le_next) != NULL) \
+ (elm2)->field.le_next->field.le_prev = \
+ &(elm2)->field.le_next; \
+ (elm2)->field.le_prev = (elm)->field.le_prev; \
+ *(elm2)->field.le_prev = (elm2); \
} while (0)
/*
*/
#define SIMPLEQ_HEAD(name, type) \
struct name { \
- struct type *sqh_first; /* first element */ \
- struct type **sqh_last; /* addr of last next element */ \
+ struct type *sqh_first; /* first element */ \
+ struct type **sqh_last; /* addr of last next element */ \
}
#define SIMPLEQ_HEAD_INITIALIZER(head) \
- { NULL, &(head).sqh_first }
+ { NULL, &(head).sqh_first }
#define SIMPLEQ_ENTRY(type) \
struct { \
- struct type *sqe_next; /* next element */ \
+ struct type *sqe_next; /* next element */ \
}
/*
#define SIMPLEQ_NEXT(elm, field) ((elm)->field.sqe_next)
#define SIMPLEQ_FOREACH(var, head, field) \
- for((var) = SIMPLEQ_FIRST(head); \
- (var) != SIMPLEQ_END(head); \
- (var) = SIMPLEQ_NEXT(var, field))
+ for((var) = SIMPLEQ_FIRST(head); \
+ (var) != SIMPLEQ_END(head); \
+ (var) = SIMPLEQ_NEXT(var, field))
#define SIMPLEQ_FOREACH_SAFE(var, head, field, tvar) \
- for((var) = SIMPLEQ_FIRST(head); \
- (var) != SIMPLEQ_END(head) && \
- ((tvar) = SIMPLEQ_NEXT(var, field), 1); \
- (var) = (tvar))
+ for((var) = SIMPLEQ_FIRST(head); \
+ (var) != SIMPLEQ_END(head) && \
+ ((tvar) = SIMPLEQ_NEXT(var, field), 1); \
+ (var) = (tvar))
/*
* Simple queue functions.
*/
#define SIMPLEQ_INIT(head) do { \
- (head)->sqh_first = NULL; \
- (head)->sqh_last = &(head)->sqh_first; \
+ (head)->sqh_first = NULL; \
+ (head)->sqh_last = &(head)->sqh_first; \
} while (0)
#define SIMPLEQ_INSERT_HEAD(head, elm, field) do { \
- if (((elm)->field.sqe_next = (head)->sqh_first) == NULL) \
- (head)->sqh_last = &(elm)->field.sqe_next; \
- (head)->sqh_first = (elm); \
+ if (((elm)->field.sqe_next = (head)->sqh_first) == NULL) \
+ (head)->sqh_last = &(elm)->field.sqe_next; \
+ (head)->sqh_first = (elm); \
} while (0)
#define SIMPLEQ_INSERT_TAIL(head, elm, field) do { \
- (elm)->field.sqe_next = NULL; \
- *(head)->sqh_last = (elm); \
- (head)->sqh_last = &(elm)->field.sqe_next; \
+ (elm)->field.sqe_next = NULL; \
+ *(head)->sqh_last = (elm); \
+ (head)->sqh_last = &(elm)->field.sqe_next; \
} while (0)
#define SIMPLEQ_INSERT_AFTER(head, listelm, elm, field) do { \
- if (((elm)->field.sqe_next = (listelm)->field.sqe_next) == NULL)\
- (head)->sqh_last = &(elm)->field.sqe_next; \
- (listelm)->field.sqe_next = (elm); \
+ if (((elm)->field.sqe_next = (listelm)->field.sqe_next) == NULL)\
+ (head)->sqh_last = &(elm)->field.sqe_next; \
+ (listelm)->field.sqe_next = (elm); \
} while (0)
#define SIMPLEQ_REMOVE_HEAD(head, elm, field) do { \
- if (((head)->sqh_first = (elm)->field.sqe_next) == NULL) \
- (head)->sqh_last = &(head)->sqh_first; \
+ if (((head)->sqh_first = (elm)->field.sqe_next) == NULL) \
+ (head)->sqh_last = &(head)->sqh_first; \
} while (0)
/*
*/
#define TAILQ_HEAD(name, type) \
struct name { \
- struct type *tqh_first; /* first element */ \
- struct type **tqh_last; /* addr of last next element */ \
+ struct type *tqh_first; /* first element */ \
+ struct type **tqh_last; /* addr of last next element */ \
}
#define TAILQ_HEAD_INITIALIZER(head) \
- { NULL, &(head).tqh_first }
+ { NULL, &(head).tqh_first }
#define TAILQ_ENTRY(type) \
struct { \
- struct type *tqe_next; /* next element */ \
- struct type **tqe_prev; /* address of previous next element */ \
+ struct type *tqe_next; /* next element */ \
+ struct type **tqe_prev; /* address of previous next element */ \
}
-/*
- * tail queue access methods
+/*
+ * tail queue access methods
*/
#define TAILQ_FIRST(head) ((head)->tqh_first)
#define TAILQ_END(head) NULL
#define TAILQ_NEXT(elm, field) ((elm)->field.tqe_next)
#define TAILQ_LAST(head, headname) \
- (*(((struct headname *)((head)->tqh_last))->tqh_last))
+ (*(((struct headname *)((head)->tqh_last))->tqh_last))
/* XXX */
#define TAILQ_PREV(elm, headname, field) \
- (*(((struct headname *)((elm)->field.tqe_prev))->tqh_last))
+ (*(((struct headname *)((elm)->field.tqe_prev))->tqh_last))
#define TAILQ_EMPTY(head) \
- (TAILQ_FIRST(head) == TAILQ_END(head))
+ (TAILQ_FIRST(head) == TAILQ_END(head))
#define TAILQ_FOREACH(var, head, field) \
- for((var) = TAILQ_FIRST(head); \
- (var) != TAILQ_END(head); \
- (var) = TAILQ_NEXT(var, field))
+ for((var) = TAILQ_FIRST(head); \
+ (var) != TAILQ_END(head); \
+ (var) = TAILQ_NEXT(var, field))
#define TAILQ_FOREACH_SAFE(var, head, field, tvar) \
- for((var) = TAILQ_FIRST(head); \
- (var) != TAILQ_END(head) && \
- ((tvar) = TAILQ_NEXT(var, field), 1); \
- (var) = (tvar))
+ for((var) = TAILQ_FIRST(head); \
+ (var) != TAILQ_END(head) && \
+ ((tvar) = TAILQ_NEXT(var, field), 1); \
+ (var) = (tvar))
#define TAILQ_FOREACH_REVERSE(var, head, field, headname) \
- for((var) = TAILQ_LAST(head, headname); \
- (var) != TAILQ_END(head); \
- (var) = TAILQ_PREV(var, headname, field))
+ for((var) = TAILQ_LAST(head, headname); \
+ (var) != TAILQ_END(head); \
+ (var) = TAILQ_PREV(var, headname, field))
#define TAILQ_FOREACH_REVERSE_SAFE(var, head, field, headname, tvar) \
- for((var) = TAILQ_LAST(head, headname); \
- (var) != TAILQ_END(head) && \
- ((tvar) = TAILQ_PREV(var, headname, field), 1); \
- (var) = (tvar))
+ for((var) = TAILQ_LAST(head, headname); \
+ (var) != TAILQ_END(head) && \
+ ((tvar) = TAILQ_PREV(var, headname, field), 1); \
+ (var) = (tvar))
/*
* Tail queue functions.
*/
#define TAILQ_INIT(head) do { \
- (head)->tqh_first = NULL; \
- (head)->tqh_last = &(head)->tqh_first; \
+ (head)->tqh_first = NULL; \
+ (head)->tqh_last = &(head)->tqh_first; \
} while (0)
#define TAILQ_INSERT_HEAD(head, elm, field) do { \
- if (((elm)->field.tqe_next = (head)->tqh_first) != NULL) \
- (head)->tqh_first->field.tqe_prev = \
- &(elm)->field.tqe_next; \
- else \
- (head)->tqh_last = &(elm)->field.tqe_next; \
- (head)->tqh_first = (elm); \
- (elm)->field.tqe_prev = &(head)->tqh_first; \
+ if (((elm)->field.tqe_next = (head)->tqh_first) != NULL) \
+ (head)->tqh_first->field.tqe_prev = \
+ &(elm)->field.tqe_next; \
+ else \
+ (head)->tqh_last = &(elm)->field.tqe_next; \
+ (head)->tqh_first = (elm); \
+ (elm)->field.tqe_prev = &(head)->tqh_first; \
} while (0)
#define TAILQ_INSERT_TAIL(head, elm, field) do { \
- (elm)->field.tqe_next = NULL; \
- (elm)->field.tqe_prev = (head)->tqh_last; \
- *(head)->tqh_last = (elm); \
- (head)->tqh_last = &(elm)->field.tqe_next; \
+ (elm)->field.tqe_next = NULL; \
+ (elm)->field.tqe_prev = (head)->tqh_last; \
+ *(head)->tqh_last = (elm); \
+ (head)->tqh_last = &(elm)->field.tqe_next; \
} while (0)
#define TAILQ_INSERT_AFTER(head, listelm, elm, field) do { \
- if (((elm)->field.tqe_next = (listelm)->field.tqe_next) != NULL)\
- (elm)->field.tqe_next->field.tqe_prev = \
- &(elm)->field.tqe_next; \
- else \
- (head)->tqh_last = &(elm)->field.tqe_next; \
- (listelm)->field.tqe_next = (elm); \
- (elm)->field.tqe_prev = &(listelm)->field.tqe_next; \
+ if (((elm)->field.tqe_next = (listelm)->field.tqe_next) != NULL)\
+ (elm)->field.tqe_next->field.tqe_prev = \
+ &(elm)->field.tqe_next; \
+ else \
+ (head)->tqh_last = &(elm)->field.tqe_next; \
+ (listelm)->field.tqe_next = (elm); \
+ (elm)->field.tqe_prev = &(listelm)->field.tqe_next; \
} while (0)
#define TAILQ_INSERT_BEFORE(listelm, elm, field) do { \
- (elm)->field.tqe_prev = (listelm)->field.tqe_prev; \
- (elm)->field.tqe_next = (listelm); \
- *(listelm)->field.tqe_prev = (elm); \
- (listelm)->field.tqe_prev = &(elm)->field.tqe_next; \
+ (elm)->field.tqe_prev = (listelm)->field.tqe_prev; \
+ (elm)->field.tqe_next = (listelm); \
+ *(listelm)->field.tqe_prev = (elm); \
+ (listelm)->field.tqe_prev = &(elm)->field.tqe_next; \
} while (0)
#define TAILQ_REMOVE(head, elm, field) do { \
- if (((elm)->field.tqe_next) != NULL) \
- (elm)->field.tqe_next->field.tqe_prev = \
- (elm)->field.tqe_prev; \
- else \
- (head)->tqh_last = (elm)->field.tqe_prev; \
- *(elm)->field.tqe_prev = (elm)->field.tqe_next; \
+ if (((elm)->field.tqe_next) != NULL) \
+ (elm)->field.tqe_next->field.tqe_prev = \
+ (elm)->field.tqe_prev; \
+ else \
+ (head)->tqh_last = (elm)->field.tqe_prev; \
+ *(elm)->field.tqe_prev = (elm)->field.tqe_next; \
} while (0)
#define TAILQ_REPLACE(head, elm, elm2, field) do { \
- if (((elm2)->field.tqe_next = (elm)->field.tqe_next) != NULL) \
- (elm2)->field.tqe_next->field.tqe_prev = \
- &(elm2)->field.tqe_next; \
- else \
- (head)->tqh_last = &(elm2)->field.tqe_next; \
- (elm2)->field.tqe_prev = (elm)->field.tqe_prev; \
- *(elm2)->field.tqe_prev = (elm2); \
+ if (((elm2)->field.tqe_next = (elm)->field.tqe_next) != NULL) \
+ (elm2)->field.tqe_next->field.tqe_prev = \
+ &(elm2)->field.tqe_next; \
+ else \
+ (head)->tqh_last = &(elm2)->field.tqe_next; \
+ (elm2)->field.tqe_prev = (elm)->field.tqe_prev; \
+ *(elm2)->field.tqe_prev = (elm2); \
} while (0)
/*
*/
#define CIRCLEQ_HEAD(name, type) \
struct name { \
- struct type *cqh_first; /* first element */ \
- struct type *cqh_last; /* last element */ \
+ struct type *cqh_first; /* first element */ \
+ struct type *cqh_last; /* last element */ \
}
#define CIRCLEQ_HEAD_INITIALIZER(head) \
- { CIRCLEQ_END(&head), CIRCLEQ_END(&head) }
+ { CIRCLEQ_END(&head), CIRCLEQ_END(&head) }
#define CIRCLEQ_ENTRY(type) \
struct { \
- struct type *cqe_next; /* next element */ \
- struct type *cqe_prev; /* previous element */ \
+ struct type *cqe_next; /* next element */ \
+ struct type *cqe_prev; /* previous element */ \
}
/*
- * Circular queue access methods
+ * Circular queue access methods
*/
#define CIRCLEQ_FIRST(head) ((head)->cqh_first)
#define CIRCLEQ_LAST(head) ((head)->cqh_last)
#define CIRCLEQ_NEXT(elm, field) ((elm)->field.cqe_next)
#define CIRCLEQ_PREV(elm, field) ((elm)->field.cqe_prev)
#define CIRCLEQ_EMPTY(head) \
- (CIRCLEQ_FIRST(head) == CIRCLEQ_END(head))
+ (CIRCLEQ_FIRST(head) == CIRCLEQ_END(head))
#define CIRCLEQ_FOREACH(var, head, field) \
- for((var) = CIRCLEQ_FIRST(head); \
- (var) != CIRCLEQ_END(head); \
- (var) = CIRCLEQ_NEXT(var, field))
+ for((var) = CIRCLEQ_FIRST(head); \
+ (var) != CIRCLEQ_END(head); \
+ (var) = CIRCLEQ_NEXT(var, field))
#define CIRCLEQ_FOREACH_SAFE(var, head, field, tvar) \
- for((var) = CIRCLEQ_FIRST(head); \
- (var) != CIRCLEQ_END(head) && \
- ((tvar) = CIRCLEQ_NEXT(var, field), 1); \
- (var) = (tvar))
+ for((var) = CIRCLEQ_FIRST(head); \
+ (var) != CIRCLEQ_END(head) && \
+ ((tvar) = CIRCLEQ_NEXT(var, field), 1); \
+ (var) = (tvar))
#define CIRCLEQ_FOREACH_REVERSE(var, head, field) \
- for((var) = CIRCLEQ_LAST(head); \
- (var) != CIRCLEQ_END(head); \
- (var) = CIRCLEQ_PREV(var, field))
+ for((var) = CIRCLEQ_LAST(head); \
+ (var) != CIRCLEQ_END(head); \
+ (var) = CIRCLEQ_PREV(var, field))
#define CIRCLEQ_FOREACH_REVERSE_SAFE(var, head, field, tvar) \
- for((var) = CIRCLEQ_LAST(head); \
- (var) != CIRCLEQ_END(head) && \
- ((tvar) = CIRCLEQ_PREV(var, field), 1); \
- (var) = (tvar))
+ for((var) = CIRCLEQ_LAST(head); \
+ (var) != CIRCLEQ_END(head) && \
+ ((tvar) = CIRCLEQ_PREV(var, field), 1); \
+ (var) = (tvar))
/*
* Circular queue functions.
*/
#define CIRCLEQ_INIT(head) do { \
- (head)->cqh_first = CIRCLEQ_END(head); \
- (head)->cqh_last = CIRCLEQ_END(head); \
+ (head)->cqh_first = CIRCLEQ_END(head); \
+ (head)->cqh_last = CIRCLEQ_END(head); \
} while (0)
#define CIRCLEQ_INSERT_AFTER(head, listelm, elm, field) do { \
- (elm)->field.cqe_next = (listelm)->field.cqe_next; \
- (elm)->field.cqe_prev = (listelm); \
- if ((listelm)->field.cqe_next == CIRCLEQ_END(head)) \
- (head)->cqh_last = (elm); \
- else \
- (listelm)->field.cqe_next->field.cqe_prev = (elm); \
- (listelm)->field.cqe_next = (elm); \
+ (elm)->field.cqe_next = (listelm)->field.cqe_next; \
+ (elm)->field.cqe_prev = (listelm); \
+ if ((listelm)->field.cqe_next == CIRCLEQ_END(head)) \
+ (head)->cqh_last = (elm); \
+ else \
+ (listelm)->field.cqe_next->field.cqe_prev = (elm); \
+ (listelm)->field.cqe_next = (elm); \
} while (0)
#define CIRCLEQ_INSERT_BEFORE(head, listelm, elm, field) do { \
- (elm)->field.cqe_next = (listelm); \
- (elm)->field.cqe_prev = (listelm)->field.cqe_prev; \
- if ((listelm)->field.cqe_prev == CIRCLEQ_END(head)) \
- (head)->cqh_first = (elm); \
- else \
- (listelm)->field.cqe_prev->field.cqe_next = (elm); \
- (listelm)->field.cqe_prev = (elm); \
+ (elm)->field.cqe_next = (listelm); \
+ (elm)->field.cqe_prev = (listelm)->field.cqe_prev; \
+ if ((listelm)->field.cqe_prev == CIRCLEQ_END(head)) \
+ (head)->cqh_first = (elm); \
+ else \
+ (listelm)->field.cqe_prev->field.cqe_next = (elm); \
+ (listelm)->field.cqe_prev = (elm); \
} while (0)
#define CIRCLEQ_INSERT_HEAD(head, elm, field) do { \
- (elm)->field.cqe_next = (head)->cqh_first; \
- (elm)->field.cqe_prev = CIRCLEQ_END(head); \
- if ((head)->cqh_last == CIRCLEQ_END(head)) \
- (head)->cqh_last = (elm); \
- else \
- (head)->cqh_first->field.cqe_prev = (elm); \
- (head)->cqh_first = (elm); \
+ (elm)->field.cqe_next = (head)->cqh_first; \
+ (elm)->field.cqe_prev = CIRCLEQ_END(head); \
+ if ((head)->cqh_last == CIRCLEQ_END(head)) \
+ (head)->cqh_last = (elm); \
+ else \
+ (head)->cqh_first->field.cqe_prev = (elm); \
+ (head)->cqh_first = (elm); \
} while (0)
#define CIRCLEQ_INSERT_TAIL(head, elm, field) do { \
- (elm)->field.cqe_next = CIRCLEQ_END(head); \
- (elm)->field.cqe_prev = (head)->cqh_last; \
- if ((head)->cqh_first == CIRCLEQ_END(head)) \
- (head)->cqh_first = (elm); \
- else \
- (head)->cqh_last->field.cqe_next = (elm); \
- (head)->cqh_last = (elm); \
+ (elm)->field.cqe_next = CIRCLEQ_END(head); \
+ (elm)->field.cqe_prev = (head)->cqh_last; \
+ if ((head)->cqh_first == CIRCLEQ_END(head)) \
+ (head)->cqh_first = (elm); \
+ else \
+ (head)->cqh_last->field.cqe_next = (elm); \
+ (head)->cqh_last = (elm); \
} while (0)
#define CIRCLEQ_REMOVE(head, elm, field) do { \
- if ((elm)->field.cqe_next == CIRCLEQ_END(head)) \
- (head)->cqh_last = (elm)->field.cqe_prev; \
- else \
- (elm)->field.cqe_next->field.cqe_prev = \
- (elm)->field.cqe_prev; \
- if ((elm)->field.cqe_prev == CIRCLEQ_END(head)) \
- (head)->cqh_first = (elm)->field.cqe_next; \
- else \
- (elm)->field.cqe_prev->field.cqe_next = \
- (elm)->field.cqe_next; \
+ if ((elm)->field.cqe_next == CIRCLEQ_END(head)) \
+ (head)->cqh_last = (elm)->field.cqe_prev; \
+ else \
+ (elm)->field.cqe_next->field.cqe_prev = \
+ (elm)->field.cqe_prev; \
+ if ((elm)->field.cqe_prev == CIRCLEQ_END(head)) \
+ (head)->cqh_first = (elm)->field.cqe_next; \
+ else \
+ (elm)->field.cqe_prev->field.cqe_next = \
+ (elm)->field.cqe_next; \
} while (0)
#define CIRCLEQ_REPLACE(head, elm, elm2, field) do { \
- if (((elm2)->field.cqe_next = (elm)->field.cqe_next) == \
- CIRCLEQ_END(head)) \
- (head).cqh_last = (elm2); \
- else \
- (elm2)->field.cqe_next->field.cqe_prev = (elm2); \
- if (((elm2)->field.cqe_prev = (elm)->field.cqe_prev) == \
- CIRCLEQ_END(head)) \
- (head).cqh_first = (elm2); \
- else \
- (elm2)->field.cqe_prev->field.cqe_next = (elm2); \
+ if (((elm2)->field.cqe_next = (elm)->field.cqe_next) == \
+ CIRCLEQ_END(head)) \
+ (head).cqh_last = (elm2); \
+ else \
+ (elm2)->field.cqe_next->field.cqe_prev = (elm2); \
+ if (((elm2)->field.cqe_prev = (elm)->field.cqe_prev) == \
+ CIRCLEQ_END(head)) \
+ (head).cqh_first = (elm2); \
+ else \
+ (elm2)->field.cqe_prev->field.cqe_next = (elm2); \
} while (0)
#endif /* !_LOCAL_SYS_QUEUE_H_ */
* To avoid problems with several return arguments, we
* pass a packet.
*
- * BSHM definition is in bshm.h
+ * BSHM definition is in bshm.h
*
* By Kern Sibbald, May MM
*
Dmsg1(110, "shm_create size=%d\n", shm->size);
for (i=0; i<MAX_TRIES; i++) {
if ((shmid = shmget(shmkey, shm->size, shm->perms | IPC_CREAT)) < 0) {
- Emsg1(M_WARN, 0, "shmget failure key = %x\n", shmkey);
+ Emsg1(M_WARN, 0, "shmget failure key = %x\n", shmkey);
shmkey++;
continue;
}
not_found = FALSE;
break;
}
- if (not_found)
+ if (not_found)
Emsg2(M_ABORT, 0, "Could not get %d bytes of shared memory: %s\n", shm->size, strerror(errno));
shm->shmkey = shmkey;
shm->shmid = shmid;
Dmsg2(110, "shm_create return key=%x id=%d\n", shmkey, shmid);
shmkey++; /* leave set for next time */
-#else
+#else
shm->shmbuf = NULL;
shm->shmkey = 0; /* reference count */
#endif
if ((shmid = shmget(shm->shmkey, shm->size, 0)) < 0)
Emsg2(M_ABORT, 0, "Could not get %d bytes of shared memory: %s\n", shm->size, strerror(errno));
Dmsg1(110, "shm_open shmat with id=%d\n", shmid);
- shmbuf = shmat(shmid, NULL, 0);
+ shmbuf = shmat(shmid, NULL, 0);
Dmsg1(110, "shm_open buf=%x\n", shmbuf);
if (shmbuf == (char *) -1)
Emsg1(M_ABORT, 0, "Could not attach shared memory: %s\n", strerror(errno));
#ifdef NEED_SHARED_MEMORY
if (shm->size) {
if (shmdt(shm->shmbuf) < 0) {
- Emsg1(M_ERROR, 0, "Error detaching shared memory: %s\n", strerror(errno));
+ Emsg1(M_ERROR, 0, "Error detaching shared memory: %s\n", strerror(errno));
}
}
#else
#ifdef NEED_SHARED_MEMORY
if (shm->size) {
if (shmctl(shm->shmid, IPC_RMID, NULL) < 0) {
- Emsg1(M_ERROR, 0, "Could not destroy shared memory: %s\n", strerror(errno));
+ Emsg1(M_ERROR, 0, "Could not destroy shared memory: %s\n", strerror(errno));
}
}
#else
FILE *spool_fd; /* spooling file */
JCR *jcr; /* jcr or NULL for error msgs */
struct sockaddr client_addr; /* client's IP address */
-};
+};
/* Signal definitions for use in bnet_sig() */
enum {
void *value; /* pointer to value */
} BPKT;
-/*
+/*
* These are the data types that can be sent.
* For all values other than string, the storage space
* is assumed to be allocated in the receiving packet.
- * For BP_STRING if the *value is non-zero, it is a
+ * For BP_STRING if the *value is non-zero, it is a
* pointer to a POOLMEM buffer, and the Memory Pool
* routines will be used to assure that the length is
* adequate. NOTE!!! This pointer will be changed
/*
* Miscellaneous Bacula memory and thread safe routines
* Generally, these are interfaces to system or standard
- * library routines.
- *
+ * library routines.
+ *
* Bacula utility functions are in util.c
*
* Version $Id$
/*
* Implement snprintf
*/
-int bsnprintf(char *str, int32_t size, const char *fmt, ...)
+int bsnprintf(char *str, int32_t size, const char *fmt, ...)
{
va_list arg_ptr;
int len;
{
static pthread_mutex_t mutex;
static bool first = true;
- struct tm *ltm,
+ struct tm *ltm,
if (first) {
pthread_mutex_init(&mutex, NULL);
e_msg(file, line, M_ERROR, 0, _("Possible mutex deadlock.\n"));
/* We didn't get the lock, so do it definitely now */
if ((errstat=pthread_mutex_lock(m))) {
- e_msg(file, line, M_ABORT, 0, _("Mutex lock failure. ERR=%s\n"),
+ e_msg(file, line, M_ABORT, 0, _("Mutex lock failure. ERR=%s\n"),
strerror(errstat));
} else {
- e_msg(file, line, M_ERROR, 0, _("Possible mutex deadlock resolved.\n"));
+ e_msg(file, line, M_ERROR, 0, _("Possible mutex deadlock resolved.\n"));
}
-
+
}
}
if (stat(fname, &statp) == 0) {
/* File exists, see what we have */
*pidbuf = 0;
- if ((pidfd = open(fname, O_RDONLY|O_BINARY, 0)) < 0 ||
+ if ((pidfd = open(fname, O_RDONLY|O_BINARY, 0)) < 0 ||
read(pidfd, &pidbuf, sizeof(pidbuf)) < 0 ||
- sscanf(pidbuf, "%d", &oldpid) != 1) {
- Emsg2(M_ERROR_TERM, 0, _("Cannot open pid file. %s ERR=%s\n"), fname, strerror(errno));
+ sscanf(pidbuf, "%d", &oldpid) != 1) {
+ Emsg2(M_ERROR_TERM, 0, _("Cannot open pid file. %s ERR=%s\n"), fname, strerror(errno));
}
/* See if other Bacula is still alive */
if (kill(oldpid, 0) != -1 || errno != ESRCH) {
- Emsg3(M_ERROR_TERM, 0, _("%s is already running. pid=%d\nCheck file %s\n"),
+ Emsg3(M_ERROR_TERM, 0, _("%s is already running. pid=%d\nCheck file %s\n"),
progname, oldpid, fname);
}
/* He is not alive, so take over file ownership */
uint64_t reserved[20];
};
-static struct s_state_hdr state_hdr = {
+static struct s_state_hdr state_hdr = {
"Bacula State\n",
3,
0
/* If file exists, see what we have */
// Dmsg1(10, "O_BINARY=%d\n", O_BINARY);
if ((sfd = open(fname, O_RDONLY|O_BINARY, 0)) < 0) {
- Dmsg3(010, "Could not open state file. sfd=%d size=%d: ERR=%s\n",
+ Dmsg3(010, "Could not open state file. sfd=%d size=%d: ERR=%s\n",
sfd, sizeof(hdr), strerror(errno));
goto bail_out;
}
if ((stat=read(sfd, &hdr, hdr_size)) != hdr_size) {
- Dmsg4(010, "Could not read state file. sfd=%d stat=%d size=%d: ERR=%s\n",
+ Dmsg4(010, "Could not read state file. sfd=%d stat=%d size=%d: ERR=%s\n",
sfd, (int)stat, hdr_size, strerror(errno));
goto bail_out;
}
if (hdr.version != state_hdr.version) {
- Dmsg2(010, "Bad hdr version. Wanted %d got %d\n",
+ Dmsg2(010, "Bad hdr version. Wanted %d got %d\n",
state_hdr.version, hdr.version);
}
hdr.id[13] = 0;
}
// Dmsg1(010, "Wrote header of %d bytes\n", sizeof(state_hdr));
state_hdr.last_jobs_addr = sizeof(state_hdr);
- state_hdr.reserved[0] = write_last_jobs_list(sfd, state_hdr.last_jobs_addr);
+ state_hdr.reserved[0] = write_last_jobs_list(sfd, state_hdr.last_jobs_addr);
// Dmsg1(010, "write last job end = %d\n", (int)state_hdr.reserved[0]);
if (lseek(sfd, 0, SEEK_SET) < 0) {
Dmsg1(000, "lseek error: ERR=%s\n", strerror(errno));
goto bail_out;
- }
+ }
if (write(sfd, &state_hdr, sizeof(state_hdr)) != sizeof(state_hdr)) {
Pmsg1(000, "Write final hdr error: ERR=%s\n", strerror(errno));
}
gid_t gr_list[1];
if ((group = getgrnam(gid)) == NULL) {
- Emsg1(M_ERROR_TERM, 0, _("Could not find specified group: %s\n"), gid);
+ Emsg1(M_ERROR_TERM, 0, _("Could not find specified group: %s\n"), gid);
}
if (setgid(group->gr_gid)) {
- Emsg1(M_ERROR_TERM, 0, _("Could not set specified group: %s\n"), gid);
+ Emsg1(M_ERROR_TERM, 0, _("Could not set specified group: %s\n"), gid);
}
gr_list[0] = group->gr_gid;
if (setgroups(1, gr_list)) {
- Emsg1(M_ERROR_TERM, 0, _("Could not set specified group: %s\n"), gid);
+ Emsg1(M_ERROR_TERM, 0, _("Could not set specified group: %s\n"), gid);
}
}
#endif
if (uid) {
struct passwd *passw;
if ((passw = getpwnam(uid)) == NULL) {
- Emsg1(M_ERROR_TERM, 0, _("Could not find specified userid: %s\n"), uid);
+ Emsg1(M_ERROR_TERM, 0, _("Could not find specified userid: %s\n"), uid);
}
if (setuid(passw->pw_uid)) {
- Emsg1(M_ERROR_TERM, 0, _("Could not set specified userid: %s\n"), uid);
+ Emsg1(M_ERROR_TERM, 0, _("Could not set specified userid: %s\n"), uid);
}
}
#endif
-
+
}
static pthread_mutex_t timer_mutex = PTHREAD_MUTEX_INITIALIZER;
static pthread_cond_t timer = PTHREAD_COND_INITIALIZER;
/*
- * This routine will sleep (sec, microsec). Note, however, that if a
+ * This routine will sleep (sec, microsec). Note, however, that if a
* signal occurs, it will return early. It is up to the caller
* to recall this routine if he/she REALLY wants to sleep the
* requested time.
#ifdef HAVE_NANOSLEEP
stat = nanosleep(&timeout, NULL);
if (!(stat < 0 && errno == ENOSYS)) {
- return stat;
+ return stat;
}
/* If we reach here it is because nanosleep is not supported by the OS */
#endif
long long int
strtoll(const char *ptr, char **endptr, int base)
{
- return (long long int)strtod(ptr, endptr);
+ return (long long int)strtod(ptr, endptr);
}
#endif
char *bfgets(char *s, int size, FILE *fd)
{
char *p = s;
- int ch;
+ int ch;
*p = 0;
for (int i=0; i < size-1; i++) {
do {
*p = 0;
if (ch == '\r') { /* Support for Mac/Windows file format */
ch = fgetc(fd);
- if (ch == '\n') { /* Windows (\r\n) */
+ if (ch == '\n') { /* Windows (\r\n) */
*p++ = ch;
*p = 0;
}
- else { /* Mac (\r only) */
+ else { /* Mac (\r only) */
ungetc(ch, fd); /* Push next character back to fd */
}
break;
- }
+ }
if (ch == '\n') {
break;
}
* in Bacula (fdate_t, ftime_t, time_t (Unix standard), btime_t, and
* utime_t). fdate_t and ftime_t are deprecated and should no longer
* be used, and in general, Unix time time_t should no longer be used,
- * it is being phased out.
- *
- * Epoch is the base of Unix time in seconds (time_t, ...)
+ * it is being phased out.
+ *
+ * Epoch is the base of Unix time in seconds (time_t, ...)
* and is 1 Jan 1970 at 0:0 UTC
*
* The major two times that should be left are:
{
time_t ttime = (time_t)tim;
struct tm tm;
-
+
/* ***FIXME**** the format and localtime_r() should be user configurable */
localtime_r(&ttime, &tm);
strftime(dt, maxlen, "%d-%b-%Y %H:%M", &tm);
{
time_t ttime = (time_t)tim;
struct tm tm;
-
+
/* ***FIXME**** the format and localtime_r() should be user configurable */
localtime_r(&ttime, &tm);
strftime(dt, maxlen, "%d-%b-%Y %H:%M:%S", &tm);
{
time_t ttime = (time_t)tim;
struct tm tm;
-
+
/* ***FIXME**** the format and localtime_r() should be user configurable */
localtime_r(&ttime, &tm);
strftime(dt, maxlen, "%d-%b %H:%M", &tm);
{
time_t ttime = (time_t)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 */
}
/* Convert standard time string yyyy-mm-dd hh:mm:ss to Unix time */
-utime_t str_to_utime(char *str)
+utime_t str_to_utime(char *str)
{
struct tm tm;
time_t ttime;
}
if (tm.tm_mon > 0) {
tm.tm_mon--;
- } else {
+ } else {
return 0;
}
if (tm.tm_year >= 1900) {
tm.tm_wday = tm.tm_yday = 0;
tm.tm_isdst = -1;
ttime = mktime(&tm);
- if (ttime == -1) {
+ if (ttime == -1) {
ttime = 0;
}
return (utime_t)ttime;
/* Convert btime to Unix time */
time_t btime_to_unix(btime_t bt)
{
- return (time_t)(bt/1000000);
+ return (time_t)(bt/1000000);
}
/* Convert btime to utime */
int wom = 1 + (mday - fs - 1) / 7;
// Dmsg4(100, "mday=%d wom=%d wday=%d fs=%d\n", mday, wom, wday, fs);
return wom;
-}
+}
/*
* Given a Unix date return the week of the year.
time_decode(dt->julian_day_fraction, hour, minute, second, second_fraction);
}
-/* tm_encode -- Encode a civil date and time from a tm structure
+/* tm_encode -- Encode a civil date and time from a tm structure
* to a Julian day and day fraction.
*/
/* Deprecated. Do not use. */
void tm_encode(struct date_time *dt,
- struct tm *tm)
+ struct tm *tm)
{
uint32_t year;
uint8_t month, day, hour, minute, second;
/* Deprecated. Do not use. */
void tm_decode(struct date_time *dt,
- struct tm *tm)
+ struct tm *tm)
{
uint32_t year;
uint8_t month, day, hour, minute, second;
-/*
+/*
See btime.c for defintions.
/*
* Process and thread timer routines, built on top of watchdogs.
- *
+ *
* Nic Bellamy <nic@bellamy.co.nz>, October 2004.
*
*/
static void destructor_child_timer(watchdog_t *self);
#endif
-/*
+/*
* Start a timer on a child process of pid, kill it after wait seconds.
*
* Returns: btimer_t *(pointer to btimer_t struct) on success
}
}
-/*
+/*
* Start a timer on a thread. kill it after wait seconds.
*
* Returns: btimer_t *(pointer to btimer_t struct) on success
return wid;
}
-/*
+/*
* Start a timer on a BSOCK. kill it after wait seconds.
*
* Returns: btimer_t *(pointer to btimer_t struct) on success
wid->wd->interval = wait;
register_watchdog(wid->wd);
- Dmsg4(50, "Start bsock timer %p tid=%p for %d secs at %d\n", wid,
+ Dmsg4(50, "Start bsock timer %p tid=%p for %d secs at %d\n", wid,
wid->tid, wait, time(NULL));
return wid;
{
btimer_t *wid = (btimer_t *)self->data;
- Dmsg4(50, "thread timer %p kill %s tid=%p at %d.\n", self,
+ Dmsg4(50, "thread timer %p kill %s tid=%p at %d.\n", self,
wid->type == TYPE_BSOCK ? "bsock" : "thread", wid->tid, time(NULL));
if (wid->type == TYPE_BSOCK && wid->bsock) {
/*
* Process and thread timer routines, built on top of watchdogs.
- *
+ *
* Nic Bellamy <nic@bellamy.co.nz>, October 2003.
*
*/
* Challenge Response Authentication Method using MD5 (CRAM-MD5)
*
* cram-md5 is based on RFC2104.
- *
+ *
* Written for Bacula by Kern E. Sibbald, May MMI.
*
* Version $Id$
if (sscanf(bs->msg, "auth cram-md5 %s ssl=%d\n", chal, &ssl_has) != 2) {
ssl_has = BNET_SSL_NONE;
if (sscanf(bs->msg, "auth cram-md5 %s\n", chal) != 1) {
- Dmsg1(50, "Cannot scan challenge: %s", bs->msg);
- bnet_fsend(bs, "1999 Authorization failed.\n");
+ Dmsg1(50, "Cannot scan challenge: %s", bs->msg);
+ bnet_fsend(bs, "1999 Authorization failed.\n");
bmicrosleep(5, 0);
return 0;
}
* The following code can be used to generate the static CRC table.
*
* Note, the magic number 0xedb88320L below comes from the terms
- * of the defining polynomial x^n,
+ * of the defining polynomial x^n,
* where n=0,1,2,4,5,7,8,10,11,12,16,22,23,26
*/
#include <stdio.h>
buf[k++] = crc;
if (k == 5) {
k = 0;
- printf(" 0x%08x, 0x%08x, 0x%08x, 0x%08x, 0x%08x,\n",
+ printf(" 0x%08x, 0x%08x, 0x%08x, 0x%08x, 0x%08x,\n",
buf[0], buf[1], buf[2], buf[3], buf[4]);
}
}
* in the UNIX Environment"
*
* Initialize a daemon process completely detaching us from
- * any terminal processes.
+ * any terminal processes.
*
- */
+ */
/*
Copyright (C) 2000-2004 Kern Sibbald and John Walker
#include "bacula.h"
extern int debug_level;
-void
+void
daemon_start()
{
#if !defined(HAVE_CYGWIN) && !defined(HAVE_WIN32)
else if (cpid > 0)
exit(0); /* parent exits */
/* Child continues */
-
+
setsid();
/* In the PRODUCTION system, we close ALL
chdir("/");
#endif
- /*
+ /*
* Avoid creating files 666 but don't override any
* more restrictive mask set by the user.
*/
/*
- * Bacula doubly linked list routines.
+ * Bacula doubly linked list routines.
*
* dlist is a doubly linked list with the links being in the
* list data item.
- *
+ *
* Kern Sibbald, July MMIII
*
* Version $Id$
/*
* Append an item to the list
*/
-void dlist::append(void *item)
+void dlist::append(void *item)
{
((dlink *)(((char *)item)+loffset))->next = NULL;
((dlink *)(((char *)item)+loffset))->prev = tail;
/*
* Append an item to the list
*/
-void dlist::prepend(void *item)
+void dlist::prepend(void *item)
{
((dlink *)(((char *)item)+loffset))->next = head;
((dlink *)(((char *)item)+loffset))->prev = NULL;
((dlink *)(((char *)head)+loffset))->prev = item;
}
head = item;
- if (tail == NULL) { /* if empty list, */
+ if (tail == NULL) { /* if empty list, */
tail = item; /* item is tail too */
}
num_items++;
}
-void dlist::insert_before(void *item, void *where)
+void dlist::insert_before(void *item, void *where)
{
- dlink *where_link = (dlink *)((char *)where+loffset);
+ dlink *where_link = (dlink *)((char *)where+loffset);
((dlink *)(((char *)item)+loffset))->next = where;
((dlink *)(((char *)item)+loffset))->prev = where_link->prev;
num_items++;
}
-void dlist::insert_after(void *item, void *where)
+void dlist::insert_after(void *item, void *where)
{
- dlink *where_link = (dlink *)((char *)where+loffset);
+ dlink *where_link = (dlink *)((char *)where+loffset);
((dlink *)(((char *)item)+loffset))->next = where_link->next;
((dlink *)(((char *)item)+loffset))->prev = where;
return item;
}
if (num_items == 1) {
- comp = compare(item, first());
+ comp = compare(item, first());
if (comp < 0) {
prepend(item);
//Dmsg0(000, "Insert before first.\n");
cur++;
}
while (nxt < cur) {
- cur_item = prev(cur_item);
+ cur_item = prev(cur_item);
cur--;
}
//Dmsg1(000, "Compare item to %d\n", cur);
jcr_chain = (dlist *)malloc(sizeof(dlist));
jcr_chain->init(jcr, &jcr->link);
-
+
printf("Prepend 20 items 0-19\n");
for (int i=0; i<20; i++) {
sprintf(buf, "This is dlist item %d", i);
jcr_chain->remove(save_jcr);
printf("Re-insert 10th item\n");
jcr_chain->insert_before(jcr, next_jcr);
-
+
printf("Print remaining list.\n");
foreach_dlist (jcr, jcr_chain) {
printf("Dlist item = %s\n", jcr->buf);
jcr_chain->remove(save_jcr);
printf("Re-insert 10th item\n");
jcr_chain->insert_before(jcr, next_jcr);
-
+
printf("Print remaining list.\n");
foreach_dlist (jcr, jcr_chain) {
printf("Dlist item = %s\n", jcr->buf);
for (int k=0; k<CNT; k++) {
count++;
if ((count & 0x3FF) == 0) {
- Dmsg1(000, "At %d\n", count);
+ Dmsg1(000, "At %d\n", count);
}
jcr = (MYJCR *)malloc(sizeof(MYJCR));
jcr->buf = bstrdup(buf);
jcr1 = (MYJCR *)jcr_chain->binary_insert(jcr, my_compare);
if (jcr != jcr1) {
- Dmsg2(000, "Insert of %s vs %s failed.\n", jcr->buf, jcr1->buf);
+ Dmsg2(000, "Insert of %s vs %s failed.\n", jcr->buf, jcr1->buf);
}
buf[1]--;
}
- buf[1] = 'Z';
+ buf[1] = 'Z';
buf[2]--;
}
buf[2] = 'Z';
*/
/* ========================================================================
- *
+ *
* Doubly linked list -- dlist
*
* Kern Sibbald, MMIV
/* In case you want to specifically specify the offset to the link */
#define OFFSET(item, link) ((char *)(link) - (char *)(item))
-/*
+/*
* There is a lot of extra casting here to work around the fact
* that some compilers (Sun and Visual C++) do not accept
* (void *) as an lvalue on the left side of an equal.
#ifdef the_old_way
#define foreach_dlist(var, list) \
- for((var)=NULL; (((void *)(var))=(list)->next(var)); )
+ for((var)=NULL; (((void *)(var))=(list)->next(var)); )
#endif
};
-/*
+/*
* This allows us to do explicit initialization,
* allowing us to mix C++ classes inside malloc'ed
* C structures. Define before called in constructor.
*/
-inline void dlist::init(void *item, dlink *link)
+inline void dlist::init(void *item, dlink *link)
{
head = tail = NULL;
loffset = (char *)link - (char *)item;
num_items = 0;
}
-/*
- * Constructor called with the address of a
+/*
+ * Constructor called with the address of a
* member of the list (not the list head), and
* the address of the link within that member.
* If the link is at the beginning of the list member,
- * then there is no need to specify the link address
+ * then there is no need to specify the link address
* since the offset is zero.
*/
inline dlist::dlist(void *item, dlink *link)
return num_items;
}
-
+
inline void * dlist::first() const
{
/*
- * edit.c edit string to ascii, and ascii to internal
- *
+ * edit.c edit string to ascii, and ascii to internal
+ *
* Kern Sibbald, December MMII
*
* Version $Id$
#include <math.h>
/* We assume ASCII input and don't worry about overflow */
-uint64_t str_to_uint64(char *str)
+uint64_t str_to_uint64(char *str)
{
register char *p = str;
register uint64_t value = 0;
return value;
}
-int64_t str_to_int64(char *str)
+int64_t str_to_int64(char *str)
{
register char *p = str;
register int64_t value;
*/
char *edit_uint64_with_commas(uint64_t val, char *buf)
{
- /*
+ /*
* Replacement for sprintf(buf, "%" llu, val)
*/
char mbuf[50];
mbuf[i--] = '0';
} else {
while (val != 0) {
- mbuf[i--] = "0123456789"[val%10];
+ mbuf[i--] = "0123456789"[val%10];
val /= 10;
}
}
*/
char *edit_uint64(uint64_t val, char *buf)
{
- /*
+ /*
* Replacement for sprintf(buf, "%" llu, val)
*/
char mbuf[50];
mbuf[i--] = '0';
} else {
while (val != 0) {
- mbuf[i--] = "0123456789"[val%10];
+ mbuf[i--] = "0123456789"[val%10];
val /= 10;
}
}
static bool get_modifier(char *str, char *num, int num_len, char *mod, int mod_len)
{
int i, len, num_begin, num_end, mod_begin, mod_end;
-
+
/*
* Look for modifier by walking back looking for the first
* space or digit.
char num_str[50];
/*
* The "n" = mins and months appears before minutes so that m maps
- * to months. These "kludges" make it compatible with pre 1.31
+ * to months. These "kludges" make it compatible with pre 1.31
* Baculas.
*/
- static const char *mod[] = {"n", "seconds", "months", "minutes",
- "hours", "days", "weeks", "quarters", "years", NULL};
- static const int32_t mult[] = {60, 1, 60*60*24*30, 60,
+ static const char *mod[] = {"n", "seconds", "months", "minutes",
+ "hours", "days", "weeks", "quarters", "years", NULL};
+ static const int32_t mult[] = {60, 1, 60*60*24*30, 60,
60*60, 60*60*24, 60*60*24*7, 60*60*24*91, 60*60*24*365};
while (*str) {
times = (uint32_t)(val / mult[i]);
if (times > 0) {
val = val - (utime_t)times * mult[i];
- bsnprintf(mybuf, sizeof(mybuf), "%d %s%s ", times, mod[i], times>1?"s":"");
+ bsnprintf(mybuf, sizeof(mybuf), "%d %s%s ", times, mod[i], times>1?"s":"");
bstrncat(buf, mybuf, buf_len);
}
}
- if (val == 0 && strlen(buf) == 0) {
+ if (val == 0 && strlen(buf) == 0) {
bstrncat(buf, "0 secs", buf_len);
} else if (val != 0) {
bsnprintf(mybuf, sizeof(mybuf), "%d sec%s", (uint32_t)val, val>1?"s":"");
}
/*
- * Check if the specified string is an integer
+ * Check if the specified string is an integer
*/
bool is_an_integer(const char *n)
{
/*
* Check if Bacula Resoure Name is valid
*/
-/*
+/*
* Check if the Volume name has legal characters
* If ua is non-NULL send the message
*/
continue;
}
if (msg) {
- Mmsg(msg, _("Illegal character \"%c\" in name.\n"), *p);
+ Mmsg(msg, _("Illegal character \"%c\" in name.\n"), *p);
}
return false;
}
len = strlen(name);
if (len >= MAX_NAME_LENGTH) {
if (msg) {
- Mmsg(msg, _("Name too long.\n"));
+ Mmsg(msg, _("Name too long.\n"));
}
return false;
}
if (len == 0) {
if (msg) {
- Mmsg(msg, _("Volume name must be at least one character long.\n"));
+ Mmsg(msg, _("Volume name must be at least one character long.\n"));
}
return false;
}
/*
* Add commas to a string, which is presumably
- * a number.
+ * a number.
*/
char *add_commas(char *val, char *buf)
{
*q-- = *p--;
}
*q-- = ',';
- }
+ }
return buf;
}
for (int i=0; i<8; i++) {
strcpy(buf, str[i]);
if (!duration_to_utime(buf, &val)) {
- printf("Error return from duration_to_utime for in=%s\n", str[i]);
+ printf("Error return from duration_to_utime for in=%s\n", str[i]);
continue;
}
edit_utime(val, outval);
time(&nowtime);
localtime_r(&nowtime, &tm);
- strftime(datetime, sizeof(datetime), "%a %b %d %X %Z %Y ", &tm);
+ strftime(datetime, sizeof(datetime), "%a %b %d %X %Z %Y ", &tm);
write(event_fd, datetime, strlen(datetime));
lm = strlen(msg);
- if (msg[lm-1] != '\n')
- msg[lm++] = '\n';
+ if (msg[lm-1] != '\n')
+ msg[lm++] = '\n';
write(event_fd, msg, lm);
}
}
#define MAXLE 50 /* truncate file when this many events */
/*
- * If the EVENTS file exceeds MAXLE records, truncate it.
+ * If the EVENTS file exceeds MAXLE records, truncate it.
*
* Returns:
*
int trunc = FALSE;
FILE *events_file;
int stat = 0;
-
+
if ((events_file = fopen(ups->eventfile, "r+")) == NULL)
return 0;
for (i=0; i<NLE; i++)
*buf = 0;
/* Put records in single buffer in correct order */
for (j=0; j < nrec; j++) {
- strcat(buf, le[i++]);
+ strcat(buf, le[i++]);
if (i >= NLE)
i = 0;
}
extern UPSINFO myUPS;
extern int shm_OK;
-/*
+/*
* Fill the Events list box with the last events
- *
+ *
*/
void FillEventsBox(HWND hwnd, int idlist)
{
char buf[1000];
int len;
FILE *events_file;
-
+
if (!shm_OK || myUPS.eventfile[0] == 0 ||
- (events_file = fopen(myUPS.eventfile, "r")) == NULL) {
- SendDlgItemMessage(hwnd, idlist, LB_ADDSTRING, 0,
- (LONG)"Events not available");
+ (events_file = fopen(myUPS.eventfile, "r")) == NULL) {
+ SendDlgItemMessage(hwnd, idlist, LB_ADDSTRING, 0,
+ (LONG)"Events not available");
return;
}
while (fgets(buf, sizeof(buf), events_file) != NULL) {
len = strlen(buf);
/* strip trailing cr/lfs */
- while (len > 0 && (buf[len-1] == '\n' || buf[len-1] == '\r'))
+ while (len > 0 && (buf[len-1] == '\n' || buf[len-1] == '\r'))
buf[--len] = 0;
SendDlgItemMessage(hwnd, idlist, LB_ADDSTRING, 0, (LONG)buf);
}
switch (c)
{
- case '?':
- if (*n == '\0')
+ case '?':
+ if (*n == '\0')
return FNM_NOMATCH;
- else if ((flags & FNM_FILE_NAME) && *n == '/')
+ else if ((flags & FNM_FILE_NAME) && *n == '/')
return FNM_NOMATCH;
- else if ((flags & FNM_PERIOD) && *n == '.' &&
- (n == string || ((flags & FNM_FILE_NAME) && n[-1] == '/')))
+ else if ((flags & FNM_PERIOD) && *n == '.' &&
+ (n == string || ((flags & FNM_FILE_NAME) && n[-1] == '/')))
return FNM_NOMATCH;
break;
- case '\\':
+ case '\\':
if (!(flags & FNM_NOESCAPE))
{
c = *p++;
- if (c == '\0')
- /* Trailing \ loses. */
+ if (c == '\0')
+ /* Trailing \ loses. */
return FNM_NOMATCH;
c = FOLD (c);
}
return FNM_NOMATCH;
break;
- case '*':
- if ((flags & FNM_PERIOD) && *n == '.' &&
- (n == string || ((flags & FNM_FILE_NAME) && n[-1] == '/')))
+ case '*':
+ if ((flags & FNM_PERIOD) && *n == '.' &&
+ (n == string || ((flags & FNM_FILE_NAME) && n[-1] == '/')))
return FNM_NOMATCH;
- for (c = *p++; c == '?' || c == '*'; c = *p++)
+ for (c = *p++; c == '?' || c == '*'; c = *p++)
{
- if ((flags & FNM_FILE_NAME) && *n == '/')
+ if ((flags & FNM_FILE_NAME) && *n == '/')
/* A slash does not match a wildcard under FNM_FILE_NAME. */
return FNM_NOMATCH;
- else if (c == '?')
+ else if (c == '?')
{
/* A ? needs to match one character. */
- if (*n == '\0')
- /* There isn't another character; no match. */
+ if (*n == '\0')
+ /* There isn't another character; no match. */
return FNM_NOMATCH;
else
/* One character of the string is consumed in matching
- this ? wildcard, so *??? won't match if there are
+ this ? wildcard, so *??? won't match if there are
less than three characters. */
++n;
}
}
- if (c == '\0')
+ if (c == '\0')
return 0;
{
- char c1 = (!(flags & FNM_NOESCAPE) && c == '\\') ? *p : c;
+ char c1 = (!(flags & FNM_NOESCAPE) && c == '\\') ? *p : c;
c1 = FOLD (c1);
- for (--p; *n != '\0'; ++n)
- if ((c == '[' || FOLD (*n) == c1) &&
+ for (--p; *n != '\0'; ++n)
+ if ((c == '[' || FOLD (*n) == c1) &&
fnmatch (p, n, flags & ~FNM_PERIOD) == 0)
return 0;
return FNM_NOMATCH;
}
- case '[':
+ case '[':
{
/* Nonzero if the sense of the character class is inverted. */
register int nnot;
- if (*n == '\0')
+ if (*n == '\0')
return FNM_NOMATCH;
- if ((flags & FNM_PERIOD) && *n == '.' &&
- (n == string || ((flags & FNM_FILE_NAME) && n[-1] == '/')))
+ if ((flags & FNM_PERIOD) && *n == '.' &&
+ (n == string || ((flags & FNM_FILE_NAME) && n[-1] == '/')))
return FNM_NOMATCH;
- nnot = (*p == '!' || *p == '^');
+ nnot = (*p == '!' || *p == '^');
if (nnot)
++p;
{
register char cstart = c, cend = c;
- if (!(flags & FNM_NOESCAPE) && c == '\\')
+ if (!(flags & FNM_NOESCAPE) && c == '\\')
{
- if (*p == '\0')
+ if (*p == '\0')
return FNM_NOMATCH;
cstart = cend = *p++;
}
cstart = cend = FOLD (cstart);
- if (c == '\0')
+ if (c == '\0')
/* [ (unterminated) loses. */
return FNM_NOMATCH;
c = *p++;
c = FOLD (c);
- if ((flags & FNM_FILE_NAME) && c == '/')
+ if ((flags & FNM_FILE_NAME) && c == '/')
/* [/] can never match. */
return FNM_NOMATCH;
- if (c == '-' && *p != ']')
+ if (c == '-' && *p != ']')
{
cend = *p++;
- if (!(flags & FNM_NOESCAPE) && cend == '\\')
+ if (!(flags & FNM_NOESCAPE) && cend == '\\')
cend = *p++;
- if (cend == '\0')
+ if (cend == '\0')
return FNM_NOMATCH;
cend = FOLD (cend);
if (FOLD (*n) >= cstart && FOLD (*n) <= cend)
goto matched;
- if (c == ']')
+ if (c == ']')
break;
}
if (!nnot)
matched:;
/* Skip the rest of the [...] that already matched. */
- while (c != ']')
+ while (c != ']')
{
- if (c == '\0')
+ if (c == '\0')
/* [... (unterminated) loses. */
return FNM_NOMATCH;
c = *p++;
- if (!(flags & FNM_NOESCAPE) && c == '\\')
+ if (!(flags & FNM_NOESCAPE) && c == '\\')
{
- if (*p == '\0')
+ if (*p == '\0')
return FNM_NOMATCH;
/* XXX 1003.2d11 is unclear if this is right. */
++p;
# ifndef __need_getopt
extern int getopt_long (int __argc, char *const *__argv, const char *__shortopts,
- const struct option *__longopts, int *__longind);
+ const struct option *__longopts, int *__longind);
extern int getopt_long_only (int __argc, char *const *__argv,
const char *__shortopts,
- const struct option *__longopts, int *__longind);
+ const struct option *__longopts, int *__longind);
/* Internal only. Users should not call this directly. */
extern int _getopt_internal (int __argc, char *const *__argv,
const char *__shortopts,
- const struct option *__longopts, int *__longind,
+ const struct option *__longopts, int *__longind,
int __long_only);
# endif
#else /* not __STDC__ */
* Hashed Message Authentication Code using MD5 (HMAC-MD5)
*
* hmac_md5 was based on sample code in RFC2104 (thanks guys).
- *
+ *
* Adapted to Bacula by Kern E. Sibbald, February MMI.
*
* Version $Id$
/* Zero pads and store key */
memset(k_ipad, 0, PAD_LEN);
memcpy(k_ipad, key, key_len);
- memcpy(k_opad, k_ipad, PAD_LEN);
+ memcpy(k_opad, k_ipad, PAD_LEN);
/* XOR key with ipad and opad values */
for (i=0; i<PAD_LEN; i++) {
* Just create a new larger table, walk the old table and
* re-hash insert each entry into the new table.
*
- *
+ *
* Kern Sibbald, July MMIII
*
* Version $Id$
return malloc(sizeof(htable));
}
-void htable::operator delete(void *tbl)
+void htable::operator delete(void *tbl)
{
((htable *)tbl)->destroy();
free(tbl);
return num_items;
}
-void htable::stats()
+void htable::stats()
{
int count[10];
int max = 0;
}
for (i=0; i<(int)buckets; i++) {
p = table[i];
- j = 0;
+ j = 0;
while (p) {
p = (hlink *)(p->next);
j++;
big->walk_index = 0;
/* Insert all the items in the new hash table */
Dmsg1(100, "Before copy num_items=%d\n", num_items);
- /*
+ /*
* We walk through the old smaller tree getting items,
* but since we are overwriting the colision links, we must
* explicitly save the item->next pointer and walk each
if (ni) {
item = (void *)((char *)ni-loffset);
} else {
- walkptr = NULL;
+ walkptr = NULL;
item = next();
}
}
for (hlink *hp=table[index]; hp; hp=(hlink *)hp->next) {
// Dmsg2(100, "hp=0x%x key=%s\n", (long)hp, hp->key);
if (hash == hp->hash && strcmp(key, hp->key) == 0) {
- Dmsg1(100, "lookup return %x\n", ((char *)hp)-loffset);
+ Dmsg1(100, "lookup return %x\n", ((char *)hp)-loffset);
return ((char *)hp)-loffset;
}
}
while (!walkptr && walk_index < buckets) {
walkptr = table[walk_index++];
if (walkptr) {
- Dmsg3(100, "new walkptr=0x%x next=0x%x inx=%d\n", (unsigned)walkptr,
+ Dmsg3(100, "new walkptr=0x%x next=0x%x inx=%d\n", (unsigned)walkptr,
(unsigned)(walkptr->next), walk_index-1);
}
}
if (walkptr) {
- Dmsg2(100, "next: rtn 0x%x walk_index=%d\n",
+ Dmsg2(100, "next: rtn 0x%x walk_index=%d\n",
(unsigned)(((char *)walkptr)-loffset), walk_index);
return ((char *)walkptr)-loffset;
- }
+ }
Dmsg0(100, "next: return NULL\n");
return NULL;
}
while (!walkptr && walk_index < buckets) {
walkptr = table[walk_index++]; /* go to next bucket */
if (walkptr) {
- Dmsg3(100, "first new walkptr=0x%x next=0x%x inx=%d\n", (unsigned)walkptr,
+ Dmsg3(100, "first new walkptr=0x%x next=0x%x inx=%d\n", (unsigned)walkptr,
(unsigned)(walkptr->next), walk_index-1);
}
}
if (walkptr) {
Dmsg1(100, "Leave first walkptr=0x%x\n", (unsigned)walkptr);
return ((char *)walkptr)-loffset;
- }
+ }
Dmsg0(100, "Leave first walkptr=NULL\n");
return NULL;
}
MYJCR *save_jcr = NULL, *item;
MYJCR *jcr = NULL;
int count = 0;
-
+
jcrtbl = (htable *)malloc(sizeof(htable));
jcrtbl->init(jcr, &jcr->link, NITEMS);
-
+
Dmsg1(000, "Inserting %d items\n", NITEMS);
for (int i=0; i<NITEMS; i++) {
sprintf(mkey, "This is htable item %d", i);
*/
/* ========================================================================
- *
+ *
* Hash table class -- htable
*
*/
* Loop var through each member of table
*/
#define foreach_htable(var, tbl) \
- for(((void *)(var))=(tbl)->first(); \
- (var); \
- ((void *)(var))=(tbl)->next())
+ for(((void *)(var))=(tbl)->first(); \
+ (var); \
+ ((void *)(var))=(tbl)->next())
struct hlink {
void *next; /* next hash item */
if (!last_jobs) {
last_jobs = New(dlist(job_entry, &job_entry->link));
if ((errstat=rwl_init(&lock)) != 0) {
- Emsg1(M_ABORT, 0, _("Unable to initialize jcr_chain lock. ERR=%s\n"),
+ Emsg1(M_ABORT, 0, _("Unable to initialize jcr_chain lock. ERR=%s\n"),
strerror(errstat));
}
}
{
if (last_jobs) {
while (!last_jobs->empty()) {
- void *je = last_jobs->first();
+ void *je = last_jobs->first();
last_jobs->remove(je);
- free(je);
+ free(je);
}
delete last_jobs;
last_jobs = NULL;
}
for ( ; num; num--) {
if (read(fd, &job, sizeof(job)) != sizeof(job)) {
- Dmsg1(000, "Read job entry. ERR=%s\n", strerror(errno));
+ Dmsg1(000, "Read job entry. ERR=%s\n", strerror(errno));
return;
}
if (job.JobId > 0) {
/* First record is number of entires */
num = last_jobs->size();
if (write(fd, &num, sizeof(num)) != sizeof(num)) {
- Dmsg1(000, "Error writing num_items: ERR=%s\n", strerror(errno));
+ Dmsg1(000, "Error writing num_items: ERR=%s\n", strerror(errno));
return 0;
}
foreach_dlist(je, last_jobs) {
if (write(fd, je, sizeof(struct s_last_job)) != sizeof(struct s_last_job)) {
- Dmsg1(000, "Error writing job: ERR=%s\n", strerror(errno));
+ Dmsg1(000, "Error writing job: ERR=%s\n", strerror(errno));
return 0;
}
}
stat = 0;
}
return stat;
-
+
}
-void lock_last_jobs_list()
+void lock_last_jobs_list()
{
/* Use jcr chain mutex */
lock_jcr_chain();
}
-void unlock_last_jobs_list()
+void unlock_last_jobs_list()
{
/* Use jcr chain mutex */
unlock_jcr_chain();
/*
* Free stuff common to all JCRs. N.B. Be careful to include only
- * generic stuff in the common part of the jcr.
+ * generic stuff in the common part of the jcr.
*/
static void free_common_jcr(JCR *jcr)
{
free(jcr);
}
-/*
+/*
* Global routine to free a jcr
*/
#ifdef DEBUG
}
-/*
+/*
* Global routine to free a jcr
* JCR chain is already locked
*/
/*
- * Given a JobId, find the JCR
+ * Given a JobId, find the JCR
* Returns: jcr on success
* NULL on failure
*/
JCR *get_jcr_by_id(uint32_t JobId)
{
- JCR *jcr;
+ JCR *jcr;
lock_jcr_chain(); /* lock chain */
for (jcr = jobs; jcr; jcr=jcr->next) {
P(jcr->mutex);
jcr->use_count++;
V(jcr->mutex);
- Dmsg2(400, "Inc get_jcr 0x%x use_count=%d\n", jcr, jcr->use_count);
+ Dmsg2(400, "Inc get_jcr 0x%x use_count=%d\n", jcr, jcr->use_count);
break;
}
}
unlock_jcr_chain();
- return jcr;
+ return jcr;
}
/*
- * Given a SessionId and SessionTime, find the JCR
+ * Given a SessionId and SessionTime, find the JCR
* Returns: jcr on success
* NULL on failure
*/
JCR *get_jcr_by_session(uint32_t SessionId, uint32_t SessionTime)
{
- JCR *jcr;
+ JCR *jcr;
lock_jcr_chain();
for (jcr = jobs; jcr; jcr=jcr->next) {
- if (jcr->VolSessionId == SessionId &&
+ if (jcr->VolSessionId == SessionId &&
jcr->VolSessionTime == SessionTime) {
P(jcr->mutex);
jcr->use_count++;
V(jcr->mutex);
- Dmsg2(400, "Inc get_jcr 0x%x use_count=%d\n", jcr, jcr->use_count);
+ Dmsg2(400, "Inc get_jcr 0x%x use_count=%d\n", jcr, jcr->use_count);
break;
}
}
unlock_jcr_chain();
- return jcr;
+ return jcr;
}
/*
- * Given a Job, find the JCR
+ * Given a Job, find the JCR
* compares on the number of characters in Job
* thus allowing partial matches.
* Returns: jcr on success
*/
JCR *get_jcr_by_partial_name(char *Job)
{
- JCR *jcr;
+ JCR *jcr;
int len;
if (!Job) {
P(jcr->mutex);
jcr->use_count++;
V(jcr->mutex);
- Dmsg2(400, "Inc get_jcr 0x%x use_count=%d\n", jcr, jcr->use_count);
+ Dmsg2(400, "Inc get_jcr 0x%x use_count=%d\n", jcr, jcr->use_count);
break;
}
}
unlock_jcr_chain();
- return jcr;
+ return jcr;
}
/*
- * Given a Job, find the JCR
+ * Given a Job, find the JCR
* requires an exact match of names.
* Returns: jcr on success
* NULL on failure
*/
JCR *get_jcr_by_full_name(char *Job)
{
- JCR *jcr;
+ JCR *jcr;
if (!Job) {
return NULL;
P(jcr->mutex);
jcr->use_count++;
V(jcr->mutex);
- Dmsg2(400, "Inc get_jcr 0x%x use_count=%d\n", jcr, jcr->use_count);
+ Dmsg2(400, "Inc get_jcr 0x%x use_count=%d\n", jcr, jcr->use_count);
break;
}
}
unlock_jcr_chain();
- return jcr;
+ return jcr;
}
void set_jcr_job_status(JCR *jcr, int JobStatus)
static int lock_count = 0;
#endif
-/*
+/*
* Lock the chain
*/
#ifdef TRACE_JCR_CHAIN
#endif
{
int errstat;
-#ifdef TRACE_JCR_CHAIN
+#ifdef TRACE_JCR_CHAIN
Dmsg3(400, "Lock jcr chain %d from %s:%d\n", ++lock_count,
fname, line);
#endif
#endif
{
int errstat;
-#ifdef TRACE_JCR_CHAIN
+#ifdef TRACE_JCR_CHAIN
Dmsg3(400, "Unlock jcr chain %d from %s:%d\n", lock_count--,
fname, line);
#endif
Dmsg0(400, "Start JCR timeout checks\n");
- /* Walk through all JCRs checking if any one is
+ /* Walk through all JCRs checking if any one is
* blocked for more than specified max time.
*/
lock_jcr_chain();
*/
/*
- Copyright (C) 2000-2004 Kern Sibbald and John Walker
+ Copyright (C) 2000-2004 Kern Sibbald
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
Dmsg0(2000, "start scan to eof\n");
while ((token = lex_get_token(lc, T_ALL)) != T_EOL) {
if (token == T_EOB) {
- lex_unget_char(lc);
- return;
+ lex_unget_char(lc);
+ return;
}
}
}
return token;
}
-
+
/*
- * Format a scanner error message
+ * Format a scanner error message
*/
static void s_err(const char *file, int line, LEX *lc, const char *msg, ...)
{
va_start(arg_ptr, msg);
bvsnprintf(buf, sizeof(buf), msg, arg_ptr);
va_end(arg_ptr);
-
+
if (lc->line_no > lc->begin_line_no) {
- bsnprintf(more, sizeof(more),
+ bsnprintf(more, sizeof(more),
_("Problem probably begins at line %d.\n"), lc->begin_line_no);
} else {
more[0] = 0;
}
- e_msg(file, line, M_ERROR_TERM, 0, _("Config error: %s\n\
- : line %d, col %d of file %s\n%s\n%s"),
+ e_msg(file, line, M_ERROR_TERM, 0, _("Config error: %s\n"
+" : line %d, col %d of file %s\n%s\n%s"),
buf, lc->line_no, lc->col_no, lc->fname, lc->line, more);
}
return lf;
}
-/*
+/*
* Open a new configuration file. We push the
* state of the current file (lf) so that we
* can do includes. This is a bit of a hammer.
* the next field.
*
*/
-LEX *lex_open_file(LEX *lf, const char *filename, LEX_ERROR_HANDLER *scan_error)
-
+LEX *lex_open_file(LEX *lf, const char *filename, LEX_ERROR_HANDLER *scan_error)
+
{
LEX *nf;
FILE *fd;
char *fname = bstrdup(filename);
-
+
if ((fd = fopen(fname, "r")) == NULL) {
berrno be;
- Emsg2(M_ERROR_TERM, 0, _("Cannot open config file %s: %s\n"),
- fname, be.strerror());
+ Emsg2(M_ERROR_TERM, 0, _("Cannot open config file %s: %s\n"),
+ fname, be.strerror());
return NULL; /* Never reached if exit_on_error == 1 */
}
Dmsg1(2000, "Open config file: %s\n", fname);
nf = (LEX *)malloc(sizeof(LEX));
- if (lf) {
+ if (lf) {
memcpy(nf, lf, sizeof(LEX));
memset(lf, 0, sizeof(LEX));
- lf->next = nf; /* if have lf, push it behind new one */
+ lf->next = nf; /* if have lf, push it behind new one */
lf->options = nf->options; /* preserve user options */
} else {
- lf = nf; /* start new packet */
+ lf = nf; /* start new packet */
memset(lf, 0, sizeof(LEX));
}
lf->fd = fd;
return lf;
}
-/*
+/*
* Get the next character from the input.
* Returns the character or
* L_EOF if end of file
}
if (lf->ch == L_EOL) {
if (bfgets(lf->line, MAXSTRING, lf->fd) == NULL) {
- lf->ch = L_EOF;
- if (lf->next) {
- lex_close_file(lf);
- }
- return lf->ch;
+ lf->ch = L_EOF;
+ if (lf->next) {
+ lex_close_file(lf);
+ }
+ return lf->ch;
}
lf->line_no++;
lf->col_no = 0;
void lex_unget_char(LEX *lf)
{
- lf->col_no--;
+ lf->col_no--;
if (lf->ch == L_EOL)
lf->ch = 0;
}
{
if (lf->str_len >= MAXSTRING-3) {
Emsg3(M_ERROR_TERM, 0, _(
- _("Config token too long, file: %s, line %d, begins at line %d\n")),
- lf->fname, lf->line_no, lf->begin_line_no);
+ _("Config token too long, file: %s, line %d, begins at line %d\n")),
+ lf->fname, lf->line_no, lf->begin_line_no);
}
lf->str[lf->str_len++] = ch;
lf->str[lf->str_len] = 0;
/*
* Begin the string
*/
-static void begin_str(LEX *lf, int ch)
+static void begin_str(LEX *lf, int ch)
{
lf->str_len = 0;
lf->str[0] = 0;
val = str_to_int64(str);
if (errno != 0 || val < 0) {
scan_err1(lf, _("expected a postive integer number, got: %s"), str);
- /* NOT REACHED */
+ /* NOT REACHED */
}
}
return (uint32_t)val;
}
-/*
- *
+/*
+ *
* Get the next token from the input
*
*/
switch (lf->state) {
case lex_none:
Dmsg2(2000, "Lex state lex_none ch=%d,%x\n", ch, ch);
- if (B_ISSPACE(ch))
- break;
- if (B_ISALPHA(ch)) {
- if (lf->options & LOPT_NO_IDENT)
- lf->state = lex_string;
- else
- lf->state = lex_identifier;
- begin_str(lf, ch);
- break;
- }
- if (B_ISDIGIT(ch)) {
- lf->state = lex_number;
- begin_str(lf, ch);
- break;
- }
+ if (B_ISSPACE(ch))
+ break;
+ if (B_ISALPHA(ch)) {
+ if (lf->options & LOPT_NO_IDENT || lf->options & LOPT_STRING) {
+ lf->state = lex_string;
+ } else {
+ lf->state = lex_identifier;
+ }
+ begin_str(lf, ch);
+ break;
+ }
+ if (B_ISDIGIT(ch)) {
+ if (lf->options & LOPT_STRING) {
+ lf->state = lex_string;
+ } else {
+ lf->state = lex_number;
+ }
+ begin_str(lf, ch);
+ break;
+ }
Dmsg0(2000, "Enter lex_none switch\n");
- switch (ch) {
- case L_EOF:
- token = T_EOF;
+ switch (ch) {
+ case L_EOF:
+ token = T_EOF;
Dmsg0(2000, "got L_EOF set token=T_EOF\n");
- break;
+ break;
case '#':
- lf->state = lex_comment;
- break;
+ lf->state = lex_comment;
+ break;
case '{':
- token = T_BOB;
- begin_str(lf, ch);
- break;
+ token = T_BOB;
+ begin_str(lf, ch);
+ break;
case '}':
- token = T_EOB;
- begin_str(lf, ch);
- break;
+ token = T_EOB;
+ begin_str(lf, ch);
+ break;
case '"':
- lf->state = lex_quoted_string;
- begin_str(lf, 0);
- break;
- case '=':
- token = T_EQUALS;
- begin_str(lf, ch);
- break;
+ lf->state = lex_quoted_string;
+ begin_str(lf, 0);
+ break;
+ case '=':
+ token = T_EQUALS;
+ begin_str(lf, ch);
+ break;
case ',':
- token = T_COMMA;
- begin_str(lf, ch);
- break;
+ token = T_COMMA;
+ begin_str(lf, ch);
+ break;
case ';':
- if (expect != T_SKIP_EOL) {
- token = T_EOL; /* treat ; like EOL */
- }
- break;
- case L_EOL:
+ if (expect != T_SKIP_EOL) {
+ token = T_EOL; /* treat ; like EOL */
+ }
+ break;
+ case L_EOL:
Dmsg0(2000, "got L_EOL set token=T_EOL\n");
- if (expect != T_SKIP_EOL) {
- token = T_EOL;
- }
- break;
+ if (expect != T_SKIP_EOL) {
+ token = T_EOL;
+ }
+ break;
case '@':
- lf->state = lex_include;
- begin_str(lf, 0);
- break;
- default:
- lf->state = lex_string;
- begin_str(lf, ch);
- break;
- }
- break;
+ lf->state = lex_include;
+ begin_str(lf, 0);
+ break;
+ default:
+ lf->state = lex_string;
+ begin_str(lf, ch);
+ break;
+ }
+ break;
case lex_comment:
Dmsg1(2000, "Lex state lex_comment ch=%x\n", ch);
- if (ch == L_EOL) {
- lf->state = lex_none;
- if (expect != T_SKIP_EOL) {
- token = T_EOL;
- }
- } else if (ch == L_EOF) {
- token = T_ERROR;
- }
- break;
+ if (ch == L_EOL) {
+ lf->state = lex_none;
+ if (expect != T_SKIP_EOL) {
+ token = T_EOL;
+ }
+ } else if (ch == L_EOF) {
+ token = T_ERROR;
+ }
+ break;
case lex_number:
Dmsg2(2000, "Lex state lex_number ch=%x %c\n", ch, ch);
- if (ch == L_EOF) {
- token = T_ERROR;
- break;
- }
- /* Might want to allow trailing specifications here */
- if (B_ISDIGIT(ch)) {
- add_str(lf, ch);
- break;
- }
-
- /* A valid number can be terminated by the following */
+ if (ch == L_EOF) {
+ token = T_ERROR;
+ break;
+ }
+ /* Might want to allow trailing specifications here */
+ if (B_ISDIGIT(ch)) {
+ add_str(lf, ch);
+ break;
+ }
+
+ /* A valid number can be terminated by the following */
if (B_ISSPACE(ch) || ch == L_EOL || ch == ',' || ch == ';') {
- token = T_NUMBER;
- lf->state = lex_none;
- } else {
- lf->state = lex_string;
- }
- lex_unget_char(lf);
- break;
+ token = T_NUMBER;
+ lf->state = lex_none;
+ } else {
+ lf->state = lex_string;
+ }
+ lex_unget_char(lf);
+ break;
case lex_ip_addr:
- if (ch == L_EOF) {
- token = T_ERROR;
- break;
- }
+ if (ch == L_EOF) {
+ token = T_ERROR;
+ break;
+ }
Dmsg1(2000, "Lex state lex_ip_addr ch=%x\n", ch);
- break;
+ break;
case lex_string:
Dmsg1(2000, "Lex state lex_string ch=%x\n", ch);
- if (ch == L_EOF) {
- token = T_ERROR;
- break;
- }
+ if (ch == L_EOF) {
+ token = T_ERROR;
+ break;
+ }
if (ch == '\n' || ch == L_EOL || ch == '=' || ch == '}' || ch == '{' ||
ch == '\r' || ch == ';' || ch == ',' || ch == '#' || (B_ISSPACE(ch)) ) {
- lex_unget_char(lf);
- token = T_UNQUOTED_STRING;
- lf->state = lex_none;
- break;
- }
- add_str(lf, ch);
- break;
+ lex_unget_char(lf);
+ token = T_UNQUOTED_STRING;
+ lf->state = lex_none;
+ break;
+ }
+ add_str(lf, ch);
+ break;
case lex_identifier:
Dmsg2(2000, "Lex state lex_identifier ch=%x %c\n", ch, ch);
- if (B_ISALPHA(ch)) {
- add_str(lf, ch);
- break;
- } else if (B_ISSPACE(ch)) {
- break;
+ if (B_ISALPHA(ch)) {
+ add_str(lf, ch);
+ break;
+ } else if (B_ISSPACE(ch)) {
+ break;
} else if (ch == '\n' || ch == L_EOL || ch == '=' || ch == '}' || ch == '{' ||
ch == '\r' || ch == ';' || ch == ',' || ch == '"' || ch == '#') {
- lex_unget_char(lf);
- token = T_IDENTIFIER;
- lf->state = lex_none;
- break;
- } else if (ch == L_EOF) {
- token = T_ERROR;
- lf->state = lex_none;
- begin_str(lf, ch);
- break;
- }
- /* Some non-alpha character => string */
- lf->state = lex_string;
- add_str(lf, ch);
- break;
+ lex_unget_char(lf);
+ token = T_IDENTIFIER;
+ lf->state = lex_none;
+ break;
+ } else if (ch == L_EOF) {
+ token = T_ERROR;
+ lf->state = lex_none;
+ begin_str(lf, ch);
+ break;
+ }
+ /* Some non-alpha character => string */
+ lf->state = lex_string;
+ add_str(lf, ch);
+ break;
case lex_quoted_string:
Dmsg2(2000, "Lex state lex_quoted_string ch=%x %c\n", ch, ch);
- if (ch == L_EOF) {
- token = T_ERROR;
- break;
- }
- if (ch == L_EOL) {
- esc_next = false;
- break;
- }
- if (esc_next) {
- add_str(lf, ch);
- esc_next = false;
- break;
- }
+ if (ch == L_EOF) {
+ token = T_ERROR;
+ break;
+ }
+ if (ch == L_EOL) {
+ esc_next = false;
+ break;
+ }
+ if (esc_next) {
+ add_str(lf, ch);
+ esc_next = false;
+ break;
+ }
if (ch == '\\') {
- esc_next = true;
- break;
- }
+ esc_next = true;
+ break;
+ }
if (ch == '"') {
- token = T_QUOTED_STRING;
- lf->state = lex_none;
- break;
- }
- add_str(lf, ch);
- break;
- case lex_include: /* scanning a filename */
- if (ch == L_EOF) {
- token = T_ERROR;
- break;
- }
+ token = T_QUOTED_STRING;
+ lf->state = lex_none;
+ break;
+ }
+ add_str(lf, ch);
+ break;
+ case lex_include: /* scanning a filename */
+ if (ch == L_EOF) {
+ token = T_ERROR;
+ break;
+ }
if (B_ISSPACE(ch) || ch == '\n' || ch == L_EOL || ch == '}' || ch == '{' ||
ch == ';' || ch == ',' || ch == '"' || ch == '#') {
- lf->state = lex_none;
- lf = lex_open_file(lf, lf->str, NULL);
+ lf->state = lex_none;
+ lf = lex_open_file(lf, lf->str, NULL);
if (lf == NULL) {
- return T_ERROR;
+ return T_ERROR;
}
- break;
- }
- add_str(lf, ch);
- break;
+ break;
+ }
+ add_str(lf, ch);
+ break;
}
Dmsg4(2000, "ch=%d state=%s token=%s %c\n", ch, lex_state_to_str(lf->state),
- lex_tok_to_str(token), ch);
+ lex_tok_to_str(token), ch);
}
Dmsg2(2000, "lex returning: line %d token: %s\n", lf->line_no, lex_tok_to_str(token));
lf->token = token;
- /*
- * Here is where we check to see if the user has set certain
+ /*
+ * Here is where we check to see if the user has set certain
* expectations (e.g. 32 bit integer). If so, we do type checking
* and possible additional scanning (e.g. for range).
*/
case T_PINT32_RANGE:
if (token == T_NUMBER) {
- lf->pint32_val = scan_pint(lf, lf->str);
- lf->pint32_val2 = lf->pint32_val;
- token = T_PINT32;
+ lf->pint32_val = scan_pint(lf, lf->str);
+ lf->pint32_val2 = lf->pint32_val;
+ token = T_PINT32;
} else {
char *p = strchr(lf->str, '-');
- if (!p) {
- scan_err2(lf, _("expected an integer or a range, got %s: %s"),
- lex_tok_to_str(token), lf->str);
- token = T_ERROR;
- break;
- }
- *p++ = 0; /* terminate first half of range */
- lf->pint32_val = scan_pint(lf, lf->str);
- lf->pint32_val2 = scan_pint(lf, p);
- token = T_PINT32_RANGE;
+ if (!p) {
+ scan_err2(lf, _("expected an integer or a range, got %s: %s"),
+ lex_tok_to_str(token), lf->str);
+ token = T_ERROR;
+ break;
+ }
+ *p++ = 0; /* terminate first half of range */
+ lf->pint32_val = scan_pint(lf, lf->str);
+ lf->pint32_val2 = scan_pint(lf, p);
+ token = T_PINT32_RANGE;
}
break;
case T_INT32:
if (token != T_NUMBER || !is_a_number(lf->str)) {
scan_err2(lf, _("expected an integer number, got %s: %s"),
- lex_tok_to_str(token), lf->str);
- token = T_ERROR;
- break;
+ lex_tok_to_str(token), lf->str);
+ token = T_ERROR;
+ break;
}
errno = 0;
lf->int32_val = (int32_t)str_to_int64(lf->str);
if (errno != 0) {
scan_err2(lf, _("expected an integer number, got %s: %s"),
- lex_tok_to_str(token), lf->str);
- token = T_ERROR;
+ lex_tok_to_str(token), lf->str);
+ token = T_ERROR;
} else {
- token = T_INT32;
+ token = T_INT32;
}
break;
case T_INT64:
- Dmsg2(2000, "int64=:%s: %f\n", lf->str, strtod(lf->str, NULL));
+ Dmsg2(2000, "int64=:%s: %f\n", lf->str, strtod(lf->str, NULL));
if (token != T_NUMBER || !is_a_number(lf->str)) {
scan_err2(lf, _("expected an integer number, got %s: %s"),
- lex_tok_to_str(token), lf->str);
- token = T_ERROR;
- break;
+ lex_tok_to_str(token), lf->str);
+ token = T_ERROR;
+ break;
}
errno = 0;
lf->int64_val = str_to_int64(lf->str);
if (errno != 0) {
scan_err2(lf, _("expected an integer number, got %s: %s"),
- lex_tok_to_str(token), lf->str);
- token = T_ERROR;
+ lex_tok_to_str(token), lf->str);
+ token = T_ERROR;
} else {
- token = T_INT64;
+ token = T_INT64;
}
break;
case T_NAME:
if (token != T_IDENTIFIER && token != T_UNQUOTED_STRING && token != T_QUOTED_STRING) {
scan_err2(lf, _("expected a name, got %s: %s"),
- lex_tok_to_str(token), lf->str);
- token = T_ERROR;
+ lex_tok_to_str(token), lf->str);
+ token = T_ERROR;
} else if (lf->str_len > MAX_RES_NAME_LENGTH) {
- scan_err3(lf, _("name %s length %d too long, max is %d\n"), lf->str,
- lf->str_len, MAX_RES_NAME_LENGTH);
- token = T_ERROR;
+ scan_err3(lf, _("name %s length %d too long, max is %d\n"), lf->str,
+ lf->str_len, MAX_RES_NAME_LENGTH);
+ token = T_ERROR;
}
break;
case T_STRING:
if (token != T_IDENTIFIER && token != T_UNQUOTED_STRING && token != T_QUOTED_STRING) {
scan_err2(lf, _("expected a string, got %s: %s"),
- lex_tok_to_str(token), lf->str);
- token = T_ERROR;
+ lex_tok_to_str(token), lf->str);
+ token = T_ERROR;
} else {
- token = T_STRING;
+ token = T_STRING;
}
break;
default:
- break; /* no expectation given */
+ break; /* no expectation given */
}
- lf->token = token; /* set possible new token */
+ lf->token = token; /* set possible new token */
return token;
}
/*
- * lex.h
+ * lex.h
*
* Lexical scanning of configuration files, used by parsers.
*
- * Kern Sibbald, MM
+ * Kern Sibbald, MM
*
* Version $Id$
*
*/
/*
- Copyright (C) 2000, 2001, 2002 Kern Sibbald and John Walker
+ Copyright (C) 2000-2004 Kern Sibbald
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
#define L_EOL (-2)
/* Internal tokens */
-#define T_NONE 100
+#define T_NONE 100
/* Tokens returned by get_token() */
#define T_EOF 101
#define T_ERROR 200
/*
* The following will be returned only if
- * the appropriate expect flag has been set
+ * the appropriate expect flag has been set
*/
#define T_SKIP_EOL 113 /* scan through EOLs */
#define T_PINT32 114 /* positive integer */
/* Lex scan options */
#define LOPT_NO_IDENT 0x1 /* No Identifiers -- use string */
+#define LOPT_STRING 0x2 /* Force scan for string */
/* Lexical context */
typedef struct s_lex_context {
-/*
+/*
* Library includes for Bacula lib directory
*
* This file contains an include for each library file
}
/*
- * Final wrapup - pad to 64-byte boundary with the bit pattern
+ * Final wrapup - pad to 64-byte boundary with the bit pattern
* 1 0* (64-bit count of bits processed, MSB-first)
*/
void MD5Final(unsigned char digest[16], struct MD5Context *ctx)
* Reads a single ASCII file and prints the HEX md5 sum.
*/
#include <stdio.h>
-int main(int argc, char *argv[])
+int main(int argc, char *argv[])
{
FILE *fd;
MD5Context ctx;
/*
- * Bacula memory pool routines.
+ * Bacula memory pool routines.
*
* The idea behind these routines is that there will be
* pools of memory that are pre-allocated for quick
* access. The pools will have a fixed memory size on allocation
- * but if need be, the size can be increased. This is
+ * but if need be, the size can be increased. This is
* particularly useful for filename
* buffers where 256 bytes should be sufficient in 99.99%
* of the cases, but when it isn't we want to be able to
sm_new_owner(fname, lineno, (char *)buf);
return (POOLMEM *)((char *)buf+HEAD_SIZE);
}
-
+
if ((buf = (struct abufhead *)sm_malloc(fname, lineno, pool_ctl[pool].size+HEAD_SIZE)) == NULL) {
V(mutex);
Emsg1(M_ABORT, 0, "Out of memory requesting %d bytes\n", pool_ctl[pool].size);
V(mutex);
return (POOLMEM *)((char *)buf+HEAD_SIZE);
}
-
+
if ((buf=malloc(pool_ctl[pool].size+HEAD_SIZE)) == NULL) {
V(mutex);
Emsg1(M_ABORT, 0, "Out of memory requesting %d bytes\n", pool_ctl[pool].size);
sprintf(buf, "%-6d", pool);
return buf;
}
-
-/* Print staticstics on memory pool usage
- */
+
+/* Print staticstics on memory pool usage
+ */
void print_memory_pool_stats()
{
Dmsg0(-1, "Pool Maxsize Maxused Inuse\n");
}
#else
-void print_memory_pool_stats() {}
+void print_memory_pool_stats() {}
#endif /* DEBUG */
int pm_strcpy(POOL_MEM &pm, const char *str)
-{
+{
int len = strlen(str) + 1;
pm.check_size(len);
memcpy(pm.c_str(), str, len);
int POOL_MEM::strcpy(const char *str)
-{
+{
int len = strlen(str) + 1;
check_size(len);
memcpy(mem, str, len);
#define check_pool_memory_size(buf,size) sm_check_pool_memory_size(__FILE__, __LINE__, buf, size)
extern POOLMEM *sm_check_pool_memory_size(const char *fname, int line, POOLMEM *buf, int32_t size);
-#define free_pool_memory(x) sm_free_pool_memory(__FILE__, __LINE__, x)
-#define free_memory(x) sm_free_pool_memory(__FILE__, __LINE__, x)
+#define free_pool_memory(x) sm_free_pool_memory(__FILE__, __LINE__, x)
+#define free_memory(x) sm_free_pool_memory(__FILE__, __LINE__, x)
extern void sm_free_pool_memory(const char *fname, int line, POOLMEM *buf);
extern void free_pool_memory(POOLMEM *buf);
#endif
-
+
extern void close_memory_pool();
extern void print_memory_pool_stats();
-
+
#define PM_NOPOOL 0 /* nonpooled memory */
#define PM_NAME 1 /* Bacula name */
~POOL_MEM() { free_pool_memory(mem); mem = NULL; }
char *c_str() const { return mem; }
int size() const { return sizeof_pool_memory(mem); }
- char *check_size(int32_t size) {
+ char *check_size(int32_t size) {
mem = check_pool_memory_size(mem, size);
return mem;
}
/*
* Bacula message handling routines
*
- * Kern Sibbald, April 2000
+ * Kern Sibbald, April 2000
*
* Version $Id$
*
#define FULL_LOCATION 1 /* set for file:line in Debug messages */
-/*
+/*
* This is where we define "Globals" because all the
* daemons include this file.
*/
#else
#ifdef HAVE_MYSQL
char catalog_db[] = "MySQL";
-#else
+#else
#ifdef HAVE_SQLITE
char catalog_db[] = "SQLite";
#else
/* Define if e_msg must exit when M_ERROR_TERM is received */
static int exit_on_error = 1;
-/*
+/*
* Set daemon name. Also, find canonical execution
* path. Note, exepath has spare room for tacking on
* the exename so that we can reconstruct the full name.
if (argc>0 && argv && argv[0]) {
/* strip trailing filename and save exepath */
for (l=p=argv[0]; *p; p++) {
- if (*p == '/') {
+ if (*p == '/') {
l = p; /* set pos of last slash */
}
}
l = argv[0];
#if defined(HAVE_CYGWIN) || defined(HAVE_WIN32)
/* On Windows allow c: junk */
- if (l[1] == ':') {
+ if (l[1] == ':') {
l += 2;
}
#endif
}
}
-/*
+/*
* Initialize message handler for a daemon or a Job
* We make a copy of the MSGS resource passed, so it belows
* to the job or daemon and thus can be modified.
- *
+ *
* NULL for jcr -> initialize global messages for daemon
* non-NULL -> initialize jcr using Message resource
*/
}
if (rwl_init(&con_lock) != 0) {
berrno be;
- Emsg1(M_ERROR_TERM, 0, _("Could not get con mutex: ERR=%s\n"),
+ Emsg1(M_ERROR_TERM, 0, _("Could not get con mutex: ERR=%s\n"),
be.strerror());
}
}
-/*
+/*
* Called only during parsing of the config file.
*
* Add a message destination. I.e. associate a message type with
*/
void add_msg_dest(MSGS *msg, int dest_code, int msg_type, char *where, char *mail_cmd)
{
- DEST *d;
+ DEST *d;
/*
* First search the existing chain and see if we
* can simply add this msg_type to an existing entry.
*/
for (d=msg->dest_chain; d; d=d->next) {
if (dest_code == d->dest_code && ((where == NULL && d->where == NULL) ||
- (strcmp(where, d->where) == 0))) {
- Dmsg4(200, "Add to existing d=%x msgtype=%d destcode=%d where=%s\n",
+ (strcmp(where, d->where) == 0))) {
+ Dmsg4(200, "Add to existing d=%x msgtype=%d destcode=%d where=%s\n",
d, msg_type, dest_code, NPRT(where));
set_bit(msg_type, d->msg_types);
set_bit(msg_type, msg->send_msg); /* set msg_type bit in our local */
if (mail_cmd) {
d->mail_cmd = bstrdup(mail_cmd);
}
- Dmsg5(200, "add new d=%x msgtype=%d destcode=%d where=%s mailcmd=%s\n",
+ Dmsg5(200, "add new d=%x msgtype=%d destcode=%d where=%s mailcmd=%s\n",
d, msg_type, dest_code, NPRT(where), NPRT(d->mail_cmd));
msg->dest_chain = d;
}
-/*
+/*
* Called only during parsing of the config file.
*
- * Remove a message destination
+ * Remove a message destination
*/
void rem_msg_dest(MSGS *msg, int dest_code, int msg_type, char *where)
{
Dmsg2(200, "Remove_msg_dest d=%x where=%s\n", d, NPRT(d->where));
if (bit_is_set(msg_type, d->msg_types) && (dest_code == d->dest_code) &&
((where == NULL && d->where == NULL) ||
- (strcmp(where, d->where) == 0))) {
- Dmsg3(200, "Found for remove d=%x msgtype=%d destcode=%d\n",
+ (strcmp(where, d->where) == 0))) {
+ Dmsg3(200, "Found for remove d=%x msgtype=%d destcode=%d\n",
d, msg_type, dest_code);
clear_bit(msg_type, d->msg_types);
- Dmsg0(200, "Return rem_msg_dest\n");
+ Dmsg0(200, "Return rem_msg_dest\n");
return;
}
}
static BPIPE *open_mail_pipe(JCR *jcr, POOLMEM *&cmd, DEST *d)
{
BPIPE *bpipe;
-
+
if (d->mail_cmd) {
cmd = edit_job_codes(jcr, cmd, d->mail_cmd, d->where);
} else {
if (!(bpipe = open_bpipe(cmd, 120, "rw"))) {
berrno be;
- Jmsg(jcr, M_ERROR, 0, "open mail pipe %s failed: ERR=%s\n",
+ Jmsg(jcr, M_ERROR, 0, "open mail pipe %s failed: ERR=%s\n",
cmd, be.strerror());
}
if (!d->mail_cmd) {
fprintf(bpipe->wfd, "Subject: Bacula Message\r\n\r\n");
}
-
+
return bpipe;
}
-/*
+/*
* Close the messages for this Messages resource, which means to close
* any open files, and dispatch any pending email messages.
*/
BPIPE *bpipe;
POOLMEM *cmd, *line;
int len, stat;
-
+
Dmsg1(350, "Close_msg jcr=0x%x\n", jcr);
if (jcr == NULL) { /* NULL -> global chain */
break;
case MD_MAIL:
case MD_MAIL_ON_ERROR:
- Dmsg0(350, "Got MD_MAIL or MD_MAIL_ON_ERROR\n");
+ Dmsg0(350, "Got MD_MAIL or MD_MAIL_ON_ERROR\n");
if (!d->fd) {
break;
}
jcr->JobStatus == JS_Terminated) {
goto rem_temp_file;
}
-
+
if (!(bpipe=open_mail_pipe(jcr, cmd, d))) {
- Pmsg0(000, "open mail pipe failed.\n");
+ Pmsg0(000, "open mail pipe failed.\n");
goto rem_temp_file;
}
- Dmsg0(350, "Opened mail pipe\n");
+ Dmsg0(350, "Opened mail pipe\n");
len = d->max_len+10;
line = get_memory(len);
rewind(d->fd);
}
if (!close_wpipe(bpipe)) { /* close write pipe sending mail */
berrno be;
- Pmsg1(000, "close error: ERR=%s\n", be.strerror());
+ Pmsg1(000, "close error: ERR=%s\n", be.strerror());
}
/*
- * Since we are closing all messages, before "recursing"
+ * Since we are closing all messages, before "recursing"
* make sure we are not closing the daemon messages, otherwise
* kaboom.
*/
if (msgs != daemon_msgs) {
/* read what mail prog returned -- should be nothing */
while (fgets(line, len, bpipe->rfd)) {
- Jmsg1(jcr, M_INFO, 0, _("Mail prog: %s"), line);
+ Jmsg1(jcr, M_INFO, 0, _("Mail prog: %s"), line);
}
}
if (stat != 0 && msgs != daemon_msgs) {
berrno be;
be.set_errno(stat);
- Dmsg1(350, "Calling emsg. CMD=%s\n", cmd);
- Jmsg2(jcr, M_ERROR, 0, _("Mail program terminated in error.\n"
- "CMD=%s\n"
- "ERR=%s\n"), cmd, be.strerror());
+ Dmsg1(350, "Calling emsg. CMD=%s\n", cmd);
+ Jmsg2(jcr, M_ERROR, 0, _("Mail program terminated in error.\n"
+ "CMD=%s\n"
+ "ERR=%s\n"), cmd, be.strerror());
}
free_memory(line);
rem_temp_file:
unlink(d->mail_filename);
free_pool_memory(d->mail_filename);
d->mail_filename = NULL;
- Dmsg0(350, "end mail or mail on error\n");
+ Dmsg0(350, "end mail or mail on error\n");
break;
default:
break;
}
/*
- * Free memory associated with Messages resource
+ * Free memory associated with Messages resource
*/
void free_msgs_res(MSGS *msgs)
{
}
-/*
- * Terminate the message handler for good.
+/*
+ * Terminate the message handler for good.
* Release the global destination chain.
- *
+ *
* Also, clean up a few other items (cons, exepath). Note,
* these really should be done elsewhere.
*/
*/
void dispatch_message(JCR *jcr, int type, time_t mtime, char *msg)
{
- DEST *d;
+ DEST *d;
char dt[MAX_TIME_LENGTH];
POOLMEM *mcmd;
int len, dtlen;
*/
if (mtime == 0) {
mtime = time(NULL);
- }
+ }
if (mtime == 1) {
*dt = 0;
dtlen = 0;
#if defined(HAVE_CYGWIN) || defined(HAVE_WIN32)
/* If we don't exit on error, error messages are parsed by UA */
if (exit_on_error) {
- MessageBox(NULL, msg, "Bacula", MB_OK);
+ MessageBox(NULL, msg, "Bacula", MB_OK);
}
#endif
#endif
msgs = NULL;
if (jcr) {
msgs = jcr->jcr_msgs;
- }
+ }
if (msgs == NULL) {
msgs = daemon_msgs;
}
if (bit_is_set(type, d->msg_types)) {
switch (d->dest_code) {
case MD_CONSOLE:
- Dmsg1(800, "CONSOLE for following msg: %s", msg);
+ Dmsg1(800, "CONSOLE for following msg: %s", msg);
if (!con_fd) {
- con_fd = fopen(con_fname, "a+");
- Dmsg0(800, "Console file not open.\n");
+ con_fd = fopen(con_fname, "a+");
+ Dmsg0(800, "Console file not open.\n");
}
if (con_fd) {
Pw(con_lock); /* get write lock on console message file */
len = strlen(msg);
if (len > 0) {
fwrite(msg, len, 1, con_fd);
- if (msg[len-1] != '\n') {
- fwrite("\n", 2, 1, con_fd);
+ if (msg[len-1] != '\n') {
+ fwrite("\n", 2, 1, con_fd);
}
} else {
- fwrite("\n", 2, 1, con_fd);
+ fwrite("\n", 2, 1, con_fd);
}
fflush(con_fd);
console_msg_pending = TRUE;
}
break;
case MD_SYSLOG:
- Dmsg1(800, "SYSLOG for collowing msg: %s\n", msg);
+ Dmsg1(800, "SYSLOG for collowing msg: %s\n", msg);
/*
- * We really should do an openlog() here.
+ * We really should do an openlog() here.
*/
- syslog(LOG_DAEMON|LOG_ERR, "%s", msg);
+ syslog(LOG_DAEMON|LOG_ERR, "%s", msg);
break;
case MD_OPERATOR:
- Dmsg1(800, "OPERATOR for following msg: %s\n", msg);
+ Dmsg1(800, "OPERATOR for following msg: %s\n", msg);
mcmd = get_pool_memory(PM_MESSAGE);
if ((bpipe=open_mail_pipe(jcr, mcmd, d))) {
int stat;
if (stat != 0) {
berrno be;
be.set_errno(stat);
- Qmsg2(jcr, M_ERROR, 0, _("Operator mail program terminated in error.\n"
- "CMD=%s\n"
- "ERR=%s\n"), mcmd, be.strerror());
+ Qmsg2(jcr, M_ERROR, 0, _("Operator mail program terminated in error.\n"
+ "CMD=%s\n"
+ "ERR=%s\n"), mcmd, be.strerror());
}
}
free_pool_memory(mcmd);
break;
case MD_MAIL:
case MD_MAIL_ON_ERROR:
- Dmsg1(800, "MAIL for following msg: %s", msg);
+ Dmsg1(800, "MAIL for following msg: %s", msg);
if (!d->fd) {
POOLMEM *name = get_pool_memory(PM_MESSAGE);
make_unique_mail_filename(jcr, name, d);
- d->fd = fopen(name, "w+");
+ d->fd = fopen(name, "w+");
if (!d->fd) {
berrno be;
d->fd = stdout;
- Qmsg2(jcr, M_ERROR, 0, "fopen %s failed: ERR=%s\n", name,
+ Qmsg2(jcr, M_ERROR, 0, "fopen %s failed: ERR=%s\n", name,
be.strerror());
d->fd = NULL;
free_pool_memory(name);
fputs(msg, d->fd);
break;
case MD_FILE:
- Dmsg1(800, "FILE for following msg: %s", msg);
+ Dmsg1(800, "FILE for following msg: %s", msg);
if (!d->fd) {
- d->fd = fopen(d->where, "w+");
+ d->fd = fopen(d->where, "w+");
if (!d->fd) {
berrno be;
d->fd = stdout;
- Qmsg2(jcr, M_ERROR, 0, "fopen %s failed: ERR=%s\n", d->where,
+ Qmsg2(jcr, M_ERROR, 0, "fopen %s failed: ERR=%s\n", d->where,
be.strerror());
d->fd = NULL;
break;
fputs(msg, d->fd);
break;
case MD_APPEND:
- Dmsg1(800, "APPEND for following msg: %s", msg);
+ Dmsg1(800, "APPEND for following msg: %s", msg);
if (!d->fd) {
- d->fd = fopen(d->where, "a");
+ d->fd = fopen(d->where, "a");
if (!d->fd) {
berrno be;
d->fd = stdout;
- Qmsg2(jcr, M_ERROR, 0, "fopen %s failed: ERR=%s\n", d->where,
+ Qmsg2(jcr, M_ERROR, 0, "fopen %s failed: ERR=%s\n", d->where,
be.strerror());
d->fd = NULL;
break;
fputs(msg, d->fd);
break;
case MD_DIRECTOR:
- Dmsg1(800, "DIRECTOR for following msg: %s", msg);
+ Dmsg1(800, "DIRECTOR for following msg: %s", msg);
if (jcr && jcr->dir_bsock && !jcr->dir_bsock->errors) {
- bnet_fsend(jcr->dir_bsock, "Jmsg Job=%s type=%d level=%d %s",
+ bnet_fsend(jcr->dir_bsock, "Jmsg Job=%s type=%d level=%d %s",
jcr->Job, type, mtime, msg);
}
break;
case MD_STDOUT:
- Dmsg1(800, "STDOUT for following msg: %s", msg);
+ Dmsg1(800, "STDOUT for following msg: %s", msg);
if (type != M_ABORT && type != M_ERROR_TERM) { /* already printed */
fputs(dt, stdout);
fputs(msg, stdout);
}
break;
case MD_STDERR:
- Dmsg1(800, "STDERR for following msg: %s", msg);
+ Dmsg1(800, "STDERR for following msg: %s", msg);
fputs(dt, stderr);
fputs(msg, stderr);
break;
* is less than or equal the debug_level. File and line numbers
* are included for more detail if desired, but not currently
* printed.
- *
+ *
* If the level is negative, the details of file and line number
* are not printed.
*/
-void
+void
d_msg(const char *file, int line, int level, const char *fmt,...)
{
char buf[5000];
/* visual studio passes the whole path to the file as well
* which makes for very long lines
*/
- const char *f = strrchr(file, '\\');
+ const char *f = strrchr(file, '\\');
if (f) file = f + 1;
- len = bsnprintf(buf, sizeof(buf), "%s: %s:%d ", my_name, file, line);
+ len = bsnprintf(buf, sizeof(buf), "%s: %s:%d ", my_name, file, line);
} else {
len = 0;
}
bvsnprintf(buf+len, sizeof(buf)-len, (char *)fmt, arg_ptr);
va_end(arg_ptr);
- /*
- * Used the "trace on" command in the console to turn on
- * output to the trace file. "trace off" will close the file.
+ /*
+ * Used the "trace on" command in the console to turn on
+ * output to the trace file. "trace off" will close the file.
*/
if (trace) {
if (!trace_fd) {
- bsnprintf(buf, sizeof(buf), "%s/bacula.trace", working_directory ? working_directory : ".");
- trace_fd = fopen(buf, "a+");
+ bsnprintf(buf, sizeof(buf), "%s/bacula.trace", working_directory ? working_directory : ".");
+ trace_fd = fopen(buf, "a+");
}
if (trace_fd) {
fputs(buf, trace_fd);
}
/*
- * Set trace flag on/off. If argument is negative, there is no change
+ * Set trace flag on/off. If argument is negative, there is no change
*/
void set_trace(int trace_flag)
{
/*********************************************************************
*
* This subroutine prints a message regardless of the debug level
- *
+ *
* If the level is negative, the details of file and line number
* are not printed.
*/
-void
+void
p_msg(const char *file, int line, int level, const char *fmt,...)
{
char buf[5000];
* is less than or equal the debug_level. File and line numbers
* are included for more detail if desired, but not currently
* printed.
- *
+ *
* If the level is negative, the details of file and line number
* are not printed.
*/
-void
+void
t_msg(const char *file, int line, int level, const char *fmt,...)
{
char buf[5000];
if (level <= debug_level) {
if (!trace_fd) {
- bsnprintf(buf, sizeof(buf), "%s/bacula.trace", working_directory);
- trace_fd = fopen(buf, "a+");
+ bsnprintf(buf, sizeof(buf), "%s/bacula.trace", working_directory);
+ trace_fd = fopen(buf, "a+");
}
-
+
#ifdef FULL_LOCATION
if (details) {
- len = bsnprintf(buf, sizeof(buf), "%s: %s:%d ", my_name, file, line);
+ len = bsnprintf(buf, sizeof(buf), "%s: %s:%d ", my_name, file, line);
} else {
len = 0;
}
* print an error message
*
*/
-void
+void
e_msg(const char *file, int line, int type, int level, const char *fmt,...)
{
char buf[5000];
va_list arg_ptr;
int len;
- /*
- * Check if we have a message destination defined.
- * We always report M_ABORT and M_ERROR_TERM
+ /*
+ * Check if we have a message destination defined.
+ * We always report M_ABORT and M_ERROR_TERM
*/
- if (!daemon_msgs || ((type != M_ABORT && type != M_ERROR_TERM) &&
+ if (!daemon_msgs || ((type != M_ABORT && type != M_ERROR_TERM) &&
!bit_is_set(type, daemon_msgs->send_msg))) {
return; /* no destination */
}
switch (type) {
case M_ABORT:
- len = bsnprintf(buf, sizeof(buf), "%s: ABORTING due to ERROR in %s:%d\n",
+ len = bsnprintf(buf, sizeof(buf), "%s: ABORTING due to ERROR in %s:%d\n",
my_name, file, line);
break;
case M_ERROR_TERM:
- len = bsnprintf(buf, sizeof(buf), "%s: ERROR TERMINATION at %s:%d\n",
+ len = bsnprintf(buf, sizeof(buf), "%s: ERROR TERMINATION at %s:%d\n",
my_name, file, line);
break;
case M_FATAL:
if (level == -1) /* skip details */
- len = bsnprintf(buf, sizeof(buf), "%s: Fatal Error because: ", my_name);
+ len = bsnprintf(buf, sizeof(buf), "%s: Fatal Error because: ", my_name);
else
- len = bsnprintf(buf, sizeof(buf), "%s: Fatal Error at %s:%d because:\n", my_name, file, line);
+ len = bsnprintf(buf, sizeof(buf), "%s: Fatal Error at %s:%d because:\n", my_name, file, line);
break;
case M_ERROR:
if (level == -1) /* skip details */
- len = bsnprintf(buf, sizeof(buf), "%s: ERROR: ", my_name);
+ len = bsnprintf(buf, sizeof(buf), "%s: ERROR: ", my_name);
else
- len = bsnprintf(buf, sizeof(buf), "%s: ERROR in %s:%d ", my_name, file, line);
+ len = bsnprintf(buf, sizeof(buf), "%s: ERROR in %s:%d ", my_name, file, line);
break;
case M_WARNING:
len = bsnprintf(buf, sizeof(buf), "%s: Warning: ", my_name);
* Generate a Job message
*
*/
-void
+void
Jmsg(JCR *jcr, int type, time_t mtime, const char *fmt,...)
{
char rbuf[5000];
MSGS *msgs;
const char *job;
-
+
Dmsg1(800, "Enter Jmsg type=%d\n", type);
/* Special case for the console, which has a dir_bsock and JobId==0,
* in that case, we send the message directly back to the
- * dir_bsock.
+ * dir_bsock.
*/
if (jcr && jcr->JobId == 0 && jcr->dir_bsock) {
BSOCK *dir = jcr->dir_bsock;
va_start(arg_ptr, fmt);
- dir->msglen = bvsnprintf(dir->msg, sizeof_pool_memory(dir->msg),
+ dir->msglen = bvsnprintf(dir->msg, sizeof_pool_memory(dir->msg),
fmt, arg_ptr);
va_end(arg_ptr);
bnet_send(jcr->dir_bsock);
if (jcr) {
msgs = jcr->jcr_msgs;
job = jcr->Job;
- }
+ }
if (!msgs) {
msgs = daemon_msgs; /* if no jcr, we use daemon handler */
}
job = ""; /* Set null job name if none */
}
- /*
- * Check if we have a message destination defined.
- * We always report M_ABORT and M_ERROR_TERM
+ /*
+ * Check if we have a message destination defined.
+ * We always report M_ABORT and M_ERROR_TERM
*/
if (msgs && (type != M_ABORT && type != M_ERROR_TERM) &&
!bit_is_set(type, msgs->send_msg)) {
i = Mmsg(pool_buf, "%s:%d ", file, line);
for (;;) {
- maxlen = sizeof_pool_memory(pool_buf) - i - 1;
+ maxlen = sizeof_pool_memory(pool_buf) - i - 1;
va_start(arg_ptr, fmt);
len = bvsnprintf(pool_buf+i, maxlen, fmt, arg_ptr);
va_end(arg_ptr);
/*
* Edit a message into a Pool memory buffer, with file:lineno
- */
+ */
int m_msg(const char *file, int line, POOLMEM **pool_buf, const char *fmt, ...)
{
va_list arg_ptr;
i = sprintf(*pool_buf, "%s:%d ", file, line);
for (;;) {
- maxlen = sizeof_pool_memory(*pool_buf) - i - 1;
+ maxlen = sizeof_pool_memory(*pool_buf) - i - 1;
va_start(arg_ptr, fmt);
len = bvsnprintf(*pool_buf+i, maxlen, fmt, arg_ptr);
va_end(arg_ptr);
i = sprintf(pool_buf, "%s:%d ", file, line);
for (;;) {
- maxlen = sizeof_pool_memory(pool_buf) - i - 1;
+ maxlen = sizeof_pool_memory(pool_buf) - i - 1;
va_start(arg_ptr, fmt);
len = bvsnprintf(pool_buf+i, maxlen, fmt, arg_ptr);
va_end(arg_ptr);
int len, maxlen;
for (;;) {
- maxlen = sizeof_pool_memory(*pool_buf) - 1;
+ maxlen = sizeof_pool_memory(*pool_buf) - 1;
va_start(arg_ptr, fmt);
len = bvsnprintf(*pool_buf, maxlen, fmt, arg_ptr);
va_end(arg_ptr);
int len, maxlen;
for (;;) {
- maxlen = sizeof_pool_memory(pool_buf) - 1;
+ maxlen = sizeof_pool_memory(pool_buf) - 1;
va_start(arg_ptr, fmt);
len = bvsnprintf(pool_buf, maxlen, fmt, arg_ptr);
va_end(arg_ptr);
int len, maxlen;
for (;;) {
- maxlen = pool_buf.max_size() - 1;
+ maxlen = pool_buf.max_size() - 1;
va_start(arg_ptr, fmt);
len = bvsnprintf(pool_buf.c_str(), maxlen, fmt, arg_ptr);
va_end(arg_ptr);
/*
* We queue messages rather than print them directly. This
* is generally used in low level routines (msg handler, bnet)
- * to prevent recursion (i.e. if you are in the middle of
+ * to prevent recursion (i.e. if you are in the middle of
* sending a message, it is a bit messy to recursively call
* yourself when the bnet packet is not reentrant).
*/
pool_buf = get_pool_memory(PM_EMSG);
for (;;) {
- maxlen = sizeof_pool_memory(pool_buf) - 1;
+ maxlen = sizeof_pool_memory(pool_buf) - 1;
va_start(arg_ptr, fmt);
len = bvsnprintf(pool_buf, maxlen, fmt, arg_ptr);
va_end(arg_ptr);
item = (MQUEUE_ITEM *)malloc(sizeof(MQUEUE_ITEM) + strlen(pool_buf) + 1);
item->type = type;
item->mtime = time(NULL);
- strcpy(item->msg, pool_buf);
+ strcpy(item->msg, pool_buf);
/* If no jcr or dequeuing send to daemon to avoid recursion */
if (!jcr || jcr->dequeuing) {
/* jcr==NULL => daemon message, safe to send now */
}
/*
- * Dequeue messages
+ * Dequeue messages
*/
void dequeue_messages(JCR *jcr)
{
jcr->msg_queue->destroy();
jcr->dequeuing = false;
V(msg_queue_mutex);
-}
+}
/*
i = Mmsg(pool_buf, "%s:%d ", file, line);
for (;;) {
- maxlen = sizeof_pool_memory(pool_buf) - i - 1;
+ maxlen = sizeof_pool_memory(pool_buf) - i - 1;
va_start(arg_ptr, fmt);
len = bvsnprintf(pool_buf+i, maxlen, fmt, arg_ptr);
va_end(arg_ptr);
free_memory(pool_buf);
}
-/*
+/*
* Define if e_msg must exit when M_ERROR_TERM is received
*/
void set_exit_on_error(int value) {
#undef M_ALERT
/*
- * Most of these message levels are more or less obvious.
+ * Most of these message levels are more or less obvious.
* They have evolved somewhat during the development of Bacula,
* and here are some of the details of where I am trying to
* head (in the process of changing the code) as of 15 June 2002.
* M_FATAL Bacula detected a fatal Job error. The Job will be killed,
* but Bacula continues running.
* M_ERROR Bacula detected a Job error. The Job will continue running
- * but the termination status will be error.
+ * but the termination status will be error.
* M_WARNING Job warning message.
* M_INFO Job information message.
*
/*
* Master Configuration routines.
- *
+ *
* This file contains the common parts of the Bacula
* configuration routines.
*
*
* 1. The generic lexical scanner in lib/lex.c and lib/lex.h
*
- * 2. The generic config scanner in lib/parse_conf.c and
+ * 2. The generic config scanner in lib/parse_conf.c and
* lib/parse_conf.h.
* These files contain the parser code, some utility
* routines, and the common store routines (name, int,
extern int debug_level;
-/* Each daemon has a slightly different set of
+/* Each daemon has a slightly different set of
* resources, so it will define the following
* global values.
*/
{"description", store_str, ITEM(res_msgs.hdr.desc), 0, 0, 0},
{"mailcommand", store_str, ITEM(res_msgs.mail_cmd), 0, 0, 0},
{"operatorcommand", store_str, ITEM(res_msgs.operator_cmd), 0, 0, 0},
- {"syslog", store_msgs, ITEM(res_msgs), MD_SYSLOG, 0, 0},
+ {"syslog", store_msgs, ITEM(res_msgs), MD_SYSLOG, 0, 0},
{"mail", store_msgs, ITEM(res_msgs), MD_MAIL, 0, 0},
{"mailonerror", store_msgs, ITEM(res_msgs), MD_MAIL_ON_ERROR, 0, 0},
{"file", store_msgs, ITEM(res_msgs), MD_FILE, 0, 0},
{"stdout", store_msgs, ITEM(res_msgs), MD_STDOUT, 0, 0},
{"stderr", store_msgs, ITEM(res_msgs), MD_STDERR, 0, 0},
{"director", store_msgs, ITEM(res_msgs), MD_DIRECTOR, 0, 0},
- {"console", store_msgs, ITEM(res_msgs), MD_CONSOLE, 0, 0},
+ {"console", store_msgs, ITEM(res_msgs), MD_CONSOLE, 0, 0},
{"operator", store_msgs, ITEM(res_msgs), MD_OPERATOR, 0, 0},
{NULL, NULL, NULL, 0, 0}
};
-struct s_mtypes {
+struct s_mtypes {
const char *name;
- int token;
+ int token;
};
/* Various message types */
static struct s_mtypes msg_types[] = {
}
-/*
+/*
* Initialize the static structure to zeros, then
* apply all the default values.
*/
int errstat;
if (first && (errstat=rwl_init(&res_lock)) != 0) {
- Emsg1(M_ABORT, 0, _("Unable to initialize resource lock. ERR=%s\n"),
+ Emsg1(M_ABORT, 0, _("Unable to initialize resource lock. ERR=%s\n"),
strerror(errstat));
}
first = false;
for (i=0; items[i].name; i++) {
Dmsg3(900, "Item=%s def=%s defval=%d\n", items[i].name,
- (items[i].flags & ITEM_DEFAULT) ? "yes" : "no",
+ (items[i].flags & ITEM_DEFAULT) ? "yes" : "no",
items[i].default_value);
if (items[i].flags & ITEM_DEFAULT && items[i].default_value != 0) {
if (items[i].handler == store_yesno) {
*(int *)(items[i].value) |= items[i].code;
- } else if (items[i].handler == store_pint ||
+ } else if (items[i].handler == store_pint ||
items[i].handler == store_int) {
*(int *)(items[i].value) = items[i].default_value;
} else if (items[i].handler == store_int64) {
}
/* If this triggers, take a look at lib/parse_conf.h */
if (i >= MAX_RES_ITEMS) {
- Emsg1(M_ERROR_TERM, 0, _("Too many items in %s resource\n"), resources[rindex]);
+ Emsg1(M_ERROR_TERM, 0, _("Too many items in %s resource\n"), resources[rindex]);
}
}
}
int token;
char *cmd;
POOLMEM *dest;
- int dest_len;
+ int dest_len;
Dmsg2(900, "store_msgs pass=%d code=%d\n", pass, item->code);
if (pass == 1) {
token = lex_get_token(lc, T_NAME); /* scan destination */
dest = check_pool_memory_size(dest, dest_len + lc->str_len + 2);
if (dest[0] != 0) {
- pm_strcat(dest, " "); /* separate multiple destinations with space */
+ pm_strcat(dest, " "); /* separate multiple destinations with space */
dest_len++;
}
pm_strcat(dest, lc->str);
dest_len += lc->str_len;
- Dmsg2(900, "store_msgs newdest=%s: dest=%s:\n", lc->str, NPRT(dest));
+ Dmsg2(900, "store_msgs newdest=%s: dest=%s:\n", lc->str, NPRT(dest));
token = lex_get_token(lc, T_SKIP_EOL);
- if (token == T_COMMA) {
+ if (token == T_COMMA) {
continue; /* get another destination */
}
if (token != T_EQUALS) {
- scan_err1(lc, _("expected an =, got: %s"), lc->str);
+ scan_err1(lc, _("expected an =, got: %s"), lc->str);
}
break;
}
- Dmsg1(900, "mail_cmd=%s\n", NPRT(cmd));
+ Dmsg1(900, "mail_cmd=%s\n", NPRT(cmd));
scan_types(lc, (MSGS *)(item->value), item->code, dest, cmd);
free_pool_memory(dest);
- Dmsg0(900, "done with dest codes\n");
+ Dmsg0(900, "done with dest codes\n");
break;
case MD_FILE: /* file */
case MD_APPEND: /* append */
pm_strcpy(dest, lc->str);
dest_len = lc->str_len;
token = lex_get_token(lc, T_SKIP_EOL);
- Dmsg1(900, "store_msgs dest=%s:\n", NPRT(dest));
+ Dmsg1(900, "store_msgs dest=%s:\n", NPRT(dest));
if (token != T_EQUALS) {
- scan_err1(lc, _("expected an =, got: %s"), lc->str);
+ scan_err1(lc, _("expected an =, got: %s"), lc->str);
}
scan_types(lc, (MSGS *)(item->value), item->code, dest, NULL);
free_pool_memory(dest);
- Dmsg0(900, "done with dest codes\n");
+ Dmsg0(900, "done with dest codes\n");
break;
default:
- scan_err1(lc, _("Unknown item code: %d\n"), item->code);
+ scan_err1(lc, _("Unknown item code: %d\n"), item->code);
break;
}
}
Dmsg0(900, "Done store_msgs\n");
}
-/*
+/*
* Scan for message types and add them to the message
* destination. The basic job here is to connect message types
* (WARNING, ERROR, FATAL, INFO, ...) with an appropriate
char *str;
for (quit=0; !quit;) {
- lex_get_token(lc, T_NAME); /* expect at least one type */
+ lex_get_token(lc, T_NAME); /* expect at least one type */
found = FALSE;
if (lc->str[0] == '!') {
is_not = TRUE;
}
}
if (!found) {
- scan_err1(lc, _("message type: %s not found"), str);
+ scan_err1(lc, _("message type: %s not found"), str);
/* NOT REACHED */
}
}
-/*
+/*
* This routine is ONLY for resource names
* Store a name at specified address.
*/
free_pool_memory(msg);
/* Store the name both pass 1 and pass 2 */
if (*(item->value)) {
- scan_err2(lc, _("Attempt to redefine name \"%s\" to \"%s\"."),
+ scan_err2(lc, _("Attempt to redefine name \"%s\" to \"%s\"."),
*(item->value), lc->str);
}
*(item->value) = bstrdup(lc->str);
MD5Update(&md5c, (unsigned char *) (lc->str), lc->str_len);
MD5Final(signature, &md5c);
for (i = j = 0; i < sizeof(signature); i++) {
- sprintf(&sig[j], "%02x", signature[i]);
+ sprintf(&sig[j], "%02x", signature[i]);
j += 2;
}
*(item->value) = bstrdup(sig);
/* Store a resource at specified address.
- * If we are in pass 2, do a lookup of the
+ * If we are in pass 2, do a lookup of the
* resource.
*/
void store_res(LEX *lc, RES_ITEM *item, int index, int pass)
if (pass == 2) {
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, _("Could not find config Resource %s referenced on line %d : %s\n"),
lc->str, lc->line_no, lc->line);
}
if (*(item->value)) {
- scan_err3(lc, _("Attempt to redefine resource \"%s\" referenced on line %d : %s\n"),
+ scan_err3(lc, _("Attempt to redefine resource \"%s\" referenced on line %d : %s\n"),
item->name, lc->line_no, lc->line);
}
*(item->value) = (char *)res;
* Store a resource in an alist. default_value indicates how many
* times this routine can be called -- i.e. how many alists
* there are.
- * If we are in pass 2, do a lookup of the
+ * If we are in pass 2, do a lookup of the
* resource.
*/
void store_alist_res(LEX *lc, RES_ITEM *item, int index, int pass)
/* Find empty place to store this directive */
while ((item->value)[i] != NULL && i++ < count) { }
if (i >= count) {
- scan_err3(lc, _("Too many Storage directives. Max. is %d. line %d: %s\n"),
+ scan_err3(lc, _("Too many Storage directives. Max. is %d. line %d: %s\n"),
count, lc->line_no, lc->line);
}
list = New(alist(10, not_owned_by_alist));
lex_get_token(lc, T_NAME); /* scan next item */
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, _("Could not find config Resource \"%s\" referenced on line %d : %s\n"),
lc->str, lc->line_no, lc->line);
}
list->append(res);
(item->value)[i] = (char *)list;
- if (lc->ch != ',') { /* if no other item follows */
+ if (lc->ch != ',') { /* if no other item follows */
break; /* get out */
}
lex_get_token(lc, T_ALL); /* eat comma */
/*
* Store default values for Resource from xxxDefs
- * If we are in pass 2, do a lookup of the
+ * If we are in pass 2, do a lookup of the
* resource and store everything not explicitly set
* in main resource.
*
Dmsg2(900, "Code=%d name=%s\n", item->code, lc->str);
res = GetResWithName(item->code, lc->str);
if (res == NULL) {
- scan_err3(lc, _("Missing 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 res */
#ifdef xxx
for (int i=0; item->name;; i++, item++) {
if (bit_is_set(i, res->item_present)) {
- Dmsg2(900, "Item %d is present in %s\n", i, res->name);
+ Dmsg2(900, "Item %d is present in %s\n", i, res->name);
} else {
- Dmsg2(900, "Item %d is not present in %s\n", i, res->name);
+ Dmsg2(900, "Item %d is not present in %s\n", i, res->name);
}
}
/* ***FIXME **** add code */
case T_IDENTIFIER:
case T_UNQUOTED_STRING:
if (!size_to_uint64(lc->str, lc->str_len, &uvalue)) {
- scan_err1(lc, _("expected a size number, got: %s"), lc->str);
+ scan_err1(lc, _("expected a size number, got: %s"), lc->str);
}
*(uint64_t *)(item->value) = uvalue;
break;
/* Store a time period in seconds */
void store_time(LEX *lc, RES_ITEM *item, int index, int pass)
{
- int token;
+ int token;
utime_t utime;
char period[500];
}
}
if (!duration_to_utime(period, &utime)) {
- scan_err1(lc, _("expected a time period, got: %s"), period);
+ scan_err1(lc, _("expected a time period, got: %s"), period);
}
*(utime_t *)(item->value) = utime;
break;
}
UnlockRes();
return res;
-
+
}
/*
{
RES *nres;
int rindex = rcode - r_first;
-
+
if (!res_locked) {
Emsg0(M_ABORT, 0, "Resource chain not locked.\n");
/*********************************************************************
*
* Parse configuration file
- *
+ *
* Return 0 if reading failed, 1 otherwise
*/
-int
+int
parse_config(const char *cf, int exit_on_error)
{
set_exit_on_error(exit_on_error);
int level = 0;
/* Make two passes. The first builds the name symbol table,
- * and the second picks up the items.
+ * and the second picks up the items.
*/
Dmsg0(900, "Enter parse_config()\n");
for (pass=1; pass <= 2; pass++) {
return 0;
}
while ((token=lex_get_token(lc, T_ALL)) != T_EOF) {
- Dmsg1(900, "parse got token=%s\n", lex_tok_to_str(token));
+ Dmsg1(900, "parse got token=%s\n", lex_tok_to_str(token));
switch (state) {
case p_none:
if (token == T_EOL) {
break;
}
if (token != T_IDENTIFIER) {
- scan_err1(lc, _("Expected a Resource name identifier, got: %s"), lc->str);
+ scan_err1(lc, _("Expected a Resource name identifier, got: %s"), lc->str);
set_exit_on_error(1); /* Never reached if exit_on_error == 1 */
return 0;
}
break;
}
if (state == p_none) {
- scan_err1(lc, _("expected resource name, got: %s"), lc->str);
+ scan_err1(lc, _("expected resource name, got: %s"), lc->str);
set_exit_on_error(1); /* Never reached if exit_on_error == 1 */
return 0;
}
break;
case T_IDENTIFIER:
if (level != 1) {
- scan_err1(lc, _("not in resource definition: %s"), lc->str);
+ scan_err1(lc, _("not in resource definition: %s"), lc->str);
set_exit_on_error(1); /* Never reached if exit_on_error == 1 */
return 0;
}
for (i=0; items[i].name; i++) {
if (strcasecmp(items[i].name, lc->str) == 0) {
- /* If the ITEM_NO_EQUALS flag is set we do NOT
+ /* If the ITEM_NO_EQUALS flag is set we do NOT
* scan for = after the keyword */
if (!(items[i].flags & ITEM_NO_EQUALS)) {
token = lex_get_token(lc, T_SKIP_EOL);
- Dmsg1 (900, "in T_IDENT got token=%s\n", lex_tok_to_str(token));
+ Dmsg1 (900, "in T_IDENT got token=%s\n", lex_tok_to_str(token));
if (token != T_EQUALS) {
- scan_err1(lc, _("expected an equals, got: %s"), lc->str);
+ scan_err1(lc, _("expected an equals, got: %s"), lc->str);
set_exit_on_error(1); /* Never reached if exit_on_error == 1 */
return 0;
}
}
- Dmsg1(900, "calling handler for %s\n", items[i].name);
+ Dmsg1(900, "calling handler for %s\n", items[i].name);
/* Call item handler */
items[i].handler(lc, &items[i], i, pass);
i = -1;
}
}
if (i >= 0) {
- Dmsg2(900, "level=%d id=%s\n", level, lc->str);
- Dmsg1(900, "Keyword = %s\n", lc->str);
- scan_err1(lc, _("Keyword \"%s\" not permitted in this resource.\n"
- "Perhaps you left the trailing brace off of the previous resource."), lc->str);
+ Dmsg2(900, "level=%d id=%s\n", level, lc->str);
+ Dmsg1(900, "Keyword = %s\n", lc->str);
+ scan_err1(lc, _("Keyword \"%s\" not permitted in this resource.\n"
+ "Perhaps you left the trailing brace off of the previous resource."), lc->str);
set_exit_on_error(1); /* Never reached if exit_on_error == 1 */
return 0;
}
case T_EOB:
level--;
state = p_none;
- Dmsg0(900, "T_EOB => define new resource\n");
+ Dmsg0(900, "T_EOB => define new resource\n");
save_resource(res_type, items, pass); /* save resource */
break;
break;
default:
- scan_err2(lc, _("unexpected token %d %s in resource definition"),
+ scan_err2(lc, _("unexpected token %d %s in resource definition"),
token, lex_tok_to_str(token));
set_exit_on_error(1); /* Never reached if exit_on_error == 1 */
return 0;
}
break;
default:
- scan_err1(lc, _("Unknown parser state %d\n"), state);
+ scan_err1(lc, _("Unknown parser state %d\n"), state);
set_exit_on_error(1); /* Never reached if exit_on_error == 1 */
return 0;
}
}
if (state != p_none) {
- scan_err0(lc, _("End of conf file reached with unclosed resource."));
+ scan_err0(lc, _("End of conf file reached with unclosed resource."));
set_exit_on_error(1); /* Never reached if exit_on_error == 1 */
return 0;
}
}
}
-RES **save_config_resources()
+RES **save_config_resources()
{
int num = r_last - r_first + 1;
RES **res = (RES **)malloc(num*sizeof(RES *));
*/
-struct RES_ITEM; /* Declare forward referenced structure */
+struct RES_ITEM; /* Declare forward referenced structure */
typedef void (MSG_RES_HANDLER)(LEX *lc, RES_ITEM *item, int index, int pass);
/* This is the structure that defines
};
-/*
+/*
* Master Resource configuration structure definition
* This is the structure that defines the
* resources that are available to this daemon.
*/
-struct RES_TABLE {
+struct RES_TABLE {
const char *name; /* resource name */
RES_ITEM *items; /* list of resource keywords */
int rcode; /* code if needed */
/* Loop through each resource of type, returning in var */
#define foreach_res(var, type) \
- for(var=NULL; (*((void **)&(var))=(void *)GetNextRes((type), (RES *)var));)
+ for(var=NULL; (*((void **)&(var))=(void *)GetNextRes((type), (RES *)var));)
#ifdef the_old_way
#define foreach_res(var, type) \
- for((var)=NULL; (((void *)(var))=GetNextRes((type), (RES *)var));)
+ for((var)=NULL; (((void *)(var))=GetNextRes((type), (RES *)var));)
#endif
int bnet_ssl_server (BSOCK *bsock, char *password, int ssl_need, int ssl_has);
int bnet_ssl_client (BSOCK *bsock, char *password, int ssl_need);
BSOCK * bnet_connect (JCR *jcr, int retry_interval,
- int max_retry_time, const char *name, char *host, char *service,
- int port, int verbose);
+ int max_retry_time, const char *name, char *host, char *service,
+ int port, int verbose);
void bnet_close (BSOCK *bsock);
-BSOCK * init_bsock (JCR *jcr, int sockfd, const char *who, const char *ip,
- int port, struct sockaddr *client_addr);
+BSOCK * init_bsock (JCR *jcr, int sockfd, const char *who, const char *ip,
+ int port, struct sockaddr *client_addr);
BSOCK * dup_bsock (BSOCK *bsock);
void term_bsock (BSOCK *bsock);
const char *bnet_strerror (BSOCK *bsock);
int cram_md5_get_auth(BSOCK *bs, char *password, int ssl_need);
int cram_md5_auth(BSOCK *bs, char *password, int ssl_need);
void hmac_md5(uint8_t* text, int text_len, uint8_t* key,
- int key_len, uint8_t *hmac);
+ int key_len, uint8_t *hmac);
/* crc32.c */
void set_exit_on_error (int value);
/* bnet_server.c */
-void bnet_thread_server(dlist *addr, int max_clients, workq_t *client_wq,
- void *handle_client_request(void *bsock));
+void bnet_thread_server(dlist *addr, int max_clients, workq_t *client_wq,
+ void *handle_client_request(void *bsock));
void bnet_stop_thread_server(pthread_t tid);
void bnet_server (int port, void handle_client_request(BSOCK *bsock));
int net_connect (int port);
bool skip_nonspaces (char **msg);
int fstrsch (const char *a, const char *b);
char *next_arg(char **s);
-int parse_args(POOLMEM *cmd, POOLMEM **args, int *argc,
- char **argk, char **argv, int max_args);
-void split_path_and_filename(const char *fname, POOLMEM **path,
- int *pnl, POOLMEM **file, int *fnl);
+int parse_args(POOLMEM *cmd, POOLMEM **args, int *argc,
+ char **argk, char **argv, int max_args);
+void split_path_and_filename(const char *fname, POOLMEM **path,
+ int *pnl, POOLMEM **file, int *fnl);
int bsscanf(const char *buf, const char *fmt, ...);
/*
- *
+ *
* Bacula common code library interface to Python
*
* Kern Sibbald, November MMIV
* Version $Id$
*
*/
-
+
/*
Copyright (C) 2004 Kern Sibbald
PyEval_InitThreads();
Py_InitModule("bacula", BaculaMethods);
bsnprintf(buf, sizeof(buf), "import sys\n"
- "sys.path.append('%s')\n", scripts);
+ "sys.path.append('%s')\n", scripts);
PyRun_SimpleString(buf);
PyEval_ReleaseLock();
generate_event = _generate_event;
}
-/*
+/*
* Generate and process a Bacula event by importing a Python
* module and running it.
*
if (!pValue) {
Py_DECREF(pArgs);
Py_DECREF(pModule);
- Jmsg(jcr, M_ERROR, 0, "Could not convert JCR to Python CObject.\n");
+ Jmsg(jcr, M_ERROR, 0, "Could not convert JCR to Python CObject.\n");
return -1; /* Could not convert JCR to CObject */
}
/* pValue reference stolen here: */
} else {
Py_DECREF(pModule);
PyErr_Print();
- Jmsg(jcr, M_ERROR, 0, "Error running Python module: %s\n", event);
+ Jmsg(jcr, M_ERROR, 0, "Error running Python module: %s\n", event);
return 0; /* error running function */
}
/* pDict and pFunc are borrowed and must not be Py_DECREF-ed */
if (PyErr_Occurred()) {
PyErr_Print();
}
- Jmsg(jcr, M_ERROR, 0, "Python function \"%s\" not found in module.\n", event);
- return -1; /* function not found */
+ Jmsg(jcr, M_ERROR, 0, "Python function \"%s\" not found in module.\n", event);
+ return -1; /* function not found */
}
Py_DECREF(pModule);
} else {
http://www.fourmilab.ch/smartall/
-
+
Version $Id$
*/
};
#endif
-/*
+/*
* To define a queue, use the following
*
- * static BQUEUE xyz = { &xyz, &xyz };
+ * static BQUEUE xyz = { &xyz, &xyz };
*
* Also, note, that the only real requirement is that
* the object that is passed to these routines contain
/* QREMOVE -- Remove next object from the queue given
- the queue head (or any item).
+ the queue head (or any item).
Returns NULL if queue is empty */
BQUEUE *qremove(BQUEUE *qhead)
qitem = qhead;
ASSERT(qi->qprev->qnext == qi);
ASSERT(qi->qnext->qprev == qi);
-
+
if ((object = qi->qnext) == qh)
return NULL;
return object;
#undef qh
#undef qi
-}
+}
/* QDCHAIN -- Dequeue an item from the middle of a queue. Passed
#include "bacula.h"
-/*
+/*
* Initialize a read/write lock
*
* Returns: 0 on success
int rwl_init(brwlock_t *rwl)
{
int stat;
-
+
rwl->r_active = rwl->w_active = 0;
rwl->r_wait = rwl->w_wait = 0;
if ((stat = pthread_mutex_init(&rwl->mutex, NULL)) != 0) {
return stat;
}
- /*
+ /*
* If any threads are active, report EBUSY
*/
if (rwl->r_active > 0 || rwl->w_active) {
/*
* If any threads are waiting, report EBUSY
*/
- if (rwl->r_wait > 0 || rwl->w_wait > 0) {
+ if (rwl->r_wait > 0 || rwl->w_wait > 0) {
pthread_mutex_unlock(&rwl->mutex);
return EBUSY;
}
int rwl_readlock(brwlock_t *rwl)
{
int stat;
-
+
if (rwl->valid != RWLOCK_VALID) {
return EINVAL;
}
return stat;
}
-/*
+/*
* Attempt to lock for read access, don't wait
*/
int rwl_readtrylock(brwlock_t *rwl)
{
int stat, stat2;
-
+
if (rwl->valid != RWLOCK_VALID) {
return EINVAL;
}
stat2 = pthread_mutex_unlock(&rwl->mutex);
return (stat == 0 ? stat2 : stat);
}
-
-/*
+
+/*
* Unlock read lock
*/
int rwl_readunlock(brwlock_t *rwl)
{
int stat, stat2;
-
+
if (rwl->valid != RWLOCK_VALID) {
return EINVAL;
}
int rwl_writelock(brwlock_t *rwl)
{
int stat;
-
+
if (rwl->valid != RWLOCK_VALID) {
return EINVAL;
}
return stat;
}
-/*
+/*
* Attempt to lock for write access, don't wait
*/
int rwl_writetrylock(brwlock_t *rwl)
{
int stat, stat2;
-
+
if (rwl->valid != RWLOCK_VALID) {
return EINVAL;
}
stat2 = pthread_mutex_unlock(&rwl->mutex);
return (stat == 0 ? stat2 : stat);
}
-
-/*
+
+/*
* Unlock write lock
* Start any waiting writers in preference to waiting readers
*/
int rwl_writeunlock(brwlock_t *rwl)
{
int stat, stat2;
-
+
if (rwl->valid != RWLOCK_VALID) {
return EINVAL;
}
int interval;
} thread_t;
-/*
+/*
* Read/write lock and shared data.
*/
typedef struct data_tag {
thread_t threads[THREADS];
data_t data[DATASIZE];
-/*
+/*
* Thread start routine that uses read/write locks.
*/
void *thread_routine(void *arg)
if ((iteration % self->interval) == 0) {
status = rwl_writelock(&data[element].lock);
if (status != 0) {
- Emsg1(M_ABORT, 0, "Write lock failed. ERR=%s\n", strerror(status));
+ Emsg1(M_ABORT, 0, "Write lock failed. ERR=%s\n", strerror(status));
}
data[element].data = self->thread_num;
data[element].writes++;
self->writes++;
status = rwl_writeunlock(&data[element].lock);
if (status != 0) {
- Emsg1(M_ABORT, 0, "Write unlock failed. ERR=%s\n", strerror(status));
+ Emsg1(M_ABORT, 0, "Write unlock failed. ERR=%s\n", strerror(status));
}
} else {
/*
*/
status = rwl_readlock(&data[element].lock);
if (status != 0) {
- Emsg1(M_ABORT, 0, "Read lock failed. ERR=%s\n", strerror(status));
+ Emsg1(M_ABORT, 0, "Read lock failed. ERR=%s\n", strerror(status));
}
self->reads++;
if (data[element].data == self->thread_num)
repeats++;
status = rwl_readunlock(&data[element].lock);
if (status != 0) {
- Emsg1(M_ABORT, 0, "Read unlock failed. ERR=%s\n", strerror(status));
+ Emsg1(M_ABORT, 0, "Read unlock failed. ERR=%s\n", strerror(status));
}
}
element++;
data[data_count].writes = 0;
status = rwl_init (&data[data_count].lock);
if (status != 0) {
- Emsg1(M_ABORT, 0, "Init rwlock failed. ERR=%s\n", strerror(status));
+ Emsg1(M_ABORT, 0, "Init rwlock failed. ERR=%s\n", strerror(status));
}
}
status = pthread_create (&threads[count].thread_id,
NULL, thread_routine, (void*)&threads[count]);
if (status != 0) {
- Emsg1(M_ABORT, 0, "Create thread failed. ERR=%s\n", strerror(status));
+ Emsg1(M_ABORT, 0, "Create thread failed. ERR=%s\n", strerror(status));
}
}
for (count = 0; count < THREADS; count++) {
status = pthread_join (threads[count].thread_id, NULL);
if (status != 0) {
- Emsg1(M_ABORT, 0, "Join thread failed. ERR=%s\n", strerror(status));
+ Emsg1(M_ABORT, 0, "Join thread failed. ERR=%s\n", strerror(status));
}
thread_writes += threads[count].writes;
- printf ("%02d: interval %d, writes %d, reads %d\n",
+ printf ("%02d: interval %d, writes %d, reads %d\n",
count, threads[count].interval,
threads[count].writes, threads[count].reads);
}
*/
for (data_count = 0; data_count < DATASIZE; data_count++) {
data_writes += data[data_count].writes;
- printf ("data %02d: value %d, %d writes\n",
+ printf ("data %02d: value %d, %d writes\n",
data_count, data[data_count].data, data[data_count].writes);
rwl_destroy (&data[data_count].lock);
}
self->updates++;
rwl_writeunlock (&data[element].lock);
} else
- err_abort (status, "Try write lock");
+ err_abort (status, "Try write lock");
} else {
status = rwl_readtrylock (&data[element].lock);
if (status == EBUSY)
self->r_collisions++;
else if (status != 0) {
- err_abort (status, "Try read lock");
+ err_abort (status, "Try read lock");
} else {
if (data[element].data != data[element].updates)
- printf ("%d: data[%d] %d != %d\n",
+ printf ("%d: data[%d] %d != %d\n",
self->thread_num, element,
data[element].data, data[element].updates);
rwl_readunlock (&data[element].lock);
status = pthread_create (&threads[count].thread_id,
NULL, thread_routine, (void*)&threads[count]);
if (status != 0)
- err_abort (status, "Create thread");
+ err_abort (status, "Create thread");
}
/*
for (count = 0; count < THREADS; count++) {
status = pthread_join (threads[count].thread_id, NULL);
if (status != 0)
- err_abort (status, "Join thread");
+ err_abort (status, "Join thread");
thread_updates += threads[count].updates;
- printf ("%02d: interval %d, updates %d, "
- "r_collisions %d, w_collisions %d\n",
+ printf ("%02d: interval %d, updates %d, "
+ "r_collisions %d, w_collisions %d\n",
count, threads[count].interval,
threads[count].updates,
threads[count].r_collisions, threads[count].w_collisions);
*/
for (data_count = 0; data_count < DATASIZE; data_count++) {
data_updates += data[data_count].updates;
- printf ("data %02d: value %d, %d updates\n",
+ printf ("data %02d: value %d, %d updates\n",
data_count, data[data_count].data, data[data_count].updates);
rwl_destroy (&data[data_count].lock);
}
/*
* Bacula Thread Read/Write locking code. It permits
- * multiple readers but only one writer.
+ * multiple readers but only one writer.
*
* Kern Sibbald, January MMI
*
*/
-#ifndef __RWLOCK_H
+#ifndef __RWLOCK_H
#define __RWLOCK_H 1
typedef struct s_rwlock_tag {
{PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, \
PTHREAD_COND_INITIALIZER, RWLOCK_VALID, 0, 0, 0, 0}
-/*
+/*
* read/write lock prototypes
*/
extern int rwl_init(brwlock_t *wrlock);
/*
* scan.c -- scanning routines for Bacula
- *
+ *
* Kern Sibbald, MM separated from util.c MMIII
*
* Version $Id$
/*
* Skip spaces
- * Returns: 0 on failure (EOF)
+ * Returns: 0 on failure (EOF)
* 1 on success
- * new address in passed parameter
+ * new address in passed parameter
*/
bool skip_spaces(char **msg)
{
/*
* Skip nonspaces
- * Returns: 0 on failure (EOF)
+ * Returns: 0 on failure (EOF)
* 1 on success
- * new address in passed parameter
+ * new address in passed parameter
*/
bool skip_nonspaces(char **msg)
{
}
-/*
+/*
* Return next argument from command line. Note, this
* routine is destructive.
*/
/* skip past spaces to next arg */
for (p=*s; *p && B_ISSPACE(*p); ) {
p++;
- }
+ }
Dmsg1(400, "Next arg=%s\n", p);
for (n = q = p; *p ; ) {
if (*p == '\\') {
*s = p;
Dmsg2(400, "End arg=%s next=%s\n", n, p);
return n;
-}
+}
/*
* This routine parses the input command line.
* It makes a copy in args, then builds an
* argc, argv like list where
- *
+ *
* argc = count of arguments
* argk[i] = argument keyword (part preceding =)
* argv[i] = argument value (part after =)
* argk[1] = arg2
* argv[1] = abc
* argk[2] = arg3
- * argv[2] =
+ * argv[2] =
*/
-int parse_args(POOLMEM *cmd, POOLMEM **args, int *argc,
- char **argk, char **argv, int max_args)
+int parse_args(POOLMEM *cmd, POOLMEM **args, int *argc,
+ char **argk, char **argv, int max_args)
{
char *p, *q, *n;
*argc = 0;
/* Pick up all arguments */
while (*argc < max_args) {
- n = next_arg(&p);
+ n = next_arg(&p);
if (*n) {
argk[*argc] = n;
argv[(*argc)++] = NULL;
if (p) {
*p++ = 0; /* terminate keyword and point to value */
/* Unquote quoted values */
- if (*p == '"') {
- for (n = q = ++p; *p && *p != '"'; ) {
- if (*p == '\\') {
+ if (*p == '"') {
+ for (n = q = ++p; *p && *p != '"'; ) {
+ if (*p == '\\') {
p++;
}
*q++ = *p++;
int len = slen = strlen(fname);
/*
- * Find path without the filename.
+ * Find path without the filename.
* I.e. everything after the last / is a "filename".
* OK, maybe it is a directory name, but we treat it like
* a filename. If we don't find a / then the whole name
}
/*
- * Extremely simple sscanf. Handles only %(u,d,ld,lu,lld,llu,c,nns)
+ * Extremely simple sscanf. Handles only %(u,d,ld,lu,lld,llu,c,nns)
*/
const int BIG = 1000;
int bsscanf(const char *buf, const char *fmt, ...)
// Dmsg1(000, "Got %% nxt=%c\n", *fmt);
switch_top:
switch (*fmt++) {
- case 'u':
- case 'd':
+ case 'u':
+ case 'd':
value = 0;
while (B_ISDIGIT(*buf)) {
- value = B_TIMES10(value) + *buf++ - '0';
+ value = B_TIMES10(value) + *buf++ - '0';
}
vp = (void *)va_arg(ap, void *);
// Dmsg2(000, "val=%lld at 0x%lx\n", value, (long unsigned)vp);
count++;
l = 0;
break;
- case 'l':
+ case 'l':
// Dmsg0(000, "got l\n");
l = 1;
- if (*fmt == 'l') {
+ if (*fmt == 'l') {
l++;
fmt++;
}
- if (*fmt == 'd' || *fmt == 'u') {
+ if (*fmt == 'd' || *fmt == 'u') {
goto switch_top;
}
// Dmsg1(000, "fmt=%c !=d,u\n", *fmt);
error = true;
break;
- case 'q':
+ case 'q':
l = 2;
- if (*fmt == 'd' || *fmt == 'u') {
+ if (*fmt == 'd' || *fmt == 'u') {
goto switch_top;
}
// Dmsg1(000, "fmt=%c !=d,u\n", *fmt);
error = true;
break;
- case 's':
+ case 's':
// Dmsg1(000, "Store string max_len=%d\n", max_len);
cp = (char *)va_arg(ap, char *);
while (*buf && !B_ISSPACE(*buf) && max_len-- > 0) {
count++;
max_len = BIG;
break;
- case 'c':
+ case 'c':
cp = (char *)va_arg(ap, char *);
*cp = *buf++;
count++;
break;
- case '%':
- if (*buf++ != '%') {
+ case '%':
+ if (*buf++ != '%') {
error = true;
}
break;
fmt--;
max_len = 0;
while (B_ISDIGIT(*fmt)) {
- max_len = B_TIMES10(max_len) + *fmt++ - '0';
+ max_len = B_TIMES10(max_len) + *fmt++ - '0';
}
// Dmsg1(000, "Default max_len=%d\n", max_len);
- if (*fmt == 's') {
+ if (*fmt == 's') {
goto switch_top;
}
// Dmsg1(000, "Default c=%c\n", *fmt);
int cnt;
char *helloreq= "Hello *UserAgent* calling\n";
char *hello = "Hello %127s calling\n";
- char *catreq =
+ char *catreq =
"CatReq Job=NightlySave.2004-06-11_19.11.32 CreateJobMedia FirstIndex=1 LastIndex=114 StartFile=0 EndFile=0 StartBlock=208 EndBlock=2903248";
static char Create_job_media[] = "CatReq Job=%127s CreateJobMedia "
"FirstIndex=%u LastIndex=%u StartFile=%u EndFile=%u "
uint64_t VolWriteTime; /* time spent writing this Volume */
char VolCatStatus[20]; /* Volume status */
char VolCatName[MAX_NAME_LENGTH]; /* Desired volume to mount */
-};
+};
struct VOLUME_CAT_INFO vol;
#ifdef xxx
* Bacula Semaphore code. This code permits setting up
* a semaphore that lets through a specified number
* of callers simultaneously. Once the number of callers
- * exceed the limit, they block.
+ * exceed the limit, they block.
*
* Kern Sibbald, March MMIII
*
#include "bacula.h"
-/*
+/*
* Initialize a semaphore
*
* Returns: 0 on success
int sem_init(semlock_t *sem, int max_active)
{
int stat;
-
+
sem->active = sem->waiting = 0;
sem->max_active = max_active;
if ((stat = pthread_mutex_init(&sem->mutex, NULL)) != 0) {
*/
int sem_destroy(semlock_t *sem)
{
- int stat, stat1;
+ int stat, stat1;
if (sem->valid != SEMLOCK_VALID) {
return EINVAL;
return stat;
}
- /*
+ /*
* If any threads are active, report EBUSY
*/
if (sem->active > 0) {
int sem_lock(semlock_t *sem)
{
int stat;
-
+
if (sem->valid != SEMLOCK_VALID) {
return EINVAL;
}
return stat;
}
-/*
+/*
* Attempt to lock semaphore, don't wait
*/
int sem_trylock(semlock_t *sem)
{
int stat, stat1;
-
+
if (sem->valid != SEMLOCK_VALID) {
return EINVAL;
}
stat1 = pthread_mutex_unlock(&sem->mutex);
return (stat == 0 ? stat1 : stat);
}
-
-/*
+
+/*
* Unlock semaphore
* Start any waiting callers
*/
int sem_unlock(semlock_t *sem)
{
int stat, stat1;
-
+
if (sem->valid != SEMLOCK_VALID) {
return EINVAL;
}
int interval;
} thread_t;
-/*
+/*
* Semaphore lock and shared data.
*/
typedef struct data_tag {
thread_t threads[THREADS];
data_t data[DATASIZE];
-/*
+/*
* Thread start routine that uses semaphores locks.
*/
void *thread_routine(void *arg)
if ((iteration % self->interval) == 0) {
status = sem_writelock(&data[element].lock);
if (status != 0) {
- Emsg1(M_ABORT, 0, "Write lock failed. ERR=%s\n", strerror(status));
+ Emsg1(M_ABORT, 0, "Write lock failed. ERR=%s\n", strerror(status));
}
data[element].data = self->thread_num;
data[element].writes++;
self->writes++;
status = sem_writeunlock(&data[element].lock);
if (status != 0) {
- Emsg1(M_ABORT, 0, "Write unlock failed. ERR=%s\n", strerror(status));
+ Emsg1(M_ABORT, 0, "Write unlock failed. ERR=%s\n", strerror(status));
}
} else {
/*
*/
status = sem_readlock(&data[element].lock);
if (status != 0) {
- Emsg1(M_ABORT, 0, "Read lock failed. ERR=%s\n", strerror(status));
+ Emsg1(M_ABORT, 0, "Read lock failed. ERR=%s\n", strerror(status));
}
self->reads++;
if (data[element].data == self->thread_num)
repeats++;
status = sem_readunlock(&data[element].lock);
if (status != 0) {
- Emsg1(M_ABORT, 0, "Read unlock failed. ERR=%s\n", strerror(status));
+ Emsg1(M_ABORT, 0, "Read unlock failed. ERR=%s\n", strerror(status));
}
}
element++;
data[data_count].writes = 0;
status = sem_init (&data[data_count].lock);
if (status != 0) {
- Emsg1(M_ABORT, 0, "Init rwlock failed. ERR=%s\n", strerror(status));
+ Emsg1(M_ABORT, 0, "Init rwlock failed. ERR=%s\n", strerror(status));
}
}
status = pthread_create(&threads[count].thread_id,
NULL, thread_routine, (void*)&threads[count]);
if (status != 0) {
- Emsg1(M_ABORT, 0, "Create thread failed. ERR=%s\n", strerror(status));
+ Emsg1(M_ABORT, 0, "Create thread failed. ERR=%s\n", strerror(status));
}
}
for (count = 0; count < THREADS; count++) {
status = pthread_join (threads[count].thread_id, NULL);
if (status != 0) {
- Emsg1(M_ABORT, 0, "Join thread failed. ERR=%s\n", strerror(status));
+ Emsg1(M_ABORT, 0, "Join thread failed. ERR=%s\n", strerror(status));
}
thread_writes += threads[count].writes;
- printf ("%02d: interval %d, writes %d, reads %d\n",
+ printf ("%02d: interval %d, writes %d, reads %d\n",
count, threads[count].interval,
threads[count].writes, threads[count].reads);
}
*/
for (data_count = 0; data_count < DATASIZE; data_count++) {
data_writes += data[data_count].writes;
- printf ("data %02d: value %d, %d writes\n",
+ printf ("data %02d: value %d, %d writes\n",
data_count, data[data_count].data, data[data_count].writes);
sem_destroy (&data[data_count].lock);
}
self->updates++;
sem_writeunlock (&data[element].lock);
} else
- err_abort (status, "Try write lock");
+ err_abort (status, "Try write lock");
} else {
status = sem_readtrylock (&data[element].lock);
if (status == EBUSY)
self->r_collisions++;
else if (status != 0) {
- err_abort (status, "Try read lock");
+ err_abort (status, "Try read lock");
} else {
if (data[element].data != data[element].updates)
- printf ("%d: data[%d] %d != %d\n",
+ printf ("%d: data[%d] %d != %d\n",
self->thread_num, element,
data[element].data, data[element].updates);
sem_readunlock (&data[element].lock);
status = pthread_create (&threads[count].thread_id,
NULL, thread_routine, (void*)&threads[count]);
if (status != 0)
- err_abort (status, "Create thread");
+ err_abort (status, "Create thread");
}
/*
for (count = 0; count < THREADS; count++) {
status = pthread_join(threads[count].thread_id, NULL);
if (status != 0)
- err_abort(status, "Join thread");
+ err_abort(status, "Join thread");
thread_updates += threads[count].updates;
- printf ("%02d: interval %d, updates %d, "
- "r_collisions %d, w_collisions %d\n",
+ printf ("%02d: interval %d, updates %d, "
+ "r_collisions %d, w_collisions %d\n",
count, threads[count].interval,
threads[count].updates,
threads[count].r_collisions, threads[count].w_collisions);
*/
for (data_count = 0; data_count < DATASIZE; data_count++) {
data_updates += data[data_count].updates;
- printf ("data %02d: value %d, %d updates\n",
+ printf ("data %02d: value %d, %d updates\n",
data_count, data[data_count].data, data[data_count].updates);
sem_destroy(&data[data_count].lock);
}
* Bacula Semaphore code. This code permits setting up
* a semaphore that lets through a specified number
* of callers simultaneously. Once the number of callers
- * exceed the limit, they block.
+ * exceed the limit, they block.
*
* Kern Sibbald, March MMIII
*
*/
-#ifndef __SEMLOCK_H
+#ifndef __SEMLOCK_H
#define __SEMLOCK_H 1
typedef struct s_semlock_tag {
{PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, \
PTHREAD_COND_INITIALIZER, SEMLOCK_VALID, 0, 0, 0, 0}
-/*
+/*
* semaphore lock prototypes
*/
extern int sem_init(semlock_t *sem, int max_active);
Serialisation Support Functions
John Walker
-
+
Version $Id$
*/
/*
void serial_string(uint8_t * * const ptr, const char * const str)
{
int len = strlen(str) + 1;
-
+
memcpy(*ptr, str, len);
*ptr += len;
}
/*
- Serialisation Macros
+ Serialisation Macros
These macros use a uint8_t pointer, ser_ptr, which must be
defined by the code which uses them.
#define unser_begin(x, s) ser_ptr = ((uint8_t *)(x))
/* ser_length -- Determine length in bytes of serialised into a
- buffer x. */
+ buffer x. */
#define ser_length(x) (ser_ptr - (uint8_t *)(x))
#define unser_length(x) (ser_ptr - (uint8_t *)(x))
#define unser_end(x, s) ASSERT(ser_length(x) <= (s))
/* ser_check(x, s) -- Verify length of serialised data in buffer x is
- expected length s. */
+ expected length s. */
#define ser_check(x, s) ASSERT(ser_length(x) == (s))
/* Serialisation */
* Perform SHA-1 tests
*/
for(j = 0; j < 4; ++j) {
- printf( "\nTest %d: %d, '%s'\n",
+ printf( "\nTest %d: %d, '%s'\n",
j+1,
repeatcount[j],
testarray[j]);
err = SHA1Init(&sha);
if (err) {
- fprintf(stderr, "SHA1Reset Error %d.\n", err );
+ fprintf(stderr, "SHA1Reset Error %d.\n", err );
break; /* out of for j loop */
}
(const unsigned char *) testarray[j],
strlen(testarray[j]));
if (err) {
- fprintf(stderr, "SHA1Input Error %d.\n", err );
+ fprintf(stderr, "SHA1Input Error %d.\n", err );
break; /* out of for i loop */
}
}
err = SHA1Final(&sha, Message_Digest);
if (err) {
fprintf(stderr,
- "SHA1Result Error %d, could not compute message digest.\n",
+ "SHA1Result Error %d, could not compute message digest.\n",
err );
}
else
{
- printf("\t");
+ printf("\t");
for(i = 0; i < 20 ; ++i) {
- printf("%02X ", Message_Digest[i]);
+ printf("%02X ", Message_Digest[i]);
}
- printf("\n");
+ printf("\n");
}
- printf("Should match:\n");
- printf("\t%s\n", resultarray[j]);
+ printf("Should match:\n");
+ printf("\t%s\n", resultarray[j]);
}
/* Test some error returns */
* Reads a single ASCII file and prints the HEX sha1 sum.
*/
#include <stdio.h>
-int main(int argc, char *argv[])
+int main(int argc, char *argv[])
{
FILE *fd;
SHA1Context ctx;
uint32_t Length_Low; /* Message length in bits */
uint32_t Length_High; /* Message length in bits */
- /* Index into message block array */
+ /* Index into message block array */
int32_t Message_Block_Index;
uint8_t Message_Block[64]; /* 512-bit message blocks */
int SHA1Init(SHA1Context *);
int SHA1Update(SHA1Context *,
- const uint8_t *,
- unsigned int);
+ const uint8_t *,
+ unsigned int);
int SHA1Final(SHA1Context *,
- uint8_t Message_Digest[SHA1HashSize]);
+ uint8_t Message_Digest[SHA1HashSize]);
#endif
* Kern Sibbald, April 2000
*
* Version $Id$
- *
+ *
* Note, we probably should do a core dump for the serious
- * signals such as SIGBUS, SIGPFE, ...
- * Also, for SIGHUP and SIGUSR1, we should re-read the
- * configuration file. However, since this is a "general"
+ * signals such as SIGBUS, SIGPFE, ...
+ * Also, for SIGHUP and SIGUSR1, we should re-read the
+ * configuration file. However, since this is a "general"
* routine, we leave it to the individual daemons to
* tweek their signals after calling this routine.
*
}
}
-/*
+/*
* Handle signals here
*/
extern "C" void signal_handler(int sig)
pid_t pid;
int exelen = strlen(exepath);
- fprintf(stderr, "Kaboom! %s, %s got signal %d. Attempting traceback.\n",
+ fprintf(stderr, "Kaboom! %s, %s got signal %d. Attempting traceback.\n",
exename, my_name, sig);
fprintf(stderr, "Kaboom! exepath=%s\n", exepath);
if (exelen + 12 > (int)sizeof(btpath)) {
- bstrncpy(btpath, "btraceback", sizeof(btpath));
+ bstrncpy(btpath, "btraceback", sizeof(btpath));
} else {
bstrncpy(btpath, exepath, sizeof(btpath));
- if (btpath[exelen-1] == '/') {
+ if (btpath[exelen-1] == '/') {
btpath[exelen-1] = 0;
}
- bstrncat(btpath, "/btraceback", sizeof(btpath));
+ bstrncat(btpath, "/btraceback", sizeof(btpath));
}
if (exepath[exelen-1] != '/') {
- strcat(exepath, "/");
+ strcat(exepath, "/");
}
strcat(exepath, exename);
if (!working_directory) {
*buf = 0;
}
if (*working_directory == 0) {
- strcpy((char *)working_directory, "/tmp/");
+ strcpy((char *)working_directory, "/tmp/");
}
if (chdir(working_directory) != 0) { /* dump in working directory */
berrno be;
- Pmsg2(000, "chdir to %s failed. ERR=%s\n", working_directory, be.strerror());
- strcpy((char *)working_directory, "/tmp/");
+ Pmsg2(000, "chdir to %s failed. ERR=%s\n", working_directory, be.strerror());
+ strcpy((char *)working_directory, "/tmp/");
}
unlink("./core"); /* get rid of any old core file */
sprintf(pid_buf, "%d", (int)main_pid);
Dmsg1(300, "exepath=%s\n", exepath);
switch (pid = fork()) {
case -1: /* error */
- fprintf(stderr, "Fork error: ERR=%s\n", strerror(errno));
+ fprintf(stderr, "Fork error: ERR=%s\n", strerror(errno));
break;
case 0: /* child */
argv[0] = btpath; /* path to btraceback */
argv[1] = exepath; /* path to exe */
argv[2] = pid_buf;
argv[3] = (char *)NULL;
- fprintf(stderr, "Calling: %s %s %s\n", btpath, exepath, pid_buf);
+ fprintf(stderr, "Calling: %s %s %s\n", btpath, exepath, pid_buf);
if (execv(btpath, argv) != 0) {
- printf("execv: %s failed: ERR=%s\n", btpath, strerror(errno));
+ printf("execv: %s failed: ERR=%s\n", btpath, strerror(errno));
}
exit(-1);
default: /* parent */
sigaction(sig, &sigdefault, NULL);
if (pid > 0) {
- Dmsg0(500, "Doing waitpid\n");
+ Dmsg0(500, "Doing waitpid\n");
waitpid(pid, NULL, 0); /* wait for child to produce dump */
- fprintf(stderr, "Traceback complete, attempting cleanup ...\n");
- Dmsg0(500, "Done waitpid\n");
+ fprintf(stderr, "Traceback complete, attempting cleanup ...\n");
+ Dmsg0(500, "Done waitpid\n");
exit_handler(sig); /* clean up if possible */
- Dmsg0(500, "Done exit_handler\n");
+ Dmsg0(500, "Done exit_handler\n");
} else {
- Dmsg0(500, "Doing sleep\n");
+ Dmsg0(500, "Doing sleep\n");
bmicrosleep(30, 0);
}
fprintf(stderr, "It looks like the traceback worked ...\n");
sighandle.sa_handler = signal_handler;
sigfillset(&sighandle.sa_mask);
sigignore.sa_flags = 0;
- sigignore.sa_handler = SIG_IGN;
+ sigignore.sa_handler = SIG_IGN;
sigfillset(&sigignore.sa_mask);
sigdefault.sa_flags = 0;
sigdefault.sa_handler = SIG_DFL;
sigaction(SIGCONT, &sigignore, NULL);
sigaction(SIGPROF, &sigignore, NULL);
sigaction(SIGWINCH, &sigignore, NULL);
- sigaction(SIGIO, &sighandle, NULL);
+ sigaction(SIGIO, &sighandle, NULL);
- sigaction(SIGINT, &sigdefault, NULL);
+ sigaction(SIGINT, &sigdefault, NULL);
sigaction(SIGXCPU, &sigdefault, NULL);
sigaction(SIGXFSZ, &sigdefault, NULL);
sigaction(SIGHUP, &sigignore, NULL);
- sigaction(SIGQUIT, &sighandle, NULL);
- sigaction(SIGILL, &sighandle, NULL);
- sigaction(SIGTRAP, &sighandle, NULL);
+ sigaction(SIGQUIT, &sighandle, NULL);
+ sigaction(SIGILL, &sighandle, NULL);
+ sigaction(SIGTRAP, &sighandle, NULL);
/* sigaction(SIGABRT, &sighandle, NULL); */
#ifdef SIGEMT
sigaction(SIGEMT, &sighandle, NULL);
#ifdef SIGIOT
/* sigaction(SIGIOT, &sighandle, NULL); used by debugger */
#endif
- sigaction(SIGBUS, &sighandle, NULL);
- sigaction(SIGFPE, &sighandle, NULL);
- sigaction(SIGKILL, &sighandle, NULL);
- sigaction(SIGUSR1, &sighandle, NULL);
- sigaction(SIGSEGV, &sighandle, NULL);
+ sigaction(SIGBUS, &sighandle, NULL);
+ sigaction(SIGFPE, &sighandle, NULL);
+ sigaction(SIGKILL, &sighandle, NULL);
+ sigaction(SIGUSR1, &sighandle, NULL);
+ sigaction(SIGSEGV, &sighandle, NULL);
sigaction(SIGUSR2, &sighandle, NULL);
- sigaction(SIGALRM, &sighandle, NULL);
- sigaction(SIGTERM, &sighandle, NULL);
+ sigaction(SIGALRM, &sighandle, NULL);
+ sigaction(SIGTERM, &sighandle, NULL);
#ifdef SIGSTKFLT
- sigaction(SIGSTKFLT, &sighandle, NULL);
+ sigaction(SIGSTKFLT, &sighandle, NULL);
#endif
- sigaction(SIGSTOP, &sighandle, NULL);
- sigaction(SIGTSTP, &sighandle, NULL);
- sigaction(SIGTTIN, &sighandle, NULL);
- sigaction(SIGTTOU, &sighandle, NULL);
- sigaction(SIGURG, &sighandle, NULL);
- sigaction(SIGVTALRM, &sighandle, NULL);
+ sigaction(SIGSTOP, &sighandle, NULL);
+ sigaction(SIGTSTP, &sighandle, NULL);
+ sigaction(SIGTTIN, &sighandle, NULL);
+ sigaction(SIGTTOU, &sighandle, NULL);
+ sigaction(SIGURG, &sighandle, NULL);
+ sigaction(SIGVTALRM, &sighandle, NULL);
#ifdef SIGPWR
- sigaction(SIGPWR, &sighandle, NULL);
+ sigaction(SIGPWR, &sighandle, NULL);
#endif
#ifdef SIGWAITING
sigaction(SIGWAITING,&sighandle, NULL);
http://www.fourmilab.ch/smartall/
-
+
Version $Id$
*/
#undef free
/* We normally turn off debugging here.
- * If you want it, simply #ifdef all the
+ * If you want it, simply #ifdef all the
* following off.
*/
#undef Dmsg1
#define Dmsg2(l,f,a1,a2)
#define Dmsg3(l,f,a1,a2,a3)
#define Dmsg4(l,f,a1,a2,a3,a4)
-
+
uint64_t sm_max_bytes = 0;
uint64_t sm_bytes = 0;
struct b_queue abq; /* Links on allocated queue */
unsigned ablen; /* Buffer length in bytes */
const char *abfname; /* File name pointer */
- sm_ushort ablineno; /* Line number of allocation */
+ sm_ushort ablineno; /* Line number of allocation */
};
static struct b_queue abqueue = { /* Allocated buffer queue */
struct abufhead *head = (struct abufhead *)cp;
P(mutex);
- Dmsg4(1150, "sm_free %d at %x from %s:%d\n",
- head->ablen, fp,
+ Dmsg4(1150, "sm_free %d at %x from %s:%d\n",
+ head->ablen, fp,
head->abfname, head->ablineno);
/* The following assertions will catch virtually every release
/* To catch sloppy code that assumes buffers obtained from
malloc() are zeroed, we preset the buffer contents to
- "designer garbage" consisting of alternating bits. */
+ "designer garbage" consisting of alternating bits. */
memset(buf, 0x55, (int) nbytes);
} else {
}
/* SM_REALLOC -- Adjust the size of a previously allocated buffer.
- Note that the trick of "resurrecting" a previously
+ Note that the trick of "resurrecting" a previously
freed buffer with realloc() is NOT supported by this
function. Further, because of the need to maintain
our control storage, SM_REALLOC must always allocate
if ((buf = smalloc(fname, lineno, size)) != NULL) {
memcpy(buf, ptr, (int) sm_min(size, osize));
/* If the new buffer is larger than the old, fill the balance
- of it with "designer garbage". */
+ of it with "designer garbage". */
if (size > osize) {
memset(((char *) buf) + osize, 0x55, (int) (size - osize));
}
while (ap != (struct abufhead *) &abqueue) {
if ((ap == NULL) ||
- (ap->abq.qnext->qprev != (struct b_queue *) ap) ||
+ (ap->abq.qnext->qprev != (struct b_queue *) ap) ||
(ap->abq.qprev->qnext != (struct b_queue *) ap)) {
fprintf(stderr,
- "\nOrphaned buffers exist. Dump terminated following\n");
+ "\nOrphaned buffers exist. Dump terminated following\n");
fprintf(stderr,
- " discovery of bad links in chain of orphaned buffers.\n");
+ " discovery of bad links in chain of orphaned buffers.\n");
fprintf(stderr,
- " Buffer address with bad links: %lx\n", (long) ap);
+ " Buffer address with bad links: %lx\n", (long) ap);
break;
}
char errmsg[500];
bsnprintf(errmsg, sizeof(errmsg),
- "Orphaned buffer: %6u bytes allocated at line %d of %s %s\n",
+ "Orphaned buffer: %6u bytes allocated at line %d of %s %s\n",
memsize, ap->ablineno, my_name, ap->abfname
);
- fprintf(stderr, "%s", errmsg);
+ fprintf(stderr, "%s", errmsg);
if (bufdump) {
char buf[20];
unsigned llen = 0;
errmsg[0] = EOS;
while (memsize) {
if (llen >= 16) {
- bstrncat(errmsg, "\n", sizeof(errmsg));
+ bstrncat(errmsg, "\n", sizeof(errmsg));
llen = 0;
- fprintf(stderr, "%s", errmsg);
+ fprintf(stderr, "%s", errmsg);
errmsg[0] = EOS;
}
- bsnprintf(buf, sizeof(buf), " %02X",
+ bsnprintf(buf, sizeof(buf), " %02X",
(*cp++) & 0xFF);
bstrncat(errmsg, buf, sizeof(errmsg));
llen++;
memsize--;
}
- fprintf(stderr, "%s\n", errmsg);
+ fprintf(stderr, "%s\n", errmsg);
}
}
ap = (struct abufhead *) ap->abq.qnext;
void sm_check(const char *fname, int lineno, bool bufdump)
{
if (!sm_check_rtn(fname, lineno, bufdump)) {
- Emsg2(M_ABORT, 0, "Damaged buffer found. Called from %s:%d\n",
+ Emsg2(M_ABORT, 0, "Damaged buffer found. Called from %s:%d\n",
fname, lineno);
}
}
(ap->abq.qnext->qprev != (struct b_queue *) ap)) {
bad = 0x1;
}
- if (ap->abq.qprev->qnext != (struct b_queue *) ap) {
+ if (ap->abq.qprev->qnext != (struct b_queue *) ap) {
bad |= 0x2;
}
if (((unsigned char *) ap)[((struct abufhead *) ap)->ablen - 1] !=
badbuf |= bad;
if (bad) {
fprintf(stderr,
- "\nDamaged buffers found at %s:%d\n", fname, lineno);
+ "\nDamaged buffers found at %s:%d\n", fname, lineno);
if (bad & 0x1) {
- fprintf(stderr, " discovery of bad prev link.\n");
+ fprintf(stderr, " discovery of bad prev link.\n");
}
if (bad & 0x2) {
- fprintf(stderr, " discovery of bad next link.\n");
+ fprintf(stderr, " discovery of bad next link.\n");
}
if (bad & 0x4) {
- fprintf(stderr, " discovery of data overrun.\n");
+ fprintf(stderr, " discovery of data overrun.\n");
}
- fprintf(stderr, " Buffer address: %lx\n", (long) ap);
+ fprintf(stderr, " Buffer address: %lx\n", (long) ap);
if (ap->abfname != NULL) {
unsigned memsize = ap->ablen - (HEAD_SIZE + 1);
char errmsg[80];
fprintf(stderr,
- "Damaged buffer: %6u bytes allocated at line %d of %s %s\n",
+ "Damaged buffer: %6u bytes allocated at line %d of %s %s\n",
memsize, ap->ablineno, my_name, ap->abfname
);
if (bufdump) {
errmsg[0] = EOS;
while (memsize) {
if (llen >= 16) {
- strcat(errmsg, "\n");
+ strcat(errmsg, "\n");
llen = 0;
- fprintf(stderr, "%s", errmsg);
+ fprintf(stderr, "%s", errmsg);
errmsg[0] = EOS;
}
if (*cp < 0x20) {
- sprintf(errmsg + strlen(errmsg), " %02X",
+ sprintf(errmsg + strlen(errmsg), " %02X",
(*cp++) & 0xFF);
} else {
- sprintf(errmsg + strlen(errmsg), " %c ",
+ sprintf(errmsg + strlen(errmsg), " %c ",
(*cp++) & 0xFF);
}
llen++;
memsize--;
}
- fprintf(stderr, "%s\n", errmsg);
+ fprintf(stderr, "%s\n", errmsg);
}
}
}
bufimode = (bool) (mode != 0);
}
-/*
+/*
* Here we overload C++'s global new and delete operators
* so that the memory is allocated through smartalloc.
*/
/*
- Definitions for the smart memory allocator
-
+ Definitions for the smart memory allocator
+
Version $Id$
*/
extern void *sm_malloc(const char *fname, int lineno, unsigned int nbytes),
- *sm_calloc(const char *fname, int lineno,
- unsigned int nelem, unsigned int elsize),
- *sm_realloc(const char *fname, int lineno, void *ptr, unsigned int size),
- *actuallymalloc(unsigned int size),
- *actuallycalloc(unsigned int nelem, unsigned int elsize),
- *actuallyrealloc(void *ptr, unsigned int size);
+ *sm_calloc(const char *fname, int lineno,
+ unsigned int nelem, unsigned int elsize),
+ *sm_realloc(const char *fname, int lineno, void *ptr, unsigned int size),
+ *actuallymalloc(unsigned int size),
+ *actuallycalloc(unsigned int nelem, unsigned int elsize),
+ *actuallyrealloc(void *ptr, unsigned int size);
extern void sm_free(const char *fname, int lineno, void *fp);
extern void actuallyfree(void *cp),
- sm_dump(bool bufdump), sm_static(int mode);
+ sm_dump(bool bufdump), sm_static(int mode);
extern void sm_new_owner(const char *fname, int lineno, char *buf);
#ifdef SMCHECK
#define sm_check_rtn(f, l, fl) 1
extern void *b_malloc();
-#define malloc(x) b_malloc(__FILE__, __LINE__, (x))
+#define malloc(x) b_malloc(__FILE__, __LINE__, (x))
#endif
{
free(ptr);
}
-void operator delete[](void *ptr, size_t i, const char *fname, int line)
+void operator delete[](void *ptr, size_t i, const char *fname, int line)
{
free(ptr);
}
void *operator new(size_t s) throw() { return 0; }
void *operator new[](size_t s) throw() { return 0; }
};
-
+
#else
public:
void *operator new(size_t s)
{
- return malloc(s);
+ return malloc(s);
}
void *operator new[](size_t s)
{
- return malloc(s);
+ return malloc(s);
}
void operator delete(void *ptr)
{
- free(ptr);
+ free(ptr);
}
void operator delete[](void *ptr, size_t i)
{
- free(ptr);
+ free(ptr);
}
};
#endif
/*
* @(#) tcpd.h 1.5 96/03/19 16:22:24
- *
+ *
* Author: Wietse Venema, Eindhoven University of Technology, The Netherlands.
*/
-/*
- * This version of the file has been hacked over by
- * Kern Sibbald to make it compatible with C++ for
+/*
+ * This version of the file has been hacked over by
+ * Kern Sibbald to make it compatible with C++ for
* the few functions that Bacula uses. 19 April 2002
* It now compiles with C++ but remains untested.
* A correct fix would require significantly more work.
/* Socket-specific methods, including DNS hostname lookups. */
-extern void sock_host(struct request_info *);
+extern void sock_host(struct request_info *);
extern void sock_hostname(); /* translate address to hostname */
extern void sock_hostaddr(); /* address to printable address */
#define sock_methods(r) \
- { (r)->hostname = sock_hostname; (r)->hostaddr = sock_hostaddr; }
+ { (r)->hostname = sock_hostname; (r)->hostaddr = sock_hostaddr; }
/* The System V Transport-Level Interface (TLI) interface. */
/*
* Directory tree build/traverse routines
- *
+ *
* Kern Sibbald, June MMII
*
*/
#include "bacula.h"
#include "findlib/find.h"
-
+
/* Forward referenced subroutines */
-static TREE_NODE *search_and_insert_tree_node(char *fname, int type,
+static TREE_NODE *search_and_insert_tree_node(char *fname, int type,
TREE_ROOT *root, TREE_NODE *parent);
static char *tree_alloc(TREE_ROOT *root, int size);
return root;
}
-/*
+/*
* Create a new tree node.
*/
static TREE_NODE *new_tree_node(TREE_ROOT *root)
#ifdef USE_DLIST
/*
- * This routine can be called to release the
+ * This routine can be called to release the
* previously allocated tree node.
*/
static void free_tree_node(TREE_ROOT *root)
}
-/*
+/*
* Insert a node in the tree. This is the main subroutine
* called when building a tree.
*
}
if (*fname) {
if (!parent) { /* if no parent, we need to make one */
- Dmsg1(100, "make_tree_path for %s\n", path);
+ Dmsg1(100, "make_tree_path for %s\n", path);
path_len = strlen(path); /* get new length */
if (path_len == root->cached_path_len &&
strcmp(path, root->cached_path) == 0) {
root->cached_path_len = path_len;
pm_strcpy(&root->cached_path, path);
parent = make_tree_path(path, root);
- root->cached_parent = parent;
+ root->cached_parent = parent;
}
- Dmsg1(100, "parent=%s\n", parent->fname);
+ Dmsg1(100, "parent=%s\n", parent->fname);
}
} else {
fname = path;
}
node = search_and_insert_tree_node(fname, type, root, parent);
return node;
-}
+}
#ifdef USE_DLIST
static int node_compare(void *item1, void *item2)
/*
* See if the fname already exists. If not insert a new node for it.
*/
-static TREE_NODE *search_and_insert_tree_node(char *fname, int type,
+static TREE_NODE *search_and_insert_tree_node(char *fname, int type,
TREE_ROOT *root, TREE_NODE *parent)
{
#ifdef USE_DLIST
int cmp;
/* Is it already a sibling? */
- foreach_child(sibling, parent) {
+ foreach_child(sibling, parent) {
Dmsg2(000, "sibling->fname=%s fname=%s\n", sibling->fname, fname);
if (fname[0] > sibling->fname[0] || (cmp=strcmp(fname, sibling->fname)) > 0) {
last_sibling = sibling;
if (sibling == first_child(parent)) { /* if sibling was at head of list */
parent->child_ = NULL; /* force parent to be updated below */
}
- Dmsg2(000, "insert before sibling->fname=%s fname=%s\n", sibling->fname, fname);
+ Dmsg2(000, "insert before sibling->fname=%s fname=%s\n", sibling->fname, fname);
break;
}
/* Found it */
}
- /*
- * At this point, the fname is not found. We must add it
+ /*
+ * At this point, the fname is not found. We must add it
*/
if (!node) {
node = new_tree_node(root);
return 1;
}
tree_getpath(node->parent, buf, buf_size);
- /*
- * Fixup for Win32. If we have a Win32 directory and
+ /*
+ * Fixup for Win32. If we have a Win32 directory and
* there is only a / in the buffer, remove it since
* win32 names don't generally start with /
*/
if (node->type == TN_DIR_NLS && buf[0] == '/' && buf[1] == 0) {
- buf[0] = 0;
+ buf[0] = 0;
}
bstrncat(buf, node->fname, buf_size);
/* Add a slash for all directories unless we are at the root,
return 1;
}
-/*
+/*
* Change to specified directory
*/
TREE_NODE *tree_cwd(char *path, TREE_ROOT *root, TREE_NODE *node)
Dmsg2(100, "tree_relcwd: len=%d path=%s\n", len, path);
foreach_child(cd, node) {
Dmsg1(100, "tree_relcwd: test cd=%s\n", cd->fname);
- if (cd->fname[0] == path[0] && len == (int)strlen(cd->fname)
+ if (cd->fname[0] == path[0] && len == (int)strlen(cd->fname)
&& strncmp(cd->fname, path, len) == 0) {
break;
}
char file[MAXPATHLEN];
int type;
int i;
-
+
Dmsg1(100, "FillDirectoryTree: %s\n", path);
dp = opendir(path);
if (!dp) {
bstrncpy(file, dir->d_name, sizeof(file));
snprintf(pathbuf, MAXPATHLEN-1, "%s/%s", path, file);
if (lstat(pathbuf, &statbuf) < 0) {
- printf("lstat() failed. ERR=%s\n", strerror(errno));
+ printf("lstat() failed. ERR=%s\n", strerror(errno));
continue;
}
// printf("got file=%s, pathbuf=%s\n", file, pathbuf);
type = TN_FILE; /* sock */
else {
type = TN_FILE;
- printf("Unknown file type: 0x%x\n", statbuf.st_mode);
+ printf("Unknown file type: 0x%x\n", statbuf.st_mode);
}
Dmsg2(100, "Doing: %d %s\n", type, pathbuf);
node->FileIndex = ++FileIndex;
parent = insert_tree_node(pathbuf, node, root, parent);
if (S_ISDIR(statbuf.st_mode) && !S_ISLNK(statbuf.st_mode)) {
- Dmsg2(100, "calling fill. pathbuf=%s, file=%s\n", pathbuf, file);
+ Dmsg2(100, "calling fill. pathbuf=%s, file=%s\n", pathbuf, file);
FillDirectoryTree(pathbuf, root, node);
}
}
switch (tree->type) {
case TN_DIR_NLS:
case TN_DIR:
- case TN_NEWDIR:
+ case TN_NEWDIR:
termchr = "/";
break;
case TN_ROOT:
/*
* Directory tree build/traverse routines
- *
+ *
* Kern Sibbald, June MMII
*
*/
unsigned int extract: 1; /* extract item */
unsigned int extract_dir: 1; /* extract dir entry only */
unsigned int hard_link: 1; /* set if have hard link */
- unsigned int soft_link: 1; /* set if is soft link */
+ unsigned int soft_link: 1; /* set if is soft link */
unsigned int inserted: 1; /* set when newly inserted */
struct s_tree_node *parent;
struct s_tree_node *next; /* next hash of FileIndex */
unsigned int extract: 1; /* extract item */
unsigned int extract_dir: 1; /* extract dir entry only */
unsigned int hard_link: 1; /* set if have hard link */
- unsigned int soft_link: 1; /* set if is soft link */
+ unsigned int soft_link: 1; /* set if is soft link */
unsigned int inserted: 1; /* set when newly inserted */
struct s_tree_node *parent;
struct s_tree_node *sibling_;
/*
* Use the following for traversing the whole tree. It will be
* traversed in the order the entries were inserted into the
- * tree.
+ * tree.
*/
#ifdef SLOW_WAY
TREE_NODE *first_tree_node(TREE_ROOT *root);
/*
* util.c miscellaneous utility subroutines for Bacula
- *
+ *
* Kern Sibbald, MM
*
* Version $Id$
}
}
-/* Convert spaces to non-space character.
+/* Convert spaces to non-space character.
* This makes scanf of fields containing spaces easier.
*/
void
}
}
-/* Convert spaces to non-space character.
+/* Convert spaces to non-space character.
* This makes scanf of fields containing spaces easier.
*/
void
{
while (*str) {
if (*str == 0x1)
- *str = ' ';
+ *str = ' ';
str++;
}
}
char *str = pm.c_str();
while (*str) {
if (*str == 0x1)
- *str = ' ';
+ *str = ' ';
str++;
}
}
if (JobStatus == 0) {
buf[0] = 0;
} else {
- bsnprintf(buf, sizeof(buf), _("Unknown Job termination status=%d"), JobStatus);
+ bsnprintf(buf, sizeof(buf), _("Unknown Job termination status=%d"), JobStatus);
}
jobstat = buf;
break;
/*
* Convert Job Termination Status into a string
*/
-const char *job_status_to_str(int stat)
+const char *job_status_to_str(int stat)
{
const char *str;
/*
* Convert Job Type into a string
*/
-const char *job_type_to_str(int type)
+const char *job_type_to_str(int type)
{
const char *str;
/*
* Convert Job Level into a string
*/
-const char *job_level_to_str(int level)
+const char *job_level_to_str(int level)
{
const char *str;
char *encode_mode(mode_t mode, char *buf)
{
- char *cp = buf;
+ char *cp = buf;
*cp++ = S_ISDIR(mode) ? 'd' : S_ISBLK(mode) ? 'b' : S_ISCHR(mode) ? 'c' :
- S_ISLNK(mode) ? 'l' : S_ISFIFO(mode) ? 'f' : S_ISSOCK(mode) ? 's' : '-';
+ S_ISLNK(mode) ? 'l' : S_ISFIFO(mode) ? 'f' : S_ISSOCK(mode) ? 's' : '-';
*cp++ = mode & S_IRUSR ? 'r' : '-';
*cp++ = mode & S_IWUSR ? 'w' : '-';
*cp++ = (mode & S_ISUID
- ? (mode & S_IXUSR ? 's' : 'S')
- : (mode & S_IXUSR ? 'x' : '-'));
+ ? (mode & S_IXUSR ? 's' : 'S')
+ : (mode & S_IXUSR ? 'x' : '-'));
*cp++ = mode & S_IRGRP ? 'r' : '-';
*cp++ = mode & S_IWGRP ? 'w' : '-';
*cp++ = (mode & S_ISGID
- ? (mode & S_IXGRP ? 's' : 'S')
- : (mode & S_IXGRP ? 'x' : '-'));
+ ? (mode & S_IXGRP ? 's' : 'S')
+ : (mode & S_IXGRP ? 'x' : '-'));
*cp++ = mode & S_IROTH ? 'r' : '-';
*cp++ = mode & S_IWOTH ? 'w' : '-';
*cp++ = (mode & S_ISVTX
- ? (mode & S_IXOTH ? 't' : 'T')
- : (mode & S_IXOTH ? 'x' : '-'));
+ ? (mode & S_IXOTH ? 't' : 'T')
+ : (mode & S_IXOTH ? 'x' : '-'));
*cp = '\0';
return cp;
}
cmd = get_pool_memory(PM_FNAME);
/* look for shell */
if ((shellcmd = getenv("SHELL")) == NULL) {
- shellcmd = "/bin/sh";
+ shellcmd = "/bin/sh";
}
pm_strcpy(&cmd, shellcmd);
pm_strcat(&cmd, " -c \"echo ");
fgets(line, sizeof(line), bpipe->rfd);
strip_trailing_junk(line);
stat = close_bpipe(bpipe);
- Dmsg2(400, "stat=%d got: %s\n", stat, line);
+ Dmsg2(400, "stat=%d got: %s\n", stat, line);
} else {
stat = 1; /* error */
}
/* The following creates a seed for the session key generator
based on a collection of volatile and environment-specific
information unlikely to be vulnerable (as a whole) to an
- exhaustive search attack. If one of these items isn't
+ exhaustive search attack. If one of these items isn't
available on your machine, replace it with something
equivalent or, if you like, just delete it. */
key[k++] = Rad16(rb & 0xF);
#undef Rad16
if (j & 1) {
- key[k++] = '-';
+ key[k++] = '-';
}
}
key[--k] = 0;
*
* omsg = edited output message
* imsg = input string containing edit codes (%x)
- * to = recepients list
+ * to = recepients list
*
*/
-POOLMEM *edit_job_codes(JCR *jcr, char *omsg, char *imsg, const char *to)
+POOLMEM *edit_job_codes(JCR *jcr, char *omsg, char *imsg, const char *to)
{
char *p, *q;
const char *str;
for (p=imsg; *p; p++) {
if (*p == '%') {
switch (*++p) {
- case '%':
- str = "%";
+ case '%':
+ str = "%";
break;
- case 'c':
+ case 'c':
if (jcr) {
str = jcr->client_name;
} else {
- str = "*none*";
+ str = "*none*";
}
break;
- case 'd':
- str = my_name; /* Director's name */
+ case 'd':
+ str = my_name; /* Director's name */
break;
- case 'e':
+ case 'e':
if (jcr) {
- str = job_status_to_str(jcr->JobStatus);
- } else {
- str = "*none*";
+ str = job_status_to_str(jcr->JobStatus);
+ } else {
+ str = "*none*";
}
break;
- case 'i':
+ case 'i':
if (jcr) {
- bsnprintf(add, sizeof(add), "%d", jcr->JobId);
+ bsnprintf(add, sizeof(add), "%d", jcr->JobId);
str = add;
} else {
- str = "*none*";
+ str = "*none*";
}
break;
- case 'j': /* Job name */
+ case 'j': /* Job name */
if (jcr) {
str = jcr->Job;
} else {
- str = "*none*";
+ str = "*none*";
}
break;
- case 'l':
+ case 'l':
if (jcr) {
str = job_level_to_str(jcr->JobLevel);
} else {
- str = "*none*";
+ str = "*none*";
}
break;
- case 'n':
+ case 'n':
if (jcr) {
bstrncpy(name, jcr->Job, sizeof(name));
/* There are three periods after the Job name */
for (i=0; i<3; i++) {
- if ((q=strrchr(name, '.')) != NULL) {
+ if ((q=strrchr(name, '.')) != NULL) {
*q = 0;
}
}
str = name;
} else {
- str = "*none*";
+ str = "*none*";
}
break;
- case 'r':
+ case 'r':
str = to;
break;
- case 't':
+ case 't':
if (jcr) {
str = job_type_to_str(jcr->JobType);
} else {
- str = "*none*";
+ str = "*none*";
}
break;
- case 'v':
+ case 'v':
if (jcr) {
if (jcr->VolumeName && jcr->VolumeName[0]) {
str = jcr->VolumeName;
} else {
- str = "";
+ str = "";
}
} else {
- str = "*none*";
+ str = "*none*";
}
break;
default:
- add[0] = '%';
+ add[0] = '%';
add[1] = *p;
add[2] = 0;
str = add;
void set_working_directory(char *wd)
{
- struct stat stat_buf;
+ struct stat stat_buf;
if (wd == NULL) {
Emsg0(M_ERROR_TERM, 0, _("Working directory not defined. Cannot continue.\n"));
*/
/* minimal output-independent vprintf(3) variant which supports %{c,s,d,%} only */
-static int
+static int
var_mvxprintf(
- int (*output)(void *ctx, const char *buffer, int bufsize), void *ctx,
+ int (*output)(void *ctx, const char *buffer, int bufsize), void *ctx,
const char *format, va_list ap)
{
/* sufficient integer buffer: <available-bits> x log_10(2) + safety */
- char ibuf[((sizeof(int)*8)/3)+10];
+ char ibuf[((sizeof(int)*8)/3)+10];
const char *cp;
char c;
int d;
return -1;
bytes = 0;
while (*format != '\0') {
- if (*format == '%') {
+ if (*format == '%') {
c = *(format+1);
- if (c == '%') {
- /* expand "%%" */
+ if (c == '%') {
+ /* expand "%%" */
cp = &c;
n = sizeof(char);
}
- else if (c == 'c') {
- /* expand "%c" */
+ else if (c == 'c') {
+ /* expand "%c" */
c = (char)va_arg(ap, int);
cp = &c;
n = sizeof(char);
}
- else if (c == 's') {
- /* expand "%s" */
+ else if (c == 's') {
+ /* expand "%s" */
if ((cp = (char *)va_arg(ap, char *)) == NULL)
- cp = "(null)";
+ cp = "(null)";
n = strlen(cp);
}
- else if (c == 'd') {
- /* expand "%d" */
+ else if (c == 'd') {
+ /* expand "%d" */
d = (int)va_arg(ap, int);
- bsnprintf(ibuf, sizeof(ibuf), "%d", d); /* explicitly secure */
+ bsnprintf(ibuf, sizeof(ibuf), "%d", d); /* explicitly secure */
cp = ibuf;
n = strlen(cp);
}
else {
- /* any other "%X" */
+ /* any other "%X" */
cp = (char *)format;
n = 2;
}
else {
/* plain text */
cp = (char *)format;
- if ((format = strchr(cp, '%')) == NULL)
- format = strchr(cp, '\0');
+ if ((format = strchr(cp, '%')) == NULL)
+ format = strchr(cp, '\0');
n = format - cp;
}
/* perform output operation */
} var_mvsnprintf_cb_t;
/* output callback function for var_mvsnprintf() */
-static int
+static int
var_mvsnprintf_cb(
- void *_ctx,
+ void *_ctx,
const char *buffer, int bufsize)
{
var_mvsnprintf_cb_t *ctx = (var_mvsnprintf_cb_t *)_ctx;
}
/* minimal vsnprintf(3) variant which supports %{c,s,d} only */
-static int
+static int
var_mvsnprintf(
- char *buffer, int bufsize,
+ char *buffer, int bufsize,
const char *format, va_list ap)
{
int n;
return -1;
if (buffer != NULL && bufsize == 0)
return -1;
- if (buffer == NULL)
+ if (buffer == NULL)
/* just determine output length */
n = var_mvxprintf(NULL, NULL, format, ap);
else {
if (n != -1 && ctx.buflen == 0)
n = -1;
if (n != -1)
- *(ctx.bufptr) = '\0';
+ *(ctx.bufptr) = '\0';
}
return n;
}
int buffer_size;
} tokenbuf_t;
-static void
+static void
tokenbuf_init(
tokenbuf_t *buf)
{
return;
}
-static int
+static int
tokenbuf_isundef(
tokenbuf_t *buf)
{
return 0;
}
-static int
+static int
tokenbuf_isempty(
tokenbuf_t *buf)
{
return 0;
}
-static void
+static void
tokenbuf_set(
tokenbuf_t *buf, const char *begin, const char *end, int buffer_size)
{
return;
}
-static void
+static void
tokenbuf_move(
tokenbuf_t *src, tokenbuf_t *dst)
{
return;
}
-static int
+static int
tokenbuf_assign(
tokenbuf_t *buf, const char *data, int len)
{
return 1;
}
-static int
+static int
tokenbuf_append(
tokenbuf_t *output, const char *data, int len)
{
return 1;
}
-static int
+static int
tokenbuf_merge(
tokenbuf_t *output, tokenbuf_t *input)
{
return tokenbuf_append(output, input->begin, input->end - input->begin);
}
-static void
+static void
tokenbuf_free(
tokenbuf_t *buf)
{
**
*/
-static void
+static void
expand_range(char a, char b, char_class_t chrclass)
{
do {
return;
}
-static var_rc_t
+static var_rc_t
expand_character_class(const char *desc, char_class_t chrclass)
{
int i;
/* walk through class description and set appropriate entries in array */
while (*desc != EOS) {
- if (desc[1] == '-' && desc[2] != EOS) {
+ if (desc[1] == '-' && desc[2] != EOS) {
if (desc[0] > desc[2])
return VAR_ERR_INCORRECT_CLASS_SPEC;
expand_range(desc[0], desc[2], chrclass);
**
*/
-static int
+static int
expand_isoct(
int c)
{
return 0;
}
-static var_rc_t
+static var_rc_t
expand_octal(
const char **src, char **dst, const char *end)
{
if (end - *src < 3)
return VAR_ERR_INCOMPLETE_OCTAL;
- if ( !expand_isoct(**src)
- || !expand_isoct((*src)[1])
+ if ( !expand_isoct(**src)
+ || !expand_isoct((*src)[1])
|| !expand_isoct((*src)[2]))
return VAR_ERR_INVALID_OCTAL;
return VAR_OK;
}
-static int
+static int
expand_ishex(
int c)
{
if ((c >= '0' && c <= '9') ||
- (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'))
+ (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'))
return 1;
else
return 0;
}
-static var_rc_t
+static var_rc_t
expand_simple_hex(
const char **src, char **dst, const char *end)
{
if (end - *src < 2)
return VAR_ERR_INCOMPLETE_HEX;
- if ( !expand_ishex(**src)
+ if ( !expand_ishex(**src)
|| !expand_ishex((*src)[1]))
return VAR_ERR_INVALID_HEX;
if (**src >= '0' && **src <= '9')
- c = **src - '0';
+ c = **src - '0';
else if (**src >= 'a' && **src <= 'f')
- c = **src - 'a' + 10;
+ c = **src - 'a' + 10;
else if (**src >= 'A' && **src <= 'F')
- c = **src - 'A' + 10;
+ c = **src - 'A' + 10;
c = c << 4;
(*src)++;
if (**src >= '0' && **src <= '9')
- c += **src - '0';
+ c += **src - '0';
else if (**src >= 'a' && **src <= 'f')
- c += **src - 'a' + 10;
+ c += **src - 'a' + 10;
else if (**src >= 'A' && **src <= 'F')
- c += **src - 'A' + 10;
+ c += **src - 'A' + 10;
**dst = (char)c;
(*dst)++;
return VAR_OK;
}
-static var_rc_t
+static var_rc_t
expand_grouped_hex(
const char **src, char **dst, const char *end)
{
return VAR_OK;
}
-static var_rc_t
+static var_rc_t
expand_hex(
const char **src, char **dst, const char *end)
{
return expand_simple_hex(src, dst, end);
}
-/*
+/*
**
** ==== RECURSIVE-DESCEND VARIABLE EXPANSION PARSER ====
**
static int parse_name (var_t *var, var_parse_t *ctx, const char *begin, const char *end);
/* parse pattern text */
-static int
+static int
parse_pattern(
var_t *var, var_parse_t *ctx,
const char *begin, const char *end)
}
/* parse substitution text */
-static int
+static int
parse_substext(
var_t *var, var_parse_t *ctx,
const char *begin, const char *end)
}
/* parse expression text */
-static int
+static int
parse_exptext(
var_t *var, var_parse_t *ctx,
const char *begin, const char *end)
for (p = begin; p != end
&& *p != var->syntax.delim_init
&& *p != var->syntax.delim_close
- && *p != ':'; p++) {
+ && *p != ':'; p++) {
if (*p == var->syntax.escape) {
if (p + 1 == end)
return VAR_ERR_INCOMPLETE_QUOTED_PAIR;
}
/* parse opertion argument text */
-static int
+static int
parse_opargtext(
var_t *var, var_parse_t *ctx,
const char *begin, const char *end)
return (p - begin);
}
-static int
+static int
parse_opargtext_or_variable(
var_t *var, var_parse_t *ctx,
const char *begin, const char *end,
}
/* parse expression or variable */
-static int
+static int
parse_exptext_or_variable(
var_t *var, var_parse_t *ctx,
const char *begin, const char *end,
}
/* parse substitution text or variable */
-static int
+static int
parse_substext_or_variable(
var_t *var, var_parse_t *ctx,
const char *begin, const char *end,
}
/* parse class description */
-static int
+static int
parse_class_description(
var_t *var, var_parse_t *ctx,
tokenbuf_t *src, tokenbuf_t *dst)
{
unsigned char c, d;
- const char *p;
+ const char *p;
p = src->begin;
while (p != src->end) {
- if ((src->end - p) >= 3 && p[1] == '-') {
+ if ((src->end - p) >= 3 && p[1] == '-') {
if (*p > p[2])
return VAR_ERR_INCORRECT_TRANSPOSE_CLASS_SPEC;
for (c = *p, d = p[2]; c <= d; ++c) {
}
/* parse regex replace part */
-static int
+static int
parse_regex_replace(
var_t *var, var_parse_t *ctx,
- const char *data,
+ const char *data,
tokenbuf_t *orig,
- regmatch_t *pmatch,
+ regmatch_t *pmatch,
tokenbuf_t *expanded)
{
const char *p;
tokenbuf_init(expanded);
while (p != orig->end) {
- if (*p == '\\') {
+ if (*p == '\\') {
if (orig->end - p <= 1) {
tokenbuf_free(expanded);
return VAR_ERR_INCOMPLETE_QUOTED_PAIR;
}
p++;
- if (*p == '\\') {
+ if (*p == '\\') {
if (!tokenbuf_append(expanded, p, 1)) {
tokenbuf_free(expanded);
return VAR_ERR_OUT_OF_MEMORY;
tokenbuf_free(expanded);
return VAR_ERR_UNKNOWN_QUOTED_PAIR_IN_REPLACE;
}
- i = (*p - '0');
+ i = (*p - '0');
p++;
if (pmatch[i].rm_so == -1 || pmatch[i].rm_eo == -1) {
tokenbuf_free(expanded);
}
/* operation: transpose */
-static int
+static int
op_transpose(
var_t *var, var_parse_t *ctx,
- tokenbuf_t *data,
+ tokenbuf_t *data,
tokenbuf_t *search,
tokenbuf_t *replace)
{
}
/* operation: search & replace */
-static int
+static int
op_search_and_replace(
var_t *var, var_parse_t *ctx,
- tokenbuf_t *data,
+ tokenbuf_t *data,
tokenbuf_t *search,
- tokenbuf_t *replace,
+ tokenbuf_t *replace,
tokenbuf_t *flags)
{
tokenbuf_t tmp;
for (p = flags->begin; p != flags->end; p++) {
switch (tolower(*p)) {
- case 'm':
+ case 'm':
multiline = 1;
break;
- case 'i':
+ case 'i':
case_insensitive = 1;
break;
- case 'g':
+ case 'g':
global = 1;
break;
- case 't':
+ case 't':
no_regex = 1;
break;
default:
}
/* compile the pattern. */
- rc = regcomp(&preg, tmp.begin,
+ rc = regcomp(&preg, tmp.begin,
( REG_EXTENDED
| (multiline ? REG_NEWLINE : 0)
| (case_insensitive ? REG_ICASE : 0)));
}
/* match the pattern and create the result string in the tmp buffer */
- tokenbuf_append(&tmp, "", 0);
+ tokenbuf_append(&tmp, "", 0);
for (p = mydata.begin; p < mydata.end; ) {
- if (p == mydata.begin || p[-1] == '\n')
+ if (p == mydata.begin || p[-1] == '\n')
regexec_flag = 0;
else
regexec_flag = REG_NOTBOL;
tokenbuf_append(&tmp, p, mydata.end - p);
break;
}
- else if ( multiline
- && (p + pmatch[0].rm_so) == mydata.end
+ else if ( multiline
+ && (p + pmatch[0].rm_so) == mydata.end
&& (pmatch[0].rm_eo - pmatch[0].rm_so) == 0) {
/* special case: found empty pattern (usually /^/ or /$/ only)
in multi-line at end of data (after the last newline) */
}
p++;
}
- /* append prolog string and stop processing if we
+ /* append prolog string and stop processing if we
do not perform the search & replace globally */
if (!global) {
if (!tokenbuf_append(&tmp, p, mydata.end - p)) {
}
/* operation: offset substring */
-static int
+static int
op_offset(
var_t *var, var_parse_t *ctx,
- tokenbuf_t *data,
+ tokenbuf_t *data,
int num1,
- int num2,
+ int num2,
int isrange)
{
tokenbuf_t res;
}
/* operation: padding */
-static int
+static int
op_padding(
var_t *var, var_parse_t *ctx,
- tokenbuf_t *data,
- int width,
+ tokenbuf_t *data,
+ int width,
tokenbuf_t *fill,
char position)
{
}
/* parse an integer number ("123") */
-static int
+static int
parse_integer(
var_t *var, var_parse_t *ctx,
const char *begin, const char *end,
num = 0;
while (isdigit(*p) && p != end) {
num *= 10;
- num += (*p - '0');
+ num += (*p - '0');
p++;
}
if (result != NULL)
}
/* parse an operation (":x...") */
-static int
+static int
parse_operation(
var_t *var, var_parse_t *ctx,
const char *begin, const char *end,
/* dispatch through the first operation character */
switch (tolower(*p)) {
- case 'l': {
+ case 'l': {
/* turn value to lowercase. */
if (data->begin != NULL) {
/* if the buffer does not live in an allocated buffer,
p++;
break;
}
- case 'u': {
+ case 'u': {
/* turn value to uppercase. */
if (data->begin != NULL) {
/* if the buffer does not live in an allocated buffer,
p++;
break;
}
- case 'o': {
+ case 'o': {
/* cut out substring of value. */
p++;
rc = parse_integer(var, ctx, p, end, &num1);
else if (rc < 0)
goto error_return;
p += rc;
- if (*p == ',') {
+ if (*p == ',') {
isrange = 0;
p++;
- } else if (*p == '-') {
+ } else if (*p == '-') {
isrange = 1;
p++;
} else {
}
break;
}
- case '#': {
+ case '#': {
/* determine length of the value */
if (data->begin != NULL) {
char buf[((sizeof(int)*8)/3)+10]; /* sufficient size: <#bits> x log_10(2) + safety */
- sprintf(buf, "%d", (int)(data->end - data->begin));
+ sprintf(buf, "%d", (int)(data->end - data->begin));
tokenbuf_free(data);
if (!tokenbuf_assign(data, buf, strlen(buf))) {
rc = VAR_ERR_OUT_OF_MEMORY;
p++;
break;
}
- case '-': {
+ case '-': {
/* substitute parameter if data is empty */
p++;
rc = parse_exptext_or_variable(var, ctx, p, end, &tmptokbuf);
}
break;
}
- case '*': {
+ case '*': {
/* substitute empty string if data is not empty, parameter otherwise. */
p++;
rc = parse_exptext_or_variable(var, ctx, p, end, &tmptokbuf);
tokenbuf_move(&tmptokbuf, data);
} else {
tokenbuf_free(data);
- data->begin = data->end = "";
+ data->begin = data->end = "";
data->buffer_size = 0;
}
}
break;
}
- case '+': {
+ case '+': {
/* substitute parameter if data is not empty. */
p++;
rc = parse_exptext_or_variable(var, ctx, p, end, &tmptokbuf);
}
break;
}
- case 's': {
+ case 's': {
/* search and replace. */
p++;
- if (*p != '/')
+ if (*p != '/')
return VAR_ERR_MALFORMATTED_REPLACE;
p++;
rc = parse_pattern(var, ctx, p, end);
goto error_return;
tokenbuf_set(&search, p, p + rc, 0);
p += rc;
- if (*p != '/') {
+ if (*p != '/') {
rc = VAR_ERR_MALFORMATTED_REPLACE;
goto error_return;
}
if (rc < 0)
goto error_return;
p += rc;
- if (*p != '/') {
+ if (*p != '/') {
rc = VAR_ERR_MALFORMATTED_REPLACE;
goto error_return;
}
}
break;
}
- case 'y': {
+ case 'y': {
/* transpose characters from class A to class B. */
p++;
- if (*p != '/')
+ if (*p != '/')
return VAR_ERR_MALFORMATTED_TRANSPOSE;
p++;
rc = parse_substext_or_variable(var, ctx, p, end, &search);
if (rc < 0)
goto error_return;
p += rc;
- if (*p != '/') {
+ if (*p != '/') {
rc = VAR_ERR_MALFORMATTED_TRANSPOSE;
goto error_return;
}
if (rc < 0)
goto error_return;
p += rc;
- if (*p != '/') {
+ if (*p != '/') {
rc = VAR_ERR_MALFORMATTED_TRANSPOSE;
goto error_return;
} else
}
break;
}
- case 'p': {
+ case 'p': {
/* padding. */
p++;
- if (*p != '/')
+ if (*p != '/')
return VAR_ERR_MALFORMATTED_PADDING;
p++;
rc = parse_integer(var, ctx, p, end, &num1);
goto error_return;
}
p += rc;
- if (*p != '/') {
+ if (*p != '/') {
rc = VAR_ERR_MALFORMATTED_PADDING;
goto error_return;
}
if (rc < 0)
goto error_return;
p += rc;
- if (*p != '/') {
+ if (*p != '/') {
rc = VAR_ERR_MALFORMATTED_PADDING;
goto error_return;
}
p++;
- if (*p != 'l' && *p != 'c' && *p != 'r') {
+ if (*p != 'l' && *p != 'c' && *p != 'r') {
rc = VAR_ERR_MALFORMATTED_PADDING;
goto error_return;
}
}
break;
}
- case '%': {
+ case '%': {
/* operation callback function */
const char *op_ptr;
int op_len;
const char *val_ptr;
int val_len;
const char *out_ptr;
- int out_len;
+ int out_len;
int out_size;
tokenbuf_t args;
op_ptr = p;
op_len = rc;
p += rc;
- if (*p == '(') {
+ if (*p == '(') {
p++;
tokenbuf_init(&args);
rc = parse_opargtext_or_variable(var, ctx, p, end, &args);
p += rc;
arg_ptr = args.begin;
arg_len = args.end - args.begin;
- if (*p != ')') {
+ if (*p != ')') {
rc = VAR_ERR_MALFORMED_OPERATION_ARGUMENTS;
goto error_return;
}
}
/* parse numerical expression operand */
-static int
+static int
parse_numexp_operand(
var_t *var, var_parse_t *ctx,
- const char *begin, const char *end,
+ const char *begin, const char *end,
int *result, int *failed)
{
const char *p;
if (p == end)
return VAR_ERR_INCOMPLETE_INDEX_SPEC;
/* parse closing parenthesis */
- if (*p != ')')
+ if (*p != ')')
return VAR_ERR_UNCLOSED_BRACKET_IN_INDEX;
p++;
}
}
}
/* parse relative index mark ("#") */
- else if ( var->syntax.index_mark != EOS
+ else if ( var->syntax.index_mark != EOS
&& *p == var->syntax.index_mark) {
p++;
*result = ctx->index_this;
}
/* parse numerical expression ("x+y") */
-static int
+static int
parse_numexp(
var_t *var, var_parse_t *ctx,
- const char *begin, const char *end,
+ const char *begin, const char *end,
int *result, int *failed)
{
const char *p;
/* parse numerical operator */
while (p != end) {
- if (*p == '+' || *p == '-') {
+ if (*p == '+' || *p == '-') {
op = *p++;
/* recursively parse right operand (light binding) */
rc = parse_numexp(var, ctx, p, end, &right, failed);
if (rc < 0)
return rc;
p += rc;
- if (op == '+')
+ if (op == '+')
*result = (*result + right);
else
*result = (*result - right);
}
- else if (*p == '*' || *p == '/' || *p == '%') {
+ else if (*p == '*' || *p == '/' || *p == '%') {
op = *p++;
/* recursively parse right operand (string binding) */
rc = parse_numexp_operand(var, ctx, p, end, &right, failed);
if (rc < 0)
return rc;
p += rc;
- if (op == '*')
+ if (op == '*')
*result = (*result * right);
- else if (op == '/') {
+ else if (op == '/') {
if (right == 0) {
if (*failed)
*result = 0;
else
*result = (*result / right);
}
- else if (op == '%') {
+ else if (op == '%') {
if (right == 0) {
if (*failed)
*result = 0;
}
/* parse variable name ("abc") */
-static int
+static int
parse_name(
var_t *var, var_parse_t *ctx,
const char *begin, const char *end)
}
/* lookup a variable value through the callback function */
-static int
+static int
lookup_value(
var_t *var, var_parse_t *ctx,
const char *var_ptr, int var_len, int var_inc, int var_idx,
/* pass through to original callback */
rc = (*var->cb_value_fct)(var, var->cb_value_ctx,
- var_ptr, var_len, var_inc, var_idx,
+ var_ptr, var_len, var_inc, var_idx,
val_ptr, val_len, val_size);
/* convert undefined variable into empty variable if relative
lookups are counted. This is the case inside an active loop
construct if no limits are given. There the parse_input()
- has to proceed until all variables have undefined values.
+ has to proceed until all variables have undefined values.
This trick here allows it to determine this case. */
if (ctx->rel_lookup_flag && rc == VAR_ERR_UNDEFINED_VARIABLE) {
ctx->rel_lookup_cnt--;
}
/* parse complex variable construct ("${name...}") */
-static int
+static int
parse_variable_complex(
var_t *var, var_parse_t *ctx,
const char *begin, const char *end,
int failed = 0;
int rc;
int idx = 0;
- int inc;
+ int inc;
tokenbuf_t name;
tokenbuf_t tmp;
tokenbuf_free(&tmp); /* KES 11/9/2003 */
} while (rc > 0);
- /* we must have the complete expanded variable name now,
+ /* we must have the complete expanded variable name now,
so make sure we really do. */
if (name.begin == name.end) {
if (ctx->force_expand) {
}
else {
/* If no force_expand is requested, we have to back-off.
- We're not sure whether our approach here is 100% correct,
+ We're not sure whether our approach here is 100% correct,
because it _could_ have side-effects according to Peter
Simons, but as far as we know and tried it, it is
correct. But be warned -- RSE */
tokenbuf_free(&tmp);
tokenbuf_init(&tmp);
p--;
- while (p != end && *p == ':') {
+ while (p != end && *p == ':') {
p++;
if (!failed)
rc = parse_operation(var, ctx, p, end, result);
}
/* parse variable construct ("$name" or "${name...}") */
-static int
+static int
parse_variable(
var_t *var, var_parse_t *ctx,
const char *begin, const char *end,
if (p == end)
return VAR_ERR_INCOMPLETE_VARIABLE_SPEC;
- /* parse a simple variable name.
+ /* parse a simple variable name.
(if this fails, we're try to parse a complex variable construct) */
rc = parse_name(var, ctx, p, end);
if (rc < 0)
return rc;
if (rc > 0) {
- inc = (p[rc] == '+');
+ inc = (p[rc] == '+');
rc2 = lookup_value(var, ctx, p, rc, inc, 0, &data, &len, &buffer_size);
if (rc2 == VAR_ERR_UNDEFINED_VARIABLE && !ctx->force_expand) {
tokenbuf_set(result, begin, begin + 1 + rc, 0);
}
/* parse loop construct limits ("[...]{b,s,e}") */
-static var_rc_t
+static var_rc_t
parse_looplimits(
var_t *var, var_parse_t *ctx,
const char *begin, const char *end,
}
/* parse plain text */
-static int
+static int
parse_text(
var_t *var, var_parse_t *ctx,
const char *begin, const char *end)
{
const char *p;
- /* parse until delim_init (variable construct)
+ /* parse until delim_init (variable construct)
or index_open (loop construct) is found */
for (p = begin; p != end; p++) {
if (*p == var->syntax.escape) {
else if (*p == var->syntax.delim_init)
break;
else if ( var->syntax.index_open != EOS
- && ( *p == var->syntax.index_open
+ && ( *p == var->syntax.index_open
|| *p == var->syntax.index_close))
break;
}
}
/* expand input in general */
-static var_rc_t
+static var_rc_t
parse_input(
var_t *var, var_parse_t *ctx,
const char *begin, const char *end,
do {
/* try to parse a loop construct */
- if ( p != end
- && var->syntax.index_open != EOS
+ if ( p != end
+ && var->syntax.index_open != EOS
&& *p == var->syntax.index_open) {
p++;
or there is a stop limit known and it is still not reached */
re_loop:
for (i = start;
- ( ( open_stop
- && ( loop_limit_length < 0
- || rel_lookup_cnt > ctx->rel_lookup_cnt))
- || ( !open_stop
+ ( ( open_stop
+ && ( loop_limit_length < 0
+ || rel_lookup_cnt > ctx->rel_lookup_cnt))
+ || ( !open_stop
&& i <= stop) );
i += step) {
/* remember current output end for restoring */
output_backup = (output->end - output->begin);
- /* open temporary context for recursion */
+ /* open temporary context for recursion */
ctx = var_parse_push(ctx, &myctx);
ctx->force_expand = 1;
ctx->rel_lookup_flag = 1;
ctx->index_this = i;
/* recursive parse input through ourself */
- rc = parse_input(var, ctx, p, end,
+ rc = parse_input(var, ctx, p, end,
output, recursion_level+1);
/* retrieve info and close temporary context */
/* try to parse loop construct limit specification */
if (loop_limit_length < 0) {
- rc2 = parse_looplimits(var, ctx, p+rc+1, end,
+ rc2 = parse_looplimits(var, ctx, p+rc+1, end,
&start, &step, &stop, &open_stop);
if (rc2 < 0)
goto error_return;
tokenbuf_free(&result);
p += rc;
continue;
- }
+ }
tokenbuf_free(&result);
if (rc < 0)
goto error_return;
return (var_rc_t)rc;
}
-/*
+/*
**
** ==== APPLICATION PROGRAMMING INTERFACE (API) ====
**
*/
/* create variable expansion context */
-var_rc_t
+var_rc_t
var_create(
var_t **pvar)
{
}
/* destroy variable expansion context */
-var_rc_t
+var_rc_t
var_destroy(
var_t *var)
{
}
/* configure variable expansion context */
-var_rc_t
+var_rc_t
var_config(
- var_t *var,
- var_config_t mode,
+ var_t *var,
+ var_config_t mode,
...)
{
va_list ap;
var->syntax.name_chars = NULL; /* unused internally */
if ((rc = expand_character_class(s->name_chars, var->syntax_nameclass)) != VAR_OK)
return VAR_RC(rc);
- if ( var->syntax_nameclass[(int)var->syntax.delim_init]
+ if ( var->syntax_nameclass[(int)var->syntax.delim_init]
|| var->syntax_nameclass[(int)var->syntax.delim_open]
|| var->syntax_nameclass[(int)var->syntax.delim_close]
|| var->syntax_nameclass[(int)var->syntax.escape])
}
/* perform unescape operation on a buffer */
-var_rc_t
+var_rc_t
var_unescape(
- var_t *var,
- const char *src, int srclen,
- char *dst, int dstlen,
+ var_t *var,
+ const char *src, int srclen,
+ char *dst, int dstlen,
int all)
{
const char *end;
return VAR_RC(VAR_ERR_INVALID_ARGUMENT);
end = src + srclen;
while (src < end) {
- if (*src == '\\') {
+ if (*src == '\\') {
if (++src == end)
return VAR_RC(VAR_ERR_INCOMPLETE_NAMED_CHARACTER);
switch (*src) {
- case '\\':
+ case '\\':
if (!all) {
- *dst++ = '\\';
+ *dst++ = '\\';
}
- *dst++ = '\\';
+ *dst++ = '\\';
break;
- case 'n':
- *dst++ = '\n';
+ case 'n':
+ *dst++ = '\n';
break;
- case 't':
- *dst++ = '\t';
+ case 't':
+ *dst++ = '\t';
break;
- case 'r':
- *dst++ = '\r';
+ case 'r':
+ *dst++ = '\r';
break;
- case 'x':
+ case 'x':
++src;
if ((rc = expand_hex(&src, &dst, end)) != VAR_OK)
return VAR_RC(rc);
break;
- case '0': case '1': case '2': case '3': case '4':
- case '5': case '6': case '7': case '8': case '9':
- if ( end - src >= 3
- && isdigit((int)src[1])
+ case '0': case '1': case '2': case '3': case '4':
+ case '5': case '6': case '7': case '8': case '9':
+ if ( end - src >= 3
+ && isdigit((int)src[1])
&& isdigit((int)src[2])) {
if ((rc = expand_octal(&src, &dst, end)) != 0)
return VAR_RC(rc);
}
default:
if (!all) {
- *dst++ = '\\';
+ *dst++ = '\\';
}
*dst++ = *src;
}
}
/* perform expand operation on a buffer */
-var_rc_t
+var_rc_t
var_expand(
- var_t *var,
- const char *src_ptr, int src_len,
- char **dst_ptr, int *dst_len,
+ var_t *var,
+ const char *src_ptr, int src_len,
+ char **dst_ptr, int *dst_len,
int force_expand)
{
var_parse_t ctx;
/* post-processing */
if (rc >= 0) {
- /* always EOS-terminate output for convinience reasons
+ /* always EOS-terminate output for convinience reasons
but do not count the EOS-terminator in the length */
- if (!tokenbuf_append(&output, "\0", 1)) {
+ if (!tokenbuf_append(&output, "\0", 1)) {
tokenbuf_free(&output);
return VAR_RC(VAR_ERR_OUT_OF_MEMORY);
}
}
/* format and expand a string */
-var_rc_t
+var_rc_t
var_formatv(
- var_t *var,
- char **dst_ptr, int force_expand,
+ var_t *var,
+ char **dst_ptr, int force_expand,
const char *fmt, va_list ap)
{
var_rc_t rc;
}
/* format and expand a string */
-var_rc_t
+var_rc_t
var_format(
- var_t *var,
- char **dst_ptr, int force_expand,
+ var_t *var,
+ char **dst_ptr, int force_expand,
const char *fmt, ...)
{
var_rc_t rc;
const char *str;
rc = (var_rc_t)(0 - rc);
if (rc < 0 || rc >= (int)sizeof(var_errors) / (int)sizeof(char *)) {
- str = "unknown error";
+ str = "unknown error";
} else {
str = (char *)var_errors[rc];
}
var_rc_t var_expand (var_t *var, const char *src_ptr, int src_len, char **dst_ptr, int *dst_len, int force_expand);
var_rc_t var_formatv (var_t *var, char **dst_ptr, int force_expand, const char *fmt, va_list ap);
var_rc_t var_format (var_t *var, char **dst_ptr, int force_expand, const char *fmt, ...);
-const char *var_strerror (var_t *var, var_rc_t rc);
+const char *var_strerror (var_t *var, var_rc_t rc);
#endif /* __VAR_H__ */
*/
-#ifndef __WAITQ_H
+#ifndef __WAITQ_H
#define __WAITQ_H 1
-/*
+/*
* Structure to keep track of wait queue request
*/
typedef struct waitq_ele_tag {
void *msg; /* message to be passed */
} waitq_ele_t;
-/*
+/*
* Structure describing a wait queue
*/
typedef struct workq_tag {
static dlist *wd_queue;
static dlist *wd_inactive;
-/*
+/*
* Start watchdog thread
*
* Returns: 0 on success
watchdog_time = time(NULL);
if ((errstat=rwl_init(&lock)) != 0) {
- Emsg1(M_ABORT, 0, _("Unable to initialize watchdog lock. ERR=%s\n"),
+ Emsg1(M_ABORT, 0, _("Unable to initialize watchdog lock. ERR=%s\n"),
strerror(errstat));
}
wd_queue = New(dlist(dummy, &dummy->link));
int stop_watchdog(void)
{
int stat;
- watchdog_t *p;
+ watchdog_t *p;
if (!wd_is_init) {
return 0;
wd->next_fire = watchdog_time + wd->interval;
wd_queue->append(wd);
Dmsg3(400, "Registered watchdog %p, interval %d%s\n",
- wd, wd->interval, wd->one_shot ? " one shot" : "");
+ wd, wd->interval, wd->one_shot ? " one shot" : "");
wd_unlock();
ping_watchdog();
foreach_dlist(p, wd_queue) {
if (wd == p) {
wd_queue->remove(wd);
- Dmsg1(400, "Unregistered watchdog %p\n", wd);
+ Dmsg1(400, "Unregistered watchdog %p\n", wd);
ok = true;
goto get_out;
}
foreach_dlist(p, wd_inactive) {
if (wd == p) {
wd_inactive->remove(wd);
- Dmsg1(400, "Unregistered inactive watchdog %p\n", wd);
+ Dmsg1(400, "Unregistered inactive watchdog %p\n", wd);
ok = true;
goto get_out;
}
Dmsg0(400, "NicB-reworked watchdog thread entered\n");
while (!quit) {
- watchdog_t *p;
+ watchdog_t *p;
- /*
+ /*
* We lock the jcr chain here because a good number of the
* callback routines lock the jcr chain. We need to lock
* it here *before* the watchdog lock because the SD message
/* Run the callback */
p->callback(p);
- /* Reschedule (or move to inactive list if it's a one-shot timer) */
+ /* Reschedule (or move to inactive list if it's a one-shot timer) */
if (p->one_shot) {
wd_queue->remove(p);
wd_inactive->append(p);
} else {
p->next_fire = watchdog_time + p->interval;
}
- }
+ }
if (p->next_fire < next_time) {
next_time = p->next_fire;
}
wd_unlock();
unlock_jcr_chain();
- /*
- * Wait sleep time or until someone wakes us
+ /*
+ * Wait sleep time or until someone wakes us
*/
gettimeofday(&tv, &tz);
timeout.tv_nsec = tv.tv_usec * 1000;
Emsg1(M_ABORT, 0, "rwl_writelock failure. ERR=%s\n",
strerror(errstat));
}
-}
+}
/*
* Unlock the watchdog. This can be called multiple times by the
Emsg1(M_ABORT, 0, "rwl_writeunlock failure. ERR=%s\n",
strerror(errstat));
}
-}
+}
/*
* Watchdog timer routines
- *
+ *
* Kern Sibbald, December MMII
*
*/
enum {
TYPE_CHILD = 1,
- TYPE_PTHREAD,
- TYPE_BSOCK
+ TYPE_PTHREAD,
+ TYPE_BSOCK
};
#define TIMEOUT_SIGNAL SIGUSR2
struct s_watchdog_t {
- bool one_shot;
- time_t interval;
- void (*callback)(struct s_watchdog_t *wd);
- void (*destructor)(struct s_watchdog_t *wd);
- void *data;
- /* Private data below - don't touch outside of watchdog.c */
- dlink link;
- time_t next_fire;
+ bool one_shot;
+ time_t interval;
+ void (*callback)(struct s_watchdog_t *wd);
+ void (*destructor)(struct s_watchdog_t *wd);
+ void *data;
+ /* Private data below - don't touch outside of watchdog.c */
+ dlink link;
+ time_t next_fire;
};
typedef struct s_watchdog_t watchdog_t;
/* Forward referenced functions */
extern "C" void *workq_server(void *arg);
-/*
+/*
* Initialize a work queue
*
* Returns: 0 on success
int workq_init(workq_t *wq, int threads, void *(*engine)(void *arg))
{
int stat;
-
+
if ((stat = pthread_attr_init(&wq->attr)) != 0) {
return stat;
}
wq->num_workers = 0; /* no threads yet */
wq->idle_workers = 0; /* no idle threads */
wq->engine = engine; /* routine to run */
- wq->valid = WORKQ_VALID;
+ wq->valid = WORKQ_VALID;
return 0;
}
}
wq->valid = 0; /* prevent any more operations */
- /*
- * If any threads are active, wake them
+ /*
+ * If any threads are active, wake them
*/
if (wq->num_workers > 0) {
wq->quit = 1;
/*
* Add work to a queue
* wq is a queue that was created with workq_init
- * element is a user unique item that will be passed to the
+ * element is a user unique item that will be passed to the
* processing routine
* work_item will get internal work queue item -- if it is not NULL
* priority if non-zero will cause the item to be placed on the
int stat;
workq_ele_t *item;
pthread_t id;
-
+
Dmsg0(400, "workq_add\n");
if (wq->valid != WORKQ_VALID) {
return EINVAL;
int stat, found = 0;
pthread_t id;
workq_ele_t *item, *prev;
-
+
Dmsg0(400, "workq_remove\n");
if (wq->valid != WORKQ_VALID) {
return EINVAL;
if (!found) {
return EINVAL;
}
-
+
/* Move item to be first on list */
if (wq->first != work_item) {
- prev->next = work_item->next;
+ prev->next = work_item->next;
if (wq->last == work_item) {
wq->last = prev;
}
}
-/*
+/*
* This is the worker thread that serves the work queue.
* In due course, it will call the user's engine.
*/
/*
* Wait 2 seconds, then if no more work, exit
*/
- Dmsg0(400, "pthread_cond_timedwait()\n");
+ Dmsg0(400, "pthread_cond_timedwait()\n");
#ifdef xxxxxxxxxxxxxxxx_was_HAVE_CYGWIN
/* CYGWIN dies with a page fault the second
* time that pthread_cond_timedwait() is called
#else
stat = pthread_cond_timedwait(&wq->work, &wq->mutex, &timeout);
#endif
- Dmsg1(400, "timedwait=%d\n", stat);
+ Dmsg1(400, "timedwait=%d\n", stat);
if (stat == ETIMEDOUT) {
timedout = 1;
break;
} else if (stat != 0) {
- /* This shouldn't happen */
- Dmsg0(400, "This shouldn't happen\n");
+ /* This shouldn't happen */
+ Dmsg0(400, "This shouldn't happen\n");
wq->num_workers--;
pthread_mutex_unlock(&wq->mutex);
return NULL;
}
- }
+ }
we = wq->first;
if (we != NULL) {
wq->first = we->next;
if ((stat = pthread_mutex_unlock(&wq->mutex)) != 0) {
return NULL;
}
- /* Call user's routine here */
- Dmsg0(400, "Calling user engine.\n");
+ /* Call user's routine here */
+ Dmsg0(400, "Calling user engine.\n");
wq->engine(we->data);
- Dmsg0(400, "Back from user engine.\n");
+ Dmsg0(400, "Back from user engine.\n");
free(we); /* release work entry */
- Dmsg0(400, "relock mutex\n");
+ Dmsg0(400, "relock mutex\n");
if ((stat = pthread_mutex_lock(&wq->mutex)) != 0) {
return NULL;
}
- Dmsg0(400, "Done lock mutex\n");
+ Dmsg0(400, "Done lock mutex\n");
}
/*
* If no more work request, and we are asked to quit, then do it
if (wq->first == NULL && wq->quit) {
wq->num_workers--;
if (wq->num_workers == 0) {
- Dmsg0(400, "Wake up destroy routine\n");
+ Dmsg0(400, "Wake up destroy routine\n");
/* Wake up destroy routine if he is waiting */
pthread_cond_broadcast(&wq->work);
}
- Dmsg0(400, "Unlock mutex\n");
+ Dmsg0(400, "Unlock mutex\n");
pthread_mutex_unlock(&wq->mutex);
- Dmsg0(400, "Return from workq_server\n");
+ Dmsg0(400, "Return from workq_server\n");
return NULL;
}
Dmsg0(400, "Check for work request\n");
- /*
+ /*
* If no more work requests, and we waited long enough, quit
*/
Dmsg1(400, "wq->first==NULL = %d\n", wq->first==NULL);
Dmsg1(400, "timedout=%d\n", timedout);
if (wq->first == NULL && timedout) {
- Dmsg0(400, "break big loop\n");
+ Dmsg0(400, "break big loop\n");
wq->num_workers--;
break;
}
*/
-#ifndef __WORKQ_H
+#ifndef __WORKQ_H
#define __WORKQ_H 1
-/*
+/*
* Structure to keep track of work queue request
*/
typedef struct workq_ele_tag {
void *data;
} workq_ele_t;
-/*
+/*
* Structure describing a work queue
*/
typedef struct workq_tag {
#define WORKQ_VALID 0xdec1992
extern int workq_init(
- workq_t *wq,
- int threads, /* maximum threads */
- void *(*engine)(void *) /* engine routine */
- );
+ workq_t *wq,
+ int threads, /* maximum threads */
+ void *(*engine)(void *) /* engine routine */
+ );
extern int workq_destroy(workq_t *wq);
extern int workq_add(workq_t *wq, void *element, workq_ele_t **work_item, int priority);
extern int workq_remove(workq_t *wq, workq_ele_t *work_item);
* Routines to acquire and release a device for read/write
*
* Kern Sibbald, August MMII
- *
+ *
* Version $Id$
*/
/*
}
-/*********************************************************************
+/*********************************************************************
* Acquire device for reading. We permit (for the moment)
* only one reader. We read the Volume label from the block and
* leave the block pointers just after the label.
int i;
DCR *dcr = jcr->dcr;
DEVICE *dev;
-
+
/* Called for each volume */
if (!dcr) {
dcr = new_dcr(jcr, jcr->device->dev);
init_dev_wait_timers(dev);
if (dev_state(dev, ST_READ) || dev->num_writers > 0) {
- Jmsg2(jcr, M_FATAL, 0, _("Device %s is busy. Job %d canceled.\n"),
+ Jmsg2(jcr, M_FATAL, 0, _("Device %s is busy. Job %d canceled.\n"),
dev_name(dev), jcr->JobId);
goto get_out;
}
- tape_previously_mounted = dev_state(dev, ST_READ) ||
+ tape_previously_mounted = dev_state(dev, ST_READ) ||
dev_state(dev, ST_APPEND) ||
dev_state(dev, ST_LABEL);
tape_initially_mounted = tape_previously_mounted;
for (i=0; i<5; i++) {
dcr->dev->state &= ~ST_LABEL; /* force reread of label */
if (job_canceled(jcr)) {
- Mmsg1(dev->errmsg, _("Job %d canceled.\n"), jcr->JobId);
+ Mmsg1(dev->errmsg, _("Job %d canceled.\n"), jcr->JobId);
goto get_out; /* error return */
}
/*
* This code ensures that the device is ready for
* reading. If it is a file, it opens it.
- * If it is a tape, it checks the volume name
+ * If it is a tape, it checks the volume name
*/
for ( ; !(dev->state & ST_OPENED); ) {
- Dmsg1(120, "bstored: open vol=%s\n", dcr->VolumeName);
+ Dmsg1(120, "bstored: open vol=%s\n", dcr->VolumeName);
if (open_dev(dev, dcr->VolumeName, OPEN_READ_ONLY) < 0) {
if (dev->dev_errno == EIO) { /* no tape loaded */
goto default_path;
}
- Jmsg(jcr, M_FATAL, 0, _("Open device %s volume %s failed, ERR=%s\n"),
+ Jmsg(jcr, M_FATAL, 0, _("Open device %s volume %s failed, ERR=%s\n"),
dev_name(dev), dcr->VolumeName, strerror_dev(dev));
goto get_out;
}
- Dmsg1(129, "open_dev %s OK\n", dev_name(dev));
+ Dmsg1(129, "open_dev %s OK\n", dev_name(dev));
}
/****FIXME***** do not reread label if ioctl() says we are
* correctly possitioned. Possibly have way user can turn
* error messages when nothing is mounted.
*/
if (tape_previously_mounted) {
- Jmsg(jcr, M_WARNING, 0, "%s", jcr->errmsg);
+ Jmsg(jcr, M_WARNING, 0, "%s", jcr->errmsg);
}
goto default_path;
case VOL_NAME_ERROR:
}
/* Fall through */
default:
- Jmsg(jcr, M_WARNING, 0, "%s", jcr->errmsg);
+ Jmsg(jcr, M_WARNING, 0, "%s", jcr->errmsg);
default_path:
tape_previously_mounted = true;
- Dmsg0(200, "dir_get_volume_info\n");
- if (!dir_get_volume_info(dcr, GET_VOL_INFO_FOR_READ)) {
- Jmsg1(jcr, M_WARNING, 0, "%s", jcr->errmsg);
+ Dmsg0(200, "dir_get_volume_info\n");
+ if (!dir_get_volume_info(dcr, GET_VOL_INFO_FOR_READ)) {
+ Jmsg1(jcr, M_WARNING, 0, "%s", jcr->errmsg);
}
/* Call autochanger only once unless ask_sysop called */
if (try_autochanger) {
int stat;
- Dmsg2(200, "calling autoload Vol=%s Slot=%d\n",
- dcr->VolumeName, dcr->VolCatInfo.Slot);
+ Dmsg2(200, "calling autoload Vol=%s Slot=%d\n",
+ dcr->VolumeName, dcr->VolCatInfo.Slot);
stat = autoload_device(dcr, 0, NULL);
if (stat > 0) {
try_autochanger = false;
}
}
/* Mount a specific volume and no other */
- Dmsg0(200, "calling dir_ask_sysop\n");
+ Dmsg0(200, "calling dir_ask_sysop\n");
if (!dir_ask_sysop_to_mount_volume(dcr)) {
goto get_out; /* error return */
}
dcr->VolumeName, dev_name(dev));
get_out:
- P(dev->mutex);
+ P(dev->mutex);
unblock_device(dev);
V(dev->mutex);
if (!vol_ok) {
* Returns: NULL if failed for any reason
* dev if successful (may change if new dev opened)
* This routine must be single threaded because we may create
- * multiple devices (for files), thus we have our own mutex
+ * multiple devices (for files), thus we have our own mutex
* on top of the device mutex.
*/
DCR *acquire_device_for_append(JCR *jcr)
unlock_device(dev);
P(mutex); /* lock all devices */
Dmsg1(190, "acquire_append device is %s\n", dev_is_tape(dev)?"tape":"disk");
-
+
if (dev_state(dev, ST_APPEND)) {
Dmsg0(190, "device already in append.\n");
- /*
- * Device already in append mode
+ /*
+ * Device already in append mode
*
- * Check if we have the right Volume mounted
+ * Check if we have the right Volume mounted
* OK if current volume info OK
* OK if next volume matches current volume
* otherwise mount desired volume obtained from
if (!dir_get_volume_info(dcr, GET_VOL_INFO_FOR_WRITE) &&
!(dir_find_next_appendable_volume(dcr) &&
strcmp(dev->VolHdr.VolName, dcr->VolumeName) == 0)) { /* wrong tape mounted */
- Dmsg0(190, "Wrong tape mounted.\n");
+ Dmsg0(190, "Wrong tape mounted.\n");
if (dev->num_writers != 0) {
DEVICE *d = ((DEVRES *)dev->device)->dev;
uint32_t open_vols = 0;
d->next = dev->next;
dev->next = d;
/* Release old device */
- P(dev->mutex);
+ P(dev->mutex);
unblock_device(dev);
V(dev->mutex);
free_dcr(dcr); /* release dcr pointing to old dev */
block_device(dev, BST_DOING_ACQUIRE);
unlock_device(dev);
} else {
- Jmsg(jcr, M_FATAL, 0, _("Device %s is busy writing on another Volume.\n"), dev_name(dev));
+ Jmsg(jcr, M_FATAL, 0, _("Device %s is busy writing on another Volume.\n"), dev_name(dev));
goto get_out;
}
}
/* Wrong tape mounted, release it, then fall through to get correct one */
- Dmsg0(190, "Wrong tape mounted, release and try mount.\n");
+ Dmsg0(190, "Wrong tape mounted, release and try mount.\n");
release = true;
do_mount = true;
} else {
- /*
- * At this point, the correct tape is already mounted, so
+ /*
+ * At this point, the correct tape is already mounted, so
* we do not need to do mount_next_write_volume(), unless
* we need to recycle the tape.
*/
- recycle = strcmp(dcr->VolCatInfo.VolCatStatus, "Recycle") == 0;
- Dmsg1(190, "Correct tape mounted. recycle=%d\n", recycle);
+ recycle = strcmp(dcr->VolCatInfo.VolCatStatus, "Recycle") == 0;
+ Dmsg1(190, "Correct tape mounted. recycle=%d\n", recycle);
if (recycle && dev->num_writers != 0) {
- Jmsg(jcr, M_FATAL, 0, _("Cannot recycle volume \"%s\""
- " because it is in use by another job.\n"));
+ Jmsg(jcr, M_FATAL, 0, _("Cannot recycle volume \"%s\""
+ " because it is in use by another job.\n"));
goto get_out;
}
if (dev->num_writers == 0) {
memcpy(&dev->VolCatInfo, &dcr->VolCatInfo, sizeof(dev->VolCatInfo));
}
}
- } else {
+ } else {
/* Not already in append mode, so mount the device */
Dmsg0(190, "Not in append mode, try mount.\n");
if (dev_state(dev, ST_READ)) {
- Jmsg(jcr, M_FATAL, 0, _("Device %s is busy reading.\n"), dev_name(dev));
+ Jmsg(jcr, M_FATAL, 0, _("Device %s is busy reading.\n"), dev_name(dev));
goto get_out;
- }
+ }
ASSERT(dev->num_writers == 0);
do_mount = true;
}
P(mutex); /* re-lock */
if (!mounted) {
if (!job_canceled(jcr)) {
- /* Reduce "noise" -- don't print if job canceled */
- Jmsg(jcr, M_FATAL, 0, _("Could not ready device \"%s\" for append.\n"),
+ /* Reduce "noise" -- don't print if job canceled */
+ Jmsg(jcr, M_FATAL, 0, _("Could not ready device \"%s\" for append.\n"),
dev_name(dev));
}
goto get_out;
free_dcr(dcr);
dcr = NULL;
ok_out:
- P(dev->mutex);
+ P(dev->mutex);
unblock_device(dev);
V(dev->mutex);
V(mutex); /* unlock other threads */
bool release_device(JCR *jcr)
{
DCR *dcr = jcr->dcr;
- DEVICE *dev = dcr->dev;
+ DEVICE *dev = dcr->dev;
lock_device(dev);
Dmsg1(100, "release_device device is %s\n", dev_is_tape(dev)?"tape":"disk");
if (dev_state(dev, ST_READ)) {
dev->num_writers--;
Dmsg1(100, "There are %d writers in release_device\n", dev->num_writers);
if (dev_state(dev, ST_LABEL)) {
- Dmsg0(100, "dir_create_jobmedia_record. Release\n");
+ Dmsg0(100, "dir_create_jobmedia_record. Release\n");
if (!dir_create_jobmedia_record(dcr)) {
- Jmsg(jcr, M_FATAL, 0, _("Could not create JobMedia record for Volume=\"%s\" Job=%s\n"),
+ Jmsg(jcr, M_FATAL, 0, _("Could not create JobMedia record for Volume=\"%s\" Job=%s\n"),
dcr->VolCatInfo.VolCatName, jcr->Job);
}
/* If no more writers, write an EOF */
dev->VolCatInfo.VolCatFiles = dev->file; /* set number of files */
dev->VolCatInfo.VolCatJobs++; /* increment number of jobs */
/* Note! do volume update before close, which zaps VolCatInfo */
- Dmsg0(100, "dir_update_vol_info. Release0\n");
+ Dmsg0(100, "dir_update_vol_info. Release0\n");
dir_update_volume_info(dcr, false); /* send Volume info to Director */
}
close_dev(dev);
}
} else {
- Jmsg2(jcr, M_FATAL, 0, _("BAD ERROR: release_device %s, Volume \"%s\" not in use.\n"),
+ Jmsg2(jcr, M_FATAL, 0, _("BAD ERROR: release_device %s, Volume \"%s\" not in use.\n"),
dev_name(dev), NPRT(dcr->VolumeName));
Jmsg2(jcr, M_ERROR, 0, _("num_writers=%d state=%x\n"), dev->num_writers, dev->state);
}
bpipe = open_bpipe(alert, 0, "r");
if (bpipe) {
while (fgets(line, sizeof(line), bpipe->rfd)) {
- Jmsg(jcr, M_ALERT, 0, _("Alert: %s"), line);
+ Jmsg(jcr, M_ALERT, 0, _("Alert: %s"), line);
}
status = close_bpipe(bpipe);
} else {
}
if (status != 0) {
berrno be;
- Jmsg(jcr, M_ALERT, 0, _("3997 Bad alert command: %s: ERR=%s.\n"),
+ Jmsg(jcr, M_ALERT, 0, _("3997 Bad alert command: %s: ERR=%s.\n"),
alert, be.strerror(status));
}
/* Forward referenced functions */
-/*
- * Append Data sent from File daemon
+/*
+ * Append Data sent from File daemon
*
*/
-bool do_append_data(JCR *jcr)
+bool do_append_data(JCR *jcr)
{
int32_t n;
int32_t file_index, stream, last_file_index;
DEVICE *dev;
DEV_RECORD rec;
DCR *dcr;
-
+
Dmsg0(10, "Start append data.\n");
ds = fd_sock;
return false;
}
- /*
+ /*
* Acquire output device for writing. Note, after acquiring a
* device, we MUST release it, which is done at the end of this
* subroutine.
ok = false;
}
- /*
+ /*
* Get Data from File daemon, write to device. To clarify what is
- * going on here. We expect:
+ * going on here. We expect:
* - A stream header
* - Multiple records of data
* - EOD record
* none of the stream header is written to tape.
* The Multiple records of data, contain first the Attributes,
* then after another stream header, the file data, then
- * after another stream header, the MD5 data if any.
+ * after another stream header, the MD5 data if any.
*
* So we get the (stream header, data, EOD) three time for each
- * file. 1. for the Attributes, 2. for the file data if any,
+ * file. 1. for the Attributes, 2. for the file data if any,
* and 3. for the MD5 if any.
*/
dcr->VolFirstIndex = dcr->VolLastIndex = 0;
if (n == BNET_SIGNAL && ds->msglen == BNET_EOD) {
break; /* end of data */
}
- Jmsg1(jcr, M_FATAL, 0, _("Error reading data header from FD. ERR=%s\n"),
+ Jmsg1(jcr, M_FATAL, 0, _("Error reading data header from FD. ERR=%s\n"),
bnet_strerror(ds));
ok = false;
break;
}
-
- /*
+
+ /*
* This hand scanning is a bit more complicated than a simple
* sscanf, but it allows us to handle any size integer up to
- * int64_t without worrying about whether %d, %ld, %lld, or %q
+ * int64_t without worrying about whether %d, %ld, %lld, or %q
* is the correct format for each different architecture.
* It is a real pity that sscanf() is not portable.
*/
p++;
}
if (!B_ISSPACE(*p) || !B_ISDIGIT(*(p+1))) {
- Jmsg1(jcr, M_FATAL, 0, _("Malformed data header from FD: %s\n"), ds->msg);
+ Jmsg1(jcr, M_FATAL, 0, _("Malformed data header from FD: %s\n"), ds->msg);
ok = false;
break;
}
if (!(file_index > 0 && (file_index == last_file_index ||
file_index == last_file_index + 1))) {
- Jmsg0(jcr, M_FATAL, 0, _("File index from FD not positive or sequential\n"));
+ Jmsg0(jcr, M_FATAL, 0, _("File index from FD not positive or sequential\n"));
ok = false;
break;
}
jcr->JobFiles = file_index;
last_file_index = file_index;
}
-
+
/* Read data stream from the File daemon.
* The data stream is just raw bytes
*/
rec.data_len = ds->msglen;
rec.data = ds->msg; /* use message buffer */
- Dmsg4(850, "before writ_rec FI=%d SessId=%d Strm=%s len=%d\n",
- rec.FileIndex, rec.VolSessionId, stream_to_ascii(rec.Stream,rec.FileIndex),
+ Dmsg4(850, "before writ_rec FI=%d SessId=%d Strm=%s len=%d\n",
+ rec.FileIndex, rec.VolSessionId, stream_to_ascii(rec.Stream,rec.FileIndex),
rec.data_len);
-
+
while (!write_record_to_block(dcr->block, &rec)) {
- Dmsg2(850, "!write_record_to_block data_len=%d rem=%d\n", rec.data_len,
+ Dmsg2(850, "!write_record_to_block data_len=%d rem=%d\n", rec.data_len,
rec.remainder);
if (!write_block_to_device(dcr)) {
- Dmsg2(90, "Got write_block_to_dev error on device %s. %s\n",
+ Dmsg2(90, "Got write_block_to_dev error on device %s. %s\n",
dev_name(dev), strerror_dev(dev));
- Jmsg(jcr, M_FATAL, 0, _("Fatal device error: ERR=%s\n"),
+ Jmsg(jcr, M_FATAL, 0, _("Fatal device error: ERR=%s\n"),
strerror_dev(dev));
ok = false;
break;
}
}
if (!ok) {
- Dmsg0(400, "Not OK\n");
+ Dmsg0(400, "Not OK\n");
break;
}
jcr->JobBytes += rec.data_len; /* increment bytes this job */
- Dmsg4(850, "write_record FI=%s SessId=%d Strm=%s len=%d\n",
- FI_to_ascii(rec.FileIndex), rec.VolSessionId,
+ Dmsg4(850, "write_record FI=%s SessId=%d Strm=%s len=%d\n",
+ FI_to_ascii(rec.FileIndex), rec.VolSessionId,
stream_to_ascii(rec.Stream, rec.FileIndex), rec.data_len);
/* Send attributes and MD5 to Director for Catalog */
if (stream == STREAM_UNIX_ATTRIBUTES || stream == STREAM_MD5_SIGNATURE ||
- stream == STREAM_UNIX_ATTRIBUTES_EX || stream == STREAM_SHA1_SIGNATURE) {
+ stream == STREAM_UNIX_ATTRIBUTES_EX || stream == STREAM_SHA1_SIGNATURE) {
if (!jcr->no_attributes) {
if (are_attributes_spooled(jcr)) {
jcr->dir_bsock->spool = true;
}
- Dmsg0(850, "Send attributes to dir.\n");
+ Dmsg0(850, "Send attributes to dir.\n");
if (!dir_update_file_attributes(dcr, &rec)) {
jcr->dir_bsock->spool = false;
- Jmsg(jcr, M_FATAL, 0, _("Error updating file attributes. ERR=%s\n"),
+ Jmsg(jcr, M_FATAL, 0, _("Error updating file attributes. ERR=%s\n"),
bnet_strerror(jcr->dir_bsock));
ok = false;
break;
jcr->dir_bsock->spool = false;
}
}
- Dmsg0(350, "Enter bnet_get\n");
+ Dmsg0(350, "Enter bnet_get\n");
}
Dmsg1(350, "End read loop with FD. Stat=%d\n", n);
if (is_bnet_error(ds)) {
- Dmsg1(350, "Network read error from FD. ERR=%s\n", bnet_strerror(ds));
- Jmsg1(jcr, M_FATAL, 0, _("Network error on data channel. ERR=%s\n"),
+ Dmsg1(350, "Network read error from FD. ERR=%s\n", bnet_strerror(ds));
+ Jmsg1(jcr, M_FATAL, 0, _("Network error on data channel. ERR=%s\n"),
bnet_strerror(ds));
ok = false;
break;
*/
if (ok || dev_can_write(dev)) {
if (!write_session_label(dcr, EOS_LABEL)) {
- Jmsg1(jcr, M_FATAL, 0, _("Error writting end session label. ERR=%s\n"),
+ Jmsg1(jcr, M_FATAL, 0, _("Error writting end session label. ERR=%s\n"),
strerror_dev(dev));
set_jcr_job_status(jcr, JS_ErrorTerminated);
ok = false;
}
if (dev->VolCatInfo.VolCatName[0] == 0) {
- Dmsg0(000, "NULL Volume name. This shouldn't happen!!!\n");
+ Dmsg0(000, "NULL Volume name. This shouldn't happen!!!\n");
}
Dmsg0(90, "back from write_end_session_label()\n");
/* Flush out final partial block of this session */
if (!write_block_to_device(dcr)) {
- Dmsg0(100, _("Set ok=FALSE after write_block_to_device.\n"));
+ Dmsg0(100, _("Set ok=FALSE after write_block_to_device.\n"));
set_jcr_job_status(jcr, JS_ErrorTerminated);
ok = false;
}
" VolJobs=%u VolFiles=%u VolBlocks=%u VolBytes=%s VolMounts=%u"
" VolErrors=%u VolWrites=%u MaxVolBytes=%s EndTime=%d VolStatus=%s"
" Slot=%d relabel=%d InChanger=%d VolReadTime=%s VolWriteTime=%s\n";
-static char Create_job_media[] = "CatReq Job=%s CreateJobMedia"
- " FirstIndex=%u LastIndex=%u StartFile=%u EndFile=%u"
+static char Create_job_media[] = "CatReq Job=%s CreateJobMedia"
+ " FirstIndex=%u LastIndex=%u StartFile=%u EndFile=%u"
" StartBlock=%u EndBlock=%u\n";
static char FileAttributes[] = "UpdCat Job=%s FileAttributes ";
static char Job_status[] = "3012 Job %s jobstatus %d\n";
* dir_get_volume_info()
* and
* dir_find_next_appendable_volume()
- *
+ *
* Returns: true on success and vol info in dcr->VolCatInfo
* false on failure
*/
}
memset(&vol, 0, sizeof(vol));
Dmsg1(300, "Get vol info=%s", dir->msg);
- n = sscanf(dir->msg, OK_media, vol.VolCatName,
+ n = sscanf(dir->msg, OK_media, vol.VolCatName,
&vol.VolCatJobs, &vol.VolCatFiles,
&vol.VolCatBlocks, &vol.VolCatBytes,
&vol.VolCatMounts, &vol.VolCatErrors,
unbash_spaces(vol.VolCatName);
bstrncpy(dcr->VolumeName, vol.VolCatName, sizeof(dcr->VolumeName));
memcpy(&dcr->VolCatInfo, &vol, sizeof(dcr->VolCatInfo));
-
- Dmsg2(300, "do_reqest_vol_info got slot=%d Volume=%s\n",
+
+ Dmsg2(300, "do_reqest_vol_info got slot=%d Volume=%s\n",
vol.Slot, vol.VolCatName);
return true;
}
bstrncpy(dcr->VolCatInfo.VolCatName, dcr->VolumeName, sizeof(dcr->VolCatInfo.VolCatName));
Dmsg1(300, "dir_get_volume_info=%s\n", dcr->VolCatInfo.VolCatName);
bash_spaces(dcr->VolCatInfo.VolCatName);
- bnet_fsend(dir, Get_Vol_Info, jcr->Job, dcr->VolCatInfo.VolCatName,
+ bnet_fsend(dir, Get_Vol_Info, jcr->Job, dcr->VolCatInfo.VolCatName,
writing==GET_VOL_INFO_FOR_WRITE?1:0);
return do_get_volume_info(dcr);
}
for (int vol_index=1; vol_index < 3; vol_index++) {
bnet_fsend(dir, Find_media, jcr->Job, vol_index);
if (do_get_volume_info(dcr)) {
- Dmsg2(300, "JobId=%d got possible Vol=%s\n", jcr->JobId, dcr->VolumeName);
+ Dmsg2(300, "JobId=%d got possible Vol=%s\n", jcr->JobId, dcr->VolumeName);
bool found = false;
- /*
- * Walk through all jobs and see if the volume is
+ /*
+ * Walk through all jobs and see if the volume is
* already mounted. If so, try a different one.
- * This would be better done by walking through
+ * This would be better done by walking through
* all the devices.
*/
lock_jcr_chain();
free_locked_jcr(njcr);
continue; /* us */
}
- Dmsg2(300, "Compare to JobId=%d using Vol=%s\n", njcr->JobId, njcr->dcr->VolumeName);
+ Dmsg2(300, "Compare to JobId=%d using Vol=%s\n", njcr->JobId, njcr->dcr->VolumeName);
if (njcr->dcr && strcmp(dcr->VolumeName, njcr->dcr->VolumeName) == 0) {
found = true;
- Dmsg1(400, "Vol in use by JobId=%u\n", njcr->JobId);
+ Dmsg1(400, "Vol in use by JobId=%u\n", njcr->JobId);
free_locked_jcr(njcr);
break;
}
}
unlock_jcr_chain();
if (!found) {
- Dmsg0(400, "dir_find_next_appendable_volume return true\n");
+ Dmsg0(400, "dir_find_next_appendable_volume return true\n");
return true; /* Got good Volume */
}
} else {
- Dmsg0(200, "No volume info, return false\n");
+ Dmsg0(200, "No volume info, return false\n");
return false;
}
}
Dmsg0(400, "dir_find_next_appendable_volume return true\n");
- return true;
+ return true;
}
-
+
/*
* After writing a Volume, send the updated statistics
* back to the director. The information comes from the
- * dev record.
+ * dev record.
*/
bool dir_update_volume_info(DCR *dcr, bool label)
{
}
bash_spaces(vol->VolCatName);
InChanger = vol->InChanger;
- bnet_fsend(dir, Update_media, jcr->Job,
+ bnet_fsend(dir, Update_media, jcr->Job,
vol->VolCatName, vol->VolCatJobs, vol->VolCatFiles,
vol->VolCatBlocks, edit_uint64(vol->VolCatBytes, ed1),
vol->VolCatMounts, vol->VolCatErrors,
- vol->VolCatWrites, edit_uint64(vol->VolCatMaxBytes, ed2),
+ vol->VolCatWrites, edit_uint64(vol->VolCatMaxBytes, ed2),
LastWritten, vol->VolCatStatus, vol->Slot, label,
InChanger, /* bool in structure */
- edit_uint64(vol->VolReadTime, ed3),
+ edit_uint64(vol->VolReadTime, ed3),
edit_uint64(vol->VolWriteTime, ed4) );
Dmsg1(300, "update_volume_info(): %s", dir->msg);
}
dcr->WroteVol = false;
- bnet_fsend(dir, Create_job_media, jcr->Job,
+ bnet_fsend(dir, Create_job_media, jcr->Job,
dcr->VolFirstIndex, dcr->VolLastIndex,
dcr->StartFile, dcr->EndFile,
dcr->StartBlock, dcr->EndBlock);
Dmsg1(400, "create_jobmedia(): %s", dir->msg);
if (bnet_recv(dir) <= 0) {
Dmsg0(190, "create_jobmedia error bnet_recv\n");
- Jmsg(jcr, M_FATAL, 0, _("Error creating JobMedia record: ERR=%s\n"),
+ Jmsg(jcr, M_FATAL, 0, _("Error creating JobMedia record: ERR=%s\n"),
bnet_strerror(dir));
return false;
}
}
-/*
+/*
* Update File Attribute data
*/
bool dir_update_file_attributes(DCR *dcr, DEV_RECORD *rec)
ser_declare;
dir->msglen = sprintf(dir->msg, FileAttributes, jcr->Job);
- dir->msg = check_pool_memory_size(dir->msg, dir->msglen +
+ dir->msg = check_pool_memory_size(dir->msg, dir->msglen +
sizeof(DEV_RECORD) + rec->data_len);
ser_begin(dir->msg + dir->msglen, 0);
ser_uint32(rec->VolSessionId);
for ( ;; ) {
if (job_canceled(jcr)) {
Mmsg(dev->errmsg,
- _("Job %s canceled while waiting for mount on Storage Device \"%s\".\n"),
+ _("Job %s canceled while waiting for mount on Storage Device \"%s\".\n"),
jcr->Job, dcr->dev_name);
- Jmsg(jcr, M_INFO, 0, "%s", dev->errmsg);
+ Jmsg(jcr, M_INFO, 0, "%s", dev->errmsg);
return false;
}
/* First pass, we *know* there are no appendable volumes, so no need to call */
* Slot for an autochanger, otherwise wait
* for the operator to mount the media.
*/
- if (!unmounted && ((dcr->VolumeName[0] && !dev_cap(dev, CAP_REM) &&
+ if (!unmounted && ((dcr->VolumeName[0] && !dev_cap(dev, CAP_REM) &&
dev_cap(dev, CAP_LABEL)) ||
(dcr->VolumeName[0] && dcr->VolCatInfo.Slot))) {
- Dmsg0(400, "Return 1 from mount without wait.\n");
+ Dmsg0(400, "Return 1 from mount without wait.\n");
return true;
}
jstat = JS_WaitMount;
"Please mount Volume \"%s\" on Storage Device \"%s\" for Job %s\n"
"Use \"mount\" command to release Job.\n"),
dcr->VolumeName, dcr->dev_name, jcr->Job);
- Dmsg3(400, "Mount %s on %s for Job %s\n",
+ Dmsg3(400, "Mount %s on %s for Job %s\n",
dcr->VolumeName, dcr->dev_name, jcr->Job);
}
} else {
jstat = JS_WaitMedia;
if (!dev->poll) {
Jmsg(jcr, M_MOUNT, 0, _(
-"Job %s waiting. Cannot find any appendable volumes.\n\
-Please use the \"label\" command to create a new Volume for:\n\
- Storage: %s\n\
- Media type: %s\n\
- Pool: %s\n"),
- jcr->Job,
- dcr->dev_name,
+"Job %s waiting. Cannot find any appendable volumes.\n"
+"Please use the \"label\" command to create a new Volume for:\n"
+" Storage: %s\n"
+" Media type: %s\n"
+" Pool: %s\n"),
+ jcr->Job,
+ dcr->dev_name,
dcr->media_type,
dcr->pool_name);
}
stat = wait_for_sysop(dcr);
if (dev->poll) {
- Dmsg1(400, "Poll timeout in create append vol on device %s\n", dev_name(dev));
+ Dmsg1(400, "Poll timeout in create append vol on device %s\n", dev_name(dev));
continue;
}
if (stat == ETIMEDOUT) {
if (!double_dev_wait_time(dev)) {
- Mmsg(dev->errmsg, _("Max time exceeded waiting to mount Storage Device \"%s\" for Job %s\n"),
+ Mmsg(dev->errmsg, _("Max time exceeded waiting to mount Storage Device \"%s\" for Job %s\n"),
dev_name(dev), jcr->Job);
- Jmsg(jcr, M_FATAL, 0, "%s", dev->errmsg);
- Dmsg1(400, "Gave up waiting on device %s\n", dev_name(dev));
+ Jmsg(jcr, M_FATAL, 0, "%s", dev->errmsg);
+ Dmsg1(400, "Gave up waiting on device %s\n", dev_name(dev));
return false; /* exceeded maximum waits */
}
continue;
}
if (stat == EINVAL) {
berrno be;
- Mmsg2(dev->errmsg, _("pthread error in mount_next_volume stat=%d ERR=%s\n"),
+ Mmsg2(dev->errmsg, _("pthread error in mount_next_volume stat=%d ERR=%s\n"),
stat, be.strerror(stat));
- Jmsg(jcr, M_FATAL, 0, "%s", dev->errmsg);
+ Jmsg(jcr, M_FATAL, 0, "%s", dev->errmsg);
return false;
}
if (stat != 0) {
berrno be;
- Jmsg(jcr, M_WARNING, 0, _("pthread error in mount_next_volume stat=%d ERR=%s\n"), stat,
+ Jmsg(jcr, M_WARNING, 0, _("pthread error in mount_next_volume stat=%d ERR=%s\n"), stat,
be.strerror(stat));
}
Dmsg1(400, "Someone woke me for device %s\n", dev_name(dev));
if (dcr->VolumeName[0] == 0 && !job_canceled(jcr) &&
!dir_find_next_appendable_volume(dcr)) {
Jmsg(jcr, M_MOUNT, 0, _(
-"Someone woke me up, but I cannot find any appendable\n\
-volumes for Job=%s.\n"), jcr->Job);
+"Someone woke me up, but I cannot find any appendable\n"
+"volumes for Job=%s.\n"), jcr->Job);
/* Restart wait counters after user interaction */
init_dev_wait_timers(dev);
continue;
- }
+ }
unmounted = (dev->dev_blocked == BST_UNMOUNTED) ||
(dev->dev_blocked == BST_UNMOUNTED_WAITING_FOR_SYSOP);
if (unmounted) {
}
/*
- * Device mounted, we have a volume, break and return
+ * Device mounted, we have a volume, break and return
*/
break;
}
ASSERT(dev->dev_blocked);
for ( ;; ) {
if (job_canceled(jcr)) {
- Mmsg(dev->errmsg, _("Job %s canceled while waiting for mount on Storage Device \"%s\".\n"),
+ Mmsg(dev->errmsg, _("Job %s canceled while waiting for mount on Storage Device \"%s\".\n"),
jcr->Job, dcr->dev_name);
return false;
}
if (!dev->poll) {
- msg = _("Please mount");
- Jmsg(jcr, M_MOUNT, 0, _("%s Volume \"%s\" on Storage Device \"%s\" for Job %s\n"),
+ msg = _("Please mount");
+ Jmsg(jcr, M_MOUNT, 0, _("%s Volume \"%s\" on Storage Device \"%s\" for Job %s\n"),
msg, dcr->VolumeName, dcr->dev_name, jcr->Job);
- Dmsg3(400, "Mount \"%s\" on device \"%s\" for Job %s\n",
+ Dmsg3(400, "Mount \"%s\" on device \"%s\" for Job %s\n",
dcr->VolumeName, dcr->dev_name, jcr->Job);
}
stat = wait_for_sysop(dcr); ; /* wait on device */
if (dev->poll) {
- Dmsg1(400, "Poll timeout in mount vol on device %s\n", dev_name(dev));
- Dmsg1(400, "Blocked=%s\n", edit_blocked_reason(dev));
+ Dmsg1(400, "Poll timeout in mount vol on device %s\n", dev_name(dev));
+ Dmsg1(400, "Blocked=%s\n", edit_blocked_reason(dev));
return true;
}
if (stat == ETIMEDOUT) {
if (!double_dev_wait_time(dev)) {
- Mmsg(dev->errmsg, _("Max time exceeded waiting to mount Storage Device \"%s\" for Job %s\n"),
+ Mmsg(dev->errmsg, _("Max time exceeded waiting to mount Storage Device \"%s\" for Job %s\n"),
dev_name(dev), jcr->Job);
- Jmsg(jcr, M_FATAL, 0, "%s", dev->errmsg);
- Dmsg1(400, "Gave up waiting on device %s\n", dev_name(dev));
+ Jmsg(jcr, M_FATAL, 0, "%s", dev->errmsg);
+ Dmsg1(400, "Gave up waiting on device %s\n", dev_name(dev));
return false; /* exceeded maximum waits */
}
continue;
}
if (stat == EINVAL) {
berrno be;
- Mmsg2(dev->errmsg, _("pthread error in mount_volume stat=%d ERR=%s\n"),
+ Mmsg2(dev->errmsg, _("pthread error in mount_volume stat=%d ERR=%s\n"),
stat, be.strerror(stat));
- Jmsg(jcr, M_FATAL, 0, "%s", dev->errmsg);
+ Jmsg(jcr, M_FATAL, 0, "%s", dev->errmsg);
return false;
}
if (stat != 0) {
berrno be;
- Jmsg(jcr, M_FATAL, 0, _("pthread error in mount_next_volume stat=%d ERR=%s\n"), stat,
+ Jmsg(jcr, M_FATAL, 0, _("pthread error in mount_next_volume stat=%d ERR=%s\n"), stat,
be.strerror(stat));
}
Dmsg1(400, "Someone woke me for device %s\n", dev_name(dev));
bool unmounted;
DEVICE *dev = dcr->dev;
JCR *jcr = dcr->jcr;
-
+
P(dev->mutex);
unmounted = (dev->dev_blocked == BST_UNMOUNTED) ||
(dev->dev_blocked == BST_UNMOUNTED_WAITING_FOR_SYSOP);
add_wait = me->heartbeat_interval;
}
/* If the user did not unmount the tape and we are polling, ensure
- * that we poll at the correct interval.
+ * that we poll at the correct interval.
*/
if (!unmounted && dev->vol_poll_interval && add_wait > dev->vol_poll_interval) {
add_wait = dev->vol_poll_interval;
/* send heartbeats */
if (jcr->file_bsock) {
bnet_sig(jcr->file_bsock, BNET_HEARTBEAT);
- Dmsg0(400, "Send heartbeat to FD.\n");
+ Dmsg0(400, "Send heartbeat to FD.\n");
}
if (jcr->dir_bsock) {
bnet_sig(jcr->dir_bsock, BNET_HEARTBEAT);
break; /* on error return */
}
if (dev->rem_wait_sec <= 0) { /* on exceeding wait time return */
- Dmsg0(400, "Exceed wait time.\n");
+ Dmsg0(400, "Exceed wait time.\n");
break;
}
-
- if (!unmounted && dev->vol_poll_interval &&
+
+ if (!unmounted && dev->vol_poll_interval &&
(now - first_start >= dev->vol_poll_interval)) {
- Dmsg1(400, "In wait blocked=%s\n", edit_blocked_reason(dev));
+ Dmsg1(400, "In wait blocked=%s\n", edit_blocked_reason(dev));
dev->poll = true; /* returning a poll event */
break;
}
* Kern Sibbald, October 2000
*
* Version $Id$
- *
+ *
*/
/*
Copyright (C) 2000, 2001, 2002 Kern Sibbald and John Walker
MA 02111-1307, USA.
*/
-
+
#include "bacula.h"
#include "stored.h"
static char OK_hello[] = "3000 OK Hello\n";
-/*********************************************************************
+/*********************************************************************
*
*
*/
return 0;
}
if (bs->msglen < 25 || bs->msglen > 200) {
- Dmsg2(50, _("Bad Hello command from Director at %s. Len=%d.\n"),
+ Dmsg2(50, _("Bad Hello command from Director at %s. Len=%d.\n"),
bs->who, bs->msglen);
- Emsg2(M_FATAL, 0, _("Bad Hello command from Director at %s. Len=%d.\n"),
+ Emsg2(M_FATAL, 0, _("Bad Hello command from Director at %s. Len=%d.\n"),
bs->who, bs->msglen);
return 0;
}
if (sscanf(bs->msg, "Hello Director %127s calling\n", dirname) != 1) {
bs->msg[100] = 0;
- Dmsg2(50, _("Bad Hello command from Director at %s: %s\n"),
+ Dmsg2(50, _("Bad Hello command from Director at %s: %s\n"),
bs->who, bs->msg);
- Emsg2(M_FATAL, 0, _("Bad Hello command from Director at %s: %s\n"),
+ Emsg2(M_FATAL, 0, _("Bad Hello command from Director at %s: %s\n"),
bs->who, bs->msg);
return 0;
}
}
UnlockRes();
if (!director) {
- Dmsg2(50, _("Connection from unknown Director %s at %s rejected.\n"),
+ Dmsg2(50, _("Connection from unknown Director %s at %s rejected.\n"),
dirname, bs->who);
- Emsg2(M_FATAL, 0, _("Connection from unknown Director %s at %s rejected.\n"
- "Please see http://www.bacula.org/html-manual/faq.html#AuthorizationErrors for help.\n"),
+ Emsg2(M_FATAL, 0, _("Connection from unknown Director %s at %s rejected.\n"
+ "Please see http://www.bacula.org/html-manual/faq.html#AuthorizationErrors for help.\n"),
dirname, bs->who);
free_pool_memory(dirname);
return 0;
if (auth) {
get_auth = cram_md5_get_auth(bs, director->password, ssl_need);
if (!get_auth) {
- Dmsg1(50, "cram_get_auth failed with %s\n", bs->who);
+ Dmsg1(50, "cram_get_auth failed with %s\n", bs->who);
}
} else {
Dmsg1(50, "cram_auth failed with %s\n", bs->who);
}
if (!auth || !get_auth) {
stop_bsock_timer(tid);
- Emsg0(M_FATAL, 0, _("Incorrect password given by Director.\n"
+ Emsg0(M_FATAL, 0, _("Incorrect password given by Director.\n"
"Please see http://www.bacula.org/html-manual/faq.html#AuthorizationErrors for help.\n"));
free_pool_memory(dirname);
return 0;
/*
* Inititiate the message channel with the Director.
* He has made a connection to our server.
- *
+ *
* Basic tasks done here:
* Assume the Hello message is already in the input
* buffer. We then authenticate him.
if (auth) {
get_auth = cram_md5_get_auth(fd, jcr->sd_auth_key, ssl_need);
if (!get_auth) {
- Dmsg1(50, "cram-get-auth failed with %s\n", fd->who);
+ Dmsg1(50, "cram-get-auth failed with %s\n", fd->who);
}
} else {
Dmsg1(50, "cram-auth failed with %s\n", fd->who);
* On success this routine loads the indicated tape, but the
* label is not read, so it must be verified.
*
- * Note if dir is not NULL, it is the console requesting the
+ * Note if dir is not NULL, it is the console requesting the
* autoload for labeling, so we respond directly to the
* dir bsock.
*
* Returns: 1 on success
- * 0 on failure (no changer available)
+ * 0 on failure (no changer available)
* -1 on error on autochanger
*/
int autoload_device(DCR *dcr, int writing, BSOCK *dir)
int slot;
int drive = jcr->device->drive_index;
int rtn_stat = -1; /* error status */
-
+
slot = dcr->VolCatInfo.InChanger ? dcr->VolCatInfo.Slot : 0;
/*
* Handle autoloaders here. If we cannot autoload it, we
if (slot > 0 && jcr->device->changer_name && jcr->device->changer_command) {
uint32_t timeout = jcr->device->max_changer_wait;
POOLMEM *changer;
- int loaded, status;
+ int loaded, status;
changer = get_pool_memory(PM_FNAME);
loaded = get_autochanger_loaded_slot(jcr);
/* If tape we want is not loaded, load it. */
- if (loaded != slot) {
+ if (loaded != slot) {
offline_or_rewind_dev(dev);
/* We are going to load a new tape, so close the device */
force_close_dev(dev);
if (loaded != 0 && loaded != -1) { /* must unload drive */
- Dmsg0(400, "Doing changer unload.\n");
- Jmsg(jcr, M_INFO, 0,
- _("3303 Issuing autochanger \"unload slot %d, drive %d\" command.\n"),
+ Dmsg0(400, "Doing changer unload.\n");
+ Jmsg(jcr, M_INFO, 0,
+ _("3303 Issuing autochanger \"unload slot %d, drive %d\" command.\n"),
loaded, drive);
dcr->VolCatInfo.Slot = loaded; /* slot to be unloaded */
- changer = edit_device_codes(jcr, changer,
- jcr->device->changer_command, "unload");
+ changer = edit_device_codes(jcr, changer,
+ jcr->device->changer_command, "unload");
status = run_program(changer, timeout, NULL);
if (status != 0) {
berrno be;
be.set_errno(status);
- Jmsg(jcr, M_INFO, 0, _("3992 Bad autochanger \"unload slot %d, drive %d\": ERR=%s.\n"),
+ Jmsg(jcr, M_INFO, 0, _("3992 Bad autochanger \"unload slot %d, drive %d\": ERR=%s.\n"),
slot, drive, be.strerror());
}
- Dmsg1(400, "unload status=%d\n", status);
+ Dmsg1(400, "unload status=%d\n", status);
}
/*
- * Load the desired cassette
+ * Load the desired cassette
*/
- Dmsg1(400, "Doing changer load slot %d\n", slot);
- Jmsg(jcr, M_INFO, 0,
- _("3304 Issuing autochanger \"load slot %d, drive %d\" command.\n"),
+ Dmsg1(400, "Doing changer load slot %d\n", slot);
+ Jmsg(jcr, M_INFO, 0,
+ _("3304 Issuing autochanger \"load slot %d, drive %d\" command.\n"),
slot, drive);
dcr->VolCatInfo.Slot = slot; /* slot to be loaded */
- changer = edit_device_codes(jcr, changer,
- jcr->device->changer_command, "load");
+ changer = edit_device_codes(jcr, changer,
+ jcr->device->changer_command, "load");
status = run_program(changer, timeout, NULL);
if (status == 0) {
- Jmsg(jcr, M_INFO, 0, _("3305 Autochanger \"load slot %d, drive %d\", status is OK.\n"),
+ Jmsg(jcr, M_INFO, 0, _("3305 Autochanger \"load slot %d, drive %d\", status is OK.\n"),
slot, drive);
} else {
berrno be;
be.set_errno(status);
- Jmsg(jcr, M_INFO, 0, _("3992 Bad autochanger \"load slot %d, drive %d\": ERR=%s.\n"),
+ Jmsg(jcr, M_INFO, 0, _("3992 Bad autochanger \"load slot %d, drive %d\": ERR=%s.\n"),
slot, drive, be.strerror());
}
- Dmsg2(400, "load slot %d status=%d\n", slot, status);
- } else {
+ Dmsg2(400, "load slot %d status=%d\n", slot, status);
+ } else {
status = 0; /* we got what we want */
}
free_pool_memory(changer);
/* Find out what is loaded, zero means device is unloaded */
Jmsg(jcr, M_INFO, 0, _("3301 Issuing autochanger \"loaded drive %d\" command.\n"),
drive);
- changer = edit_device_codes(jcr, changer, jcr->device->changer_command,
+ changer = edit_device_codes(jcr, changer, jcr->device->changer_command,
"loaded");
status = run_program(changer, timeout, results);
Dmsg3(50, "run_prog: %s stat=%d result=%s\n", changer, status, results);
} else {
berrno be;
be.set_errno(status);
- Jmsg(jcr, M_INFO, 0, _("3991 Bad autochanger \"loaded drive %d\" command: ERR=%s.\n"),
+ Jmsg(jcr, M_INFO, 0, _("3991 Bad autochanger \"loaded drive %d\" command: ERR=%s.\n"),
drive, be.strerror());
loaded = -1; /* force unload */
}
}
/*
- * The Volume is not in the correct slot, so mark this
+ * The Volume is not in the correct slot, so mark this
* Volume as not being in the Changer.
*/
void invalid_slot_in_catalog(DCR *dcr)
loaded = get_autochanger_loaded_slot(jcr);
if (loaded > 0) {
bnet_fsend(dir, _("3305 Issuing autochanger \"unload slot %d\" command.\n"), loaded);
- slot = dcr->VolCatInfo.Slot;
+ slot = dcr->VolCatInfo.Slot;
dcr->VolCatInfo.Slot = loaded;
changer = edit_device_codes(jcr, changer, jcr->device->changer_command, "unload");
int stat = run_program(changer, timeout, NULL);
if (stat != 0) {
berrno be;
be.set_errno(stat);
- Jmsg(jcr, M_INFO, 0, _("3995 Bad autochanger \"unload slot %d\" command: ERR=%s.\n"),
+ Jmsg(jcr, M_INFO, 0, _("3995 Bad autochanger \"unload slot %d\" command: ERR=%s.\n"),
loaded, be.strerror());
}
dcr->VolCatInfo.Slot = slot;
return false;
}
/* Get output from changer */
- while (fgets(dir->msg, len, bpipe->rfd)) {
+ while (fgets(dir->msg, len, bpipe->rfd)) {
dir->msglen = strlen(dir->msg);
bnet_send(dir);
}
* %% = %
* %a = archive device name
* %c = changer device name
- * %d = changer drive index
+ * %d = changer drive index
* %f = Client's name
* %j = Job name
* %o = command
*
* omsg = edited output message
* imsg = input string containing edit codes (%x)
- * cmd = command string (load, unload, ...)
+ * cmd = command string (load, unload, ...)
*
*/
-char *edit_device_codes(JCR *jcr, char *omsg, const char *imsg, const char *cmd)
+char *edit_device_codes(JCR *jcr, char *omsg, const char *imsg, const char *cmd)
{
const char *p;
const char *str;
for (p=imsg; *p; p++) {
if (*p == '%') {
switch (*++p) {
- case '%':
- str = "%";
+ case '%':
+ str = "%";
break;
- case 'a':
+ case 'a':
str = dev_name(jcr->device->dev);
break;
- case 'c':
+ case 'c':
str = NPRT(jcr->device->changer_name);
break;
- case 'd':
- sprintf(add, "%d", jcr->device->dev->drive_index);
+ case 'd':
+ sprintf(add, "%d", jcr->device->dev->drive_index);
str = add;
break;
- case 'o':
+ case 'o':
str = NPRT(cmd);
break;
- case 's':
- sprintf(add, "%d", jcr->dcr->VolCatInfo.Slot - 1);
+ case 's':
+ sprintf(add, "%d", jcr->dcr->VolCatInfo.Slot - 1);
str = add;
break;
- case 'S':
- sprintf(add, "%d", jcr->dcr->VolCatInfo.Slot);
+ case 'S':
+ sprintf(add, "%d", jcr->dcr->VolCatInfo.Slot);
str = add;
break;
- case 'j': /* Job name */
+ case 'j': /* Job name */
str = jcr->Job;
break;
- case 'v':
+ case 'v':
str = NPRT(jcr->dcr->VolumeName);
break;
- case 'f':
+ case 'f':
str = NPRT(jcr->client_name);
break;
default:
- add[0] = '%';
+ add[0] = '%';
add[1] = *p;
add[2] = 0;
str = add;
case 'd': /* debug level */
debug_level = atoi(optarg);
if (debug_level <= 0)
- debug_level = 1;
+ debug_level = 1;
break;
case 'i': /* input Volume name */
ignore_label_errors = true;
forge_on = true;
break;
-
+
case 'v':
verbose++;
break;
default:
usage();
- }
+ }
}
argc -= optind;
argv += optind;
}
in_jcr->ignore_label_errors = ignore_label_errors;
in_dev = in_jcr->dcr->dev;
- if (!in_dev) {
+ if (!in_dev) {
exit(1);
}
exit(1);
}
out_dev = out_jcr->dcr->dev;
- if (!out_dev) {
- exit(1);
+ if (!out_dev) {
+ exit(1);
}
/* For we must now acquire the device for writing */
lock_device(out_dev);
term_dev(out_dev);
return 0;
}
-
+
/*
* read_records() calls back here for each record it gets
{
if (list_records) {
Pmsg5(000, _("Record: SessId=%u SessTim=%u FileIndex=%d Stream=%d len=%u\n"),
- rec->VolSessionId, rec->VolSessionTime, rec->FileIndex,
+ rec->VolSessionId, rec->VolSessionTime, rec->FileIndex,
rec->Stream, rec->data_len);
}
- /*
- * Check for Start or End of Session Record
+ /*
+ * Check for Start or End of Session Record
*
*/
if (rec->FileIndex < 0) {
}
switch (rec->FileIndex) {
case PRE_LABEL:
- Pmsg0(000, "Volume is prelabeled. This volume cannot be copied.\n");
+ Pmsg0(000, "Volume is prelabeled. This volume cannot be copied.\n");
return false;
case VOL_LABEL:
- Pmsg0(000, "Volume label not copied.\n");
+ Pmsg0(000, "Volume label not copied.\n");
return true;
case SOS_LABEL:
jobs++;
break;
case EOS_LABEL:
while (!write_record_to_block(out_block, rec)) {
- Dmsg2(150, "!write_record_to_block data_len=%d rem=%d\n", rec->data_len,
+ Dmsg2(150, "!write_record_to_block data_len=%d rem=%d\n", rec->data_len,
rec->remainder);
if (!write_block_to_device(out_jcr->dcr)) {
- Dmsg2(90, "Got write_block_to_dev error on device %s. %s\n",
+ Dmsg2(90, "Got write_block_to_dev error on device %s. %s\n",
dev_name(out_dev), strerror_dev(out_dev));
- Jmsg(out_jcr, M_FATAL, 0, _("Cannot fixup device error. %s\n"),
+ Jmsg(out_jcr, M_FATAL, 0, _("Cannot fixup device error. %s\n"),
strerror_dev(out_dev));
}
}
if (!write_block_to_device(out_jcr->dcr)) {
- Dmsg2(90, "Got write_block_to_dev error on device %s. %s\n",
+ Dmsg2(90, "Got write_block_to_dev error on device %s. %s\n",
dev_name(out_dev), strerror_dev(out_dev));
- Jmsg(out_jcr, M_FATAL, 0, _("Cannot fixup device error. %s\n"),
+ Jmsg(out_jcr, M_FATAL, 0, _("Cannot fixup device error. %s\n"),
strerror_dev(out_dev));
}
break;
case EOM_LABEL:
- Pmsg0(000, "EOM label not copied.\n");
+ Pmsg0(000, "EOM label not copied.\n");
return true;
case EOT_LABEL: /* end of all tapes */
- Pmsg0(000, "EOT label not copied.\n");
+ Pmsg0(000, "EOT label not copied.\n");
return true;
default:
break;
Dmsg2(150, "!write_record_to_block data_len=%d rem=%d\n", rec->data_len,
rec->remainder);
if (!write_block_to_device(out_jcr->dcr)) {
- Dmsg2(90, "Got write_block_to_dev error on device %s. %s\n",
+ Dmsg2(90, "Got write_block_to_dev error on device %s. %s\n",
dev_name(out_dev), strerror_dev(out_dev));
- Jmsg(out_jcr, M_FATAL, 0, _("Cannot fixup device error. %s\n"),
+ Jmsg(out_jcr, M_FATAL, 0, _("Cannot fixup device error. %s\n"),
strerror_dev(out_dev));
break;
}
DEVICE *dev = dcr->dev;
fprintf(stderr, "Mount Volume \"%s\" on device %s and press return when ready: ",
dcr->VolumeName, dev_name(dev));
- getchar();
+ getchar();
return true;
}
int main (int argc, char *argv[])
{
- int ch;
+ int ch;
FILE *fd;
char line[1000];
int got_inc = FALSE;
case 'd': /* debug level */
debug_level = atoi(optarg);
if (debug_level <= 0)
- debug_level = 1;
+ debug_level = 1;
break;
case 'e': /* exclude list */
- if ((fd = fopen(optarg, "r")) == NULL) {
+ if ((fd = fopen(optarg, "r")) == NULL) {
berrno be;
- Pmsg2(0, "Could not open exclude file: %s, ERR=%s\n",
+ Pmsg2(0, "Could not open exclude file: %s, ERR=%s\n",
optarg, be.strerror());
exit(1);
}
while (fgets(line, sizeof(line), fd) != NULL) {
strip_trailing_junk(line);
- Dmsg1(900, "add_exclude %s\n", line);
+ Dmsg1(900, "add_exclude %s\n", line);
add_fname_to_exclude_list(ff, line);
}
fclose(fd);
break;
case 'i': /* include list */
- if ((fd = fopen(optarg, "r")) == NULL) {
+ if ((fd = fopen(optarg, "r")) == NULL) {
berrno be;
- Pmsg2(0, "Could not open include file: %s, ERR=%s\n",
+ Pmsg2(0, "Could not open include file: %s, ERR=%s\n",
optarg, be.strerror());
exit(1);
}
while (fgets(line, sizeof(line), fd) != NULL) {
strip_trailing_junk(line);
- Dmsg1(900, "add_include %s\n", line);
+ Dmsg1(900, "add_include %s\n", line);
add_fname_to_include_list(ff, 0, line);
}
fclose(fd);
read_records(dcr, record_cb, mount_next_read_volume);
/* If output file is still open, it was the last one in the
- * archive since we just hit an end of file, so close the file.
+ * archive since we just hit an end of file, so close the file.
*/
if (is_bopen(&bfd)) {
set_attributes(jcr, attr, &bfd);
switch (rec->Stream) {
case STREAM_UNIX_ATTRIBUTES:
- case STREAM_UNIX_ATTRIBUTES_EX:
+ case STREAM_UNIX_ATTRIBUTES_EX:
/* If extracting, it was from previous stream, so
* close the output file.
*/
if (extract) {
if (!is_bopen(&bfd)) {
- Emsg0(M_ERROR, 0, _("Logic error output file should be open but is not.\n"));
+ Emsg0(M_ERROR, 0, _("Logic error output file should be open but is not.\n"));
}
set_attributes(jcr, attr, &bfd);
extract = false;
}
if (!unpack_attributes_record(jcr, rec->Stream, rec->data, attr)) {
- Emsg0(M_ERROR_TERM, 0, _("Cannot continue.\n"));
+ Emsg0(M_ERROR_TERM, 0, _("Cannot continue.\n"));
}
if (attr->file_index != rec->FileIndex) {
- Emsg2(M_ERROR_TERM, 0, _("Record header file index %ld not equal record index %ld\n"),
+ Emsg2(M_ERROR_TERM, 0, _("Record header file index %ld not equal record index %ld\n"),
rec->FileIndex, attr->file_index);
}
-
+
if (file_is_included(ff, attr->fname) && !file_is_excluded(ff, attr->fname)) {
attr->data_stream = decode_stat(attr->attr, &attr->statp, &attr->LinkFI);
if (!is_stream_supported(attr->data_stream)) {
if (!non_support_data++) {
- Jmsg(jcr, M_ERROR, 0, _("%s stream not supported on this Client.\n"),
+ Jmsg(jcr, M_ERROR, 0, _("%s stream not supported on this Client.\n"),
stream_to_ascii(attr->data_stream));
}
extract = false;
build_attr_output_fnames(jcr, attr);
extract = false;
- stat = create_file(jcr, attr, &bfd, REPLACE_ALWAYS);
+ stat = create_file(jcr, attr, &bfd, REPLACE_ALWAYS);
switch (stat) {
case CF_ERROR:
case CF_SKIP:
num_files++;
fileAddr = 0;
break;
- }
+ }
}
break;
/* Data stream and extracting */
case STREAM_FILE_DATA:
case STREAM_SPARSE_DATA:
- case STREAM_WIN32_DATA:
+ case STREAM_WIN32_DATA:
if (extract) {
if (rec->Stream == STREAM_SPARSE_DATA) {
fileAddr = faddr;
if (blseek(&bfd, (off_t)fileAddr, SEEK_SET) < 0) {
berrno be;
- Emsg2(M_ERROR_TERM, 0, _("Seek error on %s: %s\n"),
+ Emsg2(M_ERROR_TERM, 0, _("Seek error on %s: %s\n"),
attr->ofname, be.strerror());
}
}
wsize = rec->data_len;
}
total += wsize;
- Dmsg2(8, "Write %u bytes, total=%u\n", wsize, total);
+ Dmsg2(8, "Write %u bytes, total=%u\n", wsize, total);
if ((uint32_t)bwrite(&bfd, wbuf, wsize) != wsize) {
berrno be;
- Emsg2(M_ERROR_TERM, 0, _("Write error on %s: %s\n"),
+ Emsg2(M_ERROR_TERM, 0, _("Write error on %s: %s\n"),
attr->ofname, be.strerror());
}
fileAddr += wsize;
/* GZIP data stream */
case STREAM_GZIP_DATA:
- case STREAM_SPARSE_GZIP_DATA:
- case STREAM_WIN32_GZIP_DATA:
+ case STREAM_SPARSE_GZIP_DATA:
+ case STREAM_WIN32_GZIP_DATA:
#ifdef HAVE_LIBZ
if (extract) {
uLong compress_len;
fileAddr = faddr;
if (blseek(&bfd, (off_t)fileAddr, SEEK_SET) < 0) {
berrno be;
- Emsg3(M_ERROR, 0, _("Seek to %s error on %s: ERR=%s\n"),
+ Emsg3(M_ERROR, 0, _("Seek to %s error on %s: ERR=%s\n"),
edit_uint64(fileAddr, ec1), attr->ofname, be.strerror());
extract = false;
return true;
wsize = rec->data_len;
}
compress_len = compress_buf_size;
- if ((stat=uncompress((Bytef *)compress_buf, &compress_len,
+ if ((stat=uncompress((Bytef *)compress_buf, &compress_len,
(const Bytef *)wbuf, (uLong)wsize) != Z_OK)) {
- Emsg1(M_ERROR, 0, _("Uncompression error. ERR=%d\n"), stat);
+ Emsg1(M_ERROR, 0, _("Uncompression error. ERR=%d\n"), stat);
extract = false;
return true;
}
- Dmsg2(100, "Write uncompressed %d bytes, total before write=%d\n", compress_len, total);
+ Dmsg2(100, "Write uncompressed %d bytes, total before write=%d\n", compress_len, total);
if ((uLongf)bwrite(&bfd, compress_buf, (size_t)compress_len) != compress_len) {
berrno be;
- Pmsg0(0, "===Write error===\n");
- Emsg2(M_ERROR, 0, _("Write error on %s: %s\n"),
+ Pmsg0(0, "===Write error===\n");
+ Emsg2(M_ERROR, 0, _("Write error on %s: %s\n"),
attr->ofname, be.strerror());
extract = false;
return true;
}
total += compress_len;
fileAddr += compress_len;
- Dmsg2(100, "Compress len=%d uncompressed=%d\n", rec->data_len,
+ Dmsg2(100, "Compress len=%d uncompressed=%d\n", rec->data_len,
compress_len);
}
#else
if (extract) {
- Emsg0(M_ERROR, 0, "GZIP data stream found, but GZIP not configured!\n");
+ Emsg0(M_ERROR, 0, "GZIP data stream found, but GZIP not configured!\n");
extract = false;
return true;
}
case STREAM_PROGRAM_NAMES:
case STREAM_PROGRAM_DATA:
if (!prog_name_msg) {
- Pmsg0(000, "Got Program Name or Data Stream. Ignored.\n");
+ Pmsg0(000, "Got Program Name or Data Stream. Ignored.\n");
prog_name_msg++;
}
break;
/* If extracting, wierd stream (not 1 or 2), close output file anyway */
if (extract) {
if (!is_bopen(&bfd)) {
- Emsg0(M_ERROR, 0, "Logic error output file should be open but is not.\n");
+ Emsg0(M_ERROR, 0, "Logic error output file should be open but is not.\n");
}
set_attributes(jcr, attr, &bfd);
extract = false;
}
- Jmsg(jcr, M_ERROR, 0, _("Unknown stream=%d ignored. This shouldn't happen!\n"),
+ Jmsg(jcr, M_ERROR, 0, _("Unknown stream=%d ignored. This shouldn't happen!\n"),
rec->Stream);
break;
-
+
} /* end switch */
return true;
}
DEVICE *dev = dcr->dev;
fprintf(stderr, "Mount Volume \"%s\" on device %s and press return when ready: ",
dcr->VolumeName, dev_name(dev));
- getchar();
+ getchar();
return true;
}
BlockCheckSum = bcrc32((uint8_t *)b->buf+BLKHDR_CS_LENGTH,
block_len-BLKHDR_CS_LENGTH);
- Pmsg6(000, "Dump block %s %x: size=%d BlkNum=%d\n\
- Hdrcksum=%x cksum=%x\n",
+ Pmsg6(000, "Dump block %s %x: size=%d BlkNum=%d\n"
+" Hdrcksum=%x cksum=%x\n",
msg, b, block_len, BlockNumber, CheckSum, BlockCheckSum);
p = b->buf + bhl;
- while (p < (b->buf + block_len+WRITE_RECHDR_LENGTH)) {
+ while (p < (b->buf + block_len+WRITE_RECHDR_LENGTH)) {
unser_begin(p, WRITE_RECHDR_LENGTH);
if (rhl == RECHDR1_LENGTH) {
unser_uint32(VolSessionId);
unser_int32(Stream);
unser_uint32(data_len);
Pmsg6(000, " Rec: VId=%u VT=%u FI=%s Strm=%s len=%d p=%x\n",
- VolSessionId, VolSessionTime, FI_to_ascii(FileIndex),
+ VolSessionId, VolSessionTime, FI_to_ascii(FileIndex),
stream_to_ascii(Stream, FileIndex), data_len, p);
p += data_len + rhl;
}
}
-
+
/*
- * Create a new block structure.
+ * Create a new block structure.
* We pass device so that the block can inherit the
* min and max block sizes.
*/
}
block->dev = dev;
block->block_len = block->buf_len; /* default block size */
- block->buf = get_memory(block->buf_len);
+ block->buf = get_memory(block->buf_len);
empty_block(block);
block->BlockVer = BLOCK_VER; /* default write version */
Dmsg1(350, "Returning new block=%x\n", block);
}
-/*
+/*
* Only the first block checksum error was reported.
* If there are more, report it now.
*/
}
/*
- * Free block
+ * Free block
*/
void free_block(DEV_BLOCK *block)
{
ser_declare;
uint32_t CheckSum = 0;
uint32_t block_len = block->binbuf;
-
+
Dmsg1(390, "ser_block_header: block_len=%d\n", block_len);
ser_begin(block->buf, BLKHDR2_LENGTH);
ser_uint32(CheckSum);
}
/* Checksum whole block except for the checksum */
- CheckSum = bcrc32((uint8_t *)block->buf+BLKHDR_CS_LENGTH,
+ CheckSum = bcrc32((uint8_t *)block->buf+BLKHDR_CS_LENGTH,
block_len-BLKHDR_CS_LENGTH);
Dmsg1(390, "ser_bloc_header: checksum=%x\n", CheckSum);
ser_begin(block->buf, BLKHDR2_LENGTH);
block->bufp = block->buf + bhl;
if (strncmp(Id, BLKHDR1_ID, BLKHDR_ID_LENGTH) != 0) {
dev->dev_errno = EIO;
- Mmsg4(dev->errmsg, _("Volume data error at %u:%u! Wanted ID: \"%s\", got \"%s\". Buffer discarded.\n"),
+ Mmsg4(dev->errmsg, _("Volume data error at %u:%u! Wanted ID: \"%s\", got \"%s\". Buffer discarded.\n"),
dev->file, dev->block_num, BLKHDR1_ID, Id);
if (block->read_errors == 0 || verbose >= 2) {
- Jmsg(jcr, M_ERROR, 0, "%s", dev->errmsg);
+ Jmsg(jcr, M_ERROR, 0, "%s", dev->errmsg);
}
block->read_errors++;
return false;
block->bufp = block->buf + bhl;
if (strncmp(Id, BLKHDR2_ID, BLKHDR_ID_LENGTH) != 0) {
dev->dev_errno = EIO;
- Mmsg4(dev->errmsg, _("Volume data error at %u:%u! Wanted ID: \"%s\", got \"%s\". Buffer discarded.\n"),
+ Mmsg4(dev->errmsg, _("Volume data error at %u:%u! Wanted ID: \"%s\", got \"%s\". Buffer discarded.\n"),
dev->file, dev->block_num, BLKHDR2_ID, Id);
if (block->read_errors == 0 || verbose >= 2) {
- Jmsg(jcr, M_ERROR, 0, "%s", dev->errmsg);
+ Jmsg(jcr, M_ERROR, 0, "%s", dev->errmsg);
}
block->read_errors++;
return false;
Mmsg4(dev->errmsg, _("Volume data error at %u:%u! Wanted ID: \"%s\", got \"%s\". Buffer discarded.\n"),
dev->file, dev->block_num, BLKHDR2_ID, Id);
if (block->read_errors == 0 || verbose >= 2) {
- Jmsg(jcr, M_ERROR, 0, "%s", dev->errmsg);
+ Jmsg(jcr, M_ERROR, 0, "%s", dev->errmsg);
}
block->read_errors++;
unser_uint32(block->VolSessionId);
Mmsg3(dev->errmsg, _("Volume data error at %u:%u! Block length %u is insane (too large), probably due to a bad archive.\n"),
dev->file, dev->block_num, block_len);
if (block->read_errors == 0 || verbose >= 2) {
- Jmsg(jcr, M_ERROR, 0, "%s", dev->errmsg);
+ Jmsg(jcr, M_ERROR, 0, "%s", dev->errmsg);
}
block->read_errors++;
return false;
block_len-BLKHDR_CS_LENGTH);
if (BlockCheckSum != CheckSum) {
dev->dev_errno = EIO;
- Mmsg5(dev->errmsg, _("Volume data error at %u:%u! Block checksum mismatch in block %u: calc=%x blk=%x\n"),
+ Mmsg5(dev->errmsg, _("Volume data error at %u:%u! Block checksum mismatch in block %u: calc=%x blk=%x\n"),
dev->file, dev->block_num, (unsigned)BlockNumber, BlockCheckSum, CheckSum);
if (block->read_errors == 0 || verbose >= 2) {
- Jmsg(jcr, M_ERROR, 0, "%s", dev->errmsg);
+ Jmsg(jcr, M_ERROR, 0, "%s", dev->errmsg);
}
block->read_errors++;
if (!forge_on) {
return true;
}
-/*
+/*
* Write a block to the device, with locking and unlocking
*
* Returns: true on success
/*
* If a new volume has been mounted since our last write
* Create a JobMedia record for the previous volume written,
- * and set new parameters to write this volume
+ * and set new parameters to write this volume
* The same applies for if we are in a new file.
*/
if (dcr->NewVol || dcr->NewFile) {
/* Create a jobmedia record for this job */
if (!dir_create_jobmedia_record(dcr)) {
dev->dev_errno = EIO;
- Jmsg(jcr, M_FATAL, 0, _("Could not create JobMedia record for Volume=\"%s\" Job=%s\n"),
+ Jmsg(jcr, M_FATAL, 0, _("Could not create JobMedia record for Volume=\"%s\" Job=%s\n"),
dcr->VolCatInfo.VolCatName, jcr->Job);
set_new_volume_parameters(dcr);
stat = false;
}
/*
- * Write a block to the device
+ * Write a block to the device
*
* Returns: true on success or EOT
* false on hard error
Dmsg0(100, "return write_block_to_dev no data to write\n");
return true;
}
- /*
+ /*
* Clear to the end of the buffer if it is not full,
* and on tape devices, apply min and fixed blocking.
*/
if (wlen-blen > 0) {
memset(block->bufp, 0, wlen-blen); /* clear garbage */
}
- }
+ }
ser_block_header(block);
((dev->VolCatInfo.VolCatBytes + block->binbuf)) >= dev->max_volume_size;
hit_max2 = (dev->VolCatInfo.VolCatMaxBytes > 0) &&
((dev->VolCatInfo.VolCatBytes + block->binbuf)) >= dev->VolCatInfo.VolCatMaxBytes;
- if (hit_max1 || hit_max2) {
+ if (hit_max1 || hit_max2) {
char ed1[50];
uint64_t max_cap;
Dmsg0(10, "==== Output bytes Triggered medium max capacity.\n");
}
/* Limit maximum File size on volume to user specified value */
- if ((dev->max_file_size > 0) &&
+ if ((dev->max_file_size > 0) &&
(dev->file_size+block->binbuf) >= dev->max_file_size) {
dev->file_size = 0; /* reset file size */
if (dev_state(dev, ST_TAPE) && weof_dev(dev, 1) != 0) { /* write eof */
- Dmsg0(190, "WEOF error in max file size.\n");
+ Dmsg0(190, "WEOF error in max file size.\n");
terminate_writing_volume(dcr);
dev->dev_errno = ENOSPC;
return false;
/* Create a JobMedia record so restore can seek */
if (!dir_create_jobmedia_record(dcr)) {
- Dmsg0(190, "Error from create_job_media.\n");
+ Dmsg0(190, "Error from create_job_media.\n");
dev->dev_errno = EIO;
- Jmsg(jcr, M_FATAL, 0, _("Could not create JobMedia record for Volume=\"%s\" Job=%s\n"),
+ Jmsg(jcr, M_FATAL, 0, _("Could not create JobMedia record for Volume=\"%s\" Job=%s\n"),
dcr->VolCatInfo.VolCatName, jcr->Job);
terminate_writing_volume(dcr);
dev->dev_errno = EIO;
}
dev->VolCatInfo.VolCatFiles = dev->file;
if (!dir_update_volume_info(dcr, false)) {
- Dmsg0(190, "Error from update_vol_info.\n");
+ Dmsg0(190, "Error from update_vol_info.\n");
terminate_writing_volume(dcr);
dev->dev_errno = EIO;
return false;
}
dev->VolCatInfo.VolCatWrites++;
- Dmsg1(300, "Write block of %u bytes\n", wlen);
+ Dmsg1(300, "Write block of %u bytes\n", wlen);
#ifdef DEBUG_BLOCK_ZEROING
uint32_t *bp = (uint32_t *)block->buf;
if (bp[0] == 0 && bp[1] == 0 && bp[2] == 0 && block->buf[12] == 0) {
dev->dev_errno = ENOSPC; /* out of space */
}
if (dev->dev_errno != ENOSPC) {
- Jmsg4(jcr, M_ERROR, 0, _("Write error at %u:%u on device %s. ERR=%s.\n"),
+ Jmsg4(jcr, M_ERROR, 0, _("Write error at %u:%u on device %s. ERR=%s.\n"),
dev->file, dev->block_num, dev->dev_name, be.strerror());
}
} else {
dev->dev_errno = ENOSPC; /* out of space */
- }
+ }
if (dev->dev_errno == ENOSPC) {
- Jmsg(jcr, M_INFO, 0, _("End of Volume \"%s\" at %u:%u on device %s. Write of %u bytes got %d.\n"),
+ Jmsg(jcr, M_INFO, 0, _("End of Volume \"%s\" at %u:%u on device %s. Write of %u bytes got %d.\n"),
dev->VolCatInfo.VolCatName,
dev->file, dev->block_num, dev->dev_name, wlen, stat);
}
- Dmsg6(100, "=== Write error. size=%u rtn=%d dev_blk=%d blk_blk=%d errno=%d: ERR=%s\n",
+ Dmsg6(100, "=== Write error. size=%u rtn=%d dev_blk=%d blk_blk=%d errno=%d: ERR=%s\n",
wlen, stat, dev->block_num, block->BlockNumber, dev->dev_errno, strerror(dev->dev_errno));
ok = terminate_writing_volume(dcr);
#define CHECK_LAST_BLOCK
#ifdef CHECK_LAST_BLOCK
- /*
+ /*
* If the device is a tape and it supports backspace record,
- * we backspace over one or two eof marks depending on
+ * we backspace over one or two eof marks depending on
* how many we just wrote, then over the last record,
* then re-read it and verify that the block number is
* correct.
/* Now back up over what we wrote and read the last block */
if (!bsf_dev(dev, 1)) {
ok = false;
- Jmsg(jcr, M_ERROR, 0, _("Backspace file at EOT failed. ERR=%s\n"), strerror(dev->dev_errno));
+ Jmsg(jcr, M_ERROR, 0, _("Backspace file at EOT failed. ERR=%s\n"), strerror(dev->dev_errno));
}
if (ok && dev_cap(dev, CAP_TWOEOF) && !bsf_dev(dev, 1)) {
ok = false;
- Jmsg(jcr, M_ERROR, 0, _("Backspace file at EOT failed. ERR=%s\n"), strerror(dev->dev_errno));
+ Jmsg(jcr, M_ERROR, 0, _("Backspace file at EOT failed. ERR=%s\n"), strerror(dev->dev_errno));
}
/* Backspace over record */
if (ok && !bsr_dev(dev, 1)) {
ok = false;
- Jmsg(jcr, M_ERROR, 0, _("Backspace record at EOT failed. ERR=%s\n"), strerror(dev->dev_errno));
+ Jmsg(jcr, M_ERROR, 0, _("Backspace record at EOT failed. ERR=%s\n"), strerror(dev->dev_errno));
/*
* On FreeBSD systems, if the user got here, it is likely that his/her
- * tape drive is "frozen". The correct thing to do is a
+ * tape drive is "frozen". The correct thing to do is a
* rewind(), but if we do that, higher levels in cleaning up, will
* most likely write the EOS record over the beginning of the
* tape. The rewind *is* done later in mount.c when another
/* Note, this can destroy dev->errmsg */
dcr->block = lblock;
if (!read_block_from_dev(dcr, NO_BLOCK_NUMBER_CHECK)) {
- Jmsg(jcr, M_ERROR, 0, _("Re-read last block at EOT failed. ERR=%s"), dev->errmsg);
+ Jmsg(jcr, M_ERROR, 0, _("Re-read last block at EOT failed. ERR=%s"), dev->errmsg);
} else {
if (lblock->BlockNumber+1 == block->BlockNumber) {
- Jmsg(jcr, M_INFO, 0, _("Re-read of last block succeeded.\n"));
+ Jmsg(jcr, M_INFO, 0, _("Re-read of last block succeeded.\n"));
} else {
Jmsg(jcr, M_ERROR, 0, _(
"Re-read of last block failed. Last block=%u Current block=%u.\n"),
/* We successfully wrote the block, now do housekeeping */
dev->VolCatInfo.VolCatBytes += block->binbuf;
- dev->VolCatInfo.VolCatBlocks++;
+ dev->VolCatInfo.VolCatBlocks++;
dev->EndBlock = dev->block_num;
dev->EndFile = dev->file;
dev->block_num++;
if (weof_dev(dev, 1) != 0) { /* end the tape */
dev->VolCatInfo.VolCatErrors++;
Jmsg(dcr->jcr, M_ERROR, 0, "Error writing final EOF to tape. This tape may not be readable.\n"
- "%s", dev->errmsg);
+ "%s", dev->errmsg);
ok = false;
Dmsg0(100, "WEOF error.\n");
}
}
-/*
+/*
* Read block with locking
*
*/
// block->buf[12],block->buf[13],block->buf[14],block->buf[15]);
if (retry == 1) {
- dev->VolCatInfo.VolCatErrors++;
+ dev->VolCatInfo.VolCatErrors++;
}
} while (stat == -1 && (errno == EINTR || errno == EIO) && retry++ < 11);
if (stat < 0) {
clrerror_dev(dev, -1);
Dmsg1(200, "Read device got: ERR=%s\n", be.strerror());
block->read_len = 0;
- Mmsg4(dev->errmsg, _("Read error at file:blk %u:%u on device %s. ERR=%s.\n"),
+ Mmsg4(dev->errmsg, _("Read error at file:blk %u:%u on device %s. ERR=%s.\n"),
dev->file, dev->block_num, dev->dev_name, be.strerror());
Jmsg(jcr, M_ERROR, 0, "%s", dev->errmsg);
if (dev->state & ST_EOF) { /* EOF just seen? */
Dmsg1(200, "Read device got %d bytes\n", stat);
if (stat == 0) { /* Got EOF ! */
dev->block_num = block->read_len = 0;
- Mmsg3(dev->errmsg, _("Read zero bytes at %u:%u on device %s.\n"),
+ Mmsg3(dev->errmsg, _("Read zero bytes at %u:%u on device %s.\n"),
dev->file, dev->block_num, dev->dev_name);
if (dev->state & ST_EOF) { /* EOF already read? */
dev->state |= ST_EOT; /* yes, 2 EOFs => EOT */
block->read_len = stat; /* save length read */
if (block->read_len < BLKHDR2_LENGTH) {
dev->dev_errno = EIO;
- Mmsg4(dev->errmsg, _("Volume data error at %u:%u! Very short block of %d bytes on device %s discarded.\n"),
+ Mmsg4(dev->errmsg, _("Volume data error at %u:%u! Very short block of %d bytes on device %s discarded.\n"),
dev->file, dev->block_num, block->read_len, dev->dev_name);
Jmsg(jcr, M_ERROR, 0, "%s", dev->errmsg);
dev->state |= ST_SHORT; /* set short block */
block->read_len = block->binbuf = 0;
return false; /* return error */
- }
+ }
BlockNumber = block->BlockNumber + 1;
if (!unser_block_header(jcr, dev, block)) {
Pmsg1(000, "%s", dev->errmsg);
/* Attempt to reposition to re-read the block */
if (dev->state & ST_TAPE) {
- Dmsg0(200, "BSR for reread; block too big for buffer.\n");
+ Dmsg0(200, "BSR for reread; block too big for buffer.\n");
if (!bsr_dev(dev, 1)) {
- Jmsg(jcr, M_ERROR, 0, "%s", strerror_dev(dev));
+ Jmsg(jcr, M_ERROR, 0, "%s", strerror_dev(dev));
block->read_len = 0;
return false;
}
} else {
- Dmsg0(200, "Seek to beginning of block for reread.\n");
+ Dmsg0(200, "Seek to beginning of block for reread.\n");
off_t pos = lseek(dev->fd, (off_t)0, SEEK_CUR); /* get curr pos */
pos -= block->read_len;
- lseek(dev->fd, pos, SEEK_SET);
+ lseek(dev->fd, pos, SEEK_SET);
dev->file_addr = pos;
}
Mmsg1(dev->errmsg, _("Setting block buffer size to %u bytes.\n"), block->block_len);
if (block->block_len > block->read_len) {
dev->dev_errno = EIO;
- Mmsg4(dev->errmsg, _("Volume data error at %u:%u! Short block of %d bytes on device %s discarded.\n"),
+ Mmsg4(dev->errmsg, _("Volume data error at %u:%u! Short block of %d bytes on device %s discarded.\n"),
dev->file, dev->block_num, block->read_len, dev->dev_name);
Jmsg(jcr, M_ERROR, 0, "%s", dev->errmsg);
dev->state |= ST_SHORT; /* set short block */
block->read_len = block->binbuf = 0;
return false; /* return error */
- }
+ }
dev->state &= ~(ST_EOF|ST_SHORT); /* clear EOF and short block */
- dev->VolCatInfo.VolCatReads++;
+ dev->VolCatInfo.VolCatReads++;
dev->VolCatInfo.VolCatRBytes += block->read_len;
dev->VolCatInfo.VolCatBytes += block->block_len;
- dev->VolCatInfo.VolCatBlocks++;
+ dev->VolCatInfo.VolCatBlocks++;
dev->EndBlock = dev->block_num;
dev->EndFile = dev->file;
dev->block_num++;
if (block->read_len > block->block_len && !(dev->state & ST_TAPE)) {
off_t pos = lseek(dev->fd, (off_t)0, SEEK_CUR); /* get curr pos */
pos -= (block->read_len - block->block_len);
- lseek(dev->fd, pos, SEEK_SET);
+ lseek(dev->fd, pos, SEEK_SET);
Dmsg2(200, "Did lseek blk_size=%d rdlen=%d\n", block->block_len,
block->read_len);
dev->file_addr = pos;
* Note, when written, it is serialized.
uint32_t CheckSum;
- uint32_t block_len;
+ uint32_t block_len;
uint32_t BlockNumber;
char Id[BLKHDR_ID_LENGTH];
case 'd': /* debug level */
debug_level = atoi(optarg);
if (debug_level <= 0)
- debug_level = 1;
+ debug_level = 1;
break;
case 'e': /* exclude list */
- if ((fd = fopen(optarg, "r")) == NULL) {
- Pmsg2(0, _("Could not open exclude file: %s, ERR=%s\n"),
+ if ((fd = fopen(optarg, "r")) == NULL) {
+ Pmsg2(0, _("Could not open exclude file: %s, ERR=%s\n"),
optarg, strerror(errno));
exit(1);
}
while (fgets(line, sizeof(line), fd) != NULL) {
strip_trailing_junk(line);
- Dmsg1(100, "add_exclude %s\n", line);
+ Dmsg1(100, "add_exclude %s\n", line);
add_fname_to_exclude_list(&ff, line);
}
fclose(fd);
break;
case 'i': /* include list */
- if ((fd = fopen(optarg, "r")) == NULL) {
- Pmsg2(0, "Could not open include file: %s, ERR=%s\n",
+ if ((fd = fopen(optarg, "r")) == NULL) {
+ Pmsg2(0, "Could not open include file: %s, ERR=%s\n",
optarg, strerror(errno));
exit(1);
}
while (fgets(line, sizeof(line), fd) != NULL) {
strip_trailing_junk(line);
- Dmsg1(100, "add_include %s\n", line);
+ Dmsg1(100, "add_include %s\n", line);
add_fname_to_include_list(&ff, 0, line);
}
fclose(fd);
if (bsrName) {
bsr = parse_bsr(NULL, bsrName);
}
- jcr = setup_jcr("bls", argv[i], bsr, VolumeName, 1); /* acquire for read */
+ jcr = setup_jcr("bls", argv[i], bsr, VolumeName, 1); /* acquire for read */
if (!jcr) {
exit(1);
}
attr = new_attr();
/*
* Assume that we have already read the volume label.
- * If on second or subsequent volume, adjust buffer pointer
+ * If on second or subsequent volume, adjust buffer pointer
*/
if (dev->VolHdr.PrevVolName[0] != 0) { /* second volume */
- Pmsg1(0, "\n\
-Warning, this Volume is a continuation of Volume %s\n",
+ Pmsg1(0, "\n"
+"Warning, this Volume is a continuation of Volume %s\n",
dev->VolHdr.PrevVolName);
}
}
for ( ;; ) {
if (!read_block_from_device(dcr, NO_BLOCK_NUMBER_CHECK)) {
- Dmsg1(100, "!read_block(): ERR=%s\n", strerror_dev(dev));
+ Dmsg1(100, "!read_block(): ERR=%s\n", strerror_dev(dev));
if (dev->state & ST_EOT) {
if (!mount_next_read_volume(dcr)) {
- Jmsg(jcr, M_INFO, 0, _("Got EOM at file %u on device %s, Volume \"%s\"\n"),
+ Jmsg(jcr, M_INFO, 0, _("Got EOM at file %u on device %s, Volume \"%s\"\n"),
dev->file, dev_name(dev), dcr->VolumeName);
break;
}
read_record_from_block(block, record);
get_session_record(dev, record, &sessrec);
free_record(record);
- Jmsg(jcr, M_INFO, 0, _("Mounted Volume \"%s\".\n"), dcr->VolumeName);
-
+ Jmsg(jcr, M_INFO, 0, _("Mounted Volume \"%s\".\n"), dcr->VolumeName);
+
} else if (dev->state & ST_EOF) {
- Jmsg(jcr, M_INFO, 0, _("Got EOF at file %u on device %s, Volume \"%s\"\n"),
+ Jmsg(jcr, M_INFO, 0, _("Got EOF at file %u on device %s, Volume \"%s\"\n"),
dev->file, dev_name(dev), dcr->VolumeName);
- Dmsg0(20, "read_record got eof. try again\n");
+ Dmsg0(20, "read_record got eof. try again\n");
continue;
} else if (dev->state & ST_SHORT) {
- Jmsg(jcr, M_INFO, 0, "%s", dev->errmsg);
+ Jmsg(jcr, M_INFO, 0, "%s", dev->errmsg);
continue;
} else {
/* I/O error */
}
}
if (!match_bsr_block(bsr, block)) {
- Dmsg5(100, "reject Blk=%u blen=%u bVer=%d SessId=%u SessTim=%u\n",
+ Dmsg5(100, "reject Blk=%u blen=%u bVer=%d SessId=%u SessTim=%u\n",
block->BlockNumber, block->block_len, block->BlockVer,
block->VolSessionId, block->VolSessionTime);
continue;
block->VolSessionId, block->VolSessionTime);
if (verbose == 1) {
read_record_from_block(block, rec);
- Pmsg9(-1, "File:blk=%u:%u blk_num=%u blen=%u First rec FI=%s SessId=%u SessTim=%u Strm=%s rlen=%d\n",
+ Pmsg9(-1, "File:blk=%u:%u blk_num=%u blen=%u First rec FI=%s SessId=%u SessTim=%u Strm=%s rlen=%d\n",
dev->file, dev->block_num,
block->BlockNumber, block->block_len,
FI_to_ascii(rec->FileIndex), rec->VolSessionId, rec->VolSessionTime,
stream_to_ascii(rec->Stream, rec->FileIndex), rec->data_len);
rec->remainder = 0;
} else if (verbose > 1) {
- dump_block(block, "");
+ dump_block(block, "");
} else {
- printf("Block: %d size=%d\n", block->BlockNumber, block->block_len);
+ printf("Block: %d size=%d\n", block->BlockNumber, block->block_len);
}
}
return true;
}
/* File Attributes stream */
- if (rec->Stream == STREAM_UNIX_ATTRIBUTES ||
+ if (rec->Stream == STREAM_UNIX_ATTRIBUTES ||
rec->Stream == STREAM_UNIX_ATTRIBUTES_EX) {
if (verbose > 1) {
- const char *rtype = "Attributes";
- Pmsg5(-1, "%s Record: VolSessionId=%d VolSessionTime=%d JobId=%d DataLen=%d\n",
+ const char *rtype = "Attributes";
+ Pmsg5(-1, "%s Record: VolSessionId=%d VolSessionTime=%d JobId=%d DataLen=%d\n",
rtype, rec->VolSessionId, rec->VolSessionTime, rec->Stream, rec->data_len);
}
if (!unpack_attributes_record(jcr, rec->Stream, rec->data, attr)) {
if (!forge_on) {
- Emsg0(M_ERROR_TERM, 0, _("Cannot continue.\n"));
+ Emsg0(M_ERROR_TERM, 0, _("Cannot continue.\n"));
}
num_files++;
return true;
}
if (attr->file_index != rec->FileIndex) {
- Emsg2(forge_on?M_WARNING:M_ERROR_TERM, 0, _("Record header file index %ld not equal record index %ld\n"),
+ Emsg2(forge_on?M_WARNING:M_ERROR_TERM, 0, _("Record header file index %ld not equal record index %ld\n"),
rec->FileIndex, attr->file_index);
}
memset(sessrec, 0, sizeof(sessrec));
switch (rec->FileIndex) {
case PRE_LABEL:
- rtype = "Fresh Volume Label";
+ rtype = "Fresh Volume Label";
break;
case VOL_LABEL:
rtype = "Volume Label";
DEVICE *dev = dcr->dev;
fprintf(stderr, "Mount Volume \"%s\" on device %s and press return when ready: ",
dcr->VolumeName, dev_name(dev));
- getchar();
+ getchar();
return true;
}
/* Forward referenced functions */
static void do_scan(void);
static bool record_cb(DCR *dcr, DEV_RECORD *rec);
-static int create_file_attributes_record(B_DB *db, JCR *mjcr,
+static int create_file_attributes_record(B_DB *db, JCR *mjcr,
char *fname, char *lname, int type,
char *ap, DEV_RECORD *rec);
static int create_media_record(B_DB *db, MEDIA_DBR *mr, VOLUME_LABEL *vl);
static bool update_media_record(B_DB *db, MEDIA_DBR *mr);
static int create_pool_record(B_DB *db, POOL_DBR *pr);
static JCR *create_job_record(B_DB *db, JOB_DBR *mr, SESSION_LABEL *label, DEV_RECORD *rec);
-static int update_job_record(B_DB *db, JOB_DBR *mr, SESSION_LABEL *elabel,
+static int update_job_record(B_DB *db, JOB_DBR *mr, SESSION_LABEL *elabel,
DEV_RECORD *rec);
static int create_client_record(B_DB *db, CLIENT_DBR *cr);
static int create_fileset_record(B_DB *db, FILESET_DBR *fsr);
case 'd': /* debug level */
debug_level = atoi(optarg);
if (debug_level <= 0)
- debug_level = 1;
+ debug_level = 1;
break;
case 'h':
default:
usage();
- }
+ }
}
argc -= optind;
argv += optind;
me = (STORES *)GetNextRes(R_STORAGE, NULL);
if (!me) {
UnlockRes();
- Emsg1(M_ERROR_TERM, 0, _("No Storage resource defined in %s. Cannot continue.\n"),
+ Emsg1(M_ERROR_TERM, 0, _("No Storage resource defined in %s. Cannot continue.\n"),
configfile);
}
UnlockRes();
/* Check if -w option given, otherwise use resource for working directory */
- if (wd) {
+ if (wd) {
working_directory = wd;
} else if (!me->working_directory) {
Emsg1(M_ERROR_TERM, 0, _("No Working Directory defined in %s. Cannot continue.\n"),
}
bjcr = setup_jcr("bscan", argv[0], bsr, VolumeName, 1); /* read device */
- if (!bjcr) {
+ if (!bjcr) {
exit(1);
}
dev = bjcr->dcr->dev;
Pmsg1(000, _("Current Volume Size = %" llu "\n"), currentVolumeSize);
}
- if ((db=db_init_database(NULL, db_name, db_user, db_password,
+ if ((db=db_init_database(NULL, db_name, db_user, db_password,
db_host, 0, NULL, 0)) == NULL) {
Emsg0(M_ERROR_TERM, 0, _("Could not init Bacula database\n"));
}
term_dev(dev);
return 0;
}
-
-/*
+
+/*
* We are at the end of reading a tape. Now, we simulate handling
* the end of writing a tape by wiffling through the attached
* jcrs creating jobmedia records.
continue;
}
if (verbose) {
- Pmsg1(000, _("Create JobMedia for Job %s\n"), mjcr->Job);
+ Pmsg1(000, _("Create JobMedia for Job %s\n"), mjcr->Job);
}
if (dev->state & ST_TAPE) {
mdcr->EndBlock = dev->EndBlock;
mdcr->EndFile = (uint32_t)(dev->file_addr >> 32);
}
if (!create_jobmedia_record(db, mjcr)) {
- Pmsg2(000, _("Could not create JobMedia record for Volume=%s Job=%s\n"),
+ Pmsg2(000, _("Could not create JobMedia record for Volume=%s Job=%s\n"),
dev->VolCatInfo.VolCatName, mjcr->Job);
}
- }
+ }
/* Now let common read routine get up next tape. Note,
* we call mount_next... with bscan's jcr because that is where we
* have the Volume list, but we get attached.
return stat;
}
-static void do_scan()
+static void do_scan()
{
attr = new_attr();
if (showProgress) {
int64_t pct = (mr.VolBytes * 100) / currentVolumeSize;
if (pct != last_pct) {
- fprintf(stdout, "done: %" lld "\n", pct);
+ fprintf(stdout, "done: %" lld "\n", pct);
fflush(stdout);
last_pct = pct;
}
}
}
-
+
if (list_records) {
Pmsg5(000, _("Record: SessId=%u SessTim=%u FileIndex=%d Stream=%d len=%u\n"),
- rec->VolSessionId, rec->VolSessionTime, rec->FileIndex,
+ rec->VolSessionId, rec->VolSessionTime, rec->FileIndex,
rec->Stream, rec->data_len);
}
- /*
- * Check for Start or End of Session Record
+ /*
+ * Check for Start or End of Session Record
*
*/
if (rec->FileIndex < 0) {
}
switch (rec->FileIndex) {
case PRE_LABEL:
- Pmsg0(000, _("Volume is prelabeled. This tape cannot be scanned.\n"));
+ Pmsg0(000, _("Volume is prelabeled. This tape cannot be scanned.\n"));
return false;
break;
num_pools++;
if (db_get_pool_record(bjcr, db, &pr)) {
if (verbose) {
- Pmsg1(000, _("Pool record for %s found in DB.\n"), pr.Name);
+ Pmsg1(000, _("Pool record for %s found in DB.\n"), pr.Name);
}
} else {
if (!update_db) {
- Pmsg1(000, _("VOL_LABEL: Pool record not found for Pool: %s\n"),
+ Pmsg1(000, _("VOL_LABEL: Pool record not found for Pool: %s\n"),
pr.Name);
}
create_pool_record(db, &pr);
}
if (strcmp(pr.PoolType, dev->VolHdr.PoolType) != 0) {
- Pmsg2(000, _("VOL_LABEL: PoolType mismatch. DB=%s Vol=%s\n"),
+ Pmsg2(000, _("VOL_LABEL: PoolType mismatch. DB=%s Vol=%s\n"),
pr.PoolType, dev->VolHdr.PoolType);
return true;
} else if (verbose) {
- Pmsg1(000, _("Pool type \"%s\" is OK.\n"), pr.PoolType);
+ Pmsg1(000, _("Pool type \"%s\" is OK.\n"), pr.PoolType);
}
/* Check Media Info */
num_media++;
if (db_get_media_record(bjcr, db, &mr)) {
if (verbose) {
- Pmsg1(000, _("Media record for %s found in DB.\n"), mr.VolumeName);
+ Pmsg1(000, _("Media record for %s found in DB.\n"), mr.VolumeName);
}
/* Clear out some volume statistics that will be updated */
mr.VolJobs = mr.VolFiles = mr.VolBlocks = 0;
mr.VolBytes = rec->data_len + 20;
} else {
if (!update_db) {
- Pmsg1(000, _("VOL_LABEL: Media record not found for Volume: %s\n"),
+ Pmsg1(000, _("VOL_LABEL: Media record not found for Volume: %s\n"),
mr.VolumeName);
}
bstrncpy(mr.MediaType, dev->VolHdr.MediaType, sizeof(mr.MediaType));
create_media_record(db, &mr, &dev->VolHdr);
}
if (strcmp(mr.MediaType, dev->VolHdr.MediaType) != 0) {
- Pmsg2(000, _("VOL_LABEL: MediaType mismatch. DB=%s Vol=%s\n"),
+ Pmsg2(000, _("VOL_LABEL: MediaType mismatch. DB=%s Vol=%s\n"),
mr.MediaType, dev->VolHdr.MediaType);
return true; /* ignore error */
} else if (verbose) {
- Pmsg1(000, _("Media type \"%s\" is OK.\n"), mr.MediaType);
+ Pmsg1(000, _("Media type \"%s\" is OK.\n"), mr.MediaType);
}
/* Reset some JCR variables */
foreach_dlist(dcr, dev->attached_dcrs) {
dcr->StartFile = dcr->EndFile = 0;
}
- Pmsg1(000, _("VOL_LABEL: OK for Volume: %s\n"), mr.VolumeName);
+ Pmsg1(000, _("VOL_LABEL: OK for Volume: %s\n"), mr.VolumeName);
break;
case SOS_LABEL:
mr.VolJobs++;
num_jobs++;
if (ignored_msgs > 0) {
- Pmsg1(000, _("%d \"errors\" ignored before first Start of Session record.\n"),
+ Pmsg1(000, _("%d \"errors\" ignored before first Start of Session record.\n"),
ignored_msgs);
ignored_msgs = 0;
}
bstrncpy(jr.Job, label.Job, sizeof(jr.Job));
if (db_get_job_record(bjcr, db, &jr)) {
/* Job record already exists in DB */
- update_db = false; /* don't change db in create_job_record */
+ update_db = false; /* don't change db in create_job_record */
if (verbose) {
- Pmsg1(000, _("SOS_LABEL: Found Job record for JobId: %d\n"), jr.JobId);
+ Pmsg1(000, _("SOS_LABEL: Found Job record for JobId: %d\n"), jr.JobId);
}
} else {
/* Must create a Job record in DB */
if (!update_db) {
- Pmsg1(000, _("SOS_LABEL: Job record not found for JobId: %d\n"),
+ Pmsg1(000, _("SOS_LABEL: Job record not found for JobId: %d\n"),
jr.JobId);
}
}
create_client_record(db, &cr);
jr.ClientId = cr.ClientId;
- /* process label, if Job record exists don't update db */
+ /* process label, if Job record exists don't update db */
mjcr = create_job_record(db, &jr, &label, rec);
dcr = mjcr->dcr;
update_db = save_update_db;
if (dev->state & ST_TAPE) {
/*
* Note, we have already advanced past current block,
- * so the correct number is block_num - 1
- */
+ * so the correct number is block_num - 1
+ */
dcr->StartBlock = dev->block_num - 1;
dcr->StartFile = dev->file;
} else {
bstrncpy(dcr->pool_name, label.PoolName, sizeof(dcr->pool_name));
if (rec->VolSessionId != jr.VolSessionId) {
- Pmsg3(000, _("SOS_LABEL: VolSessId mismatch for JobId=%u. DB=%d Vol=%d\n"),
+ Pmsg3(000, _("SOS_LABEL: VolSessId mismatch for JobId=%u. DB=%d Vol=%d\n"),
jr.JobId,
jr.VolSessionId, rec->VolSessionId);
return true; /* ignore error */
}
if (rec->VolSessionTime != jr.VolSessionTime) {
- Pmsg3(000, _("SOS_LABEL: VolSessTime mismatch for JobId=%u. DB=%d Vol=%d\n"),
+ Pmsg3(000, _("SOS_LABEL: VolSessTime mismatch for JobId=%u. DB=%d Vol=%d\n"),
jr.JobId,
jr.VolSessionTime, rec->VolSessionTime);
return true; /* ignore error */
}
if (jr.PoolId != pr.PoolId) {
- Pmsg3(000, _("SOS_LABEL: PoolId mismatch for JobId=%u. DB=%d Vol=%d\n"),
+ Pmsg3(000, _("SOS_LABEL: PoolId mismatch for JobId=%u. DB=%d Vol=%d\n"),
jr.JobId,
jr.PoolId, pr.PoolId);
return true; /* ignore error */
mjcr = get_jcr_by_session(rec->VolSessionId, rec->VolSessionTime);
if (!mjcr) {
- Pmsg2(000, _("Could not find SessId=%d SessTime=%d for EOS record.\n"),
+ Pmsg2(000, _("Could not find SessId=%d SessTime=%d for EOS record.\n"),
rec->VolSessionId, rec->VolSessionTime);
break;
}
break;
case EOT_LABEL: /* end of all tapes */
- /*
+ /*
* Wiffle through all jobs still open and close
* them.
*/
jr.JobTDate = (utime_t)mjcr->start_time;
jr.ClientId = mjcr->ClientId;
if (!db_update_job_end_record(bjcr, db, &jr)) {
- Pmsg1(0, _("Could not update job record. ERR=%s\n"), db_strerror(db));
+ Pmsg1(0, _("Could not update job record. ERR=%s\n"), db_strerror(db));
}
mjcr->dcr = NULL;
free_jcr(mjcr);
mr.VolBytes += mr.VolBlocks * WRITE_BLKHDR_LENGTH; /* approx. */
mr.VolMounts++;
update_media_record(db, &mr);
- Pmsg3(0, _("End of all Volumes. VolFiles=%u VolBlocks=%u VolBytes=%s\n"), mr.VolFiles,
+ Pmsg3(0, _("End of all Volumes. VolFiles=%u VolBlocks=%u VolBytes=%s\n"), mr.VolFiles,
mr.VolBlocks, edit_uint64_with_commas(mr.VolBytes, ec1));
break;
default:
mjcr = get_jcr_by_session(rec->VolSessionId, rec->VolSessionTime);
if (!mjcr) {
if (mr.VolJobs > 0) {
- Pmsg2(000, _("Could not find Job for SessId=%d SessTime=%d record.\n"),
+ Pmsg2(000, _("Could not find Job for SessId=%d SessTime=%d record.\n"),
rec->VolSessionId, rec->VolSessionTime);
} else {
ignored_msgs++;
/* File Attributes stream */
switch (rec->Stream) {
- case STREAM_UNIX_ATTRIBUTES:
- case STREAM_UNIX_ATTRIBUTES_EX:
+ case STREAM_UNIX_ATTRIBUTES:
+ case STREAM_UNIX_ATTRIBUTES_EX:
if (!unpack_attributes_record(bjcr, rec->Stream, rec->data, attr)) {
- Emsg0(M_ERROR_TERM, 0, _("Cannot continue.\n"));
+ Emsg0(M_ERROR_TERM, 0, _("Cannot continue.\n"));
}
if (attr->file_index != rec->FileIndex) {
- Emsg2(M_ERROR_TERM, 0, _("Record header file index %ld not equal record index %ld\n"),
+ Emsg2(M_ERROR_TERM, 0, _("Record header file index %ld not equal record index %ld\n"),
rec->FileIndex, attr->file_index);
}
-
+
if (verbose > 1) {
decode_stat(attr->attr, &attr->statp, &attr->LinkFI);
build_attr_output_fnames(bjcr, attr);
num_files++;
if (verbose && (num_files & 0x7FFF) == 0) {
char ed1[30], ed2[30], ed3[30], ed4[30];
- Pmsg4(000, _("%s file records. At file:blk=%s:%s bytes=%s\n"),
+ Pmsg4(000, _("%s file records. At file:blk=%s:%s bytes=%s\n"),
edit_uint64_with_commas(num_files, ed1),
edit_uint64_with_commas(rec->File, ed2),
edit_uint64_with_commas(rec->Block, ed3),
edit_uint64_with_commas(mr.VolBytes, ed4));
- }
- create_file_attributes_record(db, mjcr, attr->fname, attr->lname,
+ }
+ create_file_attributes_record(db, mjcr, attr->fname, attr->lname,
attr->type, attr->attr, rec);
free_jcr(mjcr);
break;
if (rec->Stream == STREAM_SPARSE_DATA) {
mjcr->JobBytes -= sizeof(uint64_t);
}
-
+
free_jcr(mjcr); /* done using JCR */
break;
char MD5buf[50];
bin_to_base64(MD5buf, (char *)rec->data, 16); /* encode 16 bytes */
if (verbose > 1) {
- Pmsg1(000, _("Got MD5 record: %s\n"), MD5buf);
+ Pmsg1(000, _("Got MD5 record: %s\n"), MD5buf);
}
update_SIG_record(db, MD5buf, rec, MD5_SIG);
break;
char SIGbuf[50];
bin_to_base64(SIGbuf, (char *)rec->data, 20); /* encode 20 bytes */
if (verbose > 1) {
- Pmsg1(000, _("Got SHA1 record: %s\n"), SIGbuf);
+ Pmsg1(000, _("Got SHA1 record: %s\n"), SIGbuf);
}
update_SIG_record(db, SIGbuf, rec, SHA1_SIG);
break;
case STREAM_PROGRAM_NAMES:
if (verbose) {
- Pmsg1(000, _("Got Prog Names Stream: %s\n"), rec->data);
+ Pmsg1(000, _("Got Prog Names Stream: %s\n"), rec->data);
}
break;
case STREAM_PROGRAM_DATA:
if (verbose > 1) {
- Pmsg0(000, _("Got Prog Data Stream record.\n"));
+ Pmsg0(000, _("Got Prog Data Stream record.\n"));
}
break;
default:
mjcr->FileId = ar.FileId;
if (verbose > 1) {
- Pmsg1(000, _("Created File record: %s\n"), fname);
+ Pmsg1(000, _("Created File record: %s\n"), fname);
}
return 1;
}
/*
- * Called from SOS to create a client for the current Job
+ * Called from SOS to create a client for the current Job
*/
static int create_client_record(B_DB *db, CLIENT_DBR *cr)
{
}
if (db_get_fileset_record(bjcr, db, fsr)) {
if (verbose) {
- Pmsg1(000, _("Fileset \"%s\" already exists.\n"), fsr->FileSet);
+ Pmsg1(000, _("Fileset \"%s\" already exists.\n"), fsr->FileSet);
}
} else {
if (!db_create_fileset_record(bjcr, db, fsr)) {
- Pmsg2(0, _("Could not create FileSet record \"%s\". ERR=%s\n"),
+ Pmsg2(0, _("Could not create FileSet record \"%s\". ERR=%s\n"),
fsr->FileSet, db_strerror(db));
return 0;
}
if (verbose) {
- Pmsg1(000, _("Created FileSet record \"%s\"\n"), fsr->FileSet);
+ Pmsg1(000, _("Created FileSet record \"%s\"\n"), fsr->FileSet);
}
}
return 1;
* the Job record and to update it when the Job actually
* begins running.
*/
-static JCR *create_job_record(B_DB *db, JOB_DBR *jr, SESSION_LABEL *label,
+static JCR *create_job_record(B_DB *db, JOB_DBR *jr, SESSION_LABEL *label,
DEV_RECORD *rec)
{
JCR *mjcr;
Pmsg1(0, _("Could not update job start record. ERR=%s\n"), db_strerror(db));
return mjcr;
}
- Pmsg2(000, _("Created new JobId=%u record for original JobId=%u\n"), jr->JobId,
+ Pmsg2(000, _("Created new JobId=%u record for original JobId=%u\n"), jr->JobId,
label->JobId);
mjcr->JobId = jr->JobId; /* set new JobId */
return mjcr;
}
-/*
- * Simulate the database call that updates the Job
+/*
+ * Simulate the database call that updates the Job
* at Job termination time.
*/
static int update_job_record(B_DB *db, JOB_DBR *jr, SESSION_LABEL *elabel,
free_jcr(mjcr);
return 1;
}
-
+
if (!db_update_job_end_record(bjcr, db, jr)) {
Pmsg2(0, _("Could not update JobId=%u record. ERR=%s\n"), jr->JobId, db_strerror(db));
free_jcr(mjcr);
switch (mjcr->JobStatus) {
case JS_Terminated:
- term_msg = _("Backup OK");
+ term_msg = _("Backup OK");
break;
case JS_FatalError:
case JS_ErrorTerminated:
- term_msg = _("*** Backup Error ***");
+ term_msg = _("*** Backup Error ***");
break;
case JS_Canceled:
- term_msg = _("Backup Canceled");
+ term_msg = _("Backup Canceled");
break;
default:
term_msg = term_code;
- sprintf(term_code, _("Job Termination code: %d"), mjcr->JobStatus);
+ sprintf(term_code, _("Job Termination code: %d"), mjcr->JobStatus);
break;
}
bstrftime(sdt, sizeof(sdt), mjcr->start_time);
bstrftime(edt, sizeof(edt), mjcr->end_time);
- Pmsg14(000, _("%s\n\
-JobId: %d\n\
-Job: %s\n\
-FileSet: %s\n\
-Backup Level: %s\n\
-Client: %s\n\
-Start time: %s\n\
-End time: %s\n\
-Files Written: %s\n\
-Bytes Written: %s\n\
-Volume Session Id: %d\n\
-Volume Session Time: %d\n\
-Last Volume Bytes: %s\n\
-Termination: %s\n\n"),
+ Pmsg14(000, _("%s\n"
+"JobId: %d\n"
+"Job: %s\n"
+"FileSet: %s\n"
+"Backup Level: %s\n"
+"Client: %s\n"
+"Start time: %s\n"
+"End time: %s\n"
+"Files Written: %s\n"
+"Bytes Written: %s\n"
+"Volume Session Id: %d\n"
+"Volume Session Time: %d\n"
+"Last Volume Bytes: %s\n"
+"Termination: %s\n\n"),
edt,
mjcr->JobId,
mjcr->Job,
return 0;
}
if (verbose) {
- Pmsg2(000, _("Created JobMedia record JobId %d, MediaId %d\n"),
+ Pmsg2(000, _("Created JobMedia record JobId %d, MediaId %d\n"),
jmr.JobId, jmr.MediaId);
}
return 1;
}
-/*
+/*
* Simulate the database call that updates the MD5/SHA1 record
*/
static int update_SIG_record(B_DB *db, char *SIGbuf, DEV_RECORD *rec, int type)
mjcr = get_jcr_by_session(rec->VolSessionId, rec->VolSessionTime);
if (!mjcr) {
if (mr.VolJobs > 0) {
- Pmsg2(000, _("Could not find SessId=%d SessTime=%d for MD5/SHA1 record.\n"),
+ Pmsg2(000, _("Could not find SessId=%d SessTime=%d for MD5/SHA1 record.\n"),
rec->VolSessionId, rec->VolSessionTime);
} else {
ignored_msgs++;
free_jcr(mjcr);
return 1;
}
-
+
if (!db_add_SIG_to_file_record(bjcr, db, mjcr->FileId, SIGbuf, type)) {
Pmsg1(0, _("Could not add MD5/SHA1 to File record. ERR=%s\n"), db_strerror(db));
free_jcr(mjcr);
}
-/*
+/*
* Create a JCR as if we are really starting the job
*/
static JCR *create_jcr(JOB_DBR *jr, DEV_RECORD *rec, uint32_t JobId)
force_close_dev(dev);
fprintf(stderr, "Mount Volume \"%s\" on device %s and press return when ready: ",
dcr->VolumeName, dev_name(dev));
- getchar();
+ getchar();
return true;
}
/*
* List of Volume names to be read by Storage daemon.
- * Formed by Storage daemon from BSR
+ * Formed by Storage daemon from BSR
*/
struct VOL_LIST {
VOL_LIST *next;
char VolumeName[MAX_NAME_LENGTH];
- int Slot;
+ int Slot;
uint32_t start_file;
};
struct BSR_VOLUME {
BSR_VOLUME *next;
char VolumeName[MAX_NAME_LENGTH];
-};
+};
struct BSR_CLIENT {
BSR_CLIENT *next;
char ClientName[MAX_NAME_LENGTH];
-};
+};
struct BSR_SESSID {
BSR_SESSID *next;
BSR_SESSTIME *next;
uint32_t sesstime;
bool done; /* local done */
-};
+};
struct BSR_VOLFILE {
BSR_VOLFILE *next;
uint32_t sblock; /* start block */
uint32_t eblock; /* end block */
bool done; /* local done */
-};
+};
struct BSR_FINDEX {
int32_t findex; /* start file index */
int32_t findex2; /* end file index */
bool done; /* local done */
-};
+};
struct BSR_JOBID {
BSR_JOBID *next;
uint32_t JobId;
uint32_t JobId2;
-};
+};
struct BSR_JOBTYPE {
BSR_JOBTYPE *next;
uint32_t JobType;
-};
+};
struct BSR_JOBLEVEL {
BSR_JOBLEVEL *next;
uint32_t JobLevel;
-};
+};
struct BSR_JOB {
BSR_JOB *next;
struct BSR_STREAM {
BSR_STREAM *next;
int32_t stream; /* stream desired */
-};
+};
struct BSR {
BSR *next; /* pointer to next one */
bool forge_on = false;
/*
- * If you change the format of the state file,
+ * If you change the format of the state file,
* increment this value
- */
+ */
static uint32_t btape_state_level = 2;
DEVICE *dev = NULL;
DCR *dcr;
DEVRES *device = NULL;
-
+
/* Forward referenced subroutines */
static void do_tape_cmds();
static void helpcmd();
static uint32_t last_block_num2 = 0;
static uint32_t last_block_num = 0;
static uint32_t BlockNumber = 0;
-static bool simple = true;
+static bool simple = true;
static const char *VolumeName = NULL;
static int vol_num = 0;
case 'd': /* set debug level */
debug_level = atoi(optarg);
if (debug_level <= 0) {
- debug_level = 1;
+ debug_level = 1;
}
break;
helpcmd();
exit(0);
- }
+ }
}
margc -= optind;
margv += optind;
cmd = get_pool_memory(PM_FNAME);
args = get_pool_memory(PM_FNAME);
-
+
if (signals) {
init_signals(terminate_btape);
}
Dmsg0(200, "Do tape commands\n");
do_tape_cmds();
-
+
terminate:
terminate_btape(0);
return 0;
}
if (debug_level > 10)
- print_memory_pool_stats();
+ print_memory_pool_stats();
if (this_block) {
free_block(this_block);
static bool open_the_device()
{
DEV_BLOCK *block;
-
+
block = new_block(dev);
lock_device(dev);
if (!(dev->state & ST_OPENED)) {
Dmsg1(200, "Opening device %s\n", dcr->VolumeName);
if (open_dev(dev, dcr->VolumeName, OPEN_READ_WRITE) < 0) {
- Emsg1(M_FATAL, 0, _("dev open failed: %s\n"), dev->errmsg);
+ Emsg1(M_FATAL, 0, _("dev open failed: %s\n"), dev->errmsg);
unlock_device(dev);
free_block(block);
return false;
}
/*
- * Write a label to the tape
+ * Write a label to the tape
*/
static void labelcmd()
{
return;
}
}
-
+
if (!(dev->state & ST_OPENED)) {
if (!first_open_device(dev)) {
- Pmsg1(0, "Device open failed. ERR=%s\n", strerror_dev(dev));
+ Pmsg1(0, "Device open failed. ERR=%s\n", strerror_dev(dev));
}
}
rewind_dev(dev);
}
/*
- * Read the tape label
+ * Read the tape label
*/
static void readlabelcmd()
{
}
debug_level = 20;
- dump_volume_label(dev);
+ dump_volume_label(dev);
debug_level = save_debug_level;
}
}
/*
- * Rewind the tape.
+ * Rewind the tape.
*/
static void rewindcmd()
{
}
/*
- * Clear any tape error
+ * Clear any tape error
*/
static void clearcmd()
{
}
/*
- * Write and end of file on the tape
+ * Write and end of file on the tape
*/
static void weofcmd()
{
}
-/* Go to the end of the medium -- raw command
+/* Go to the end of the medium -- raw command
* The idea was orginally that the end of the Bacula
* medium would be flagged differently. This is not
* currently the case. So, this is identical to the
}
/*
- * Backspace file
+ * Backspace file
*/
static void bsfcmd()
{
}
/*
- * Backspace record
+ * Backspace record
*/
static void bsrcmd()
{
}
/*
- * List device capabilities as defined in the
+ * List device capabilities as defined in the
* stored.conf file.
*/
static void capcmd()
}
/*
- * Test writting larger and larger records.
+ * Test writting larger and larger records.
* This is a torture test for records.
*/
static void rectestcmd()
if (write_record_to_block(block, rec)) {
empty_block(block);
blkno++;
- Pmsg2(0, "Block %d i=%d\n", blkno, i);
+ Pmsg2(0, "Block %d i=%d\n", blkno, i);
} else {
break;
}
Pmsg0(-1, _("\n=== Write, backup, and re-read test ===\n\n"
"I'm going to write three records and an EOF\n"
- "then backup over the EOF and re-read the last record.\n"
+ "then backup over the EOF and re-read the last record.\n"
"Bacula does this after writing the last block on the\n"
"tape to verify that the block was written correctly.\n\n"
- "This is not an *essential* feature ...\n\n"));
+ "This is not an *essential* feature ...\n\n"));
rewindcmd();
empty_block(block);
rec = new_record();
len = rec->data_len = block->buf_len-100;
memset(rec->data, 1, rec->data_len);
if (!write_record_to_block(block, rec)) {
- Pmsg0(0, _("Error writing record to block.\n"));
+ Pmsg0(0, _("Error writing record to block.\n"));
goto bail_out;
}
if (!write_block_to_dev(dcr)) {
- Pmsg0(0, _("Error writing block to device.\n"));
+ Pmsg0(0, _("Error writing block to device.\n"));
goto bail_out;
} else {
Pmsg1(0, _("Wrote first record of %d bytes.\n"), rec->data_len);
}
memset(rec->data, 2, rec->data_len);
if (!write_record_to_block(block, rec)) {
- Pmsg0(0, _("Error writing record to block.\n"));
+ Pmsg0(0, _("Error writing record to block.\n"));
goto bail_out;
}
if (!write_block_to_dev(dcr)) {
- Pmsg0(0, _("Error writing block to device.\n"));
+ Pmsg0(0, _("Error writing block to device.\n"));
goto bail_out;
} else {
Pmsg1(0, _("Wrote second record of %d bytes.\n"), rec->data_len);
}
memset(rec->data, 3, rec->data_len);
if (!write_record_to_block(block, rec)) {
- Pmsg0(0, _("Error writing record to block.\n"));
+ Pmsg0(0, _("Error writing record to block.\n"));
goto bail_out;
}
if (!write_block_to_dev(dcr)) {
- Pmsg0(0, _("Error writing block to device.\n"));
+ Pmsg0(0, _("Error writing block to device.\n"));
goto bail_out;
} else {
Pmsg1(0, _("Wrote third record of %d bytes.\n"), rec->data_len);
}
if (dev_cap(dev, CAP_TWOEOF)) {
if (!bsf_dev(dev, 1)) {
- Pmsg1(0, _("Backspace file failed! ERR=%s\n"), strerror_dev(dev));
+ Pmsg1(0, _("Backspace file failed! ERR=%s\n"), strerror_dev(dev));
goto bail_out;
}
}
}
for (int i=0; i<len; i++) {
if (rec->data[i] != 3) {
- Pmsg0(0, _("Bad data in record. Test failed!\n"));
+ Pmsg0(0, _("Bad data in record. Test failed!\n"));
goto bail_out;
}
}
free_record(rec);
if (stat == 0) {
Pmsg0(0, _("This is not terribly serious since Bacula only uses\n"
- "this function to verify the last block written to the\n"
- "tape. Bacula will skip the last block verification\n"
- "if you add:\n\n"
- "Backward Space Record = No\n\n"
- "to your Storage daemon's Device resource definition.\n"));
- }
+ "this function to verify the last block written to the\n"
+ "tape. Bacula will skip the last block verification\n"
+ "if you add:\n\n"
+ "Backward Space Record = No\n\n"
+ "to your Storage daemon's Device resource definition.\n"));
+ }
return stat;
}
Pmsg0(-1, _("\n=== Write, rewind, and re-read test ===\n\n"
"I'm going to write 1000 records and an EOF\n"
- "then write 1000 records and an EOF, then rewind,\n"
+ "then write 1000 records and an EOF, then rewind,\n"
"and re-read the data to verify that it is correct.\n\n"
- "This is an *essential* feature ...\n\n"));
+ "This is an *essential* feature ...\n\n"));
block = dcr->block;
rec = new_record();
if (!rewind_dev(dev)) {
*p++ = i;
}
if (!write_record_to_block(block, rec)) {
- Pmsg0(0, _("Error writing record to block.\n"));
+ Pmsg0(0, _("Error writing record to block.\n"));
goto bail_out;
}
if (!write_block_to_dev(dcr)) {
- Pmsg0(0, _("Error writing block to device.\n"));
+ Pmsg0(0, _("Error writing block to device.\n"));
goto bail_out;
}
}
*p++ = i;
}
if (!write_record_to_block(block, rec)) {
- Pmsg0(0, _("Error writing record to block.\n"));
+ Pmsg0(0, _("Error writing record to block.\n"));
goto bail_out;
}
if (!write_block_to_dev(dcr)) {
- Pmsg0(0, _("Error writing block to device.\n"));
+ Pmsg0(0, _("Error writing block to device.\n"));
goto bail_out;
}
}
if (!read_block_from_dev(dcr, NO_BLOCK_NUMBER_CHECK)) {
berrno be;
if (dev_state(dev, ST_EOF)) {
- Pmsg0(-1, _("Got EOF on tape.\n"));
+ Pmsg0(-1, _("Got EOF on tape.\n"));
if (i == 1001) {
goto read_again;
}
}
- Pmsg2(0, _("Read block %d failed! ERR=%s\n"), i, be.strerror(dev->dev_errno));
+ Pmsg2(0, _("Read block %d failed! ERR=%s\n"), i, be.strerror(dev->dev_errno));
goto bail_out;
}
memset(rec->data, 0, rec->data_len);
if (!read_record_from_block(block, rec)) {
berrno be;
- Pmsg2(0, _("Read record failed. Block %d! ERR=%s\n"), i, be.strerror(dev->dev_errno));
+ Pmsg2(0, _("Read record failed. Block %d! ERR=%s\n"), i, be.strerror(dev->dev_errno));
goto bail_out;
}
p = (int *)rec->data;
for (j=0; j<len; j++) {
if (*p != i) {
- Pmsg3(0, _("Bad data in record. Expected %d, got %d at byte %d. Test failed!\n"),
+ Pmsg3(0, _("Bad data in record. Expected %d, got %d at byte %d. Test failed!\n"),
i, *p, j);
goto bail_out;
}
p++;
}
if (i == 1000 || i == 2000) {
- Pmsg0(-1, _("1000 blocks re-read correctly.\n"));
+ Pmsg0(-1, _("1000 blocks re-read correctly.\n"));
}
}
Pmsg0(-1, _("=== Test Succeeded. End Write, rewind, and re-read test ===\n\n"));
Pmsg0(-1, _("\n=== Write, rewind, and position test ===\n\n"
"I'm going to write 1000 records and an EOF\n"
- "then write 1000 records and an EOF, then rewind,\n"
+ "then write 1000 records and an EOF, then rewind,\n"
"and position to a few blocks and verify that it is correct.\n\n"
- "This is an *essential* feature ...\n\n"));
+ "This is an *essential* feature ...\n\n"));
empty_block(block);
rec = new_record();
if (!rewind_dev(dev)) {
*p++ = i;
}
if (!write_record_to_block(block, rec)) {
- Pmsg0(0, _("Error writing record to block.\n"));
+ Pmsg0(0, _("Error writing record to block.\n"));
goto bail_out;
}
if (!write_block_to_dev(dcr)) {
- Pmsg0(0, _("Error writing block to device.\n"));
+ Pmsg0(0, _("Error writing block to device.\n"));
goto bail_out;
}
}
*p++ = i;
}
if (!write_record_to_block(block, rec)) {
- Pmsg0(0, _("Error writing record to block.\n"));
+ Pmsg0(0, _("Error writing record to block.\n"));
goto bail_out;
}
if (!write_block_to_dev(dcr)) {
- Pmsg0(0, _("Error writing block to device.\n"));
+ Pmsg0(0, _("Error writing block to device.\n"));
goto bail_out;
}
}
}
Pmsg2(-1, "Reposition to file:block %d:%d\n", file, blk);
if (!reposition_dev(dev, file, blk)) {
- Pmsg0(0, "Reposition error.\n");
+ Pmsg0(0, "Reposition error.\n");
goto bail_out;
}
read_again:
if (!read_block_from_dev(dcr, NO_BLOCK_NUMBER_CHECK)) {
berrno be;
if (dev_state(dev, ST_EOF)) {
- Pmsg0(-1, _("Got EOF on tape.\n"));
+ Pmsg0(-1, _("Got EOF on tape.\n"));
if (!got_eof) {
got_eof = true;
goto read_again;
}
}
- Pmsg4(0, _("Read block %d failed! file=%d blk=%d. ERR=%s\n\n"),
+ Pmsg4(0, _("Read block %d failed! file=%d blk=%d. ERR=%s\n\n"),
recno, file, blk, be.strerror(dev->dev_errno));
- Pmsg0(0, _("This may be because the tape drive block size is not\n"
- " set to variable blocking as normally used by Bacula.\n"
- " Please see the Tape Testing chapter in the manual and \n"
- " look for using mt with defblksize and setoptions\n"
- "If your tape drive block size is correct, then perhaps\n"
- " your SCSI driver is *really* stupid and does not\n"
- " correctly report the file:block after a FSF. In this\n"
- " case try setting:\n"
- " Fast Forward Space File = no\n"
- " in your Device resource.\n"));
+ Pmsg0(0, _("This may be because the tape drive block size is not\n"
+ " set to variable blocking as normally used by Bacula.\n"
+ " Please see the Tape Testing chapter in the manual and \n"
+ " look for using mt with defblksize and setoptions\n"
+ "If your tape drive block size is correct, then perhaps\n"
+ " your SCSI driver is *really* stupid and does not\n"
+ " correctly report the file:block after a FSF. In this\n"
+ " case try setting:\n"
+ " Fast Forward Space File = no\n"
+ " in your Device resource.\n"));
goto bail_out;
}
memset(rec->data, 0, rec->data_len);
if (!read_record_from_block(block, rec)) {
berrno be;
- Pmsg1(0, _("Read record failed! ERR=%s\n"), be.strerror(dev->dev_errno));
+ Pmsg1(0, _("Read record failed! ERR=%s\n"), be.strerror(dev->dev_errno));
goto bail_out;
}
p = (int *)rec->data;
for (j=0; j<len; j++) {
if (p[j] != recno) {
- Pmsg3(0, _("Bad data in record. Expected %d, got %d at byte %d. Test failed!\n"),
+ Pmsg3(0, _("Bad data in record. Expected %d, got %d at byte %d. Test failed!\n"),
recno, p[j], j);
goto bail_out;
}
static int append_test()
{
Pmsg0(-1, _("\n\n=== Append files test ===\n\n"
- "This test is essential to Bacula.\n\n"
+ "This test is essential to Bacula.\n\n"
"I'm going to write one record in file 0,\n"
" two records in file 1,\n"
" and three records in file 2\n\n"));
rewindcmd();
Pmsg0(0, _("Now moving to end of medium.\n"));
eodcmd();
- Pmsg2(-1, _("We should be in file 3. I am at file %d. This is %s\n"),
+ Pmsg2(-1, _("We should be in file 3. I am at file %d. This is %s\n"),
dev->file, dev->file == 3 ? "correct!" : "NOT correct!!!!");
if (dev->file != 3) {
}
Pmsg0(-1, _("\nNow the important part, I am going to attempt to append to the tape.\n\n"));
- wrcmd();
+ wrcmd();
weofcmd();
if (dev_cap(dev, CAP_TWOEOF)) {
weofcmd();
Pmsg0(-1, "Doing Bacula scan of blocks:\n");
scan_blocks();
Pmsg0(-1, _("End scanning the tape.\n"));
- Pmsg2(-1, _("We should be in file 4. I am at file %d. This is %s\n"),
+ Pmsg2(-1, _("We should be in file 4. I am at file %d. This is %s\n"),
dev->file, dev->file == 4 ? "correct!" : "NOT correct!!!!");
if (dev->file != 4) {
}
Pmsg0(-1, "\nAh, I see you have an autochanger configured.\n"
- "To test the autochanger you must have a blank tape\n"
- " that I can write on in Slot 1.\n");
+ "To test the autochanger you must have a blank tape\n"
+ " that I can write on in Slot 1.\n");
if (!get_cmd("\nDo you wish to continue with the Autochanger test? (y/n): ")) {
return 0;
}
dcr->VolCatInfo.Slot = slot;
/* Find out what is loaded, zero means device is unloaded */
Pmsg0(-1, _("3301 Issuing autochanger \"loaded\" command.\n"));
- changer = edit_device_codes(jcr, changer, jcr->device->changer_command,
- "loaded");
+ changer = edit_device_codes(jcr, changer, jcr->device->changer_command,
+ "loaded");
status = run_program(changer, timeout, results);
Dmsg3(100, "run_prog: %s stat=%d result=\"%s\"\n", changer, status, results);
if (status == 0) {
force_close_dev(dev);
Pmsg2(-1, _("3302 Issuing autochanger \"unload %d %d\" command.\n"),
loaded, dev->drive_index);
- changer = edit_device_codes(jcr, changer,
- jcr->device->changer_command, "unload");
+ changer = edit_device_codes(jcr, changer,
+ jcr->device->changer_command, "unload");
status = run_program(changer, timeout, results);
Pmsg2(-1, "unload status=%s %d\n", status==0?"OK":"Bad", status);
if (status != 0) {
berrno be;
- Pmsg1(-1, _("3992 Bad autochanger command: %s\n"), changer);
- Pmsg2(-1, _("3992 result=\"%s\": ERR=%s\n"), results, be.strerror(status));
+ Pmsg1(-1, _("3992 Bad autochanger command: %s\n"), changer);
+ Pmsg2(-1, _("3992 result=\"%s\": ERR=%s\n"), results, be.strerror(status));
}
}
/*
* Load the Slot 1
*/
-
+
slot = 1;
dcr->VolCatInfo.Slot = slot;
- Pmsg2(-1, _("3303 Issuing autochanger \"load slot %d %d\" command.\n"),
+ Pmsg2(-1, _("3303 Issuing autochanger \"load slot %d %d\" command.\n"),
slot, dev->drive_index);
changer = edit_device_codes(jcr, changer, jcr->device->changer_command, "load");
Dmsg1(100, "Changer=%s\n", changer);
if (!open_the_device()) {
goto bail_out;
}
- /*
+ /*
* Start with sleep_time 0 then increment by 30 seconds if we get
* a failure.
*/
Pmsg1(0, "Bad status from rewind. ERR=%s\n", strerror_dev(dev));
clrerror_dev(dev, -1);
Pmsg0(-1, "\nThe test failed, probably because you need to put\n"
- "a longer sleep time in the mtx-script in the load) case.\n"
- "Adding a 30 second sleep and trying again ...\n");
+ "a longer sleep time in the mtx-script in the load) case.\n"
+ "Adding a 30 second sleep and trying again ...\n");
sleep_time += 30;
goto try_again;
} else {
Pmsg1(0, "Rewound %s\n", dev_name(dev));
}
-
+
if ((status = weof_dev(dev, 1)) < 0) {
Pmsg2(0, "Bad status from weof %d. ERR=%s\n", status, strerror_dev(dev));
goto bail_out;
if (sleep_time) {
Pmsg1(-1, "\nThe test worked this time. Please add:\n\n"
- " sleep %d\n\n"
- "to your mtx-changer script in the load) case.\n\n",
+ " sleep %d\n\n"
+ "to your mtx-changer script in the load) case.\n\n",
sleep_time);
} else {
Pmsg0(-1, "\nThe test autochanger worked!!\n\n");
static int fsf_test()
{
bool set_off = false;
-
+
Pmsg0(-1, _("\n\n=== Forward space files test ===\n\n"
- "This test is essential to Bacula.\n\n"
- "I'm going to write five files then test forward spacing\n\n"));
+ "This test is essential to Bacula.\n\n"
+ "I'm going to write five files then test forward spacing\n\n"));
argc = 1;
rewindcmd();
wrcmd();
Pmsg1(0, "Bad status from fsr. ERR=%s\n", strerror_dev(dev));
goto bail_out;
}
- Pmsg2(-1, _("We should be in file 1. I am at file %d. This is %s\n"),
+ Pmsg2(-1, _("We should be in file 1. I am at file %d. This is %s\n"),
dev->file, dev->file == 1 ? "correct!" : "NOT correct!!!!");
if (dev->file != 1) {
Pmsg1(0, "Bad status from fsr. ERR=%s\n", strerror_dev(dev));
goto bail_out;
}
- Pmsg2(-1, _("We should be in file 3. I am at file %d. This is %s\n"),
+ Pmsg2(-1, _("We should be in file 3. I am at file %d. This is %s\n"),
dev->file, dev->file == 3 ? "correct!" : "NOT correct!!!!");
if (dev->file != 3) {
Pmsg1(0, "Bad status from fsr. ERR=%s\n", strerror_dev(dev));
goto bail_out;
}
- Pmsg2(-1, _("We should be in file 4. I am at file %d. This is %s\n"),
+ Pmsg2(-1, _("We should be in file 4. I am at file %d. This is %s\n"),
dev->file, dev->file == 4 ? "correct!" : "NOT correct!!!!");
if (dev->file != 4) {
}
if (set_off) {
Pmsg0(-1, "The test worked this time. Please add:\n\n"
- " Fast Forward Space File = no\n\n"
- "to your Device resource for this drive.\n");
+ " Fast Forward Space File = no\n\n"
+ "to your Device resource for this drive.\n");
}
Pmsg0(-1, "\n");
if (!fsf_dev(dev, 1)) {
Pmsg1(0, "Bad status from fsr. ERR=%s\n", strerror_dev(dev));
}
- Pmsg2(-1, _("We should be in file 5. I am at file %d. This is %s\n"),
+ Pmsg2(-1, _("We should be in file 5. I am at file %d. This is %s\n"),
dev->file, dev->file == 5 ? "correct!" : "NOT correct!!!!");
if (dev->file != 5) {
goto bail_out;
Pmsg0(-1, _("\nThe forward space file test failed.\n"));
if (dev_cap(dev, CAP_FASTFSF)) {
Pmsg0(-1, "You have Fast Forward Space File enabled.\n"
- "I am turning it off then retrying the test.\n");
+ "I am turning it off then retrying the test.\n");
dev->capabilities &= ~CAP_FASTFSF;
set_off = true;
goto test_again;
}
Pmsg0(-1, "You must correct this error or Bacula will not work.\n"
- "Some systems, e.g. OpenBSD, require you to set\n"
- " Use MTIOCGET= no\n"
- "in your device resource. Use with caution.\n");
+ "Some systems, e.g. OpenBSD, require you to set\n"
+ " Use MTIOCGET= no\n"
+ "in your device resource. Use with caution.\n");
return -2;
}
-/*
+/*
* This is a general test of Bacula's functions
* needed to read and write the tape.
*/
}
if (stat == -1) { /* first test failed */
if (dev_cap(dev, CAP_EOM) || dev_cap(dev, CAP_FASTFSF)) {
- Pmsg0(-1, "\nAppend test failed. Attempting again.\n"
- "Setting \"Hardware End of Medium = no\n"
- " and \"Fast Forward Space File = no\n"
- "and retrying append test.\n\n");
+ Pmsg0(-1, "\nAppend test failed. Attempting again.\n"
+ "Setting \"Hardware End of Medium = no\n"
+ " and \"Fast Forward Space File = no\n"
+ "and retrying append test.\n\n");
dev->capabilities &= ~CAP_EOM; /* turn off eom */
dev->capabilities &= ~CAP_FASTFSF; /* turn off fast fsf */
stat = append_test();
if (stat == 1) {
- Pmsg0(-1, "\n\nIt looks like the test worked this time, please add:\n\n"
- " Hardware End of Medium = No\n\n"
- " Fast Forward Space File = No\n"
- "to your Device resource in the Storage conf file.\n");
+ Pmsg0(-1, "\n\nIt looks like the test worked this time, please add:\n\n"
+ " Hardware End of Medium = No\n\n"
+ " Fast Forward Space File = No\n"
+ "to your Device resource in the Storage conf file.\n");
goto all_done;
}
if (stat == -1) {
- Pmsg0(-1, "\n\nThat appears *NOT* to have corrected the problem.\n");
+ Pmsg0(-1, "\n\nThat appears *NOT* to have corrected the problem.\n");
goto failed;
}
/* Wrong count after append */
if (stat == -2) {
- Pmsg0(-1, "\n\nIt looks like the append failed. Attempting again.\n"
- "Setting \"BSF at EOM = yes\" and retrying append test.\n");
+ Pmsg0(-1, "\n\nIt looks like the append failed. Attempting again.\n"
+ "Setting \"BSF at EOM = yes\" and retrying append test.\n");
dev->capabilities |= CAP_BSFATEOM; /* backspace on eom */
stat = append_test();
if (stat == 1) {
- Pmsg0(-1, "\n\nIt looks like the test worked this time, please add:\n\n"
- " Hardware End of Medium = No\n"
- " Fast Forward Space File = No\n"
- " BSF at EOM = yes\n\n"
- "to your Device resource in the Storage conf file.\n");
+ Pmsg0(-1, "\n\nIt looks like the test worked this time, please add:\n\n"
+ " Hardware End of Medium = No\n"
+ " Fast Forward Space File = No\n"
+ " BSF at EOM = yes\n\n"
+ "to your Device resource in the Storage conf file.\n");
goto all_done;
}
}
failed:
Pmsg0(-1, "\nAppend test failed.\n\n");
Pmsg0(-1, "\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"
- "Unable to correct the problem. You MUST fix this\n"
- "problem before Bacula can use your tape drive correctly\n");
+ "Unable to correct the problem. You MUST fix this\n"
+ "problem before Bacula can use your tape drive correctly\n");
Pmsg0(-1, "\nPerhaps running Bacula in fixed block mode will work.\n"
- "Do so by setting:\n\n"
- "Minimum Block Size = nnn\n"
- "Maximum Block Size = nnn\n\n"
- "in your Storage daemon's Device definition.\n"
- "nnn must match your tape driver's block size, which\n"
- "can be determined by reading your tape manufacturers\n"
- "information, and the information on your kernel dirver.\n"
- "Fixed block sizes, however, are not normally an ideal solution.\n"
- "\n"
- "Some systems, e.g. OpenBSD, require you to set\n"
- " Use MTIOCGET= no\n"
- "in your device resource. Use with caution.\n");
+ "Do so by setting:\n\n"
+ "Minimum Block Size = nnn\n"
+ "Maximum Block Size = nnn\n\n"
+ "in your Storage daemon's Device definition.\n"
+ "nnn must match your tape driver's block size, which\n"
+ "can be determined by reading your tape manufacturers\n"
+ "information, and the information on your kernel dirver.\n"
+ "Fixed block sizes, however, are not normally an ideal solution.\n"
+ "\n"
+ "Some systems, e.g. OpenBSD, require you to set\n"
+ " Use MTIOCGET= no\n"
+ "in your device resource. Use with caution.\n");
return;
}
all_done:
Pmsg0(-1, _("\nThe above Bacula scan should have output identical to what follows.\n"
- "Please double check it ...\n"
- "=== Sample correct output ===\n"
- "1 block of 64448 bytes in file 1\n"
- "End of File mark.\n"
- "2 blocks of 64448 bytes in file 2\n"
- "End of File mark.\n"
- "3 blocks of 64448 bytes in file 3\n"
- "End of File mark.\n"
- "1 block of 64448 bytes in file 4\n"
- "End of File mark.\n"
- "Total files=4, blocks=7, bytes = 451,136\n"
- "=== End sample correct output ===\n\n"));
+ "Please double check it ...\n"
+ "=== Sample correct output ===\n"
+ "1 block of 64448 bytes in file 1\n"
+ "End of File mark.\n"
+ "2 blocks of 64448 bytes in file 2\n"
+ "End of File mark.\n"
+ "3 blocks of 64448 bytes in file 3\n"
+ "End of File mark.\n"
+ "1 block of 64448 bytes in file 4\n"
+ "End of File mark.\n"
+ "Total files=4, blocks=7, bytes = 451,136\n"
+ "=== End sample correct output ===\n\n"));
Pmsg0(-1, _("If the above scan output is not identical to the\n"
- "sample output, you MUST correct the problem\n"
- "or Bacula will not be able to write multiple Jobs to \n"
- "the tape.\n\n"));
+ "sample output, you MUST correct the problem\n"
+ "or Bacula will not be able to write multiple Jobs to \n"
+ "the tape.\n\n"));
if (stat == 1) {
re_read_block_test();
fsf_test(); /* do fast forward space file test */
autochanger_test(); /* do autochanger test */
-
+
}
/* Forward space a file */
rec->data_len = i;
sm_check(__FILE__, __LINE__, false);
if (!write_record_to_block(block, rec)) {
- Pmsg0(0, _("Error writing record to block.\n"));
+ Pmsg0(0, _("Error writing record to block.\n"));
goto bail_out;
}
if (!write_block_to_dev(dcr)) {
- Pmsg0(0, _("Error writing block to device.\n"));
+ Pmsg0(0, _("Error writing block to device.\n"));
goto bail_out;
} else {
Pmsg1(0, _("Wrote one record of %d bytes.\n"), i);
sm_check(__FILE__, __LINE__, false);
}
-/*
+/*
* Read a record from the tape
*/
static void rrcmd()
bytes = 0;
if (dev->state & ST_EOT) {
Pmsg0(0, "End of tape\n");
- return;
+ return;
}
update_pos_dev(dev);
tot_files = dev->file;
if ((stat = read(dev->fd, buf, sizeof(buf))) < 0) {
berrno be;
clrerror_dev(dev, -1);
- Mmsg2(dev->errmsg, "read error on %s. ERR=%s.\n",
+ Mmsg2(dev->errmsg, "read error on %s. ERR=%s.\n",
dev->dev_name, be.strerror());
- Pmsg2(0, "Bad status from read %d. ERR=%s\n", stat, strerror_dev(dev));
+ Pmsg2(0, "Bad status from read %d. ERR=%s\n", stat, strerror_dev(dev));
if (blocks > 0)
- printf("%d block%s of %d bytes in file %d\n",
- blocks, blocks>1?"s":"", block_size, dev->file);
+ printf("%d block%s of %d bytes in file %d\n",
+ blocks, blocks>1?"s":"", block_size, dev->file);
return;
}
Dmsg1(200, "read status = %d\n", stat);
if (stat != block_size) {
update_pos_dev(dev);
if (blocks > 0) {
- printf("%d block%s of %d bytes in file %d\n",
- blocks, blocks>1?"s":"", block_size, dev->file);
+ printf("%d block%s of %d bytes in file %d\n",
+ blocks, blocks>1?"s":"", block_size, dev->file);
blocks = 0;
}
block_size = stat;
}
if (stat == 0) { /* EOF */
update_pos_dev(dev);
- printf("End of File mark.\n");
+ printf("End of File mark.\n");
/* Two reads of zero means end of tape */
if (dev->state & ST_EOF)
dev->state |= ST_EOT;
dev->file++;
}
if (dev->state & ST_EOT) {
- printf("End of tape\n");
+ printf("End of tape\n");
break;
}
} else { /* Got data */
}
update_pos_dev(dev);
tot_files = dev->file - tot_files;
- printf("Total files=%d, blocks=%d, bytes = %s\n", tot_files, tot_blocks,
+ printf("Total files=%d, blocks=%d, bytes = %s\n", tot_files, tot_blocks,
edit_uint64_with_commas(bytes, ec1));
}
tot_files = dev->file;
for (;;) {
if (!read_block_from_device(dcr, NO_BLOCK_NUMBER_CHECK)) {
- Dmsg1(100, "!read_block(): ERR=%s\n", strerror_dev(dev));
+ Dmsg1(100, "!read_block(): ERR=%s\n", strerror_dev(dev));
if (dev->state & ST_EOT) {
if (blocks > 0) {
- printf("%d block%s of %d bytes in file %d\n",
- blocks, blocks>1?"s":"", block_size, dev->file);
+ printf("%d block%s of %d bytes in file %d\n",
+ blocks, blocks>1?"s":"", block_size, dev->file);
blocks = 0;
}
goto bail_out;
}
if (dev->state & ST_EOF) {
if (blocks > 0) {
- printf("%d block%s of %d bytes in file %d\n",
- blocks, blocks>1?"s":"", block_size, dev->file);
+ printf("%d block%s of %d bytes in file %d\n",
+ blocks, blocks>1?"s":"", block_size, dev->file);
blocks = 0;
}
- printf(_("End of File mark.\n"));
+ printf(_("End of File mark.\n"));
continue;
}
if (dev->state & ST_SHORT) {
if (blocks > 0) {
- printf("%d block%s of %d bytes in file %d\n",
- blocks, blocks>1?"s":"", block_size, dev->file);
+ printf("%d block%s of %d bytes in file %d\n",
+ blocks, blocks>1?"s":"", block_size, dev->file);
blocks = 0;
}
- printf(_("Short block read.\n"));
+ printf(_("Short block read.\n"));
continue;
}
- printf(_("Error reading block. ERR=%s\n"), strerror_dev(dev));
+ printf(_("Error reading block. ERR=%s\n"), strerror_dev(dev));
goto bail_out;
}
if (block->block_len != block_size) {
if (blocks > 0) {
- printf("%d block%s of %d bytes in file %d\n",
- blocks, blocks>1?"s":"", block_size, dev->file);
+ printf("%d block%s of %d bytes in file %d\n",
+ blocks, blocks>1?"s":"", block_size, dev->file);
blocks = 0;
}
block_size = block->block_len;
if (verbose == 1) {
DEV_RECORD *rec = new_record();
read_record_from_block(block, rec);
- Pmsg8(-1, "Blk_block: %u dev_blk=%u blen=%u First rec FI=%s SessId=%u SessTim=%u Strm=%s rlen=%d\n",
+ Pmsg8(-1, "Blk_block: %u dev_blk=%u blen=%u First rec FI=%s SessId=%u SessTim=%u Strm=%s rlen=%d\n",
block->BlockNumber, dev->block_num, block->block_len,
FI_to_ascii(rec->FileIndex), rec->VolSessionId, rec->VolSessionTime,
stream_to_ascii(rec->Stream, rec->FileIndex), rec->data_len);
rec->remainder = 0;
free_record(rec);
} else if (verbose > 1) {
- dump_block(block, "");
+ dump_block(block, "");
}
}
bail_out:
tot_files = dev->file - tot_files;
- printf("Total files=%d, blocks=%d, bytes = %s\n", tot_files, tot_blocks,
+ printf("Total files=%d, blocks=%d, bytes = %s\n", tot_files, tot_blocks,
edit_uint64_with_commas(bytes, ec1));
}
}
-/*
+/*
* First we label the tape, then we fill
* it with data get a new tape and write a few blocks.
- */
+ */
static void fillcmd()
{
DEV_RECORD rec;
last_block_num = 0;
BlockNumber = 0;
- Pmsg0(-1, "\n\
-This command simulates Bacula writing to a tape.\n\
-It requires either one or two blank tapes, which it\n\
-will label and write.\n\n\
-If you have an autochanger configured, it will use\n\
-the tapes that are in slots 1 and 2, otherwise, you will\n\
-be prompted to insert the tapes when necessary.\n\n\
-It will print a status approximately\n\
-every 322 MB, and write an EOF every 3.2 GB. If you have\n\
-selected the simple test option, after writing the first tape\n\
-it will rewind it and re-read the last block written.\n\n\
-If you have selected the multiple tape test, when the first tape\n\
-fills, it will ask for a second, and after writing a few more \n\
-blocks, it will stop. Then it will begin re-reading the\n\
-two tapes.\n\n\
-This may take a long time -- hours! ...\n\n");
+ Pmsg0(-1, "\n"
+"This command simulates Bacula writing to a tape.\n"
+"It requires either one or two blank tapes, which it\n"
+"will label and write.\n\n"
+"If you have an autochanger configured, it will use\n"
+"the tapes that are in slots 1 and 2, otherwise, you will\n"
+"be prompted to insert the tapes when necessary.\n\n"
+"It will print a status approximately\n"
+"every 322 MB, and write an EOF every 3.2 GB. If you have\n"
+"selected the simple test option, after writing the first tape\n"
+"it will rewind it and re-read the last block written.\n\n"
+"If you have selected the multiple tape test, when the first tape\n"
+"fills, it will ask for a second, and after writing a few more \n"
+"blocks, it will stop. Then it will begin re-reading the\n"
+"two tapes.\n\n"
+"This may take a long time -- hours! ...\n\n");
get_cmd("Do you want to run the simplified test (s) with one tape\n"
- "or the complete multiple tape (m) test: (s/m) ");
+ "or the complete multiple tape (m) test: (s/m) ");
if (cmd[0] == 's') {
Pmsg0(-1, "Simple test (single tape) selected.\n");
simple = true;
} else if (cmd[0] == 'm') {
- Pmsg0(-1, "Multiple tape test selected.\n");
+ Pmsg0(-1, "Multiple tape test selected.\n");
simple = false;
} else {
Pmsg0(000, "Command aborted.\n");
labelcmd();
dev->state &= ~ST_APPEND; /* force volume to be relabeled */
- /*
+ /*
* Acquire output device for writing. Note, after acquiring a
* device, we MUST release it, which is done at the end of this
* subroutine.
#define REC_SIZE 32768
rec.data_len = REC_SIZE;
- /*
+ /*
* Put some random data in the record
*/
fd = open("/dev/urandom", O_RDONLY);
}
}
- /*
- * Generate data as if from File daemon, write to device
+ /*
+ * Generate data as if from File daemon, write to device
*/
jcr->dcr->VolFirstIndex = 0;
time(&jcr->run_time); /* start counting time for rates */
}
Dmsg4(250, "before write_rec FI=%d SessId=%d Strm=%s len=%d\n",
- rec.FileIndex, rec.VolSessionId, stream_to_ascii(rec.Stream, rec.FileIndex),
+ rec.FileIndex, rec.VolSessionId, stream_to_ascii(rec.Stream, rec.FileIndex),
rec.data_len);
-
+
while (!write_record_to_block(block, &rec)) {
/*
* When we get here we have just filled a block
*/
- Dmsg2(150, "!write_record_to_block data_len=%d rem=%d\n", rec.data_len,
+ Dmsg2(150, "!write_record_to_block data_len=%d rem=%d\n", rec.data_len,
rec.remainder);
/* Write block to tape */
now = 1; /* prevent divide error */
}
kbs = (double)dev->VolCatInfo.VolCatBytes / (1000.0 * (double)now);
- Pmsg4(-1, "Wrote blk_block=%u, dev_blk_num=%u VolBytes=%s rate=%.1f KB/s\n",
+ Pmsg4(-1, "Wrote blk_block=%u, dev_blk_num=%u VolBytes=%s rate=%.1f KB/s\n",
block->BlockNumber, dev->block_num,
edit_uint64_with_commas(dev->VolCatInfo.VolCatBytes, ec1), (float)kbs);
}
/* Every 15000 blocks (approx 1GB) write an EOF.
*/
if ((block->BlockNumber % 15000) == 0) {
- Pmsg0(-1, "Flush block, write EOF\n");
+ Pmsg0(-1, "Flush block, write EOF\n");
flush_block(block, 0);
weof_dev(dev, 1);
}
/* Get out after writing 10 blocks to the second tape */
if (++BlockNumber > 10 && stop != 0) { /* get out */
- break;
+ break;
}
}
if (!ok) {
- Pmsg0(000, _("Not OK\n"));
+ Pmsg0(000, _("Not OK\n"));
break;
}
jcr->JobBytes += rec.data_len; /* increment bytes this job */
Dmsg4(190, "write_record FI=%s SessId=%d Strm=%s len=%d\n",
- FI_to_ascii(rec.FileIndex), rec.VolSessionId,
+ FI_to_ascii(rec.FileIndex), rec.VolSessionId,
stream_to_ascii(rec.Stream, rec.FileIndex), rec.data_len);
/* Get out after writing 10 blocks to the second tape */
if (BlockNumber > 10 && stop != 0) { /* get out */
- Pmsg0(-1, "Done writing ...\n");
- break;
+ Pmsg0(-1, "Done writing ...\n");
+ break;
}
}
if (vol_num > 1) {
set_jcr_job_status(jcr, JS_ErrorTerminated);
}
if (!write_session_label(dcr, EOS_LABEL)) {
- Pmsg1(000, _("Error writting end session label. ERR=%s\n"), strerror_dev(dev));
+ Pmsg1(000, _("Error writting end session label. ERR=%s\n"), strerror_dev(dev));
ok = false;
}
/* Write out final block of this session */
if (!write_block_to_device(dcr)) {
- Pmsg0(-1, _("Set ok=false after write_block_to_device.\n"));
+ Pmsg0(-1, _("Set ok=false after write_block_to_device.\n"));
ok = false;
}
Pmsg0(-1, _("Wrote End of Session label.\n"));
sprintf(buf, "%s/btape.state", working_directory);
fd = open(buf, O_RDONLY);
if (fd >= 0) {
- uint32_t state_level;
+ uint32_t state_level;
read(fd, &state_level, sizeof(btape_state_level));
read(fd, &simple, sizeof(simple));
read(fd, &last_block_num1, sizeof(last_block_num1));
read(fd, first_block->buf, first_block->buf_len);
close(fd);
if (state_level != btape_state_level) {
- Pmsg0(-1, "\nThe state file level has changed. You must redo\n"
- "the fill command.\n");
+ Pmsg0(-1, "\nThe state file level has changed. You must redo\n"
+ "the fill command.\n");
return;
}
} else {
berrno be;
Pmsg2(-1, "\nCould not find the state file: %s ERR=%s\n"
- "You must redo the fill command.\n", buf, be.strerror());
+ "You must redo the fill command.\n", buf, be.strerror());
return;
}
do_unfill();
autochanger = autoload_device(dcr, 1, NULL);
if (!autochanger) {
force_close_dev(dev);
- get_cmd(_("Mount first tape. Press enter when ready: "));
+ get_cmd(_("Mount first tape. Press enter when ready: "));
}
free_vol_list(jcr);
jcr->dcr = new_dcr(jcr, dev);
dev->state &= ~(ST_READ|ST_APPEND);
dev->num_writers = 0;
if (!acquire_device_for_read(jcr)) {
- Pmsg1(-1, "%s", dev->errmsg);
+ Pmsg1(-1, "%s", dev->errmsg);
goto bail_out;
}
}
/*
* We now have the first tape mounted.
- * Note, re-reading last block may have caused us to
+ * Note, re-reading last block may have caused us to
* loose track of where we are (block number unknown).
*/
if (!rewind_dev(dev)) { /* get to a known place on tape */
}
if (compare_blocks(last_block, block)) {
if (simple) {
- Pmsg0(-1, _("\nThe last block on the tape matches. Test succeeded.\n\n"));
+ Pmsg0(-1, _("\nThe last block on the tape matches. Test succeeded.\n\n"));
} else {
- Pmsg0(-1, _("\nThe last block of the first tape matches.\n\n"));
+ Pmsg0(-1, _("\nThe last block of the first tape matches.\n\n"));
}
}
if (simple) {
autochanger = autoload_device(dcr, 1, NULL);
if (!autochanger) {
force_close_dev(dev);
- get_cmd(_("Mount second tape. Press enter when ready: "));
+ get_cmd(_("Mount second tape. Press enter when ready: "));
}
dev->state &= ~ST_READ;
return quickie_count < 1000;
}
-static bool compare_blocks(DEV_BLOCK *last_block, DEV_BLOCK *block)
+static bool compare_blocks(DEV_BLOCK *last_block, DEV_BLOCK *block)
{
char *p, *q;
uint32_t CheckSum, block_len;
ser_declare;
- p = last_block->buf;
+ p = last_block->buf;
q = block->buf;
unser_begin(q, BLKHDR2_LENGTH);
unser_uint32(CheckSum);
dump_block(block, _("Block read back"));
Pmsg1(-1, "\n\nThe blocks differ at byte %u\n", p - last_block->buf);
Pmsg0(-1, "\n\n!!!! The last block written and the block\n"
- "that was read back differ. The test FAILED !!!!\n"
- "This must be corrected before you use Bacula\n"
- "to write multi-tape Volumes.!!!!\n");
+ "that was read back differ. The test FAILED !!!!\n"
+ "This must be corrected before you use Bacula\n"
+ "to write multi-tape Volumes.!!!!\n");
return false;
}
if (verbose) {
this_file = dev->file;
this_block_num = dev->block_num;
if (!write_block_to_dev(dcr)) {
- Pmsg3(000, "Last block at: %u:%u this_dev_block_num=%d\n",
+ Pmsg3(000, "Last block at: %u:%u this_dev_block_num=%d\n",
last_file, last_block_num, this_block_num);
if (vol_num == 1) {
- /*
+ /*
* This is 1st tape, so save first tape info separate
- * from second tape info
+ * from second tape info
*/
last_block_num1 = last_block_num;
last_file1 = last_file;
first_block = dup_block(block); /* first block second tape */
}
if (verbose) {
- Pmsg3(000, "Block not written: FileIndex=%u blk_block=%u Size=%u\n",
+ Pmsg3(000, "Block not written: FileIndex=%u blk_block=%u Size=%u\n",
(unsigned)file_index, block->BlockNumber, block->block_len);
- dump_block(last_block, "Last block written");
- Pmsg0(-1, "\n");
- dump_block(block, "Block not written");
+ dump_block(last_block, "Last block written");
+ Pmsg0(-1, "\n");
+ dump_block(block, "Block not written");
}
if (stop == 0) {
eot_block = block->BlockNumber;
now = time(NULL);
now -= jcr->run_time;
if (now <= 0) {
- now = 1; /* don't divide by zero */
+ now = 1; /* don't divide by zero */
}
kbs = (double)dev->VolCatInfo.VolCatBytes / (1000 * now);
vol_size = dev->VolCatInfo.VolCatBytes;
- Pmsg4(000, "End of tape %d:%d. VolumeCapacity=%s. Write rate = %.1f KB/s\n",
+ Pmsg4(000, "End of tape %d:%d. VolumeCapacity=%s. Write rate = %.1f KB/s\n",
dev->file, dev->block_num,
edit_uint64_with_commas(dev->VolCatInfo.VolCatBytes, ec1), kbs);
} else {
/* Full test in progress */
if (!fixup_device_block_write_error(jcr->dcr)) {
- Pmsg1(000, _("Cannot fixup device error. %s\n"), strerror_dev(dev));
+ Pmsg1(000, _("Cannot fixup device error. %s\n"), strerror_dev(dev));
ok = false;
unlock_device(dev);
return 0;
* Note, we always read/write to block, but we toggle
* copying it to one or another of two allocated blocks.
* Switch blocks so that the block just successfully written is
- * always in last_block.
+ * always in last_block.
*/
tblock = last_block;
- last_block = this_block;
+ last_block = this_block;
this_block = tblock;
last_file = this_file;
last_block_num = this_block_num;
}
-/*
+/*
* First we label the tape, then we fill
* it with data get a new tape and write a few blocks.
- */
+ */
static void qfillcmd()
{
DEV_BLOCK *block = dcr->block;
Pmsg1(0, "Begin writing %d Bacula blocks to tape ...\n", count);
for (i=0; i < count; i++) {
if (i % 100 == 0) {
- printf("+");
+ printf("+");
fflush(stdout);
}
if (!write_record_to_block(block, rec)) {
- Pmsg0(0, _("Error writing record to block.\n"));
+ Pmsg0(0, _("Error writing record to block.\n"));
goto bail_out;
}
if (!write_block_to_dev(dcr)) {
- Pmsg0(0, _("Error writing block to device.\n"));
+ Pmsg0(0, _("Error writing block to device.\n"));
goto bail_out;
}
}
stat = write(dev->fd, block->buf, block->buf_len);
if (stat == (int)block->buf_len) {
if ((block_num++ % 100) == 0) {
- printf("+");
+ printf("+");
fflush(stdout);
}
p[0] += p[13];
uint32_t block_num = 0;
uint32_t *p;
int my_errno;
- int fd;
+ int fd;
uint32_t i;
fd = open("/dev/urandom", O_RDONLY);
break;
}
if ((block_num++ % 100) == 0) {
- printf("+");
+ printf("+");
fflush(stdout);
}
p[0] += p[13];
}
my_errno = errno;
printf("\n");
- printf("Write failed at block %u.\n", block_num);
+ printf("Write failed at block %u.\n", block_num);
weofcmd();
}
-struct cmdstruct { const char *key; void (*func)(); const char *help; };
+struct cmdstruct { const char *key; void (*func)(); const char *help; };
static struct cmdstruct commands[] = {
{"autochanger", autochangercmd, "test autochanger"},
{"bsf", bsfcmd, "backspace file"},
{"help", helpcmd, "print this command"},
{"label", labelcmd, "write a Bacula label to the tape"},
{"load", loadcmd, "load a tape"},
- {"quit", quitcmd, "quit btape"},
+ {"quit", quitcmd, "quit btape"},
{"rawfill", rawfill_cmd, "use write() to fill tape"},
{"readlabel", readlabelcmd, "read and print the Bacula tape label"},
{"rectest", rectestcmd, "test record handling functions"},
{"rewind", rewindcmd, "rewind the tape"},
- {"scan", scancmd, "read() tape block by block to EOT and report"},
+ {"scan", scancmd, "read() tape block by block to EOT and report"},
{"scanblocks", scan_blocks, "Bacula read block by block to EOT and report"},
{"status", statcmd, "print tape status"},
{"test", testcmd, "General test Bacula tape functions"},
{"weof", weofcmd, "write an EOF on the tape"},
- {"wr", wrcmd, "write a single Bacula block"},
+ {"wr", wrcmd, "write a single Bacula block"},
{"rr", rrcmd, "read a single record"},
{"qfill", qfillcmd, "quick fill command"},
};
break;
}
if (!found)
- Pmsg1(0, _("%s is an illegal command\n"), cmd);
+ Pmsg1(0, _("%s is an illegal command\n"), cmd);
if (quit)
break;
}
" -p proceed inspite of I/O errors\n"
" -s turn off signals\n"
" -v be verbose\n"
-" -? print this message.\n"
+" -? print this message.\n"
"\n"));
}
-/*
+/*
* Get next input command from terminal. This
* routine is REALLY primitive, and should be enhanced
* to have correct backspacing, etc.
*/
-int
+int
get_cmd(const char *prompt)
{
int i = 0;
* up a bit.
*/
cmd[i] = 0;
- while ((ch = fgetc(stdin)) != EOF) {
+ while ((ch = fgetc(stdin)) != EOF) {
if (ch == '\n') {
strip_trailing_junk(cmd);
return 1;
if (i > 0)
cmd[--i] = 0;
continue;
- }
-
+ }
+
cmd[i++] = ch;
cmd[i] = 0;
}
bool dir_update_file_attributes(DCR *dcr, DEV_RECORD *rec) { return 1;}
bool dir_send_job_status(JCR *jcr) {return 1;}
-bool dir_update_volume_info(DCR *dcr, bool relabel)
-{
+bool dir_update_volume_info(DCR *dcr, bool relabel)
+{
return 1;
}
-bool dir_get_volume_info(DCR *dcr, enum get_vol_info_rw writing)
+bool dir_get_volume_info(DCR *dcr, enum get_vol_info_rw writing)
{
Dmsg0(20, "Enter dir_get_volume_info\n");
bstrncpy(dcr->VolCatInfo.VolCatName, dcr->VolumeName, sizeof(dcr->VolCatInfo.VolCatName));
}
-bool dir_find_next_appendable_volume(DCR *dcr)
-{
+bool dir_find_next_appendable_volume(DCR *dcr)
+{
Dmsg1(20, "Enter dir_find_next_appendable_volume. stop=%d\n", stop);
return dcr->VolumeName[0] != 0;
}
fprintf(stderr, "Mount Volume \"%s\" on device %s and press return when ready: ",
dcr->VolumeName, dev_name(dev));
}
- getchar();
+ getchar();
return true;
}
force_close_dev(dev);
fprintf(stderr, "Mount blank Volume on device %s and press return when ready: ",
dev_name(dev));
- getchar();
+ getchar();
}
open_device(dcr);
labelcmd();
jcr->bsr = NULL;
create_vol_list(jcr);
close_dev(dev);
- dev->state &= ~ST_READ;
+ dev->state &= ~ST_READ;
if (!acquire_device_for_read(jcr)) {
Pmsg2(0, "Cannot open Dev=%s, Vol=%s\n", dev_name(dev), dcr->VolumeName);
return false;
return true; /* next volume mounted */
}
-static void set_volume_name(const char *VolName, int volnum)
+static void set_volume_name(const char *VolName, int volnum)
{
DCR *dcr = jcr->dcr;
VolumeName = VolName;
* bextract, ... Some routines also used by Bacula.
*
* Kern Sibbald, MM
- *
- * Normally nothing in this file is called by the Storage
+ *
+ * Normally nothing in this file is called by the Storage
* daemon because we interact more directly with the user
* i.e. printf, ...
*
#ifdef DEBUG
char *rec_state_to_str(DEV_RECORD *rec)
{
- static char buf[200];
+ static char buf[200];
buf[0] = 0;
if (rec->state & REC_NO_HEADER) {
strcat(buf, "Nohdr,");
/*
* If no volume name already given and no bsr, and it is a file,
- * try getting name from Filename
+ * try getting name from Filename
*/
if (VolumeName) {
bstrncpy(VolName, VolumeName, sizeof(VolName));
/* Try stripping file part */
p = dev_name + strlen(dev_name);
- while (p >= dev_name && *p != '/')
+ while (p >= dev_name && *p != '/')
p--;
- if (*p == '/') {
+ if (*p == '/') {
bstrncpy(VolName, p+1, sizeof(VolName));
*p = 0;
}
}
if ((device=find_device_res(dev_name, mode)) == NULL) {
- Jmsg2(jcr, M_FATAL, 0, _("Cannot find device \"%s\" in config file %s.\n"),
+ Jmsg2(jcr, M_FATAL, 0, _("Cannot find device \"%s\" in config file %s.\n"),
dev_name, configfile);
return NULL;
}
jcr->device = device;
-
+
dev = init_dev(NULL, device);
if (!dev) {
Jmsg1(jcr, M_FATAL, 0, _("Cannot init device %s\n"), dev_name);
return NULL;
}
device->dev = dev;
- dcr = new_dcr(jcr, dev);
+ dcr = new_dcr(jcr, dev);
if (VolName[0]) {
bstrncpy(dcr->VolumeName, VolName, sizeof(dcr->VolumeName));
}
/*
- * Called here when freeing JCR so that we can get rid
+ * Called here when freeing JCR so that we can get rid
* of "daemon" specific memory allocated.
*/
static void my_free_jcr(JCR *jcr)
}
if (jcr->VolList) {
free_vol_list(jcr);
- }
+ }
if (jcr->dcr) {
free_dcr(jcr->dcr);
jcr->dcr = NULL;
/*
- * Search for device resource that corresponds to
+ * Search for device resource that corresponds to
* device name on command line (or default).
- *
+ *
* Returns: NULL on failure
* Device resource pointer on success
*/
found = true;
break;
}
- }
+ }
if (!found) {
/* Search for name of Device resource rather than archive name */
if (device_name[0] == '"') {
strcpy(device_name, device_name+1);
int len = strlen(device_name);
if (len > 0) {
- device_name[len-1] = 0; /* zap trailing " */
+ device_name[len-1] = 0; /* zap trailing " */
}
}
foreach_res(device, R_DEVICE) {
found = true;
break;
}
- }
+ }
}
UnlockRes();
if (!found) {
return NULL;
}
Pmsg2(0, _("Using device: \"%s\" for %s.\n"), device_name,
- read_access?"reading":"writing");
+ read_access?"reading":"writing");
return device;
}
*
* dev.c -- low level operations on device (storage device)
*
- * Kern Sibbald, MM
+ * Kern Sibbald, MM
*
* NOTE!!!! None of these routines are reentrant. You must
* use lock_device() and unlock_device() at a higher level,
* or use the xxx_device() equivalents. By moving the
* thread synchronization to a higher level, we permit
- * the higher level routines to "seize" the device and
+ * the higher level routines to "seize" the device and
* to carry out operations without worrying about who
* set what lock (i.e. race conditions).
*
* Note, this is the device dependent code, and my have
* to be modified for each system, but is meant to
* be as "generic" as possible.
- *
+ *
* The purpose of this code is to develop a SIMPLE Storage
* daemon. More complicated coding (double buffering, writer
* thread, ...) is left for a later version.
* be able to read and write the tape (he sort of tunnels through
* the locking mechanism -- see lock_dev() for details).
*
- * Now presumably somewhere higher in the chain of command
- * (device.c), someone will notice the EOT condition and
- * get a new tape up, get the tape label read, and mark
- * the label for rewriting. Then this higher level routine
+ * Now presumably somewhere higher in the chain of command
+ * (device.c), someone will notice the EOT condition and
+ * get a new tape up, get the tape label read, and mark
+ * the label for rewriting. Then this higher level routine
* will write the unwritten buffer to the new volume.
* Finally, he will release
* any blocked threads by doing a broadcast on the condition
- * variable. At that point, we should be totally back in
+ * variable. At that point, we should be totally back in
* business with no lost data.
*/
/* Forward referenced functions */
void set_os_device_parameters(DEVICE *dev);
-/*
+/*
* Allocate and initialize the DEVICE structure
* Note, if dev is non-NULL, it is already allocated,
* thus we neither allocate it nor free it. This allows
berrno be;
if (dev) {
dev->dev_errno = errno;
- }
- Emsg2(M_FATAL, 0, "Unable to stat device %s : %s\n", device->device_name,
+ }
+ Emsg2(M_FATAL, 0, "Unable to stat device %s : %s\n", device->device_name,
be.strerror());
return NULL;
}
}
if (dev->max_block_size > 1000000) {
- Emsg3(M_ERROR, 0, _("Block size %u on device %s is too large, using default %u\n"),
+ Emsg3(M_ERROR, 0, _("Block size %u on device %s is too large, using default %u\n"),
dev->max_block_size, dev->dev_name, DEFAULT_BLOCK_SIZE);
dev->max_block_size = 0;
}
if (dev->max_block_size % TAPE_BSIZE != 0) {
Emsg2(M_WARNING, 0, _("Max block size %u not multiple of device %s block size.\n"),
dev->max_block_size, dev->dev_name);
- }
-
+ }
+
dev->errmsg = get_pool_memory(PM_EMSG);
*dev->errmsg = 0;
return -1;
}
dev->use_count++;
- Mmsg2(&dev->errmsg, _("WARNING!!!! device %s opened %d times!!!\n"),
+ Mmsg2(&dev->errmsg, _("WARNING!!!! device %s opened %d times!!!\n"),
dev->dev_name, dev->use_count);
Emsg1(M_WARNING, 0, "%s", dev->errmsg);
return dev->fd;
bstrncpy(dev->VolCatInfo.VolCatName, VolName, sizeof(dev->VolCatInfo.VolCatName));
}
- Dmsg3(29, "open_dev: tape=%d dev_name=%s vol=%s\n", dev_is_tape(dev),
+ Dmsg3(29, "open_dev: tape=%d dev_name=%s vol=%s\n", dev_is_tape(dev),
dev->dev_name, dev->VolCatInfo.VolCatName);
dev->state &= ~(ST_LABEL|ST_APPEND|ST_READ|ST_EOT|ST_WEOT|ST_EOF);
dev->file_size = 0;
} else if (mode == OPEN_WRITE_ONLY) {
dev->mode = O_WRONLY | O_BINARY;
} else {
- Emsg0(M_ABORT, 0, _("Illegal mode given to open_dev.\n"));
+ Emsg0(M_ABORT, 0, _("Illegal mode given to open_dev.\n"));
}
timeout = dev->max_open_wait;
errno = 0;
continue;
}
if (errno == EBUSY && timeout-- > 0) {
- Dmsg2(100, "Device %s busy. ERR=%s\n", dev->dev_name, be.strerror());
+ Dmsg2(100, "Device %s busy. ERR=%s\n", dev->dev_name, be.strerror());
bmicrosleep(1, 0);
continue;
}
dev->dev_errno = errno;
- Mmsg2(&dev->errmsg, _("stored: unable to open device %s: ERR=%s\n"),
+ Mmsg2(&dev->errmsg, _("stored: unable to open device %s: ERR=%s\n"),
dev->dev_name, be.strerror());
/* Stop any open timer we set */
if (dev->tid) {
* Handle opening of File Archive (not a tape)
*/
if (VolName == NULL || *VolName == 0) {
- Mmsg(dev->errmsg, _("Could not open file device %s. No Volume name given.\n"),
+ Mmsg(dev->errmsg, _("Could not open file device %s. No Volume name given.\n"),
dev->dev_name);
return -1;
}
archive_name = get_pool_memory(PM_FNAME);
pm_strcpy(archive_name, dev->dev_name);
if (archive_name[strlen(archive_name)] != '/') {
- pm_strcat(archive_name, "/");
+ pm_strcat(archive_name, "/");
}
pm_strcat(archive_name, VolName);
Dmsg1(29, "open_dev: device is disk %s\n", archive_name);
} else if (mode == OPEN_WRITE_ONLY) {
dev->mode = O_WRONLY | O_BINARY;
} else {
- Emsg0(M_ABORT, 0, _("Illegal mode given to open_dev.\n"));
+ Emsg0(M_ABORT, 0, _("Illegal mode given to open_dev.\n"));
}
/* If creating file, give 0640 permissions */
if ((dev->fd = open(archive_name, dev->mode, 0640)) < 0) {
berrno be;
dev->dev_errno = errno;
- Mmsg2(&dev->errmsg, _("Could not open: %s, ERR=%s\n"), archive_name, be.strerror());
+ Mmsg2(&dev->errmsg, _("Could not open: %s, ERR=%s\n"), archive_name, be.strerror());
Emsg0(M_FATAL, 0, dev->errmsg);
} else {
dev->dev_errno = 0;
berrno be;
clrerror_dev(dev, MTREW);
if (i == dev->max_rewind_wait) {
- Dmsg1(200, "Rewind error, %s. retrying ...\n", be.strerror());
+ Dmsg1(200, "Rewind error, %s. retrying ...\n", be.strerror());
}
if (dev->dev_errno == EIO && i > 0) {
- Dmsg0(200, "Sleeping 5 seconds.\n");
+ Dmsg0(200, "Sleeping 5 seconds.\n");
bmicrosleep(5, 0);
continue;
}
- Mmsg2(&dev->errmsg, _("Rewind error on %s. ERR=%s.\n"),
+ Mmsg2(&dev->errmsg, _("Rewind error on %s. ERR=%s.\n"),
dev->dev_name, be.strerror());
return false;
}
if (lseek(dev->fd, (off_t)0, SEEK_SET) < 0) {
berrno be;
dev->dev_errno = errno;
- Mmsg2(&dev->errmsg, _("lseek error on %s. ERR=%s.\n"),
+ Mmsg2(&dev->errmsg, _("lseek error on %s. ERR=%s.\n"),
dev->dev_name, be.strerror());
return false;
}
return true;
}
-/*
+/*
* Position device to end of medium (end of data)
* Returns: 1 on succes
* 0 on error
*/
-int
+int
eod_dev(DEVICE *dev)
{
struct mtop mt_com;
if (dev_cap(dev, CAP_MTIOCGET) && (dev_cap(dev, CAP_FASTFSF) || dev_cap(dev, CAP_EOM))) {
if (dev_cap(dev, CAP_EOM)) {
- Dmsg0(100,"Using EOM for EOM\n");
+ Dmsg0(100,"Using EOM for EOM\n");
mt_com.mt_op = MTEOM;
mt_com.mt_count = 1;
}
if ((stat=ioctl(dev->fd, MTIOCTOP, (char *)&mt_com)) < 0) {
berrno be;
clrerror_dev(dev, mt_com.mt_op);
- Dmsg1(50, "ioctl error: %s\n", be.strerror());
+ Dmsg1(50, "ioctl error: %s\n", be.strerror());
update_pos_dev(dev);
- Mmsg2(&dev->errmsg, _("ioctl MTEOM error on %s. ERR=%s.\n"),
+ Mmsg2(&dev->errmsg, _("ioctl MTEOM error on %s. ERR=%s.\n"),
dev->dev_name, be.strerror());
return 0;
}
if (ioctl(dev->fd, MTIOCGET, (char *)&mt_stat) < 0) {
berrno be;
clrerror_dev(dev, -1);
- Mmsg2(&dev->errmsg, _("ioctl MTIOCGET error on %s. ERR=%s.\n"),
+ Mmsg2(&dev->errmsg, _("ioctl MTIOCGET error on %s. ERR=%s.\n"),
dev->dev_name, be.strerror());
return 0;
}
if (!rewind_dev(dev)) {
return 0;
}
- /*
+ /*
* Move file by file to the end of the tape
*/
int file_num;
for (file_num=dev->file; !(dev->state & ST_EOT); file_num++) {
- Dmsg0(200, "eod_dev: doing fsf 1\n");
+ Dmsg0(200, "eod_dev: doing fsf 1\n");
if (!fsf_dev(dev, 1)) {
- Dmsg0(200, "fsf_dev error.\n");
+ Dmsg0(200, "fsf_dev error.\n");
return 0;
}
/*
*/
if (file_num == (int)dev->file) {
struct mtget mt_stat;
- Dmsg1(100, "fsf_dev did not advance from file %d\n", file_num);
- if (dev_cap(dev, CAP_MTIOCGET) && ioctl(dev->fd, MTIOCGET, (char *)&mt_stat) == 0 &&
+ Dmsg1(100, "fsf_dev did not advance from file %d\n", file_num);
+ if (dev_cap(dev, CAP_MTIOCGET) && ioctl(dev->fd, MTIOCGET, (char *)&mt_stat) == 0 &&
mt_stat.mt_fileno >= 0) {
- Dmsg2(100, "Adjust file from %d to %d\n", dev->file , mt_stat.mt_fileno);
+ Dmsg2(100, "Adjust file from %d to %d\n", dev->file , mt_stat.mt_fileno);
dev->file = mt_stat.mt_fileno;
}
stat = 0;
stat = bsf_dev(dev, 1);
/* If BSF worked and fileno is known (not -1), set file */
if (dev_cap(dev, CAP_MTIOCGET) && ioctl(dev->fd, MTIOCGET, (char *)&mt_stat) == 0 && mt_stat.mt_fileno >= 0) {
- Dmsg2(100, "BSFATEOF adjust file from %d to %d\n", dev->file , mt_stat.mt_fileno);
+ Dmsg2(100, "BSFATEOF adjust file from %d to %d\n", dev->file , mt_stat.mt_fileno);
dev->file = mt_stat.mt_fileno;
} else {
dev->file++; /* wing it -- not correct on all OSes */
if (pos < 0) {
berrno be;
dev->dev_errno = errno;
- Pmsg1(000, "Seek error: ERR=%s\n", be.strerror());
- Mmsg2(&dev->errmsg, _("lseek error on %s. ERR=%s.\n"),
+ Pmsg1(000, "Seek error: ERR=%s\n", be.strerror());
+ Mmsg2(&dev->errmsg, _("lseek error on %s. ERR=%s.\n"),
dev->dev_name, be.strerror());
ok = false;
} else {
}
-/*
+/*
* Return the status of the device. This was meant
* to be a generic routine. Unfortunately, it doesn't
* seem possible (at least I do not know how to do it
if (ioctl(dev->fd, MTIOCGET, (char *)&mt_stat) < 0) {
berrno be;
dev->dev_errno = errno;
- Mmsg2(&dev->errmsg, _("ioctl MTIOCGET error on %s. ERR=%s.\n"),
+ Mmsg2(&dev->errmsg, _("ioctl MTIOCGET error on %s. ERR=%s.\n"),
dev->dev_name, be.strerror());
return 0;
}
#if defined(HAVE_LINUX_OS)
if (GMT_EOF(mt_stat.mt_gstat)) {
stat |= BMT_EOF;
- Dmsg0(-20, " EOF");
+ Dmsg0(-20, " EOF");
}
if (GMT_BOT(mt_stat.mt_gstat)) {
stat |= BMT_BOT;
- Dmsg0(-20, " BOT");
+ Dmsg0(-20, " BOT");
}
if (GMT_EOT(mt_stat.mt_gstat)) {
stat |= BMT_EOT;
- Dmsg0(-20, " EOT");
+ Dmsg0(-20, " EOT");
}
if (GMT_SM(mt_stat.mt_gstat)) {
stat |= BMT_SM;
- Dmsg0(-20, " SM");
+ Dmsg0(-20, " SM");
}
if (GMT_EOD(mt_stat.mt_gstat)) {
stat |= BMT_EOD;
- Dmsg0(-20, " EOD");
+ Dmsg0(-20, " EOD");
}
if (GMT_WR_PROT(mt_stat.mt_gstat)) {
stat |= BMT_WR_PROT;
- Dmsg0(-20, " WR_PROT");
+ Dmsg0(-20, " WR_PROT");
}
if (GMT_ONLINE(mt_stat.mt_gstat)) {
stat |= BMT_ONLINE;
- Dmsg0(-20, " ONLINE");
+ Dmsg0(-20, " ONLINE");
}
if (GMT_DR_OPEN(mt_stat.mt_gstat)) {
stat |= BMT_DR_OPEN;
- Dmsg0(-20, " DR_OPEN");
+ Dmsg0(-20, " DR_OPEN");
}
if (GMT_IM_REP_EN(mt_stat.mt_gstat)) {
stat |= BMT_IM_REP_EN;
- Dmsg0(-20, " IM_REP_EN");
+ Dmsg0(-20, " IM_REP_EN");
}
#endif /* !SunOS && !OSF */
if (dev_cap(dev, CAP_MTIOCGET)) {
- Dmsg2(-20, " file=%d block=%d\n", mt_stat.mt_fileno, mt_stat.mt_blkno);
+ Dmsg2(-20, " file=%d block=%d\n", mt_stat.mt_fileno, mt_stat.mt_blkno);
} else {
- Dmsg2(-20, " file=%d block=%d\n", -1, -1);
+ Dmsg2(-20, " file=%d block=%d\n", -1, -1);
}
} else {
stat |= BMT_ONLINE | BMT_BOT;
if (dev_cap(dev, CAP_OFFLINEUNMOUNT)) {
return offline_dev(dev);
} else {
- /*
+ /*
* Note, this rewind probably should not be here (it wasn't
* in prior versions of Bacula), but on FreeBSD, this is
* needed in the case the tape was "frozen" due to an error
}
}
-/*
- * Foward space a file
+/*
+ * Foward space a file
* Returns: true on success
* false on failure
*/
bool
fsf_dev(DEVICE *dev, int num)
-{
+{
struct mtget mt_stat;
struct mtop mt_com;
int stat = 0;
if (dev->state & ST_EOF) {
Dmsg0(200, "ST_EOF set on entry to FSF\n");
}
-
+
Dmsg0(100, "fsf_dev\n");
dev->block_num = 0;
/*
* If Fast forward space file is set, then we
* use MTFSF to forward space and MTIOCGET
- * to get the file position. We assume that
+ * to get the file position. We assume that
* the SCSI driver will ensure that we do not
* forward space past the end of the medium.
*/
if (stat < 0 || ioctl(dev->fd, MTIOCGET, (char *)&mt_stat) < 0) {
berrno be;
dev->state |= ST_EOT;
- Dmsg0(200, "Set ST_EOT\n");
+ Dmsg0(200, "Set ST_EOT\n");
clrerror_dev(dev, MTFSF);
- Mmsg2(dev->errmsg, _("ioctl MTFSF error on %s. ERR=%s.\n"),
+ Mmsg2(dev->errmsg, _("ioctl MTFSF error on %s. ERR=%s.\n"),
dev->dev_name, be.strerror());
- Dmsg1(200, "%s", dev->errmsg);
+ Dmsg1(200, "%s", dev->errmsg);
return false;
}
Dmsg2(200, "fsf file=%d block=%d\n", mt_stat.mt_fileno, mt_stat.mt_blkno);
dev->file_size = 0;
return true;
- /*
+ /*
* Here if CAP_FSF is set, and virtually all drives
* these days support it, we read a record, then forward
* space one file. Using this procedure, which is slow,
mt_com.mt_op = MTFSF;
mt_com.mt_count = 1;
while (num-- && !(dev->state & ST_EOT)) {
- Dmsg0(100, "Doing read before fsf\n");
+ Dmsg0(100, "Doing read before fsf\n");
if ((stat = read(dev->fd, (char *)rbuf, rbuf_len)) < 0) {
if (errno == ENOMEM) { /* tape record exceeds buf len */
stat = rbuf_len; /* This is OK */
berrno be;
dev->state |= ST_EOT;
clrerror_dev(dev, -1);
- Dmsg2(100, "Set ST_EOT read errno=%d. ERR=%s\n", dev->dev_errno,
+ Dmsg2(100, "Set ST_EOT read errno=%d. ERR=%s\n", dev->dev_errno,
be.strerror());
- Mmsg2(dev->errmsg, _("read error on %s. ERR=%s.\n"),
+ Mmsg2(dev->errmsg, _("read error on %s. ERR=%s.\n"),
dev->dev_name, be.strerror());
- Dmsg1(100, "%s", dev->errmsg);
+ Dmsg1(100, "%s", dev->errmsg);
break;
}
}
if (stat == 0) { /* EOF */
update_pos_dev(dev);
- Dmsg1(100, "End of File mark from read. File=%d\n", dev->file+1);
+ Dmsg1(100, "End of File mark from read. File=%d\n", dev->file+1);
/* Two reads of zero means end of tape */
if (dev->state & ST_EOF) {
dev->state |= ST_EOT;
- Dmsg0(100, "Set ST_EOT\n");
+ Dmsg0(100, "Set ST_EOT\n");
break;
} else {
dev->state |= ST_EOF;
dev->state &= ~(ST_EOF|ST_EOT);
}
- Dmsg0(100, "Doing MTFSF\n");
+ Dmsg0(100, "Doing MTFSF\n");
stat = ioctl(dev->fd, MTIOCTOP, (char *)&mt_com);
if (stat < 0) { /* error => EOT */
berrno be;
dev->state |= ST_EOT;
- Dmsg0(100, "Set ST_EOT\n");
+ Dmsg0(100, "Set ST_EOT\n");
clrerror_dev(dev, MTFSF);
- Mmsg2(&dev->errmsg, _("ioctl MTFSF error on %s. ERR=%s.\n"),
+ Mmsg2(&dev->errmsg, _("ioctl MTFSF error on %s. ERR=%s.\n"),
dev->dev_name, be.strerror());
- Dmsg0(100, "Got < 0 for MTFSF\n");
- Dmsg1(100, "%s", dev->errmsg);
+ Dmsg0(100, "Got < 0 for MTFSF\n");
+ Dmsg1(100, "%s", dev->errmsg);
} else {
dev->state |= ST_EOF; /* just read EOF */
dev->file++;
dev->file_addr = 0;
dev->file_size = 0;
- }
+ }
}
free_memory(rbuf);
-
+
/*
* No FSF, so use FSR to simulate it
*/
}
if (dev->state & ST_EOT) {
dev->dev_errno = 0;
- Mmsg1(dev->errmsg, _("Device %s at End of Tape.\n"), dev->dev_name);
+ Mmsg1(dev->errmsg, _("Device %s at End of Tape.\n"), dev->dev_name);
stat = -1;
} else {
stat = 0;
return stat == 0;
}
-/*
- * Backward space a file
+/*
+ * Backward space a file
* Returns: false on failure
* true on success
*/
bool
bsf_dev(DEVICE *dev, int num)
-{
+{
struct mtop mt_com;
int stat;
}
-/*
+/*
* Foward space a record
* Returns: false on failure
* true on success
*/
bool
fsr_dev(DEVICE *dev, int num)
-{
+{
struct mtop mt_com;
int stat;
clrerror_dev(dev, MTFSR);
Dmsg1(100, "FSF fail: ERR=%s\n", be.strerror());
if (dev_cap(dev, CAP_MTIOCGET) && ioctl(dev->fd, MTIOCGET, (char *)&mt_stat) == 0 && mt_stat.mt_fileno >= 0) {
- Dmsg4(100, "Adjust from %d:%d to %d:%d\n", dev->file,
+ Dmsg4(100, "Adjust from %d:%d to %d:%d\n", dev->file,
dev->block_num, mt_stat.mt_fileno, mt_stat.mt_blkno);
dev->file = mt_stat.mt_fileno;
dev->block_num = mt_stat.mt_blkno;
return stat == 0;
}
-/*
+/*
* Backward space a record
* Returns: false on failure
* true on success
*/
bool
bsr_dev(DEVICE *dev, int num)
-{
+{
struct mtop mt_com;
int stat;
return stat == 0;
}
-/*
+/*
* Reposition the device to file, block
* Returns: false on failure
* true on success
*/
bool
reposition_dev(DEVICE *dev, uint32_t file, uint32_t block)
-{
+{
if (dev->fd < 0) {
dev->dev_errno = EBADF;
Mmsg0(dev->errmsg, _("Bad call to reposition_dev. Archive not open\n"));
if (lseek(dev->fd, pos, SEEK_SET) == (off_t)-1) {
berrno be;
dev->dev_errno = errno;
- Mmsg2(dev->errmsg, _("lseek error on %s. ERR=%s.\n"),
+ Mmsg2(dev->errmsg, _("lseek error on %s. ERR=%s.\n"),
dev->dev_name, be.strerror());
return false;
}
dev->file_addr = pos;
return true;
}
- Dmsg4(100, "reposition_dev from %u:%u to %u:%u\n",
+ Dmsg4(100, "reposition_dev from %u:%u to %u:%u\n",
dev->file, dev->block_num, file, block);
if (file < dev->file) {
Dmsg0(100, "Rewind_dev\n");
if (file > dev->file) {
Dmsg1(100, "fsf %d\n", file-dev->file);
if (!fsf_dev(dev, file-dev->file)) {
- Dmsg1(100, "fsf failed! ERR=%s\n", strerror_dev(dev));
+ Dmsg1(100, "fsf failed! ERR=%s\n", strerror_dev(dev));
return false;
}
Dmsg2(100, "wanted_file=%d at_file=%d\n", file, dev->file);
* Returns: 0 on success
* non-zero on failure
*/
-int
+int
weof_dev(DEVICE *dev, int num)
-{
+{
struct mtop mt_com;
int stat;
berrno be;
clrerror_dev(dev, MTWEOF);
if (stat == -1) {
- Mmsg2(dev->errmsg, _("ioctl MTWEOF error on %s. ERR=%s.\n"),
+ Mmsg2(dev->errmsg, _("ioctl MTWEOF error on %s. ERR=%s.\n"),
dev->dev_name, be.strerror());
}
}
if (errno == ENOTTY || errno == ENOSYS) { /* Function not implemented */
switch (func) {
case -1:
- Emsg0(M_ABORT, 0, "Got ENOTTY on read/write!\n");
+ Emsg0(M_ABORT, 0, "Got ENOTTY on read/write!\n");
break;
case MTWEOF:
- msg = "WTWEOF";
+ msg = "WTWEOF";
dev->capabilities &= ~CAP_EOF; /* turn off feature */
break;
#ifdef MTEOM
case MTEOM:
- msg = "WTEOM";
+ msg = "WTEOM";
dev->capabilities &= ~CAP_EOM; /* turn off feature */
break;
-#endif
+#endif
case MTFSF:
- msg = "MTFSF";
+ msg = "MTFSF";
dev->capabilities &= ~CAP_FSF; /* turn off feature */
break;
case MTBSF:
- msg = "MTBSF";
+ msg = "MTBSF";
dev->capabilities &= ~CAP_BSF; /* turn off feature */
break;
case MTFSR:
- msg = "MTFSR";
+ msg = "MTFSR";
dev->capabilities &= ~CAP_FSR; /* turn off feature */
break;
case MTBSR:
- msg = "MTBSR";
+ msg = "MTBSR";
dev->capabilities &= ~CAP_BSR; /* turn off feature */
break;
default:
- msg = "Unknown";
+ msg = "Unknown";
break;
}
if (msg != NULL) {
dev->dev_errno = ENOSYS;
- Mmsg1(&dev->errmsg, _("This device does not support %s.\n"), msg);
+ Mmsg1(&dev->errmsg, _("This device does not support %s.\n"), msg);
Emsg0(M_ERROR, 0, dev->errmsg);
}
}
/* On some systems such as NetBSD, this clears all errors */
- ioctl(dev->fd, MTIOCGET, (char *)&mt_stat);
+ ioctl(dev->fd, MTIOCGET, (char *)&mt_stat);
/* Found on Linux */
#ifdef MTIOCLRERR
dev->use_count = 0;
}
-/*
+/*
* Close the device
*/
void
} else if (dev->use_count > 0) {
dev->use_count--;
}
-
+
#ifdef FULL_DEBUG
ASSERT(dev->use_count >= 0);
#endif
bool
dev_is_tape(DEVICE *dev)
-{
+{
return (dev->state & ST_TAPE) ? true : false;
}
return dev->file;
}
-/*
+/*
* Free memory allocated for the device
*/
void
/* #define NEW_LOCK 1 */
-#define new_lock_device(dev) _new_lock_device(__FILE__, __LINE__, (dev))
+#define new_lock_device(dev) _new_lock_device(__FILE__, __LINE__, (dev))
#define new_lock_device_state(dev,state) _new_lock_device(__FILE__, __LINE__, (dev), (state))
#define new_unlock_device(dev) _new_unlock_device(__FILE__, __LINE__, (dev))
enum {
OPEN_READ_WRITE = 0,
OPEN_READ_ONLY,
- OPEN_WRITE_ONLY
+ OPEN_WRITE_ONLY
};
/* Generic status bits returned from status_dev() */
/* Device state bits */
#define ST_OPENED (1<<0) /* set when device opened */
-#define ST_TAPE (1<<1) /* is a tape device */
+#define ST_TAPE (1<<1) /* is a tape device */
#define ST_FILE (1<<2) /* is a file device */
#define ST_FIFO (1<<3) /* is a fifo device */
#define ST_PROG (1<<4) /* is a program device */
BST_UNMOUNTED, /* User unmounted device */
BST_WAITING_FOR_SYSOP, /* Waiting for operator to mount tape */
BST_DOING_ACQUIRE, /* Opening/validating/moving tape */
- BST_WRITING_LABEL, /* Labeling a tape */
+ BST_WRITING_LABEL, /* Labeling a tape */
BST_UNMOUNTED_WAITING_FOR_SYSOP, /* Closed by user during mount request */
BST_MOUNT /* Mount request */
};
uint64_t VolWriteTime; /* time spent writing this Volume */
char VolCatStatus[20]; /* Volume status */
char VolCatName[MAX_NAME_LENGTH]; /* Desired volume to mount */
-};
+};
typedef struct s_steal_lock {
/*
* Device structure definition. There is one of these for
- * each physical device. Everything here is "global" to
+ * each physical device. Everything here is "global" to
* that device and effects all jobs using the device.
*/
struct DEVICE {
VOLUME_CAT_INFO VolCatInfo; /* Volume Catalog Information */
VOLUME_LABEL VolHdr; /* Actual volume label */
-
+
/* Device wait times ***FIXME*** look at durations */
char BadVolName[MAX_NAME_LENGTH]; /* Last wrong Volume mounted */
bool poll; /* set to poll Volume */
};
/*
- * Device Context (or Control) Record.
- * There is one of these records for each Job that is using
+ * Device Context (or Control) Record.
+ * There is one of these records for each Job that is using
* the device. Items in this record are "local" to the Job and
* do not affect other Jobs.
*/
/*
*
- * Higher Level Device routines.
- * Knows about Bacula tape labels and such
+ * Higher Level Device routines.
+ * Knows about Bacula tape labels and such
*
* NOTE! In general, subroutines that have the word
* "device" in the name do locking. Subroutines
* yyy_dev(), all is OK, but if xxx_device()
* calls yyy_device(), everything will hang.
* Obviously, no zzz_dev() is allowed to call
- * a www_device() or everything falls apart.
+ * a www_device() or everything falls apart.
*
* Concerning the routines lock_device() and block_device()
* see the end of this module for details. In general,
* blocking a device leaves it in a state where all threads
- * other than the current thread block when they attempt to
+ * other than the current thread block when they attempt to
* lock the device. They remain suspended (blocked) until the device
* is unblocked. So, a device is blocked during an operation
* that takes a long time (initialization, mounting a new
* volume, ...) locking a device is done for an operation
- * that takes a short time such as writing data to the
+ * that takes a short time such as writing data to the
* device.
*
*
* Kern Sibbald, MM, MMI
- *
+ *
* Version $Id$
*/
/*
* Here are a few things to know:
* dcr->VolCatInfo contains the info on the "current" tape for this job.
* dev->VolCatInfo contains the info on the tape in the drive.
- * The tape in the drive could have changed several times since
+ * The tape in the drive could have changed several times since
* the last time the job used it (jcr->VolCatInfo).
* dcr->VolumeName is the name of the current/desired tape in the drive.
*
- * We enter with device locked, and
+ * We enter with device locked, and
* exit with device locked.
*
* Note, we are called only from one place in block.c
unlock_device(dev);
bstrncpy(dev->VolCatInfo.VolCatStatus, "Full", sizeof(dev->VolCatInfo.VolCatStatus));
- Dmsg2(100, "Call update_vol_info Stat=%s Vol=%s\n",
+ Dmsg2(100, "Call update_vol_info Stat=%s Vol=%s\n",
dev->VolCatInfo.VolCatStatus, dev->VolCatInfo.VolCatName);
dev->VolCatInfo.VolCatFiles = dev->file; /* set number of files */
dev->VolCatInfo.VolCatJobs++; /* increment number of jobs */
dcr->block = label_blk;
/* Inform User about end of medium */
- Jmsg(jcr, M_INFO, 0, _("End of medium on Volume \"%s\" Bytes=%s Blocks=%s at %s.\n"),
+ Jmsg(jcr, M_INFO, 0, _("End of medium on Volume \"%s\" Bytes=%s Blocks=%s at %s.\n"),
PrevVolName, edit_uint64_with_commas(dev->VolCatInfo.VolCatBytes, b1),
edit_uint64_with_commas(dev->VolCatInfo.VolCatBlocks, b2),
bstrftime(dt, sizeof(dt), time(NULL)));
Jmsg(jcr, M_INFO, 0, _("New volume \"%s\" mounted on device %s at %s.\n"),
dcr->VolumeName, dev_name(dev), bstrftime(dt, sizeof(dt), time(NULL)));
- /*
+ /*
* If this is a new tape, the label_blk will contain the
* label, so write it now. If this is a previously
* used tape, mount_next_write_volume() will return an
free_block(label_blk);
dcr->block = block;
- /*
- * Walk through all attached jcrs indicating the volume has changed
+ /*
+ * Walk through all attached jcrs indicating the volume has changed
*/
Dmsg1(100, "Walk attached jcrs. Volume=%s\n", dev->VolCatInfo.VolCatName);
// for (JCR *mjcr=NULL; (mjcr=next_attached_jcr(dev, mjcr)); ) {
void set_new_file_parameters(DCR *dcr)
{
DEVICE *dev = dcr->dev;
-
+
/* Set new start/end positions */
if (dev_state(dev, ST_TAPE)) {
dcr->StartBlock = dev->block_num;
/*
- * First Open of the device. Expect dev to already be initialized.
+ * First Open of the device. Expect dev to already be initialized.
*
- * This routine is used only when the Storage daemon starts
+ * This routine is used only when the Storage daemon starts
* and always_open is set, and in the stand-alone utility
* routines such as bextract.
*
* Note, opening of a normal file is deferred to later so
* that we can get the filename; the device_name for
- * a file is the directory only.
+ * a file is the directory only.
*
* Returns: false on failure
* true on success
}
Dmsg0(129, "Opening device.\n");
if (open_dev(dev, NULL, mode) < 0) {
- Emsg1(M_FATAL, 0, _("dev open failed: %s\n"), dev->errmsg);
+ Emsg1(M_FATAL, 0, _("dev open failed: %s\n"), dev->errmsg);
unlock_device(dev);
return false;
}
return true;
}
-/*
- * Make sure device is open, if not do so
+/*
+ * Make sure device is open, if not do so
*/
bool open_device(DCR *dcr)
{
if (open_dev(dev, dcr->VolCatInfo.VolCatName, mode) < 0) {
/* If polling, ignore the error */
if (!dev->poll) {
- Jmsg2(dcr->jcr, M_FATAL, 0, _("Unable to open device %s. ERR=%s\n"),
+ Jmsg2(dcr->jcr, M_FATAL, 0, _("Unable to open device %s. ERR=%s\n"),
dev_name(dev), strerror_dev(dev));
}
return false;
}
}
-/*
+/*
* When dev_blocked is set, all threads EXCEPT thread with id no_wait_id
* must wait. The no_wait_id thread is out obtaining a new volume
* and preparing the label.
while (dev->dev_blocked) {
if ((stat = pthread_cond_wait(&dev->wait, &dev->mutex)) != 0) {
V(dev->mutex);
- Emsg1(M_ABORT, 0, _("pthread_cond_wait failure. ERR=%s\n"),
+ Emsg1(M_ABORT, 0, _("pthread_cond_wait failure. ERR=%s\n"),
strerror(stat));
}
}
case BST_UNMOUNTED:
return "user unmounted device";
case BST_WAITING_FOR_SYSOP:
- return "waiting for operator action";
+ return "waiting for operator action";
case BST_DOING_ACQUIRE:
return "opening, validating, or positioning tape";
case BST_WRITING_LABEL:
}
}
-void _unlock_device(const char *file, int line, DEVICE *dev)
+void _unlock_device(const char *file, int line, DEVICE *dev)
{
Dmsg2(500, "unlock from %s:%d\n", file, line);
V(dev->mutex);
}
-/*
+/*
* Block all other threads from using the device
* Device must already be locked. After this call,
* the device is blocked to any thread calling lock_device(),
/*
* Enter with device blocked by us but not locked
- * Exit with device locked, and blocked by previous owner
+ * Exit with device locked, and blocked by previous owner
*/
-void _give_back_device_lock(const char *file, int line, DEVICE *dev, bsteal_lock_t *hold)
+void _give_back_device_lock(const char *file, int line, DEVICE *dev, bsteal_lock_t *hold)
{
- Dmsg4(500, "return lock. old=%d new=%d from %s:%d\n",
+ Dmsg4(500, "return lock. old=%d new=%d from %s:%d\n",
dev->dev_blocked, hold->dev_blocked, file, line);
P(dev->mutex);
dev->dev_blocked = hold->dev_blocked;
/*
* This file handles accepting Director Commands
*
- * Most Director commands are handled here, with the
- * exception of the Job command command and subsequent
+ * Most Director commands are handled here, with the
+ * exception of the Job command command and subsequent
* subcommands that are handled
- * in job.c.
+ * in job.c.
*
* N.B. in this file, in general we must use P(dev->mutex) rather
* than lock_device(dev) so that we can examine the blocked
* Kern Sibbald, May MMI
*
* Version $Id$
- *
+ *
*/
/*
Copyright (C) 2001-2004 Kern Sibbald and John Walker
static DEVICE *find_device(JCR *jcr, POOL_MEM &dname);
static void read_volume_label(JCR *jcr, DEVICE *dev, int Slot);
static void label_volume_if_ok(JCR *jcr, DEVICE *dev, char *oldname,
- char *newname, char *poolname,
+ char *newname, char *poolname,
int Slot, int relabel);
static bool try_autoload_device(JCR *jcr, int slot, const char *VolName);
int monitoraccess; /* specify if monitors have access to this function */
};
-/*
- * The following are the recognized commands from the Director.
+/*
+ * The following are the recognized commands from the Director.
*/
static struct s_cmds cmds[] = {
{"JobId=", job_cmd, 0}, /* start Job */
};
-/*
- * Connection request. We accept connections either from the
+/*
+ * Connection request. We accept connections either from the
* Director or a Client (File daemon).
- *
+ *
* Note, we are running as a seperate thread of the Storage daemon.
* and it is because a Director has made a connection with
- * us on the "Message" channel.
+ * us on the "Message" channel.
*
- * Basic tasks done here:
+ * Basic tasks done here:
* - Create a JCR record
* - If it was from the FD, call handle_filed_connection()
* - Authenticate the Director
return NULL;
}
- /*
+ /*
* Do a sanity check on the message received
*/
if (bs->msglen < 25 || bs->msglen > (int)sizeof(name)-25) {
bnet_close(bs);
return NULL;
}
- /*
+ /*
* See if this is a File daemon connection. If so
* call FD handler.
*/
handle_filed_connection(bs, name);
return NULL;
}
-
+
Dmsg0(110, "Start Dir Job\n");
jcr = new_jcr(sizeof(JCR), stored_free_jcr); /* create Job Control Record */
jcr->dir_bsock = bs; /* save Director bsock */
for (i=0; cmds[i].cmd; i++) {
if (strncmp(cmds[i].cmd, bs->msg, strlen(cmds[i].cmd)) == 0) {
if ((!cmds[i].monitoraccess) && (jcr->director->monitor)) {
- Dmsg1(100, "Command %s illegal.\n", cmds[i].cmd);
+ Dmsg1(100, "Command %s illegal.\n", cmds[i].cmd);
bnet_fsend(bs, illegal_cmd);
bnet_sig(bs, BNET_EOD);
break;
}
if (!cmds[i].func(jcr)) { /* do command */
quit = true; /* error, get out */
- Dmsg1(190, "Command %s requsts quit\n", cmds[i].cmd);
+ Dmsg1(190, "Command %s requsts quit\n", cmds[i].cmd);
}
found = true; /* indicate command found */
break;
if (sscanf(dir->msg, "cancel Job=%127s", Job) == 1) {
if (!(jcr=get_jcr_by_full_name(Job))) {
- bnet_fsend(dir, _("3992 Job %s not found.\n"), Job);
+ bnet_fsend(dir, _("3992 Job %s not found.\n"), Job);
} else {
P(jcr->mutex);
oldStatus = jcr->JobStatus;
jcr->dcr->dev->dev_blocked == BST_UNMOUNTED_WAITING_FOR_SYSOP)) {
pthread_cond_signal(&jcr->dcr->dev->wait_next_vol);
}
- bnet_fsend(dir, _("3000 Job %s marked to be canceled.\n"), jcr->Job);
+ bnet_fsend(dir, _("3000 Job %s marked to be canceled.\n"), jcr->Job);
free_jcr(jcr);
}
} else {
* Label a tape
*
*/
-static bool label_cmd(JCR *jcr)
+static bool label_cmd(JCR *jcr)
{
return do_label(jcr, 0);
}
-static bool relabel_cmd(JCR *jcr)
+static bool relabel_cmd(JCR *jcr)
{
return do_label(jcr, 1);
}
-static bool do_label(JCR *jcr, int relabel)
+static bool do_label(JCR *jcr, int relabel)
{
POOLMEM *newname, *oldname, *poolname, *mtype;
POOL_MEM dname;
BSOCK *dir = jcr->dir_bsock;
DEVICE *dev;
bool ok = false;
- int slot;
+ int slot;
newname = get_memory(dir->msglen+1);
oldname = get_memory(dir->msglen+1);
if (!(dev->state & ST_OPENED)) {
label_volume_if_ok(jcr, dev, oldname, newname, poolname, slot, relabel);
force_close_dev(dev);
- /* Under certain "safe" conditions, we can steal the lock */
- } else if (dev->dev_blocked &&
+ /* Under certain "safe" conditions, we can steal the lock */
+ } else if (dev->dev_blocked &&
(dev->dev_blocked == BST_UNMOUNTED ||
dev->dev_blocked == BST_WAITING_FOR_SYSOP ||
dev->dev_blocked == BST_UNMOUNTED_WAITING_FOR_SYSOP)) {
label_volume_if_ok(jcr, dev, oldname, newname, poolname, slot, relabel);
} else if (dev_state(dev, ST_READ) || dev->num_writers) {
if (dev_state(dev, ST_READ)) {
- bnet_fsend(dir, _("3911 Device %s is busy with 1 reader.\n"),
+ bnet_fsend(dir, _("3911 Device %s is busy with 1 reader.\n"),
dev_name(dev));
} else {
- bnet_fsend(dir, _("3912 Device %s is busy with %d writer(s).\n"),
+ bnet_fsend(dir, _("3912 Device %s is busy with %d writer(s).\n"),
dev_name(dev), dev->num_writers);
}
} else { /* device not being used */
}
V(dev->mutex);
} else {
- bnet_fsend(dir, _("3999 Device \"%s\" not found\n"), dname.c_str());
+ bnet_fsend(dir, _("3999 Device \"%s\" not found\n"), dname.c_str());
}
} else {
/* NB dir->msg gets clobbered in bnet_fsend, so save command */
return true;
}
-/*
+/*
* Read the tape label and determine if we can safely
* label the tape (not a Bacula volume), then label it.
*
* Enter with the mutex set
*/
-static void label_volume_if_ok(JCR *jcr, DEVICE *dev, char *oldname,
+static void label_volume_if_ok(JCR *jcr, DEVICE *dev, char *oldname,
char *newname, char *poolname,
int slot, int relabel)
{
bsteal_lock_t hold;
DCR *dcr = jcr->dcr;
int label_status;
-
+
dcr->dev = dev;
steal_device_lock(dev, &hold, BST_WRITING_LABEL);
-
+
if (!try_autoload_device(jcr, slot, newname)) {
goto bail_out; /* error */
}
/* See what we have for a Volume */
- label_status = read_dev_volume_label(dcr);
+ label_status = read_dev_volume_label(dcr);
switch(label_status) {
case VOL_NAME_ERROR:
case VOL_VERSION_ERROR:
case VOL_OK:
if (!relabel) {
bnet_fsend(dir, _(
- "3911 Cannot label Volume because it is already labeled: \"%s\"\n"),
+ "3911 Cannot label Volume because it is already labeled: \"%s\"\n"),
dev->VolHdr.VolName);
break;
}
/* Relabel request. If oldname matches, continue */
if (strcmp(oldname, dev->VolHdr.VolName) != 0) {
- bnet_fsend(dir, _("Wrong volume mounted.\n"));
+ bnet_fsend(dir, _("Wrong volume mounted.\n"));
break;
}
/* Fall through wanted! */
case VOL_IO_ERROR:
case VOL_NO_LABEL:
if (!write_new_volume_label_to_dev(dcr, newname, poolname)) {
- bnet_fsend(dir, _("3912 Failed to label Volume: ERR=%s\n"), strerror_dev(dev));
+ bnet_fsend(dir, _("3912 Failed to label Volume: ERR=%s\n"), strerror_dev(dev));
break;
}
bstrncpy(dcr->VolumeName, newname, sizeof(dcr->VolumeName));
/* The following 3000 OK label. string is scanned in ua_label.c */
- bnet_fsend(dir, "3000 OK label. Volume=%s Device=%s\n",
+ bnet_fsend(dir, "3000 OK label. Volume=%s Device=%s\n",
newname, dev_name(dev));
break;
case VOL_NO_MEDIA:
bnet_fsend(dir, _("3912 Failed to label Volume: ERR=%s\n"), strerror_dev(dev));
break;
default:
- bnet_fsend(dir, _("3913 Cannot label Volume. \
-Unknown status %d from read_volume_label()\n"), label_status);
+ bnet_fsend(dir, _("3913 Cannot label Volume. "
+"Unknown status %d from read_volume_label()\n"), label_status);
break;
}
}
-/*
+/*
* Read the tape label
*
* Enter with the mutex set
BSOCK *dir = jcr->dir_bsock;
bsteal_lock_t hold;
DEVICE *dev = dcr->dev;
-
+
steal_device_lock(dev, &hold, BST_DOING_ACQUIRE);
-
+
dcr->VolumeName[0] = 0;
dev->state &= ~ST_LABEL; /* force read of label */
- switch (read_dev_volume_label(dcr)) {
+ switch (read_dev_volume_label(dcr)) {
case VOL_OK:
bnet_fsend(dir, _("3001 Mounted Volume: %s\n"), dev->VolHdr.VolName);
ok = true;
foreach_res(device, R_DEVICE) {
/* Find resource, and make sure we were able to open it */
if (strcmp(device->hdr.name, dname.c_str()) == 0 && device->dev) {
- Dmsg1(20, "Found device %s\n", device->hdr.name);
+ Dmsg1(20, "Found device %s\n", device->hdr.name);
jcr->device = device;
found = true;
break;
switch (dev->dev_blocked) { /* device blocked? */
case BST_WAITING_FOR_SYSOP:
/* Someone is waiting, wake him */
- Dmsg0(100, "Waiting for mount. Attempting to wake thread\n");
+ Dmsg0(100, "Waiting for mount. Attempting to wake thread\n");
dev->dev_blocked = BST_MOUNT;
- bnet_fsend(dir, "3001 OK mount. Device=%s\n", dev_name(dev));
+ bnet_fsend(dir, "3001 OK mount. Device=%s\n", dev_name(dev));
pthread_cond_signal(&dev->wait_next_vol);
break;
case BST_UNMOUNTED:
/* We freed the device, so reopen it and wake any waiting threads */
if (open_dev(dev, NULL, OPEN_READ_WRITE) < 0) {
- bnet_fsend(dir, _("3901 open device failed: ERR=%s\n"),
+ bnet_fsend(dir, _("3901 open device failed: ERR=%s\n"),
strerror_dev(dev));
break;
}
read_dev_volume_label(dcr);
if (dev->dev_blocked == BST_UNMOUNTED) {
/* We blocked the device, so unblock it */
- Dmsg0(100, "Unmounted. Unblocking device\n");
+ Dmsg0(100, "Unmounted. Unblocking device\n");
read_label(dcr); /* this should not be necessary */
unblock_device(dev);
} else {
- Dmsg0(100, "Unmounted waiting for mount. Attempting to wake thread\n");
+ Dmsg0(100, "Unmounted waiting for mount. Attempting to wake thread\n");
dev->dev_blocked = BST_MOUNT;
}
if (dev_state(dev, ST_LABEL)) {
- bnet_fsend(dir, _("3001 Device %s is mounted with Volume \"%s\"\n"),
+ bnet_fsend(dir, _("3001 Device %s is mounted with Volume \"%s\"\n"),
dev_name(dev), dev->VolHdr.VolName);
} else {
- bnet_fsend(dir, _("3905 Device %s open but no Bacula volume is mounted.\n"
- "If this is not a blank tape, try unmounting and remounting the Volume.\n"),
+ bnet_fsend(dir, _("3905 Device %s open but no Bacula volume is mounted.\n"
+ "If this is not a blank tape, try unmounting and remounting the Volume.\n"),
dev_name(dev));
}
pthread_cond_signal(&dev->wait_next_vol);
break;
case BST_DOING_ACQUIRE:
- bnet_fsend(dir, _("3001 Device %s is mounted; doing acquire.\n"),
+ bnet_fsend(dir, _("3001 Device %s is mounted; doing acquire.\n"),
dev_name(dev));
break;
case BST_WRITING_LABEL:
- bnet_fsend(dir, _("3903 Device %s is being labeled.\n"), dev_name(dev));
+ bnet_fsend(dir, _("3903 Device %s is being labeled.\n"), dev_name(dev));
break;
case BST_NOT_BLOCKED:
if (dev_state(dev, ST_OPENED)) {
if (dev_state(dev, ST_LABEL)) {
- bnet_fsend(dir, _("3001 Device %s is mounted with Volume \"%s\"\n"),
+ bnet_fsend(dir, _("3001 Device %s is mounted with Volume \"%s\"\n"),
dev_name(dev), dev->VolHdr.VolName);
} else {
- bnet_fsend(dir, _("3905 Device %s open but no Bacula volume is mounted.\n"
- "If this is not a blank tape, try unmounting and remounting the Volume.\n"),
+ bnet_fsend(dir, _("3905 Device %s open but no Bacula volume is mounted.\n"
+ "If this is not a blank tape, try unmounting and remounting the Volume.\n"),
dev_name(dev));
}
} else {
if (!dev_is_tape(dev)) {
- bnet_fsend(dir, _("3906 cannot mount non-tape.\n"));
+ bnet_fsend(dir, _("3906 cannot mount non-tape.\n"));
break;
}
if (open_dev(dev, NULL, OPEN_READ_WRITE) < 0) {
- bnet_fsend(dir, _("3901 open device failed: ERR=%s\n"),
+ bnet_fsend(dir, _("3901 open device failed: ERR=%s\n"),
strerror_dev(dev));
break;
}
read_label(dcr);
if (dev_state(dev, ST_LABEL)) {
- bnet_fsend(dir, _("3001 Device %s is already mounted with Volume \"%s\"\n"),
+ bnet_fsend(dir, _("3001 Device %s is already mounted with Volume \"%s\"\n"),
dev_name(dev), dev->VolHdr.VolName);
} else {
- bnet_fsend(dir, _("3905 Device %s open but no Bacula volume is mounted.\n"
- "If this is not a blank tape, try unmounting and remounting the Volume.\n"),
+ bnet_fsend(dir, _("3905 Device %s open but no Bacula volume is mounted.\n"
+ "If this is not a blank tape, try unmounting and remounting the Volume.\n"),
dev_name(dev));
}
}
break;
default:
- bnet_fsend(dir, _("3905 Bizarre wait state %d\n"), dev->dev_blocked);
+ bnet_fsend(dir, _("3905 Bizarre wait state %d\n"), dev->dev_blocked);
break;
}
V(dev->mutex);
} else {
- bnet_fsend(dir, _("3999 Device \"%s\" not found\n"), dname.c_str());
+ bnet_fsend(dir, _("3999 Device \"%s\" not found\n"), dname.c_str());
}
} else {
pm_strcpy(jcr->errmsg, dir->msg);
if (dev) {
P(dev->mutex); /* Use P to avoid indefinite block */
if (!(dev->state & ST_OPENED)) {
- Dmsg0(90, "Device already unmounted\n");
- bnet_fsend(dir, _("3901 Device \"%s\" is already unmounted.\n"), dev_name(dev));
+ Dmsg0(90, "Device already unmounted\n");
+ bnet_fsend(dir, _("3901 Device \"%s\" is already unmounted.\n"), dev_name(dev));
} else if (dev->dev_blocked == BST_WAITING_FOR_SYSOP) {
- Dmsg2(90, "%d waiter dev_block=%d. doing unmount\n", dev->num_waiting,
+ Dmsg2(90, "%d waiter dev_block=%d. doing unmount\n", dev->num_waiting,
dev->dev_blocked);
open_dev(dev, NULL, 0); /* fake open for close */
offline_or_rewind_dev(dev);
force_close_dev(dev);
dev->dev_blocked = BST_UNMOUNTED_WAITING_FOR_SYSOP;
- bnet_fsend(dir, _("3001 Device \"%s\" unmounted.\n"), dev_name(dev));
+ bnet_fsend(dir, _("3001 Device \"%s\" unmounted.\n"), dev_name(dev));
} else if (dev->dev_blocked == BST_DOING_ACQUIRE) {
- bnet_fsend(dir, _("3902 Device \"%s\" is busy in acquire.\n"), dev_name(dev));
+ bnet_fsend(dir, _("3902 Device \"%s\" is busy in acquire.\n"), dev_name(dev));
} else if (dev->dev_blocked == BST_WRITING_LABEL) {
- bnet_fsend(dir, _("3903 Device \"%s\" is being labeled.\n"), dev_name(dev));
+ bnet_fsend(dir, _("3903 Device \"%s\" is being labeled.\n"), dev_name(dev));
} else if (dev_state(dev, ST_READ) || dev->num_writers) {
if (dev_state(dev, ST_READ)) {
- Dmsg0(90, "Device in read mode\n");
- bnet_fsend(dir, _("3904 Device \"%s\" is busy reading.\n"), dev_name(dev));
+ Dmsg0(90, "Device in read mode\n");
+ bnet_fsend(dir, _("3904 Device \"%s\" is busy reading.\n"), dev_name(dev));
} else {
- Dmsg1(90, "Device busy with %d writers\n", dev->num_writers);
- bnet_fsend(dir, _("3905 Device %s is busy with %d writer(s).\n"),
+ Dmsg1(90, "Device busy with %d writers\n", dev->num_writers);
+ bnet_fsend(dir, _("3905 Device %s is busy with %d writer(s).\n"),
dev_name(dev), dev->num_writers);
}
} else { /* device not being used */
- Dmsg0(90, "Device not in use, unmounting\n");
+ Dmsg0(90, "Device not in use, unmounting\n");
/* On FreeBSD, I am having ASSERT() failures in block_device()
* and I can only imagine that the thread id that we are
* leaving in no_wait_id is being re-used. So here,
open_dev(dev, NULL, 0); /* fake open for close */
offline_or_rewind_dev(dev);
force_close_dev(dev);
- bnet_fsend(dir, _("3002 Device %s unmounted.\n"), dev_name(dev));
+ bnet_fsend(dir, _("3002 Device %s unmounted.\n"), dev_name(dev));
}
V(dev->mutex);
} else {
- bnet_fsend(dir, _("3999 Device \"%s\" not found\n"), dname.c_str());
+ bnet_fsend(dir, _("3999 Device \"%s\" not found\n"), dname.c_str());
}
} else {
/* NB dir->msg gets clobbered in bnet_fsend, so save command */
if (dev) {
P(dev->mutex); /* Use P to avoid indefinite block */
if (!(dev->state & ST_OPENED)) {
- Dmsg0(90, "Device already released\n");
- bnet_fsend(dir, _("3911 Device %s already released.\n"), dev_name(dev));
+ Dmsg0(90, "Device already released\n");
+ bnet_fsend(dir, _("3911 Device %s already released.\n"), dev_name(dev));
} else if (dev->dev_blocked == BST_WAITING_FOR_SYSOP ||
dev->dev_blocked == BST_UNMOUNTED_WAITING_FOR_SYSOP) {
- Dmsg2(90, "%d waiter dev_block=%d. doing unmount\n", dev->num_waiting,
+ Dmsg2(90, "%d waiter dev_block=%d. doing unmount\n", dev->num_waiting,
dev->dev_blocked);
- bnet_fsend(dir, _("3912 Device %s waiting for mount.\n"), dev_name(dev));
+ bnet_fsend(dir, _("3912 Device %s waiting for mount.\n"), dev_name(dev));
} else if (dev->dev_blocked == BST_DOING_ACQUIRE) {
- bnet_fsend(dir, _("3913 Device %s is busy in acquire.\n"), dev_name(dev));
+ bnet_fsend(dir, _("3913 Device %s is busy in acquire.\n"), dev_name(dev));
} else if (dev->dev_blocked == BST_WRITING_LABEL) {
- bnet_fsend(dir, _("3914 Device %s is being labeled.\n"), dev_name(dev));
+ bnet_fsend(dir, _("3914 Device %s is being labeled.\n"), dev_name(dev));
} else if (dev_state(dev, ST_READ) || dev->num_writers) {
if (dev_state(dev, ST_READ)) {
- Dmsg0(90, "Device in read mode\n");
- bnet_fsend(dir, _("3915 Device %s is busy with 1 reader.\n"), dev_name(dev));
+ Dmsg0(90, "Device in read mode\n");
+ bnet_fsend(dir, _("3915 Device %s is busy with 1 reader.\n"), dev_name(dev));
} else {
- Dmsg1(90, "Device busy with %d writers\n", dev->num_writers);
- bnet_fsend(dir, _("3916 Device %s is busy with %d writer(s).\n"),
+ Dmsg1(90, "Device busy with %d writers\n", dev->num_writers);
+ bnet_fsend(dir, _("3916 Device %s is busy with %d writer(s).\n"),
dev_name(dev), dev->num_writers);
}
} else { /* device not being used */
- Dmsg0(90, "Device not in use, unmounting\n");
+ Dmsg0(90, "Device not in use, unmounting\n");
release_volume(jcr->dcr);
- bnet_fsend(dir, _("3012 Device %s released.\n"), dev_name(dev));
+ bnet_fsend(dir, _("3012 Device %s released.\n"), dev_name(dev));
}
V(dev->mutex);
} else {
- bnet_fsend(dir, _("3999 Device \"%s\" not found\n"), dname.c_str());
+ bnet_fsend(dir, _("3999 Device \"%s\" not found\n"), dname.c_str());
}
} else {
/* NB dir->msg gets clobbered in bnet_fsend, so save command */
if (dev) {
P(dev->mutex); /* Use P to avoid indefinite block */
if (!dev_is_tape(dev)) {
- bnet_fsend(dir, _("3995 Device %s is not an autochanger.\n"), dev_name(dev));
+ bnet_fsend(dir, _("3995 Device %s is not an autochanger.\n"), dev_name(dev));
} else if (!(dev->state & ST_OPENED)) {
autochanger_list(dcr, dir);
- /* Under certain "safe" conditions, we can steal the lock */
- } else if (dev->dev_blocked &&
+ /* Under certain "safe" conditions, we can steal the lock */
+ } else if (dev->dev_blocked &&
(dev->dev_blocked == BST_UNMOUNTED ||
dev->dev_blocked == BST_WAITING_FOR_SYSOP ||
dev->dev_blocked == BST_UNMOUNTED_WAITING_FOR_SYSOP)) {
autochanger_list(dcr, dir);
} else if (dev_state(dev, ST_READ) || dev->num_writers) {
if (dev_state(dev, ST_READ)) {
- bnet_fsend(dir, _("3901 Device %s is busy with 1 reader.\n"), dev_name(dev));
+ bnet_fsend(dir, _("3901 Device %s is busy with 1 reader.\n"), dev_name(dev));
} else {
- bnet_fsend(dir, _("3902 Device %s is busy with %d writer(s).\n"),
+ bnet_fsend(dir, _("3902 Device %s is busy with %d writer(s).\n"),
dev_name(dev), dev->num_writers);
}
} else { /* device not being used */
}
V(dev->mutex);
} else {
- bnet_fsend(dir, _("3999 Device \"%s\" not found\n"), dname.c_str());
+ bnet_fsend(dir, _("3999 Device \"%s\" not found\n"), dname.c_str());
}
} else { /* error on scanf */
pm_strcpy(jcr->errmsg, dir->msg);
if (!dev_state(dev, ST_OPENED)) {
read_volume_label(jcr, dev, Slot);
force_close_dev(dev);
- /* Under certain "safe" conditions, we can steal the lock */
- } else if (dev->dev_blocked &&
+ /* Under certain "safe" conditions, we can steal the lock */
+ } else if (dev->dev_blocked &&
(dev->dev_blocked == BST_UNMOUNTED ||
dev->dev_blocked == BST_WAITING_FOR_SYSOP ||
dev->dev_blocked == BST_UNMOUNTED_WAITING_FOR_SYSOP)) {
read_volume_label(jcr, dev, Slot);
} else if (dev_state(dev, ST_READ) || dev->num_writers) {
if (dev_state(dev, ST_READ)) {
- bnet_fsend(dir, _("3911 Device %s is busy with 1 reader.\n"),
+ bnet_fsend(dir, _("3911 Device %s is busy with 1 reader.\n"),
dev_name(dev));
} else {
- bnet_fsend(dir, _("3912 Device %s is busy with %d writer(s).\n"),
+ bnet_fsend(dir, _("3912 Device %s is busy with %d writer(s).\n"),
dev_name(dev), dev->num_writers);
}
} else { /* device not being used */
}
V(dev->mutex);
} else {
- bnet_fsend(dir, _("3999 Device \"%s\" not found\n"), dname.c_str());
+ bnet_fsend(dir, _("3999 Device \"%s\" not found\n"), dname.c_str());
}
} else {
pm_strcpy(jcr->errmsg, dir->msg);
return true;
}
-/*
+/*
* Read the tape label
*
* Enter with the mutex set
dcr->dev = dev;
steal_device_lock(dev, &hold, BST_WRITING_LABEL);
-
+
if (!try_autoload_device(jcr, Slot, "")) {
goto bail_out; /* error */
}
dev->state &= ~ST_LABEL; /* force read of label */
- switch (read_dev_volume_label(dcr)) {
+ switch (read_dev_volume_label(dcr)) {
case VOL_OK:
/* DO NOT add quotes around the Volume name. It is scanned in the DIR */
bnet_fsend(dir, _("3001 Volume=%s Slot=%d\n"), dev->VolHdr.VolName, Slot);
dcr->VolCatInfo.Slot = slot;
dcr->VolCatInfo.InChanger = slot > 0;
if (autoload_device(dcr, 0, dir) < 0) { /* autoload if possible */
- return false;
+ return false;
}
/* Ensure that the device is open -- autoload_device() closes it */
for ( ; !(dev->state & ST_OPENED); ) {
if (open_dev(dev, dcr->VolumeName, OPEN_READ_WRITE) < 0) {
- bnet_fsend(dir, _("3910 Unable to open device %s. ERR=%s\n"),
+ bnet_fsend(dir, _("3910 Unable to open device %s. ERR=%s\n"),
dev_name(dev), strerror_dev(dev));
return false;
}
* We get here because the Director has initiated a Job with
* the Storage daemon, then done the same with the File daemon,
* then when the Storage daemon receives a proper connection from
- * the File daemon, control is passed here to handle the
+ * the File daemon, control is passed here to handle the
* subsequent File daemon commands.
*
* Version $Id$
- *
+ *
*/
/*
Copyright (C) 2000-2004 Kern Sibbald and John Walker
bool (*func)(JCR *jcr);
};
-/*
+/*
* The following are the recognized commands from the File daemon
*/
static struct s_cmds fd_cmds[] = {
/* Information sent to the Director */
static char Job_start[] = "3010 Job %s start\n";
-static char Job_end[] =
+static char Job_end[] =
"3099 Job %s end JobStatus=%d JobFiles=%d JobBytes=%s\n";
/*
fd->jcr = jcr;
dir->jcr = jcr;
Dmsg1(120, "Start run Job=%s\n", jcr->Job);
- bnet_fsend(dir, Job_start, jcr->Job);
+ bnet_fsend(dir, Job_start, jcr->Job);
jcr->start_time = time(NULL);
jcr->run_time = jcr->start_time;
set_jcr_job_status(jcr, JS_Running);
}
}
if (!found) { /* command not found */
- Dmsg1(110, "<filed: Command not found: %s\n", fd->msg);
+ Dmsg1(110, "<filed: Command not found: %s\n", fd->msg);
bnet_fsend(fd, ferrmsg);
break;
}
return;
}
-
+
/*
* Append Data command
* Open Data Channel and receive Data for archiving
}
-/*
+/*
* Append Open session command
*
*/
/*
* Append Close session command
- * Close the append session and send back Statistics
+ * Close the append session and send back Statistics
* (need to fix statistics)
*/
static bool append_close_session(JCR *jcr)
Dmsg1(120, ">filed: %s", fd->msg);
bnet_sig(fd, BNET_EOD); /* send EOD to File daemon */
-
+
Dmsg1(110, "Append close session: %s\n", dev_name(jcr->device->dev));
jcr->session_opened = false;
/*
* Read Data command
- * Open Data Channel, read the data from
+ * Open Data Channel, read the data from
* the archive device and send to File
* daemon.
*/
}
}
-/*
+/*
* Read Open session command
*
* We need to scan for the parameters of the job
return false;
}
Dmsg4(100, "read_open_session got: JobId=%d Vol=%s VolSessId=%ld VolSessT=%ld\n",
- jcr->JobId, jcr->dcr->VolumeName, jcr->read_VolSessionId,
+ jcr->JobId, jcr->dcr->VolumeName, jcr->read_VolSessionId,
jcr->read_VolSessionTime);
Dmsg4(100, " StartF=%ld EndF=%ld StartB=%ld EndB=%ld\n",
jcr->read_StartFile, jcr->read_EndFile, jcr->read_StartBlock,
Dmsg1(160, ">filed: %s\n", fd->msg);
bnet_sig(fd, BNET_EOD); /* send EOD to File daemon */
-
+
jcr->session_opened = FALSE;
return true;
}
/* Requests from the Director daemon */
static char jobcmd[] = "JobId=%d job=%127s job_name=%127s client_name=%127s "
- "type=%d level=%d FileSet=%127s NoAttr=%d SpoolAttr=%d FileSetMD5=%127s "
- "SpoolData=%d";
+ "type=%d level=%d FileSet=%127s NoAttr=%d SpoolAttr=%d FileSetMD5=%127s "
+ "SpoolData=%d";
static char use_device[] = "use device=%127s media_type=%127s pool_name=%127s pool_type=%127s\n";
static char use_devices[] = "use devices=%127s media_type=%127s pool_name=%127s pool_type=%127s\n";
* Get JobId and permissions from Director
*/
Dmsg1(100, "Job_cmd: %s\n", dir->msg);
- if (sscanf(dir->msg, jobcmd, &JobId, job.c_str(), job_name.c_str(),
+ if (sscanf(dir->msg, jobcmd, &JobId, job.c_str(), job_name.c_str(),
client_name.c_str(),
&JobType, &level, fileset_name.c_str(), &no_attributes,
&spool_attributes, fileset_md5.c_str(), &spool_data) != 11) {
set_jcr_job_status(jcr, JS_ErrorTerminated);
return false;
}
- /*
+ /*
* Since this job could be rescheduled, we
* check to see if we have it already. If so
* free the old jcr and use the new one.
bnet_fsend(dir, OKjob, jcr->VolSessionId, jcr->VolSessionTime, auth_key);
Dmsg1(110, ">dird: %s", dir->msg);
jcr->sd_auth_key = bstrdup(auth_key);
- memset(auth_key, 0, sizeof(auth_key));
+ memset(auth_key, 0, sizeof(auth_key));
/*
* Wait for the device, media, and pool information
dir_send_job_status(jcr);
gettimeofday(&tv, &tz);
- timeout.tv_nsec = tv.tv_usec * 1000;
+ timeout.tv_nsec = tv.tv_usec * 1000;
timeout.tv_sec = tv.tv_sec + 30 * 60; /* wait 30 minutes */
Dmsg1(100, "%s waiting on FD to contact SD\n", jcr->Job);
/*
* After receiving a connection (in job.c) if it is
* from the File daemon, this routine is called.
- */
+ */
void handle_filed_connection(BSOCK *fd, char *job_name)
{
JCR *jcr;
Dmsg1(110, "Found Job %s\n", job_name);
if (jcr->authenticated) {
- Jmsg2(jcr, M_FATAL, 0, "Hey!!!! JobId %u Job %s already authenticated.\n",
+ Jmsg2(jcr, M_FATAL, 0, "Hey!!!! JobId %u Job %s already authenticated.\n",
jcr->JobId, jcr->Job);
free_jcr(jcr);
return;
}
-
+
/*
* Authenticate the File daemon
*/
}
-/*
+/*
* Use Device command from Director
- * He tells is what Device Name to use, the Media Type,
+ * He tells is what Device Name to use, the Media Type,
* the Pool Name, and the Pool Type.
*
* Ensure that the device exists and is opened, then store
BSOCK *dir = jcr->dir_bsock;
DEVRES *device;
bool quit = false;
-
+
while (!quit) {
bool ok;
if (bnet_recv(dir) <= 0) {
- Jmsg0(jcr, M_FATAL, 0, _("No Device from Director\n"));
+ Jmsg0(jcr, M_FATAL, 0, _("No Device from Director\n"));
return false;
}
-
+
Dmsg1(120, "Use device: %s", dir->msg);
- /*
- * If there are multiple devices, the director sends us
+ /*
+ * If there are multiple devices, the director sends us
* use_devices (note plurel) until the last one, at which
* time, it sends us a use_device command (note singlular)
* so we stop looking after getting the use_device.
*/
- ok = sscanf(dir->msg, use_device, dev_name.c_str(), media_type.c_str(),
+ ok = sscanf(dir->msg, use_device, dev_name.c_str(), media_type.c_str(),
pool_name.c_str(), pool_type.c_str()) == 4;
if (ok) {
quit = true; /* got last device */
} else {
- ok = sscanf(dir->msg, use_devices, dev_name.c_str(), media_type.c_str(),
+ ok = sscanf(dir->msg, use_devices, dev_name.c_str(), media_type.c_str(),
pool_name.c_str(), pool_type.c_str()) == 4;
}
if (ok) {
LockRes();
foreach_res(device, R_DEVICE) {
/* Find resource, and make sure we were able to open it */
- if (fnmatch(dev_name.c_str(), device->hdr.name, 0) == 0 &&
+ if (fnmatch(dev_name.c_str(), device->hdr.name, 0) == 0 &&
device->dev && strcmp(device->media_type, media_type.c_str()) == 0) {
const int name_len = MAX_NAME_LENGTH;
DCR *dcr;
if (!dcr) {
return false;
}
- Dmsg1(120, "Found device %s\n", device->hdr.name);
+ Dmsg1(120, "Found device %s\n", device->hdr.name);
bstrncpy(dcr->pool_name, pool_name, name_len);
bstrncpy(dcr->pool_type, pool_type, name_len);
bstrncpy(dcr->media_type, media_type, name_len);
bstrncpy(dcr->dev_name, dev_name, name_len);
jcr->device = device;
- Dmsg1(220, "Got: %s", dir->msg);
+ Dmsg1(220, "Got: %s", dir->msg);
return bnet_fsend(dir, OK_device);
}
}
if (verbose) {
unbash_spaces(dir->msg);
pm_strcpy(jcr->errmsg, dir->msg);
- Jmsg(jcr, M_INFO, 0, _("Failed command: %s\n"), jcr->errmsg);
+ Jmsg(jcr, M_INFO, 0, _("Failed command: %s\n"), jcr->errmsg);
}
- Jmsg(jcr, M_FATAL, 0, _("\n"
- " Device \"%s\" with MediaType \"%s\" requested by Dir not found in SD Device resources.\n"),
+ Jmsg(jcr, M_FATAL, 0, _("\n"
+ " Device \"%s\" with MediaType \"%s\" requested by Dir not found in SD Device resources.\n"),
dev_name.c_str(), media_type.c_str());
bnet_fsend(dir, NO_device, dev_name.c_str());
} else {
unbash_spaces(dir->msg);
pm_strcpy(jcr->errmsg, dir->msg);
if (verbose) {
- Jmsg(jcr, M_INFO, 0, _("Failed command: %s\n"), jcr->errmsg);
+ Jmsg(jcr, M_INFO, 0, _("Failed command: %s\n"), jcr->errmsg);
}
- Jmsg(jcr, M_FATAL, 0, _("Bad Use Device command: %s\n"), jcr->errmsg);
+ Jmsg(jcr, M_FATAL, 0, _("Bad Use Device command: %s\n"), jcr->errmsg);
bnet_fsend(dir, BAD_use, jcr->errmsg);
}
}
return false; /* ERROR return */
}
-/*
+/*
* Destroy the Job Control Record and associated
* resources (sockets).
*/
-void stored_free_jcr(JCR *jcr)
+void stored_free_jcr(JCR *jcr)
{
if (jcr->file_bsock) {
bnet_close(jcr->file_bsock);
/*
*
- * label.c Bacula routines to handle labels
+ * label.c Bacula routines to handle labels
*
* Kern Sibbald, MM
- *
+ *
*
* Version $Id$
*/
* If dcr->VolumeName[0] == 0, we accept any Bacula Volume
* otherwise dcr->VolumeName must match the Volume.
*
- * If VolName given, ensure that it matches
+ * If VolName given, ensure that it matches
*
* Returns VOL_ code as defined in record.h
* VOL_NOT_READ
* VOL_VERSION_ERROR
* VOL_LABEL_ERROR
* VOL_NO_MEDIA
- */
+ */
int read_dev_volume_label(DCR *dcr)
{
JCR *jcr = dcr->jcr;
bool ok = false;
DEV_BLOCK *block = dcr->block;
- Dmsg3(100, "Enter read_volume_label device=%s vol=%s dev_Vol=%s\n",
+ Dmsg3(100, "Enter read_volume_label device=%s vol=%s dev_Vol=%s\n",
dev_name(dev), VolName, dev->VolHdr.VolName);
if (dev_state(dev, ST_LABEL)) { /* did we already read label? */
/* Compare Volume Names allow special wild card */
if (VolName && *VolName && *VolName != '*' && strcmp(dev->VolHdr.VolName, VolName) != 0) {
- Mmsg(jcr->errmsg, _("Wrong Volume mounted on device %s: Wanted %s have %s\n"),
+ Mmsg(jcr->errmsg, _("Wrong Volume mounted on device %s: Wanted %s have %s\n"),
dev_name(dev), VolName, dev->VolHdr.VolName);
/*
* Cancel Job if too many label errors
* => we are in a loop
*/
if (!dev->poll && jcr->label_errors++ > 100) {
- Jmsg(jcr, M_FATAL, 0, "Too many tries: %s", jcr->errmsg);
+ Jmsg(jcr, M_FATAL, 0, "Too many tries: %s", jcr->errmsg);
}
return VOL_NAME_ERROR;
}
record = new_record();
empty_block(block);
Dmsg0(90, "Big if statement in read_volume_label\n");
- if (!read_block_from_dev(dcr, NO_BLOCK_NUMBER_CHECK)) {
+ if (!read_block_from_dev(dcr, NO_BLOCK_NUMBER_CHECK)) {
Mmsg(jcr->errmsg, _("Requested Volume \"%s\" on %s is not a Bacula "
- "labeled Volume, because: ERR=%s"), NPRT(VolName), dev_name(dev),
+ "labeled Volume, because: ERR=%s"), NPRT(VolName), dev_name(dev),
strerror_dev(dev));
Dmsg1(30, "%s", jcr->errmsg);
} else if (!read_record_from_block(block, record)) {
Mmsg(jcr->errmsg, _("Could not unserialize Volume label: ERR=%s\n"),
strerror_dev(dev));
Dmsg1(30, "%s", jcr->errmsg);
- } else if (strcmp(dev->VolHdr.Id, BaculaId) != 0 &&
+ } else if (strcmp(dev->VolHdr.Id, BaculaId) != 0 &&
strcmp(dev->VolHdr.Id, OldBaculaId) != 0) {
Mmsg(jcr->errmsg, _("Volume Header Id bad: %s\n"), dev->VolHdr.Id);
Dmsg1(30, "%s", jcr->errmsg);
free_record(record);
if (forge_on || jcr->ignore_label_errors) {
dev->state |= ST_LABEL; /* set has Bacula label */
- Jmsg(jcr, M_ERROR, 0, "%s", jcr->errmsg);
+ Jmsg(jcr, M_ERROR, 0, "%s", jcr->errmsg);
return VOL_OK;
}
empty_block(block);
rewind_dev(dev);
}
- if (dev->VolHdr.VerNum != BaculaTapeVersion &&
- dev->VolHdr.VerNum != OldCompatibleBaculaTapeVersion1 &&
+ if (dev->VolHdr.VerNum != BaculaTapeVersion &&
+ dev->VolHdr.VerNum != OldCompatibleBaculaTapeVersion1 &&
dev->VolHdr.VerNum != OldCompatibleBaculaTapeVersion2) {
Mmsg(jcr->errmsg, _("Volume on %s has wrong Bacula version. Wanted %d got %d\n"),
dev_name(dev), BaculaTapeVersion, dev->VolHdr.VerNum);
* a Bacula volume label (VOL_LABEL)
*/
if (dev->VolHdr.LabelType != PRE_LABEL && dev->VolHdr.LabelType != VOL_LABEL) {
- Mmsg(jcr->errmsg, _("Volume on %s has bad Bacula label type: %x\n"),
+ Mmsg(jcr->errmsg, _("Volume on %s has bad Bacula label type: %x\n"),
dev_name(dev), dev->VolHdr.LabelType);
Dmsg1(30, "%s", jcr->errmsg);
return VOL_LABEL_ERROR;
* => we are in a loop
*/
if (!dev->poll && jcr->label_errors++ > 100) {
- Jmsg(jcr, M_FATAL, 0, "Too many tries: %s", jcr->errmsg);
+ Jmsg(jcr, M_FATAL, 0, "Too many tries: %s", jcr->errmsg);
}
return VOL_NAME_ERROR;
}
return VOL_OK;
}
-/* unser_volume_label
- *
+/* unser_volume_label
+ *
* Unserialize the Volume label into the device Volume_Label
* structure.
*
ser_declare;
if (rec->FileIndex != VOL_LABEL && rec->FileIndex != PRE_LABEL) {
- Mmsg3(dev->errmsg, _("Expecting Volume Label, got FI=%s Stream=%s len=%d\n"),
- FI_to_ascii(rec->FileIndex),
+ Mmsg3(dev->errmsg, _("Expecting Volume Label, got FI=%s Stream=%s len=%d\n"),
+ FI_to_ascii(rec->FileIndex),
stream_to_ascii(rec->Stream, rec->FileIndex),
rec->data_len);
if (!forge_on) {
if (dev->VolHdr.VerNum >= 11) {
unser_btime(dev->VolHdr.label_btime);
unser_btime(dev->VolHdr.write_btime);
- } else { /* old way */
+ } else { /* old way */
unser_float64(dev->VolHdr.label_date);
unser_float64(dev->VolHdr.label_time);
}
ser_end(rec->data, SER_LENGTH_Volume_Label);
Dmsg0(90, "ser_read_vol\n");
if (debug_level >= 90) {
- dump_volume_label(dev);
+ dump_volume_label(dev);
}
return true;
}
return true;
}
-/*
+/*
* create_volume_label_record
* Serialize label (from dev->VolHdr structure) into device record.
- * Assumes that the dev->VolHdr structure is properly
+ * Assumes that the dev->VolHdr structure is properly
* initialized.
*/
static void create_volume_label_record(DCR *dcr, DEV_RECORD *rec)
rec->Stream = jcr->NumVolumes;
Dmsg2(100, "Created Vol label rec: FI=%s len=%d\n", FI_to_ascii(rec->FileIndex),
rec->data_len);
-}
+}
/*
* a fresh volume label. Any data
* after the label will be destroyed,
* in fact, we write the label 5 times !!!!
- *
+ *
* This routine expects that open_device() was previously called.
*
* This routine should be used only when labeling a blank tape.
Dmsg0(99, "write_volume_label()\n");
empty_block(dcr->block);
- /* Create PRE_LABEL */
+ /* Create PRE_LABEL */
create_volume_label(dev, VolName, PoolName);
if (!rewind_dev(dev)) {
} else {
Dmsg2(30, "Wrote label of %d bytes to %s\n", dcr->rec->data_len, dev_name(dev));
}
-
+
Dmsg0(99, "Call write_block_to_dev()\n");
if (!write_block_to_dev(dcr)) {
memset(&dev->VolHdr, 0, sizeof(dev->VolHdr));
goto bail_out;
}
Dmsg0(99, " Wrote block to device\n");
-
+
if (weof_dev(dev, 1) == 0) {
dev->state |= ST_LABEL;
ok = true;
bail_out:
dev->state &= ~ST_APPEND; /* remove append since this is PRE_LABEL */
return ok;
-}
+}
/*
/* Write session label
* Returns: false on failure
- * true on success
+ * true on success
*/
bool write_session_label(DCR *dcr, int label)
{
create_session_label(dcr, rec, label);
rec->FileIndex = label;
- /*
+ /*
* We guarantee that the session record can totally fit
* into a block. If not, write the block, and put it in
* the next block. Having the sesssion record totally in
if (!can_write_record_to_block(block, rec)) {
Dmsg0(100, "Cannot write session label to block.\n");
if (!write_block_to_device(dcr)) {
- Dmsg0(90, "Got session label write_block_to_dev error.\n");
+ Dmsg0(90, "Got session label write_block_to_dev error.\n");
/* ****FIXME***** errno is not set here */
- Jmsg(jcr, M_FATAL, 0, _("Error writing Session label to %s: %s\n"),
+ Jmsg(jcr, M_FATAL, 0, _("Error writing Session label to %s: %s\n"),
dev_vol_name(dev), strerror(errno));
free_record(rec);
return false;
}
}
if (!write_record_to_block(block, rec)) {
- Jmsg(jcr, M_FATAL, 0, _("Error writing Session label to %s: %s\n"),
+ Jmsg(jcr, M_FATAL, 0, _("Error writing Session label to %s: %s\n"),
dev_vol_name(dev), strerror(errno));
free_record(rec);
return false;
}
- Dmsg6(20, "Write sesson_label record JobId=%d FI=%s SessId=%d Strm=%s len=%d "
- "remainder=%d\n", jcr->JobId,
- FI_to_ascii(rec->FileIndex), rec->VolSessionId,
+ Dmsg6(20, "Write sesson_label record JobId=%d FI=%s SessId=%d Strm=%s len=%d "
+ "remainder=%d\n", jcr->JobId,
+ FI_to_ascii(rec->FileIndex), rec->VolSessionId,
stream_to_ascii(rec->Stream, rec->FileIndex), rec->data_len,
rec->remainder);
free_record(rec);
- Dmsg2(20, "Leave write_session_label Block=%d File=%d\n",
+ Dmsg2(20, "Leave write_session_label Block=%d File=%d\n",
dev->block_num, dev->file);
return true;
}
File = dev->file;
switch (dev->VolHdr.LabelType) {
case PRE_LABEL:
- LabelType = "PRE_LABEL";
+ LabelType = "PRE_LABEL";
break;
case VOL_LABEL:
- LabelType = "VOL_LABEL";
+ LabelType = "VOL_LABEL";
break;
case EOM_LABEL:
- LabelType = "EOM_LABEL";
+ LabelType = "EOM_LABEL";
break;
case SOS_LABEL:
- LabelType = "SOS_LABEL";
+ LabelType = "SOS_LABEL";
break;
case EOS_LABEL:
- LabelType = "EOS_LABEL";
+ LabelType = "EOS_LABEL";
break;
case EOT_LABEL:
goto bail_out;
default:
LabelType = buf;
- sprintf(buf, "Unknown %d", dev->VolHdr.LabelType);
+ sprintf(buf, "Unknown %d", dev->VolHdr.LabelType);
break;
}
-
-
- Pmsg11(-1, "\nVolume Label:\n\
-Id : %s\
-VerNo : %d\n\
-VolName : %s\n\
-PrevVolName : %s\n\
-VolFile : %d\n\
-LabelType : %s\n\
-LabelSize : %d\n\
-PoolName : %s\n\
-MediaType : %s\n\
-PoolType : %s\n\
-HostName : %s\n\
-",
+
+
+ Pmsg11(-1, "\nVolume Label:\n"
+"Id : %s"
+"VerNo : %d\n"
+"VolName : %s\n"
+"PrevVolName : %s\n"
+"VolFile : %d\n"
+"LabelType : %s\n"
+"LabelSize : %d\n"
+"PoolName : %s\n"
+"MediaType : %s\n"
+"PoolType : %s\n"
+"HostName : %s\n"
+"",
dev->VolHdr.Id, dev->VolHdr.VerNum,
dev->VolHdr.VolName, dev->VolHdr.PrevVolName,
- File, LabelType, dev->VolHdr.LabelSize,
- dev->VolHdr.PoolName, dev->VolHdr.MediaType,
+ File, LabelType, dev->VolHdr.LabelSize,
+ dev->VolHdr.PoolName, dev->VolHdr.MediaType,
dev->VolHdr.PoolType, dev->VolHdr.HostName);
if (dev->VolHdr.VerNum >= 11) {
dt.julian_day_number = dev->VolHdr.label_date;
dt.julian_day_fraction = dev->VolHdr.label_time;
tm_decode(&dt, &tm);
- Pmsg5(-1, "\
-Date label written: %04d-%02d-%02d at %02d:%02d\n",
+ Pmsg5(-1,
+"Date label written: %04d-%02d-%02d at %02d:%02d\n",
tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday, tm.tm_hour, tm.tm_min);
}
debug_level = dbl;
}
-bool unser_session_label(SESSION_LABEL *label, DEV_RECORD *rec)
+bool unser_session_label(SESSION_LABEL *label, DEV_RECORD *rec)
{
ser_declare;
} else {
label->JobStatus = JS_Terminated; /* kludge */
}
- }
+ }
return true;
}
unser_session_label(&label, rec);
dbl = debug_level;
debug_level = 1;
- Pmsg7(-1, "\n%s Record:\n\
-JobId : %d\n\
-VerNum : %d\n\
-PoolName : %s\n\
-PoolType : %s\n\
-JobName : %s\n\
-ClientName : %s\n\
-", type, label.JobId, label.VerNum,
+ Pmsg7(-1, "\n%s Record:\n"
+"JobId : %d\n"
+"VerNum : %d\n"
+"PoolName : %s\n"
+"PoolType : %s\n"
+"JobName : %s\n"
+"ClientName : %s\n"
+"", type, label.JobId, label.VerNum,
label.PoolName, label.PoolType,
label.JobName, label.ClientName);
if (label.VerNum >= 10) {
- Pmsg4(-1, "\
-Job (unique name) : %s\n\
-FileSet : %s\n\
-JobType : %c\n\
-JobLevel : %c\n\
-", label.Job, label.FileSetName, label.JobType, label.JobLevel);
+ Pmsg4(-1, ""
+"Job (unique name) : %s\n"
+"FileSet : %s\n"
+"JobType : %c\n"
+"JobLevel : %c\n"
+"", label.Job, label.FileSetName, label.JobType, label.JobLevel);
}
if (rec->FileIndex == EOS_LABEL) {
- Pmsg8(-1, "\
-JobFiles : %s\n\
-JobBytes : %s\n\
-StartBlock : %s\n\
-EndBlock : %s\n\
-StartFile : %s\n\
-EndFile : %s\n\
-JobErrors : %s\n\
-JobStatus : %c\n\
-",
+ Pmsg8(-1, ""
+"JobFiles : %s\n"
+"JobBytes : %s\n"
+"StartBlock : %s\n"
+"EndBlock : %s\n"
+"StartFile : %s\n"
+"EndFile : %s\n"
+"JobErrors : %s\n"
+"JobStatus : %c\n"
+"",
edit_uint64_with_commas(label.JobFiles, ec1),
edit_uint64_with_commas(label.JobBytes, ec2),
edit_uint64_with_commas(label.StartBlock, ec3),
edit_uint64_with_commas(label.EndBlock, ec4),
edit_uint64_with_commas(label.StartFile, ec5),
edit_uint64_with_commas(label.EndFile, ec6),
- edit_uint64_with_commas(label.JobErrors, ec7),
+ edit_uint64_with_commas(label.JobErrors, ec7),
label.JobStatus);
}
if (label.VerNum >= 11) {
dt.julian_day_number = label.write_date;
dt.julian_day_fraction = label.write_time;
tm_decode(&dt, &tm);
- Pmsg5(-1, _("\
-Date written : %04d-%02d-%02d at %02d:%02d\n"),
+ Pmsg5(-1, _(""
+"Date written : %04d-%02d-%02d at %02d:%02d\n"),
tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday, tm.tm_hour, tm.tm_min);
}
debug_level = 1;
switch (rec->FileIndex) {
case PRE_LABEL:
- type = _("Fresh Volume");
+ type = _("Fresh Volume");
break;
case VOL_LABEL:
type = _("Volume");
dump_session_label(rec, type);
break;
case EOM_LABEL:
- Pmsg5(-1, "%s Record: SessId=%d SessTime=%d JobId=%d DataLen=%d\n",
+ Pmsg5(-1, "%s Record: SessId=%d SessTime=%d JobId=%d DataLen=%d\n",
type, rec->VolSessionId, rec->VolSessionTime, rec->Stream, rec->data_len);
break;
case EOT_LABEL:
- Pmsg0(-1, _("End of physical tape.\n"));
+ Pmsg0(-1, _("End of physical tape.\n"));
break;
default:
- Pmsg5(-1, "%s Record: SessId=%d SessTime=%d JobId=%d DataLen=%d\n",
+ Pmsg5(-1, "%s Record: SessId=%d SessTime=%d JobId=%d DataLen=%d\n",
type, rec->VolSessionId, rec->VolSessionTime, rec->Stream, rec->data_len);
break;
}
switch (rec->FileIndex) {
case SOS_LABEL:
unser_session_label(&label, rec);
- Pmsg6(-1, "%s Record: SessId=%d SessTime=%d JobId=%d Level=%c Type=%c\n",
- type, rec->VolSessionId, rec->VolSessionTime, rec->Stream,
+ Pmsg6(-1, "%s Record: SessId=%d SessTime=%d JobId=%d Level=%c Type=%c\n",
+ type, rec->VolSessionId, rec->VolSessionTime, rec->Stream,
label.JobLevel, label.JobType);
break;
case EOS_LABEL:
char ed1[30], ed2[30];
unser_session_label(&label, rec);
- Pmsg6(-1, "%s Record: SessId=%d SessTime=%d JobId=%d Level=%c Type=%c\n",
- type, rec->VolSessionId, rec->VolSessionTime, rec->Stream,
+ Pmsg6(-1, "%s Record: SessId=%d SessTime=%d JobId=%d Level=%c Type=%c\n",
+ type, rec->VolSessionId, rec->VolSessionTime, rec->Stream,
label.JobLevel, label.JobType);
- Pmsg4(-1, " Files=%s Bytes=%s Errors=%d Status=%c\n",
+ Pmsg4(-1, " Files=%s Bytes=%s Errors=%d Status=%c\n",
edit_uint64_with_commas(label.JobFiles, ed1),
edit_uint64_with_commas(label.JobBytes, ed2),
label.JobErrors, (char)label.JobStatus);
case PRE_LABEL:
case VOL_LABEL:
default:
- Pmsg5(-1, "%s Record: SessId=%d SessTime=%d JobId=%d DataLen=%d\n",
+ Pmsg5(-1, "%s Record: SessId=%d SessTime=%d JobId=%d DataLen=%d\n",
type, rec->VolSessionId, rec->VolSessionTime, rec->Stream, rec->data_len);
break;
case EOT_LABEL:
-/*
+/*
* Match Bootstrap Records (used for restores) against
* Volume Records
- *
+ *
* Kern Sibbald, June MMII
*
* Version $Id$
/*********************************************************************
*
- * Do fast block rejection based on bootstrap records.
+ * Do fast block rejection based on bootstrap records.
* use_fast_rejection will be set if we have VolSessionId and VolSessTime
* in each record. When BlockVer is >= 2, we have those in the block header
* so can do fast rejection.
if (bsr) {
bsr->reposition = false;
stat = match_all(bsr, rec, volrec, sessrec, true);
- /*
+ /*
* Note, bsr->reposition is set by match_all when
* a bsr is done. We turn it off if a match was
* found or if we cannot use positioning
BSR *bsr;
BSR *found_bsr = NULL;
- if (!root_bsr || !root_bsr->use_positioning ||
+ if (!root_bsr || !root_bsr->use_positioning ||
!root_bsr->reposition || !dev_is_tape(dev)) {
Dmsg2(100, "No nxt_bsr use_pos=%d repos=%d\n", root_bsr->use_positioning, root_bsr->reposition);
return NULL;
return return_bsr;
}
-/*
+/*
* Called to tell the matcher that the end of
* the current file has been reached.
* The bsr argument is not used, but is included
* for consistency with the other match calls.
- *
+ *
* Returns: true if we should reposition
* : false otherwise.
*/
return false;
}
-/*
+/*
* Match all the components of current record
* returns 1 on match
* returns 0 no match
* returns -1 no additional matches possible
*/
-static int match_all(BSR *bsr, DEV_RECORD *rec, VOLUME_LABEL *volrec,
+static int match_all(BSR *bsr, DEV_RECORD *rec, VOLUME_LABEL *volrec,
SESSION_LABEL *sessrec, bool done)
{
if (bsr->done) {
*/
if (!match_jobid(bsr, bsr->JobId, sessrec, 1)) {
goto no_match;
-
+
}
if (!match_job(bsr, bsr->job, sessrec, 1)) {
goto no_match;
return 0;
}
-static int match_volume(BSR *bsr, BSR_VOLUME *volume, VOLUME_LABEL *volrec, bool done)
+static int match_volume(BSR *bsr, BSR_VOLUME *volume, VOLUME_LABEL *volrec, bool done)
{
if (!volume) {
return 0; /* Volume must match */
if (volfile->done && done) {
bsr->done = true;
bsr->root->reposition = true;
- Dmsg2(100, "bsr done from volfile rec=%d volefile=%d\n",
+ Dmsg2(100, "bsr done from volfile rec=%d volefile=%d\n",
rec->File, volfile->efile);
}
return 0;
* writing.
*
* Kern Sibbald, August MMII
- *
+ *
* Version $Id$
*/
/*
/*
- * If release is set, we rewind the current volume,
- * which we no longer want, and ask the user (console)
+ * If release is set, we rewind the current volume,
+ * which we no longer want, and ask the user (console)
* to mount the next volume.
*
* Continue trying until we get it, and then ensure
init_dev_wait_timers(dev);
- /*
+ /*
* Attempt to mount the next volume. If something non-fatal goes
* wrong, we come back here to re-try (new op messages, re-read
* Volume, ...)
/* Last ditch effort before giving up, force operator to respond */
dcr->VolCatInfo.Slot = 0;
if (!dir_ask_sysop_to_mount_volume(dcr)) {
- Jmsg(jcr, M_FATAL, 0, _("Too many errors trying to mount device %s.\n"),
+ Jmsg(jcr, M_FATAL, 0, _("Too many errors trying to mount device %s.\n"),
dev_name(dev));
return false;
}
ask = true; /* ask operator to mount tape */
}
- /*
- * Get Director's idea of what tape we should have mounted.
+ /*
+ * Get Director's idea of what tape we should have mounted.
* in dcr->VolCatInfo
*/
Dmsg0(200, "Before dir_find_next_appendable_volume.\n");
Dmsg2(100, "After find_next_append. Vol=%s Slot=%d\n",
dcr->VolCatInfo.VolCatName, dcr->VolCatInfo.Slot);
- /*
+ /*
* Get next volume and ready it for append
* This code ensures that the device is ready for
* writing. We start from the assumption that there
- * may not be a tape mounted.
+ * may not be a tape mounted.
*
* If the device is a file, we create the output
* file. If it is a tape, we check the volume name
Dmsg1(100, "autoload_dev returns %d\n", autochanger);
/*
* If we autochanged to correct Volume or (we have not just
- * released the Volume AND we can automount) we go ahead
+ * released the Volume AND we can automount) we go ahead
* and read the label. If there is no tape in the drive,
* we will err, recurse and ask the operator the next time.
*/
* Now make sure we have the right tape mounted
*/
read_volume:
- /*
+ /*
* If we are writing to a stream device, ASSUME the volume label
* is correct.
*/
/* If not removable, Volume is broken */
if (!dev_cap(dev, CAP_REM)) {
- Jmsg(jcr, M_WARNING, 0, _("Volume \"%s\" not on device %s.\n"),
+ Jmsg(jcr, M_WARNING, 0, _("Volume \"%s\" not on device %s.\n"),
dcr->VolumeName, dev_name(dev));
mark_volume_in_error(dcr);
goto mount_next_vol;
}
-
+
Dmsg1(100, "Vol NAME Error Name=%s\n", dcr->VolumeName);
/* If polling and got a previous bad name, ignore it */
if (dev->poll && strcmp(dev->BadVolName, dev->VolHdr.VolName) == 0) {
ask = true;
- Dmsg1(200, "Vol Name error supress due to poll. Name=%s\n",
+ Dmsg1(200, "Vol Name error supress due to poll. Name=%s\n",
dcr->VolumeName);
goto mount_next_vol;
}
- /*
+ /*
* OK, we got a different volume mounted. First save the
* requested Volume info (jcr) structure, then query if
* this volume is really OK. If not, put back the desired
bstrncpy(dcr->VolumeName, dev->VolHdr.VolName, sizeof(dcr->VolumeName));
if (!dir_get_volume_info(dcr, GET_VOL_INFO_FOR_WRITE)) {
bstrncpy(dev->BadVolName, dev->VolHdr.VolName, sizeof(dev->BadVolName));
- Jmsg(jcr, M_WARNING, 0, _("Director wanted Volume \"%s\".\n"
- " Current Volume \"%s\" not acceptable because:\n"
- " %s"),
+ Jmsg(jcr, M_WARNING, 0, _("Director wanted Volume \"%s\".\n"
+ " Current Volume \"%s\" not acceptable because:\n"
+ " %s"),
VolCatInfo.VolCatName, dev->VolHdr.VolName,
jcr->dir_bsock->msg);
/* Restore desired volume name, note device info out of sync */
*/
case VOL_NO_LABEL:
case VOL_IO_ERROR:
- /*
+ /*
* If permitted, we label the device, make sure we can do
- * it by checking that the VolCatBytes is zero => not labeled,
+ * it by checking that the VolCatBytes is zero => not labeled,
* once the Volume is labeled we don't want to label another
* blank tape with the same name. For disk, we go ahead and
* label it anyway, because the OS insures that there is only
* previous tape (or nothing).
*/
if (dev_cap(dev, CAP_LABEL) && (dcr->VolCatInfo.VolCatBytes == 0 ||
- (!dev_is_tape(dev) && strcmp(dcr->VolCatInfo.VolCatStatus,
- "Recycle") == 0))) {
- Dmsg0(100, "Create volume label\n");
+ (!dev_is_tape(dev) && strcmp(dcr->VolCatInfo.VolCatStatus,
+ "Recycle") == 0))) {
+ Dmsg0(100, "Create volume label\n");
/* Create a new Volume label and write it to the device */
if (!write_new_volume_label_to_dev(dcr, dcr->VolumeName,
dcr->pool_name)) {
- Dmsg0(100, "!write_vol_label\n");
+ Dmsg0(100, "!write_vol_label\n");
goto mount_next_vol;
}
- Dmsg0(100, "dir_update_vol_info. Set Append\n");
- /* Copy Director's info into the device info */
+ Dmsg0(100, "dir_update_vol_info. Set Append\n");
+ /* Copy Director's info into the device info */
memcpy(&dev->VolCatInfo, &dcr->VolCatInfo, sizeof(dev->VolCatInfo));
if (!dir_update_volume_info(dcr, true)) { /* indicate tape labeled */
return false;
}
- Jmsg(jcr, M_INFO, 0, _("Labeled new Volume \"%s\" on device %s.\n"),
+ Jmsg(jcr, M_INFO, 0, _("Labeled new Volume \"%s\" on device %s.\n"),
dcr->VolumeName, dev_name(dev));
goto read_volume; /* read label we just wrote */
- }
+ }
/* If not removable, Volume is broken */
if (!dev_cap(dev, CAP_REM)) {
- Jmsg(jcr, M_WARNING, 0, _("Volume \"%s\" not on device %s.\n"),
+ Jmsg(jcr, M_WARNING, 0, _("Volume \"%s\" not on device %s.\n"),
dcr->VolumeName, dev_name(dev));
mark_volume_in_error(dcr);
goto mount_next_vol;
default:
/* Send error message */
if (!dev->poll) {
- Jmsg(jcr, M_WARNING, 0, "%s", jcr->errmsg);
+ Jmsg(jcr, M_WARNING, 0, "%s", jcr->errmsg);
} else {
- Dmsg1(200, "Msg suppressed by poll: %s\n", jcr->errmsg);
+ Dmsg1(200, "Msg suppressed by poll: %s\n", jcr->errmsg);
}
ask = true;
goto mount_next_vol;
}
- /*
+ /*
* See if we have a fresh tape or a tape with data.
*
* Note, if the LabelType is PRE_LABEL, it was labeled
Jmsg(jcr, M_INFO, 0, _("Volume \"%s\" previously written, moving to end of data.\n"),
dcr->VolumeName);
if (!eod_dev(dev)) {
- Jmsg(jcr, M_ERROR, 0, _("Unable to position to end of data on device \"%s\". ERR=%s\n"),
+ Jmsg(jcr, M_ERROR, 0, _("Unable to position to end of data on device \"%s\". ERR=%s\n"),
dev_name(dev), strerror_dev(dev));
mark_volume_in_error(dcr);
goto mount_next_vol;
* that the database says we should be.
*/
if (dev->VolCatInfo.VolCatFiles == dev_file(dev)) {
- Jmsg(jcr, M_INFO, 0, _("Ready to append to end of Volume \"%s\" at file=%d.\n"),
+ Jmsg(jcr, M_INFO, 0, _("Ready to append to end of Volume \"%s\" at file=%d.\n"),
dcr->VolumeName, dev_file(dev));
} else {
- Jmsg(jcr, M_ERROR, 0, _("I canot write on Volume \"%s\" because:\n\
-The number of files mismatch! Volume=%u Catalog=%u\n"),
+ Jmsg(jcr, M_ERROR, 0, _("I canot write on Volume \"%s\" because:\n"
+"The number of files mismatch! Volume=%u Catalog=%u\n"),
dcr->VolumeName, dev_file(dev), dev->VolCatInfo.VolCatFiles);
mark_volume_in_error(dcr);
goto mount_next_vol;
}
/*
- * Write a volume label.
+ * Write a volume label.
* Returns: true if OK
* false if unable to write it
*/
*/
if (!dev_cap(dev, CAP_STREAM)) {
if (!rewind_dev(dev)) {
- Jmsg2(jcr, M_WARNING, 0, _("Rewind error on device \"%s\". ERR=%s\n"),
+ Jmsg2(jcr, M_WARNING, 0, _("Rewind error on device \"%s\". ERR=%s\n"),
dev_name(dev), strerror_dev(dev));
}
if (recycle) {
if (!truncate_dev(dev)) {
- Jmsg2(jcr, M_WARNING, 0, _("Truncate error on device \"%s\". ERR=%s\n"),
+ Jmsg2(jcr, M_WARNING, 0, _("Truncate error on device \"%s\". ERR=%s\n"),
dev_name(dev), strerror_dev(dev));
}
}
/* Attempt write to check write permission */
Dmsg0(200, "Attempt to write to device.\n");
if (!write_block_to_dev(dcr)) {
- Jmsg2(jcr, M_ERROR, 0, _("Unable to write device \"%s\". ERR=%s\n"),
+ Jmsg2(jcr, M_ERROR, 0, _("Unable to write device \"%s\". ERR=%s\n"),
dev_name(dev), strerror_dev(dev));
- Dmsg0(200, "===ERROR write block to dev\n");
+ Dmsg0(200, "===ERROR write block to dev\n");
return false;
}
}
dev->VolCatInfo.VolCatBlocks = 0;
dev->VolCatInfo.VolCatRBytes = 0;
if (recycle) {
- dev->VolCatInfo.VolCatMounts++;
+ dev->VolCatInfo.VolCatMounts++;
dev->VolCatInfo.VolCatRecycles++;
} else {
dev->VolCatInfo.VolCatMounts = 1;
/*
- * Mark volume in error in catalog
+ * Mark volume in error in catalog
*/
void mark_volume_in_error(DCR *dcr)
{
dir_update_volume_info(dcr, false);
}
-/*
+/*
* If we are reading, we come here at the end of the tape
* and see if there are more volumes to be mounted.
*/
*/
if (jcr->NumVolumes > 1 && jcr->CurVolume < jcr->NumVolumes) {
close_dev(dev);
- dev->state &= ~ST_READ;
+ dev->state &= ~ST_READ;
if (!acquire_device_for_read(jcr)) {
- Jmsg2(jcr, M_FATAL, 0, "Cannot open Dev=%s, Vol=%s\n", dev_name(dev),
+ Jmsg2(jcr, M_FATAL, 0, "Cannot open Dev=%s, Vol=%s\n", dev_name(dev),
dcr->VolumeName);
return false;
}
Jmsg0(jcr, M_ERROR, 0, "Hey!!!!! WroteVol non-zero !!!!!\n");
Dmsg0(190, "Hey!!!!! WroteVol non-zero !!!!!\n");
}
- /*
- * First erase all memory of the current volume
+ /*
+ * First erase all memory of the current volume
*/
dev->block_num = dev->file = 0;
dev->EndBlock = dev->EndFile = 0;
dev->state &= ~(ST_LABEL|ST_READ|ST_APPEND);
dcr->VolumeName[0] = 0;
- if ((dev->state & ST_OPENED) &&
+ if ((dev->state & ST_OPENED) &&
(!dev_is_tape(dev) || !dev_cap(dev, CAP_ALWAYSOPEN))) {
offline_or_rewind_dev(dev);
close_dev(dev);
-/*
- * Parse a Bootstrap Records (used for restores)
- *
+/*
+ * Parse a Bootstrap Records (used for restores)
+ *
* Kern Sibbald, June MMII
*
* Version $Id$
};
-/*
+/*
* Create a BSR record
*/
static BSR *new_bsr()
}
/*
- * Format a scanner error message
+ * Format a scanner error message
*/
static void s_err(const char *file, int line, LEX *lc, const char *msg, ...)
{
va_start(arg_ptr, msg);
bvsnprintf(buf, sizeof(buf), msg, arg_ptr);
va_end(arg_ptr);
-
+
if (jcr) {
- Jmsg(jcr, M_FATAL, 0, _("Bootstrap file error: %s\n\
- : Line %d, col %d of file %s\n%s\n"),
+ Jmsg(jcr, M_FATAL, 0, _("Bootstrap file error: %s\n"
+" : Line %d, col %d of file %s\n%s\n"),
buf, lc->line_no, lc->col_no, lc->fname, lc->line);
} else {
- e_msg(file, line, M_FATAL, 0, _("Bootstrap file error: %s\n\
- : Line %d, col %d of file %s\n%s\n"),
+ e_msg(file, line, M_FATAL, 0, _("Bootstrap file error: %s\n"
+" : Line %d, col %d of file %s\n%s\n"),
buf, lc->line_no, lc->col_no, lc->fname, lc->line);
}
}
int token, i;
BSR *root_bsr = new_bsr();
BSR *bsr = root_bsr;
-
+
Dmsg1(200, "Enter parse_bsf %s\n", fname);
lc = lex_open_file(lc, fname, s_err);
lc->caller_ctx = (void *)jcr;
for (i=0; items[i].name; i++) {
if (strcasecmp(items[i].name, lc->str) == 0) {
token = lex_get_token(lc, T_ALL);
- Dmsg1 (200, "in T_IDENT got token=%s\n", lex_tok_to_str(token));
+ Dmsg1 (200, "in T_IDENT got token=%s\n", lex_tok_to_str(token));
if (token != T_EQUALS) {
- scan_err1(lc, "expected an equals, got: %s", lc->str);
+ scan_err1(lc, "expected an equals, got: %s", lc->str);
bsr = NULL;
break;
}
- Dmsg1(200, "calling handler for %s\n", items[i].name);
+ Dmsg1(200, "calling handler for %s\n", items[i].name);
/* Call item handler */
bsr = items[i].handler(lc, bsr);
i = -1;
}
}
if (i >= 0) {
- Dmsg1(200, "Keyword = %s\n", lc->str);
- scan_err1(lc, "Keyword %s not found", lc->str);
+ Dmsg1(200, "Keyword = %s\n", lc->str);
+ scan_err1(lc, "Keyword %s not found", lc->str);
bsr = NULL;
break;
}
int token;
BSR_VOLUME *volume;
char *p, *n;
-
+
token = lex_get_token(lc, T_STRING);
if (token == T_ERROR) {
return NULL;
bsr->next = new_bsr();
bsr = bsr->next;
}
- /* This may actually be more than one volume separated by a |
+ /* This may actually be more than one volume separated by a |
* If so, separate them.
*/
for (p=lc->str; p && *p; ) {
bsr->volume = volume;
} else {
BSR_VOLUME *bc = bsr->volume;
- for ( ;bc->next; bc=bc->next)
+ for ( ;bc->next; bc=bc->next)
{ }
bc->next = volume;
}
{
int token;
BSR_CLIENT *client;
-
+
for (;;) {
token = lex_get_token(lc, T_NAME);
if (token == T_ERROR) {
bsr->client = client;
} else {
BSR_CLIENT *bc = bsr->client;
- for ( ;bc->next; bc=bc->next)
+ for ( ;bc->next; bc=bc->next)
{ }
bc->next = client;
}
{
int token;
BSR_JOB *job;
-
+
for (;;) {
token = lex_get_token(lc, T_NAME);
if (token == T_ERROR) {
/*
- * Routine to handle Volume start/end file
+ * Routine to handle Volume start/end file
*/
static BSR *store_volfile(LEX *lc, BSR *bsr)
{
/*
- * Routine to handle Volume start/end Block
+ * Routine to handle Volume start/end Block
*/
static BSR *store_volblock(LEX *lc, BSR *bsr)
{
{
if (FileIndex) {
if (FileIndex->findex == FileIndex->findex2) {
- Dmsg1(-1, "FileIndex : %u\n", FileIndex->findex);
+ Dmsg1(-1, "FileIndex : %u\n", FileIndex->findex);
} else {
- Dmsg2(-1, "FileIndex : %u-%u\n", FileIndex->findex, FileIndex->findex2);
+ Dmsg2(-1, "FileIndex : %u-%u\n", FileIndex->findex, FileIndex->findex2);
}
dump_findex(FileIndex->next);
}
{
if (jobid) {
if (jobid->JobId == jobid->JobId2) {
- Dmsg1(-1, "JobId : %u\n", jobid->JobId);
+ Dmsg1(-1, "JobId : %u\n", jobid->JobId);
} else {
- Dmsg2(-1, "JobId : %u-%u\n", jobid->JobId, jobid->JobId2);
+ Dmsg2(-1, "JobId : %u-%u\n", jobid->JobId, jobid->JobId2);
}
dump_jobid(jobid->next);
}
{
if (sessid) {
if (sessid->sessid == sessid->sessid2) {
- Dmsg1(-1, "SessId : %u\n", sessid->sessid);
+ Dmsg1(-1, "SessId : %u\n", sessid->sessid);
} else {
- Dmsg2(-1, "SessId : %u-%u\n", sessid->sessid, sessid->sessid2);
+ Dmsg2(-1, "SessId : %u-%u\n", sessid->sessid, sessid->sessid2);
}
dump_sessid(sessid->next);
}
}
/*****************************************************************
- * Routines for handling volumes
+ * Routines for handling volumes
*/
VOL_LIST *new_vol()
{
return vol;
}
-/*
+/*
* Add current volume to end of list, only if the Volume
* is not already in the list.
*
char *p, *n;
VOL_LIST *vol;
- /*
+ /*
* Build a list of volumes to be processed
*/
jcr->NumVolumes = 0;
vol->start_file = sfile;
if (add_vol(jcr, vol)) {
jcr->NumVolumes++;
- Dmsg1(400, "Added volume %s\n", vol->VolumeName);
+ Dmsg1(400, "Added volume %s\n", vol->VolumeName);
} else {
- Dmsg1(400, "Duplicate volume %s\n", vol->VolumeName);
+ Dmsg1(400, "Duplicate volume %s\n", vol->VolumeName);
free((char *)vol);
}
sfile = 0; /* start at beginning of second volume */
}
}
} else {
- /* This is the old way -- deprecated */
+ /* This is the old way -- deprecated */
for (p = jcr->dcr->VolumeName; p && *p; ) {
- n = strchr(p, '|'); /* volume name separator */
+ n = strchr(p, '|'); /* volume name separator */
if (n) {
*n++ = 0; /* Terminate name */
}
MA 02111-1307, USA.
*/
-
+
/* From stored.c */
uint32_t new_VolSessionId();
const char *edit_blocked_reason(DEVICE *dev);
/* From dircmd.c */
-void *handle_connection_request(void *arg);
+void *handle_connection_request(void *arg);
/* From fd_cmds.c */
/* From job.c */
void stored_free_jcr(JCR *jcr);
-void connection_from_filed(void *arg);
+void connection_from_filed(void *arg);
void handle_filed_connection(BSOCK *fd, char *job_name);
/* From label.c */
bool unser_session_label(SESSION_LABEL *label, DEV_RECORD *rec);
/* From match_bsr.c */
-int match_bsr(BSR *bsr, DEV_RECORD *rec, VOLUME_LABEL *volrec,
+int match_bsr(BSR *bsr, DEV_RECORD *rec, VOLUME_LABEL *volrec,
SESSION_LABEL *sesrec);
int match_bsr_block(BSR *bsr, DEV_BLOCK *block);
void position_bsr_block(BSR *bsr, DEV_BLOCK *block);
const char *stream_to_ascii(int stream, int fi);
bool write_record_to_block(DEV_BLOCK *block, DEV_RECORD *rec);
bool can_write_record_to_block(DEV_BLOCK *block, DEV_RECORD *rec);
-bool read_record_from_block(DEV_BLOCK *block, DEV_RECORD *rec);
+bool read_record_from_block(DEV_BLOCK *block, DEV_RECORD *rec);
DEV_RECORD *new_record();
void free_record(DEV_RECORD *rec);
void empty_record(DEV_RECORD *rec);
static char FD_error[] = "3000 error\n";
static char rec_header[] = "rechdr %ld %ld %ld %ld %ld";
-/*
+/*
* Read Data and send to File Daemon
* Returns: false on failure
* true on success
*/
-bool do_read_data(JCR *jcr)
+bool do_read_data(JCR *jcr)
{
BSOCK *fd = jcr->file_bsock;
bool ok = true;
DCR *dcr;
-
+
Dmsg0(20, "Start read data.\n");
if (!bnet_set_buffer_size(fd, jcr->device->max_network_buffer_size, BNET_SETBUF_WRITE)) {
return false;
}
- Dmsg2(200, "Found %d volumes names to restore. First=%s\n", jcr->NumVolumes,
+ Dmsg2(200, "Found %d volumes names to restore. First=%s\n", jcr->NumVolumes,
jcr->VolList->VolumeName);
- /*
+ /*
* Ready device for reading, and read records
*/
if (!(dcr=acquire_device_for_read(jcr))) {
if (!release_device(jcr)) {
ok = false;
}
-
+
free_vol_list(jcr);
Dmsg0(30, "Done reading.\n");
return ok;
if (dev_state(dev, ST_EOT)) {
DEV_RECORD *trec = new_record();
- Jmsg(jcr, M_INFO, 0, "End of Volume at file %u on device %s, Volume \"%s\"\n",
+ Jmsg(jcr, M_INFO, 0, "End of Volume at file %u on device %s, Volume \"%s\"\n",
dev->file, dev_name(dev), dcr->VolumeName);
if (!mount_cb(dcr)) {
- Jmsg(jcr, M_INFO, 0, "End of all volumes.\n");
+ Jmsg(jcr, M_INFO, 0, "End of all volumes.\n");
ok = false;
/*
* Create EOT Label so that Media record may
} else if (dev_state(dev, ST_EOF)) {
if (verbose) {
- Jmsg(jcr, M_INFO, 0, "Got EOF at file %u on device %s, Volume \"%s\"\n",
+ Jmsg(jcr, M_INFO, 0, "Got EOF at file %u on device %s, Volume \"%s\"\n",
dev->file, dev_name(dev), dcr->VolumeName);
}
- Dmsg3(200, "Got EOF at file %u on device %s, Volume \"%s\"\n",
+ Dmsg3(200, "Got EOF at file %u on device %s, Volume \"%s\"\n",
dev->file, dev_name(dev), dcr->VolumeName);
continue;
} else if (dev_state(dev, ST_SHORT)) {
- Jmsg1(jcr, M_ERROR, 0, "%s", dev->errmsg);
+ Jmsg1(jcr, M_ERROR, 0, "%s", dev->errmsg);
continue;
} else {
/* I/O error or strange end of tape */
display_tape_error_status(jcr, dev);
if (forge_on || jcr->ignore_label_errors) {
fsr_dev(dev, 1); /* try skipping bad record */
- Dmsg0(000, "Did fsr\n");
+ Dmsg0(000, "Did fsr\n");
continue; /* try to continue */
}
ok = false;
/*
* Get a new record for each Job as defined by
- * VolSessionId and VolSessionTime
+ * VolSessionId and VolSessionTime
*/
bool found = false;
foreach_dlist(rec, recs) {
if (!found) {
rec = new_record();
recs->prepend(rec);
- Dmsg2(300, "New record for SI=%d ST=%d\n",
+ Dmsg2(300, "New record for SI=%d ST=%d\n",
block->VolSessionId, block->VolSessionTime);
} else {
#ifdef xxx
if (rec->Block != 0 && (rec->Block+1) != block->BlockNumber) {
- Jmsg(jcr, M_ERROR, 0, _("Invalid block number. Expected %u, got %u\n"),
+ Jmsg(jcr, M_ERROR, 0, _("Invalid block number. Expected %u, got %u\n"),
rec->Block+1, block->BlockNumber);
}
-#endif
+#endif
}
- Dmsg3(300, "After mount next vol. stat=%s blk=%d rem=%d\n", rec_state_to_str(rec),
+ Dmsg3(300, "After mount next vol. stat=%s blk=%d rem=%d\n", rec_state_to_str(rec),
block->BlockNumber, rec->remainder);
record = 0;
rec->state = 0;
Dmsg1(300, "Block empty %d\n", is_block_empty(rec));
for (rec->state=0; !is_block_empty(rec); ) {
if (!read_record_from_block(block, rec)) {
- Dmsg3(400, "!read-break. state=%s blk=%d rem=%d\n", rec_state_to_str(rec),
+ Dmsg3(400, "!read-break. state=%s blk=%d rem=%d\n", rec_state_to_str(rec),
block->BlockNumber, rec->remainder);
break;
}
- Dmsg5(300, "read-OK. state=%s blk=%d rem=%d file:block=%d:%d\n",
+ Dmsg5(300, "read-OK. state=%s blk=%d rem=%d file:block=%d:%d\n",
rec_state_to_str(rec), block->BlockNumber, rec->remainder,
dev->file, dev->block_num);
/*
* get all the data.
*/
record++;
- Dmsg6(300, "recno=%d state=%s blk=%d SI=%d ST=%d FI=%d\n", record,
+ Dmsg6(300, "recno=%d state=%s blk=%d SI=%d ST=%d FI=%d\n", record,
rec_state_to_str(rec), block->BlockNumber,
rec->VolSessionId, rec->VolSessionTime, rec->FileIndex);
if (rec->FileIndex == EOM_LABEL) { /* end of tape? */
- Dmsg0(40, "Get EOM LABEL\n");
+ Dmsg0(40, "Get EOM LABEL\n");
break; /* yes, get out */
}
- /* Some sort of label? */
+ /* Some sort of label? */
if (rec->FileIndex < 0) {
handle_session_record(dev, rec, &sessrec);
ok = record_cb(dcr, rec);
if (rec->FileIndex == EOS_LABEL) {
- Dmsg2(300, "Remove rec. SI=%d ST=%d\n", rec->VolSessionId,
+ Dmsg2(300, "Remove rec. SI=%d ST=%d\n", rec->VolSessionId,
rec->VolSessionTime);
recs->remove(rec);
free_record(rec);
continue;
} /* end if label record */
- /*
+ /*
* Apply BSR filter
*/
if (jcr->bsr) {
int stat = match_bsr(jcr->bsr, rec, &dev->VolHdr, &sessrec);
if (stat == -1) { /* no more possible matches */
done = true; /* all items found, stop */
- Dmsg2(300, "All done=(file:block) %d:%d\n", dev->file, dev->block_num);
+ Dmsg2(300, "All done=(file:block) %d:%d\n", dev->file, dev->block_num);
break;
} else if (stat == 0) { /* no match */
- Dmsg4(300, "Clear rem=%d FI=%d before set_eof pos %d:%d\n",
+ Dmsg4(300, "Clear rem=%d FI=%d before set_eof pos %d:%d\n",
rec->remainder, rec->FileIndex, dev->file, dev->block_num);
rec->remainder = 0;
rec->state &= ~REC_PARTIAL_RECORD;
if (try_repositioning(jcr, rec, dev)) {
break;
}
- continue; /* we don't want record, read next one */
+ continue; /* we don't want record, read next one */
}
}
if (is_partial_record(rec)) {
- Dmsg6(300, "Partial, break. recno=%d state=%s blk=%d SI=%d ST=%d FI=%d\n", record,
+ Dmsg6(300, "Partial, break. recno=%d state=%s blk=%d SI=%d ST=%d FI=%d\n", record,
rec_state_to_str(rec), block->BlockNumber,
rec->VolSessionId, rec->VolSessionTime, rec->FileIndex);
break; /* read second part of record */
}
ok = record_cb(dcr, rec);
if (rec->Stream == STREAM_MD5_SIGNATURE || rec->Stream == STREAM_SHA1_SIGNATURE) {
- Dmsg3(300, "Done FI=%d before set_eof pos %d:%d\n", rec->FileIndex,
+ Dmsg3(300, "Done FI=%d before set_eof pos %d:%d\n", rec->FileIndex,
dev->file, dev->block_num);
if (match_set_eof(jcr->bsr, rec) && try_repositioning(jcr, rec, dev)) {
- Dmsg2(300, "Break after match_set_eof pos %d:%d\n",
+ Dmsg2(300, "Break after match_set_eof pos %d:%d\n",
dev->file, dev->block_num);
break;
}
- Dmsg2(300, "After set_eof pos %d:%d\n", dev->file, dev->block_num);
+ Dmsg2(300, "After set_eof pos %d:%d\n", dev->file, dev->block_num);
}
} /* end for loop over records */
Dmsg2(300, "After end records position=(file:block) %d:%d\n", dev->file, dev->block_num);
dev->state |= ST_EOT;
rec->Block = 0;
return 1;
- }
+ }
if (bsr) {
if (verbose) {
- Jmsg(jcr, M_INFO, 0, "Reposition from (file:block) %d:%d to %d:%d\n",
+ Jmsg(jcr, M_INFO, 0, "Reposition from (file:block) %d:%d to %d:%d\n",
dev->file, dev->block_num, bsr->volfile->sfile,
bsr->volblock->sblock);
}
{
BSR *bsr = NULL;
/*
- * Now find and position to first file and block
+ * Now find and position to first file and block
* on this tape.
*/
if (jcr->bsr) {
jcr->bsr->reposition = true; /* force repositioning */
bsr = find_next_bsr(jcr->bsr, dev);
if (bsr && (bsr->volfile->sfile != 0 || bsr->volblock->sblock != 0)) {
- Jmsg(jcr, M_INFO, 0, _("Forward spacing to file:block %u:%u.\n"),
+ Jmsg(jcr, M_INFO, 0, _("Forward spacing to file:block %u:%u.\n"),
bsr->volfile->sfile, bsr->volblock->sblock);
- Dmsg2(300, "Forward spacing to file:block %u:%u.\n",
+ Dmsg2(300, "Forward spacing to file:block %u:%u.\n",
bsr->volfile->sfile, bsr->volblock->sblock);
reposition_dev(dev, bsr->volfile->sfile, bsr->volblock->sblock);
}
{
const char *rtype;
char buf[100];
-
+
memset(sessrec, 0, sizeof(sessrec));
switch (rec->FileIndex) {
case PRE_LABEL:
- rtype = "Fresh Volume Label";
+ rtype = "Fresh Volume Label";
break;
case VOL_LABEL:
rtype = "Volume Label";
#ifdef DEBUG
static char *rec_state_to_str(DEV_RECORD *rec)
{
- static char buf[200];
+ static char buf[200];
buf[0] = 0;
if (rec->state & REC_NO_HEADER) {
bstrncat(buf, "Nohdr,", sizeof(buf));
}
-/*
+/*
* Convert a Stream ID into a printable
* ASCII string. Not reentrant.
static char buf[20];
if (fi < 0) {
sprintf(buf, "%d", stream);
- return buf;
+ return buf;
}
switch (stream) {
case STREAM_UNIX_ATTRIBUTES:
return "contHFSPLUS-ATTR";
default:
sprintf(buf, "%d", stream);
- return buf;
+ return buf;
}
}
-/*
+/*
* Return a new record entity
*/
DEV_RECORD *new_record(void)
}
/*
- * Free the record entity
+ * Free the record entity
*
*/
-void free_record(DEV_RECORD *rec)
+void free_record(DEV_RECORD *rec)
{
Dmsg0(350, "Enter free_record.\n");
if (rec->data) {
Dmsg0(350, "Data buf is freed.\n");
free_pool_memory((POOLMEM *)rec);
Dmsg0(350, "Leave free_record.\n");
-}
+}
/*
ASSERT(block->binbuf == (uint32_t) (block->bufp - block->buf));
ASSERT(block->buf_len >= block->binbuf);
- Dmsg6(890, "write_record_to_block() FI=%s SessId=%d Strm=%s len=%d\n\
-rem=%d remainder=%d\n",
- FI_to_ascii(rec->FileIndex), rec->VolSessionId,
+ Dmsg6(890, "write_record_to_block() FI=%s SessId=%d Strm=%s len=%d\n"
+"rem=%d remainder=%d\n",
+ FI_to_ascii(rec->FileIndex), rec->VolSessionId,
stream_to_ascii(rec->Stream, rec->FileIndex), rec->data_len,
remlen, rec->remainder);
return false;
}
} else {
- /*
+ /*
* We are here to write unwritten bytes from a previous
- * time. Presumably we have a new buffer (possibly
- * containing a volume label), so the new header
+ * time. Presumably we have a new buffer (possibly
+ * containing a volume label), so the new header
* should be able to fit in the block -- otherwise we have
* an error. Note, we have to continue splitting the
* data record if it is longer than the block.
- *
- * First, write the header, then write as much as
+ *
+ * First, write the header, then write as much as
* possible of the data record.
*
* Every time we write a header and it is a continuation
/*
* Now deal with data record.
- * Part of it may have already been transferred, and we
+ * Part of it may have already been transferred, and we
* may not have enough room to transfer the whole this time.
*/
if (rec->remainder > 0) {
block->bufp += rec->remainder;
block->binbuf += rec->remainder;
} else {
- memcpy(block->bufp, rec->data+rec->data_len-rec->remainder,
+ memcpy(block->bufp, rec->data+rec->data_len-rec->remainder,
remlen);
#ifdef xxxxxSMCHECK
if (!sm_check_rtn(__FILE__, __LINE__, False)) {
/* We damaged a buffer */
- Dmsg6(0, "Damaged block FI=%s SessId=%d Strm=%s len=%d\n\
-rem=%d remainder=%d\n",
- FI_to_ascii(rec->FileIndex), rec->VolSessionId,
+ Dmsg6(0, "Damaged block FI=%s SessId=%d Strm=%s len=%d\n"
+"rem=%d remainder=%d\n",
+ FI_to_ascii(rec->FileIndex), rec->VolSessionId,
stream_to_ascii(rec->Stream, rec->FileIndex), rec->data_len,
remlen, rec->remainder);
- Dmsg5(0, "Damaged block: bufp=%x binbuf=%d buf_len=%d rem=%d moved=%d\n",
+ Dmsg5(0, "Damaged block: bufp=%x binbuf=%d buf_len=%d rem=%d moved=%d\n",
block->bufp, block->binbuf, block->buf_len, block->buf_len-block->binbuf,
remlen);
- Dmsg2(0, "Damaged block: buf=%x binbuffrombuf=%d \n",
+ Dmsg2(0, "Damaged block: buf=%x binbuffrombuf=%d \n",
block->buf, block->bufp-block->buf);
- Emsg0(M_ABORT, 0, "Damaged buffer\n");
+ Emsg0(M_ABORT, 0, "Damaged buffer\n");
}
#endif
/*
* Test if we can write whole record to the block
*
- * Returns: false on failure
+ * Returns: false on failure
* true on success (all bytes can be written)
*/
bool can_write_record_to_block(DEV_BLOCK *block, DEV_RECORD *rec)
* Read a Record from the block
* Returns: false if nothing read or if the continuation record does not match.
* In both of these cases, a block read must be done.
- * true if at least the record header was read, this
+ * true if at least the record header was read, this
* routine may have to be called again with a new
* block if the entire record was not read.
*/
rec->Block = block->BlockNumber;
rec->File = ((DEVICE *)block->dev)->file;
- /* Clear state flags */
+ /* Clear state flags */
rec->state = 0;
if (((DEVICE *)block->dev)->state & ST_TAPE) {
rec->state |= REC_ISTAPE;
}
- /*
+ /*
* Get the header. There is always a full header,
* otherwise we find it in the next block.
*/
rhl = RECHDR2_LENGTH;
}
if (remlen >= rhl) {
- Dmsg4(450, "Enter read_record_block: remlen=%d data_len=%d rem=%d blkver=%d\n",
+ Dmsg4(450, "Enter read_record_block: remlen=%d data_len=%d rem=%d blkver=%d\n",
remlen, rec->data_len, rec->remainder, block->BlockVer);
unser_begin(block->bufp, WRITE_RECHDR_LENGTH);
/* If we are looking for more (remainder!=0), we reject anything
* where the VolSessionId and VolSessionTime don't agree
*/
- if (rec->remainder && (rec->VolSessionId != VolSessionId ||
+ if (rec->remainder && (rec->VolSessionId != VolSessionId ||
rec->VolSessionTime != VolSessionTime)) {
rec->state |= REC_NO_MATCH;
- Dmsg0(450, "remainder and VolSession doesn't match\n");
+ Dmsg0(450, "remainder and VolSession doesn't match\n");
return false; /* This is from some other Session */
}
* of a previous partially written record.
*/
if (Stream < 0) { /* continuation record? */
- Dmsg1(500, "Got negative Stream => continuation. remainder=%d\n",
+ Dmsg1(500, "Got negative Stream => continuation. remainder=%d\n",
rec->remainder);
rec->state |= REC_CONTINUATION;
- if (!rec->remainder) { /* if we didn't read previously */
+ if (!rec->remainder) { /* if we didn't read previously */
rec->data_len = 0; /* return data as if no continuation */
} else if (rec->Stream != -Stream) {
rec->state |= REC_NO_MATCH;
}
Dmsg6(450, "rd_rec_blk() got FI=%s SessId=%d Strm=%s len=%u\n"
- "remlen=%d data_len=%d\n",
- FI_to_ascii(rec->FileIndex), rec->VolSessionId,
- stream_to_ascii(rec->Stream, rec->FileIndex), data_bytes, remlen,
+ "remlen=%d data_len=%d\n",
+ FI_to_ascii(rec->FileIndex), rec->VolSessionId,
+ stream_to_ascii(rec->Stream, rec->FileIndex), data_bytes, remlen,
rec->data_len);
} else {
- /*
- * No more records in this block because the number
- * of remaining bytes are less than a record header
+ /*
+ * No more records in this block because the number
+ * of remaining bytes are less than a record header
* length, so return empty handed, but indicate that
* he must read again. By returning, we allow the
* higher level routine to fetch the next block and
ASSERT(data_bytes < MAX_BLOCK_LENGTH); /* temp sanity check */
rec->data = check_pool_memory_size(rec->data, rec->data_len+data_bytes);
-
+
/*
* At this point, we have read the header, now we
- * must transfer as much of the data record as
+ * must transfer as much of the data record as
* possible taking into account: 1. A partial
* data record may have previously been transferred,
* 2. The current block may not contain the whole data
}
rec->remainder = 0;
Dmsg4(450, "Rtn full rd_rec_blk FI=%s SessId=%d Strm=%s len=%d\n",
- FI_to_ascii(rec->FileIndex), rec->VolSessionId,
+ FI_to_ascii(rec->FileIndex), rec->VolSessionId,
stream_to_ascii(rec->Stream, rec->FileIndex), rec->data_len);
return true; /* transferred full record */
}
/*
* DEV_RECORD for reading and writing records.
* It consists of a Record Header, and the Record Data
- *
+ *
* This is the memory structure for the record header.
*/
struct BSR; /* satisfy forward reference */
BSR *bsr; /* pointer to bsr that matched */
uint8_t ser_buf[WRITE_RECHDR_LENGTH]; /* serialized record header goes here */
POOLMEM *data; /* Record data. This MUST be a memory pool item */
-};
+};
/*
*/
#define PRE_LABEL -1 /* Vol label on unwritten tape */
#define VOL_LABEL -2 /* Volume label first file */
-#define EOM_LABEL -3 /* Writen at end of tape */
+#define EOM_LABEL -3 /* Writen at end of tape */
#define SOS_LABEL -4 /* Start of Session */
#define EOS_LABEL -5 /* End of Session */
#define EOT_LABEL -6 /* End of physical tape (2 eofs) */
-/*
+/*
* Volume Label Record. This is the in-memory definition. The
* tape definition is defined in the serialization code itself
* ser_volume_label() and unser_volume_label() and is slightly different.
*/
-
+
struct Volume_Label {
- /*
+ /*
* The first items in this structure are saved
* in the DEVICE buffer, but are not actually written
* to the tape.
int32_t LabelType; /* This is written in header only */
uint32_t LabelSize; /* length of serialized label */
/*
- * The items below this line are stored on
+ * The items below this line are stored on
* the tape
*/
char Id[32]; /* Bacula Immortal ... */
/*
- * Spooling code
+ * Spooling code
*
* Kern Sibbald, March 2004
*
struct spool_stats_t {
uint32_t data_jobs; /* current jobs spooling data */
- uint32_t attr_jobs;
+ uint32_t attr_jobs;
uint32_t total_data_jobs; /* total jobs to have spooled data */
uint32_t total_attr_jobs;
int64_t max_data_size; /* max data size */
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
spool_stats_t spool_stats;
-/*
+/*
* Header for data spool record */
struct spool_hdr {
int32_t FirstIndex; /* FirstIndex for buffer */
if (spool_stats.data_jobs || spool_stats.max_data_size) {
bnet_fsend(bs, "Data spooling: %u active jobs, %s bytes; %u total jobs, %s max bytes/job.\n",
spool_stats.data_jobs, edit_uint64_with_commas(spool_stats.data_size, ed1),
- spool_stats.total_data_jobs,
+ spool_stats.total_data_jobs,
edit_uint64_with_commas(spool_stats.max_data_size, ed2));
}
if (spool_stats.attr_jobs || spool_stats.max_attr_size) {
bnet_fsend(bs, "Attr spooling: %u active jobs, %s bytes; %u total jobs, %s max bytes.\n",
- spool_stats.attr_jobs, edit_uint64_with_commas(spool_stats.attr_size, ed1),
- spool_stats.total_attr_jobs,
+ spool_stats.attr_jobs, edit_uint64_with_commas(spool_stats.attr_size, ed1),
+ spool_stats.total_attr_jobs,
edit_uint64_with_commas(spool_stats.max_attr_size, ed2));
}
}
stat = open_data_spool_file(jcr);
if (stat) {
jcr->dcr->spooling = true;
- Jmsg(jcr, M_INFO, 0, _("Spooling data ...\n"));
+ Jmsg(jcr, M_INFO, 0, _("Spooling data ...\n"));
P(mutex);
spool_stats.data_jobs++;
V(mutex);
Dmsg0(100, "Committing spooled data\n");
stat = despool_data(jcr->dcr, true /*commit*/);
if (!stat) {
- Pmsg1(000, "Bad return from despool WroteVol=%d\n", jcr->dcr->WroteVol);
+ Pmsg1(000, "Bad return from despool WroteVol=%d\n", jcr->dcr->WroteVol);
close_data_spool_file(jcr);
return false;
}
static void make_unique_data_spool_filename(JCR *jcr, POOLMEM **name)
{
- const char *dir;
+ const char *dir;
if (jcr->dcr->dev->device->spool_directory) {
dir = jcr->dcr->dev->device->spool_directory;
} else {
static const char *spool_name = "*spool*";
-static bool despool_data(DCR *dcr, bool commit)
+static bool despool_data(DCR *dcr, bool commit)
{
DEVICE *rdev;
DCR *rdcr;
edit_uint64_with_commas(jcr->dcr->spool_size, ec1));
dcr->spooling = false;
lock_device(dcr->dev);
- dcr->dev_locked = true;
+ dcr->dev_locked = true;
- /*
+ /*
* This is really quite kludgy and should be fixed some time.
- * We create a dev structure to read from the spool file
+ * We create a dev structure to read from the spool file
* in rdev and rdcr.
*/
rdev = (DEVICE *)malloc(sizeof(DEVICE));
rdev->min_block_size = dcr->dev->min_block_size;
rdev->device = dcr->dev->device;
rdcr = new_dcr(NULL, rdev);
- rdcr->spool_fd = dcr->spool_fd;
+ rdcr->spool_fd = dcr->spool_fd;
rdcr->jcr = jcr; /* set a valid jcr */
block = dcr->block; /* save block */
dcr->block = rdcr->block; /* make read and write block the same */
lseek(rdcr->spool_fd, 0, SEEK_SET); /* rewind */
if (ftruncate(rdcr->spool_fd, 0) != 0) {
berrno be;
- Jmsg(dcr->jcr, M_ERROR, 0, _("Ftruncate spool file failed: ERR=%s\n"),
+ Jmsg(dcr->jcr, M_ERROR, 0, _("Ftruncate spool file failed: ERR=%s\n"),
be.strerror());
Pmsg1(000, "Bad return from ftruncate. ERR=%s\n", be.strerror());
ok = false;
/*
* Read a block from the spool file
- *
+ *
* Returns RB_OK on success
* RB_EOT when file done
* RB_ERROR on error
} else if (stat != (ssize_t)rlen) {
if (stat == -1) {
berrno be;
- Jmsg(dcr->jcr, M_FATAL, 0, _("Spool header read error. ERR=%s\n"),
+ Jmsg(dcr->jcr, M_FATAL, 0, _("Spool header read error. ERR=%s\n"),
be.strerror());
} else {
- Pmsg2(000, "Spool read error. Wanted %u bytes, got %u\n", rlen, stat);
- Jmsg2(dcr->jcr, M_FATAL, 0, _("Spool header read error. Wanted %u bytes, got %u\n"), rlen, stat);
+ Pmsg2(000, "Spool read error. Wanted %u bytes, got %u\n", rlen, stat);
+ Jmsg2(dcr->jcr, M_FATAL, 0, _("Spool header read error. Wanted %u bytes, got %u\n"), rlen, stat);
}
return RB_ERROR;
}
}
V(mutex);
if (despool) {
-#ifdef xDEBUG
+#ifdef xDEBUG
char ec1[30], ec2[30], ec3[30], ec4[30];
Dmsg4(100, "Despool in write_block_to_spool_file max_size=%s size=%s "
- "max_job_size=%s job_size=%s\n",
+ "max_job_size=%s job_size=%s\n",
edit_uint64_with_commas(dcr->max_spool_size, ec1),
edit_uint64_with_commas(dcr->spool_size, ec2),
edit_uint64_with_commas(dcr->dev->max_spool_size, ec3),
#endif
Jmsg(dcr->jcr, M_INFO, 0, _("User specified spool size reached.\n"));
if (!despool_data(dcr, false)) {
- Pmsg0(000, "Bad return from despool in write_block.\n");
+ Pmsg0(000, "Bad return from despool in write_block.\n");
return false;
}
/* Despooling cleared these variables so reset them */
dcr->dev->spool_size += hlen + wlen;
V(dcr->dev->spool_mutex);
Jmsg(dcr->jcr, M_INFO, 0, _("Spooling data again ...\n"));
- }
+ }
if (!write_spool_header(dcr)) {
static bool write_spool_header(DCR *dcr)
{
- spool_hdr hdr;
+ spool_hdr hdr;
ssize_t stat;
DEV_BLOCK *block = dcr->block;
stat = write(dcr->spool_fd, (char*)&hdr, sizeof(hdr));
if (stat == -1) {
berrno be;
- Jmsg(dcr->jcr, M_FATAL, 0, _("Error writing header to spool file. ERR=%s\n"),
+ Jmsg(dcr->jcr, M_FATAL, 0, _("Error writing header to spool file. ERR=%s\n"),
be.strerror());
}
if (stat != (ssize_t)sizeof(hdr)) {
if (stat != -1) {
if (ftruncate(dcr->spool_fd, lseek(dcr->spool_fd, (off_t)0, SEEK_CUR) - stat) != 0) {
berrno be;
- Jmsg(dcr->jcr, M_FATAL, 0, _("Ftruncate spool file failed: ERR=%s\n"),
+ Jmsg(dcr->jcr, M_FATAL, 0, _("Ftruncate spool file failed: ERR=%s\n"),
be.strerror());
return false;
}
}
if (!despool_data(dcr, false)) {
- Jmsg(dcr->jcr, M_FATAL, 0, _("Fatal despooling error."));
+ Jmsg(dcr->jcr, M_FATAL, 0, _("Fatal despooling error."));
return false;
}
continue; /* try again */
stat = write(dcr->spool_fd, block->buf, (size_t)block->binbuf);
if (stat == -1) {
berrno be;
- Jmsg(dcr->jcr, M_FATAL, 0, _("Error writing data to spool file. ERR=%s\n"),
+ Jmsg(dcr->jcr, M_FATAL, 0, _("Error writing data to spool file. ERR=%s\n"),
be.strerror());
}
if (stat != (ssize_t)block->binbuf) {
- /*
+ /*
* If we wrote something, truncate it and the header, then despool
*/
if (stat != -1) {
if (ftruncate(dcr->spool_fd, lseek(dcr->spool_fd, (off_t)0, SEEK_CUR)
- stat - sizeof(spool_hdr)) != 0) {
berrno be;
- Jmsg(dcr->jcr, M_FATAL, 0, _("Ftruncate spool file failed: ERR=%s\n"),
+ Jmsg(dcr->jcr, M_FATAL, 0, _("Ftruncate spool file failed: ERR=%s\n"),
be.strerror());
return false;
}
}
if (!despool_data(dcr, false)) {
- Jmsg(dcr->jcr, M_FATAL, 0, _("Fatal despooling error."));
+ Jmsg(dcr->jcr, M_FATAL, 0, _("Fatal despooling error."));
return false;
}
if (!write_spool_header(dcr)) {
return jcr->spool_attributes && jcr->dir_bsock->spool_fd;
}
-/*
+/*
* Create spool file for attributes.
* This is done by "attaching" to the bsock, and when
* it is called, the output is written to a file.
if (are_attributes_spooled(jcr)) {
if (fseek(jcr->dir_bsock->spool_fd, 0, SEEK_END) != 0) {
berrno be;
- Jmsg(jcr, M_FATAL, 0, _("Fseek on attributes file failed: ERR=%s\n"),
+ Jmsg(jcr, M_FATAL, 0, _("Fseek on attributes file failed: ERR=%s\n"),
be.strerror());
}
size = ftell(jcr->dir_bsock->spool_fd);
if (size > 0) {
if (spool_stats.attr_size + size > spool_stats.max_attr_size) {
spool_stats.max_attr_size = spool_stats.attr_size + size;
- }
+ }
}
spool_stats.attr_size += size;
V(mutex);
bool close_attr_spool_file(JCR *jcr, BSOCK *bs)
{
POOLMEM *name;
-
+
if (!bs->spool_fd) {
return true;
}
* Kern Sibbald, May MMIII
*
* Version $Id$
- *
+ *
*/
/*
Copyright (C) 2000-2004 Kern Sibbald and John Walker
HOST_OS, DISTNAME, DISTVER);
bstrftime_nc(dt, sizeof(dt), daemon_start_time);
bnet_fsend(user, _("Daemon started %s, %d Job%s run since started.\n"), dt, num_jobs_run,
- num_jobs_run == 1 ? "" : "s");
+ num_jobs_run == 1 ? "" : "s");
if (debug_level > 0) {
char b1[35], b2[35], b3[35], b4[35];
bnet_fsend(user, _(" Heap: bytes=%s max_bytes=%s bufs=%s max_bufs=%s\n"),
for (dev=device->dev; dev; dev=dev->next) {
if (dev_state(dev, ST_OPENED)) {
if (dev_state(dev, ST_LABEL)) {
- bnet_fsend(user, _("Device \"%s\" is mounted with Volume \"%s\"\n"),
+ bnet_fsend(user, _("Device \"%s\" is mounted with Volume \"%s\"\n"),
dev_name(dev), dev->VolHdr.VolName);
} else {
- bnet_fsend(user, _("Device \"%s\" open but no Bacula volume is mounted.\n"), dev_name(dev));
+ bnet_fsend(user, _("Device \"%s\" open but no Bacula volume is mounted.\n"), dev_name(dev));
}
send_blocked_status(jcr, dev);
if (dev_state(dev, ST_APPEND)) {
bpb = 1;
}
bpb = dev->VolCatInfo.VolCatBytes / bpb;
- bnet_fsend(user, _(" Total Bytes=%s Blocks=%s Bytes/block=%s\n"),
+ bnet_fsend(user, _(" Total Bytes=%s Blocks=%s Bytes/block=%s\n"),
edit_uint64_with_commas(dev->VolCatInfo.VolCatBytes, b1),
- edit_uint64_with_commas(dev->VolCatInfo.VolCatBlocks, b2),
+ edit_uint64_with_commas(dev->VolCatInfo.VolCatBlocks, b2),
edit_uint64_with_commas(bpb, b3));
} else { /* reading */
bpb = dev->VolCatInfo.VolCatReads;
} else {
bpb = 0;
}
- bnet_fsend(user, _(" Total Bytes Read=%s Blocks Read=%s Bytes/block=%s\n"),
+ bnet_fsend(user, _(" Total Bytes Read=%s Blocks Read=%s Bytes/block=%s\n"),
edit_uint64_with_commas(dev->VolCatInfo.VolCatRBytes, b1),
- edit_uint64_with_commas(dev->VolCatInfo.VolCatReads, b2),
+ edit_uint64_with_commas(dev->VolCatInfo.VolCatReads, b2),
edit_uint64_with_commas(bpb, b3));
}
- bnet_fsend(user, _(" Positioned at File=%s Block=%s\n"),
+ bnet_fsend(user, _(" Positioned at File=%s Block=%s\n"),
edit_uint64_with_commas(dev->file, b1),
edit_uint64_with_commas(dev->block_num, b2));
} else {
- bnet_fsend(user, _("Device \"%s\" is not open.\n"), dev_name(dev));
+ bnet_fsend(user, _("Device \"%s\" is not open.\n"), dev_name(dev));
send_blocked_status(jcr, dev);
}
}
return true;
}
-static void send_blocked_status(JCR *jcr, DEVICE *dev)
+static void send_blocked_status(JCR *jcr, DEVICE *dev)
{
BSOCK *user = jcr->dir_bsock;
DCR *dcr = jcr->dcr;
break;
case BST_WAITING_FOR_SYSOP:
if (jcr->JobStatus == JS_WaitMount) {
- bnet_fsend(user, _(" Device is BLOCKED waiting for mount of volume \"%s\".\n"),
+ bnet_fsend(user, _(" Device is BLOCKED waiting for mount of volume \"%s\".\n"),
dcr->VolumeName);
} else {
- bnet_fsend(user, _(" Device is BLOCKED waiting for appendable media.\n"));
+ bnet_fsend(user, _(" Device is BLOCKED waiting for appendable media.\n"));
}
break;
case BST_DOING_ACQUIRE:
JCR *jcr;
char JobName[MAX_NAME_LENGTH];
char b1[30], b2[30], b3[30];
-
+
bnet_fsend(user, _("\nRunning Jobs:\n"));
lock_jcr_chain();
foreach_jcr(jcr) {
if (jcr->JobStatus == JS_WaitFD) {
- bnet_fsend(user, _("%s Job %s waiting for Client connection.\n"),
+ bnet_fsend(user, _("%s Job %s waiting for Client connection.\n"),
job_type_to_str(jcr->JobType), jcr->Job);
}
if (jcr->device) {
/* There are three periods after the Job name */
char *p;
for (int i=0; i<3; i++) {
- if ((p=strrchr(JobName, '.')) != NULL) {
+ if ((p=strrchr(JobName, '.')) != NULL) {
*p = 0;
}
}
- bnet_fsend(user, _("%s %s job %s JobId=%d Volume=\"%s\" device=\"%s\"\n"),
+ bnet_fsend(user, _("%s %s job %s JobId=%d Volume=\"%s\" device=\"%s\"\n"),
job_level_to_str(jcr->JobLevel),
job_type_to_str(jcr->JobType),
JobName,
jcr->JobId,
- jcr->dcr?jcr->dcr->VolumeName:"*none*",
- jcr->device?jcr->device->device_name:"none");
+ jcr->dcr?jcr->dcr->VolumeName:"*none*",
+ jcr->device?jcr->device->device_name:"none");
sec = time(NULL) - jcr->run_time;
if (sec <= 0) {
sec = 1;
}
bps = jcr->JobBytes / sec;
- bnet_fsend(user, _(" Files=%s Bytes=%s Bytes/sec=%s\n"),
+ bnet_fsend(user, _(" Files=%s Bytes=%s Bytes/sec=%s\n"),
edit_uint64_with_commas(jcr->JobFiles, b1),
edit_uint64_with_commas(jcr->JobBytes, b2),
edit_uint64_with_commas(bps, b3));
found = true;
#ifdef DEBUG
if (jcr->file_bsock) {
- bnet_fsend(user, " FDReadSeqNo=%s in_msg=%u out_msg=%d fd=%d\n",
+ bnet_fsend(user, " FDReadSeqNo=%s in_msg=%u out_msg=%d fd=%d\n",
edit_uint64_with_commas(jcr->file_bsock->read_seqno, b1),
jcr->file_bsock->in_msg_no, jcr->file_bsock->out_msg_no,
jcr->file_bsock->fd);
} else {
- bnet_fsend(user, " FDSocket closed\n");
+ bnet_fsend(user, " FDSocket closed\n");
}
#endif
}
const char *msg;
if (last_jobs->size() == 0) {
- msg = _("No Terminated Jobs.\n");
+ msg = _("No Terminated Jobs.\n");
sendit(msg, strlen(msg), arg);
return;
}
lock_last_jobs_list();
- msg = _("\nTerminated Jobs:\n");
+ msg = _("\nTerminated Jobs:\n");
sendit(msg, strlen(msg), arg);
msg = _(" JobId Level Files Bytes Status Finished Name \n");
sendit(msg, strlen(msg), arg);
- msg = _("======================================================================\n");
+ msg = _("======================================================================\n");
sendit(msg, strlen(msg), arg);
foreach_dlist(je, last_jobs) {
char JobName[MAX_NAME_LENGTH];
switch (je->JobType) {
case JT_ADMIN:
case JT_RESTORE:
- bstrncpy(level, " ", sizeof(level));
+ bstrncpy(level, " ", sizeof(level));
break;
default:
bstrncpy(level, level_to_str(je->JobLevel), sizeof(level));
}
switch (je->JobStatus) {
case JS_Created:
- termstat = "Created";
+ termstat = "Created";
break;
case JS_FatalError:
case JS_ErrorTerminated:
- termstat = "Error";
+ termstat = "Error";
break;
case JS_Differences:
- termstat = "Diffs";
+ termstat = "Diffs";
break;
case JS_Canceled:
- termstat = "Cancel";
+ termstat = "Cancel";
break;
case JS_Terminated:
- termstat = "OK";
+ termstat = "OK";
break;
default:
- termstat = "Other";
+ termstat = "Other";
break;
}
bstrncpy(JobName, je->Job, sizeof(JobName));
/* There are three periods after the Job name */
char *p;
for (int i=0; i<3; i++) {
- if ((p=strrchr(JobName, '.')) != NULL) {
+ if ((p=strrchr(JobName, '.')) != NULL) {
*p = 0;
}
}
- bsnprintf(buf, sizeof(buf), _("%6d %-6s %8s %14s %-7s %-8s %s\n"),
+ bsnprintf(buf, sizeof(buf), _("%6d %-6s %8s %14s %-7s %-8s %s\n"),
je->JobId,
- level,
+ level,
edit_uint64_with_commas(je->JobFiles, b1),
- edit_uint64_with_commas(je->JobBytes, b2),
+ edit_uint64_with_commas(je->JobBytes, b2),
termstat,
dt, JobName);
sendit(buf, strlen(buf), arg);
/*
* Convert Job Level into a string
*/
-static const char *level_to_str(int level)
+static const char *level_to_str(int level)
{
const char *str;
}
/*
- * Send to Director
+ * Send to Director
*/
static void sendit(const char *msg, int len, void *arg)
{
return false;
}
unbash_spaces(time);
-
+
if (strcmp(time.c_str(), "current") == 0) {
bnet_fsend(dir, OKqstatus, time.c_str());
lock_jcr_chain();
* It accepts a number of simple commands from the File daemon
* and acts on them. When a request to append data is made,
* it opens a data channel and accepts data from the
- * File daemon.
+ * File daemon.
*
* Version $Id$
- *
+ *
*/
/*
Copyright (C) 2000-2004 Kern Sibbald and John Walker
exit(1);
}
-/*********************************************************************
+/*********************************************************************
*
* Main Bacula Unix Storage Daemon
*
*/
int main (int argc, char *argv[])
{
- int ch;
+ int ch;
int no_signals = FALSE;
int test_config = FALSE;
pthread_t thid;
case 'd': /* debug level */
debug_level = atoi(optarg);
if (debug_level <= 0) {
- debug_level = 1;
+ debug_level = 1;
}
break;
default:
usage();
break;
- }
+ }
}
argc -= optind;
argv += optind;
free(configfile);
}
configfile = bstrdup(*argv);
- argc--;
+ argc--;
argv++;
}
if (argc)
init_jcr_subsystem(); /* start JCR watchdogs etc. */
- /*
+ /*
* Sleep a bit to give device thread a chance to lock the resource
* chain before we start the server.
*/
bmicrosleep(1, 0);
-
+
/* Single server used for Director and File daemon */
bnet_thread_server(me->sdaddrs, me->max_concurrent_jobs * 2 + 1,
&dird_workq, handle_connection_request);
if (GetNextRes(R_STORAGE, (RES *)me) != NULL) {
UnlockRes();
- Emsg1(M_ERROR_TERM, 0, _("Only one Storage resource permitted in %s\n"),
+ Emsg1(M_ERROR_TERM, 0, _("Only one Storage resource permitted in %s\n"),
configfile);
}
if (GetNextRes(R_DIRECTOR, NULL) == NULL) {
if (!me->messages) {
me->messages = (MSGS *)GetNextRes(R_MSGS, NULL);
if (!me->messages) {
- Emsg1(M_ERROR_TERM, 0, _("No Messages resource defined in %s. Cannot continue.\n"),
+ Emsg1(M_ERROR_TERM, 0, _("No Messages resource defined in %s. Cannot continue.\n"),
configfile);
}
}
Emsg1(M_ERROR_TERM, 0, _("No Working Directory defined in %s. Cannot continue.\n"),
configfile);
}
-
+
set_working_directory(me->working_directory);
}
device->dev = init_dev(NULL, device);
Dmsg1(10, "SD init done %s\n", device->device_name);
if (!device->dev) {
- Emsg1(M_ERROR, 0, _("Could not initialize %s\n"), device->device_name);
+ Emsg1(M_ERROR, 0, _("Could not initialize %s\n"), device->device_name);
continue;
}
if (device->cap_bits & CAP_ALWAYSOPEN) {
- Dmsg1(20, "calling first_open_device %s\n", device->device_name);
+ Dmsg1(20, "calling first_open_device %s\n", device->device_name);
if (!first_open_device(device->dev)) {
- Emsg1(M_ERROR, 0, _("Could not open device %s\n"), device->device_name);
+ Emsg1(M_ERROR, 0, _("Could not open device %s\n"), device->device_name);
}
}
- if (device->cap_bits & CAP_AUTOMOUNT && device->dev &&
+ if (device->cap_bits & CAP_AUTOMOUNT && device->dev &&
device->dev->state & ST_OPENED) {
JCR *jcr;
DCR *dcr;
/* Initialize FD start condition variable */
int errstat = pthread_cond_init(&jcr->job_start_wait, NULL);
if (errstat != 0) {
- Jmsg1(jcr, M_ABORT, 0, _("Unable to init job cond variable: ERR=%s\n"), strerror(errstat));
+ Jmsg1(jcr, M_ABORT, 0, _("Unable to init job cond variable: ERR=%s\n"), strerror(errstat));
}
jcr->device = device;
dcr = new_dcr(jcr, device->dev);
memcpy(&dcr->dev->VolCatInfo, &dcr->VolCatInfo, sizeof(dcr->dev->VolCatInfo));
break;
default:
- Emsg1(M_WARNING, 0, _("Could not mount device %s\n"), device->device_name);
+ Emsg1(M_WARNING, 0, _("Could not mount device %s\n"), device->device_name);
break;
}
free_jcr(jcr);
}
- }
+ }
UnlockRes();
return NULL;
}
continue; /* ignore console */
}
set_jcr_job_status(jcr, JS_Canceled);
- fd = jcr->file_bsock;
+ fd = jcr->file_bsock;
if (fd) {
fd->timed_out = true;
- Dmsg1(100, "term_stored killing JobId=%d\n", jcr->JobId);
+ Dmsg1(100, "term_stored killing JobId=%d\n", jcr->JobId);
pthread_kill(jcr->my_thread_id, TIMEOUT_SIGNAL);
if (jcr->device && jcr->device->dev && jcr->device->dev->dev_blocked) {
pthread_cond_signal(&jcr->device->dev->wait_next_vol);
if (device->dev) {
term_dev(device->dev);
}
- }
+ }
UnlockRes();
if (configfile)
int res_all_size = sizeof(res_all);
/* Definition of records permitted within each
- * resource with the routine to process the record
+ * resource with the routine to process the record
* information.
- */
+ */
/* Globals for the Storage daemon. */
static RES_ITEM store_items[] = {
{"requiressl", store_yesno,ITEM(res_store.require_ssl), 1, ITEM_DEFAULT, 0},
{"maximumconcurrentjobs", store_pint, ITEM(res_store.max_concurrent_jobs), 0, ITEM_DEFAULT, 10},
{"heartbeatinterval", store_time, ITEM(res_store.heartbeat_interval), 0, ITEM_DEFAULT, 0},
- {NULL, NULL, 0, 0, 0, 0}
+ {NULL, NULL, 0, 0, 0, 0}
};
{"password", store_password, ITEM(res_dir.password), 0, ITEM_REQUIRED, 0},
{"enablessl", store_yesno, ITEM(res_dir.enable_ssl), 1, ITEM_DEFAULT, 0},
{"monitor", store_yesno, ITEM(res_dir.monitor), 1, ITEM_DEFAULT, 0},
- {NULL, NULL, 0, 0, 0, 0}
+ {NULL, NULL, 0, 0, 0, 0}
};
/* Device definition */
{"maximumspoolsize", store_size, ITEM(res_dev.max_spool_size), 0, 0, 0},
{"maximumjobspoolsize", store_size, ITEM(res_dev.max_job_spool_size), 0, 0, 0},
{"driveindex", store_pint, ITEM(res_dev.drive_index), 0, 0, 0},
- {NULL, NULL, 0, 0, 0, 0}
+ {NULL, NULL, 0, 0, 0, 0}
};
// {"mountanonymousvolumes", store_yesno, ITEM(res_dev.cap_bits), CAP_ANONVOLS, ITEM_DEFAULT, 0},
break;
case R_STORAGE:
sendit(sock, "Storage: name=%s SDaddr=%s SDport=%d SDDport=%d HB=%s\n",
- res->res_store.hdr.name,
+ res->res_store.hdr.name,
NPRT(get_first_address(res->res_store.sdaddrs, buf, sizeof(buf))),
- get_first_port_host_order(res->res_store.sdaddrs),
+ get_first_port_host_order(res->res_store.sdaddrs),
get_first_port_host_order(res->res_store.sddaddrs),
edit_utime(res->res_store.heartbeat_interval, buf, sizeof(buf)));
foreach_dlist(p, res->res_store.sdaddrs) {
- sendit(sock, " SDaddr=%s SDport=%d\n",
+ sendit(sock, " SDaddr=%s SDport=%d\n",
p->get_address(buf, sizeof(buf)), p->get_port_host_order());
}
foreach_dlist(p, res->res_store.sddaddrs) {
- sendit(sock, " SDDaddr=%s SDDport=%d\n",
+ sendit(sock, " SDDaddr=%s SDDport=%d\n",
p->get_address(buf, sizeof(buf)), p->get_port_host_order());
}
break;
res->res_dev.hdr.name,
res->res_dev.media_type, res->res_dev.device_name);
sendit(sock, " rew_wait=%d min_bs=%d max_bs=%d\n",
- res->res_dev.max_rewind_wait, res->res_dev.min_block_size,
+ res->res_dev.max_rewind_wait, res->res_dev.min_block_size,
res->res_dev.max_block_size);
sendit(sock, " max_jobs=%d max_files=%" lld " max_size=%" lld "\n",
res->res_dev.max_volume_jobs, res->res_dev.max_volume_files,
res->res_dev.max_spool_size, res->res_dev.max_job_spool_size);
strcpy(buf, " ");
if (res->res_dev.cap_bits & CAP_EOF) {
- bstrncat(buf, "CAP_EOF ", sizeof(buf));
+ bstrncat(buf, "CAP_EOF ", sizeof(buf));
}
if (res->res_dev.cap_bits & CAP_BSR) {
- bstrncat(buf, "CAP_BSR ", sizeof(buf));
+ bstrncat(buf, "CAP_BSR ", sizeof(buf));
}
if (res->res_dev.cap_bits & CAP_BSF) {
- bstrncat(buf, "CAP_BSF ", sizeof(buf));
+ bstrncat(buf, "CAP_BSF ", sizeof(buf));
}
if (res->res_dev.cap_bits & CAP_FSR) {
- bstrncat(buf, "CAP_FSR ", sizeof(buf));
+ bstrncat(buf, "CAP_FSR ", sizeof(buf));
}
if (res->res_dev.cap_bits & CAP_FSF) {
- bstrncat(buf, "CAP_FSF ", sizeof(buf));
+ bstrncat(buf, "CAP_FSF ", sizeof(buf));
}
if (res->res_dev.cap_bits & CAP_EOM) {
- bstrncat(buf, "CAP_EOM ", sizeof(buf));
+ bstrncat(buf, "CAP_EOM ", sizeof(buf));
}
if (res->res_dev.cap_bits & CAP_REM) {
- bstrncat(buf, "CAP_REM ", sizeof(buf));
+ bstrncat(buf, "CAP_REM ", sizeof(buf));
}
if (res->res_dev.cap_bits & CAP_RACCESS) {
- bstrncat(buf, "CAP_RACCESS ", sizeof(buf));
+ bstrncat(buf, "CAP_RACCESS ", sizeof(buf));
}
if (res->res_dev.cap_bits & CAP_AUTOMOUNT) {
- bstrncat(buf, "CAP_AUTOMOUNT ", sizeof(buf));
+ bstrncat(buf, "CAP_AUTOMOUNT ", sizeof(buf));
}
if (res->res_dev.cap_bits & CAP_LABEL) {
- bstrncat(buf, "CAP_LABEL ", sizeof(buf));
+ bstrncat(buf, "CAP_LABEL ", sizeof(buf));
}
if (res->res_dev.cap_bits & CAP_ANONVOLS) {
- bstrncat(buf, "CAP_ANONVOLS ", sizeof(buf));
+ bstrncat(buf, "CAP_ANONVOLS ", sizeof(buf));
}
if (res->res_dev.cap_bits & CAP_ALWAYSOPEN) {
- bstrncat(buf, "CAP_ALWAYSOPEN ", sizeof(buf));
+ bstrncat(buf, "CAP_ALWAYSOPEN ", sizeof(buf));
}
bstrncat(buf, "\n", sizeof(buf));
sendit(sock, buf);
break;
case R_MSGS:
sendit(sock, "Messages: name=%s\n", res->res_msgs.hdr.name);
- if (res->res_msgs.mail_cmd)
- sendit(sock, " mailcmd=%s\n", res->res_msgs.mail_cmd);
- if (res->res_msgs.operator_cmd)
- sendit(sock, " opcmd=%s\n", res->res_msgs.operator_cmd);
+ if (res->res_msgs.mail_cmd)
+ sendit(sock, " mailcmd=%s\n", res->res_msgs.mail_cmd);
+ if (res->res_msgs.operator_cmd)
+ sendit(sock, " opcmd=%s\n", res->res_msgs.operator_cmd);
break;
default:
sendit(sock, _("Warning: unknown resource type %d\n"), type);
dump_resource(type, (RES *)res->res_dir.hdr.next, sendit, sock);
}
-/*
- * Free memory of resource.
+/*
+ * Free memory of resource.
* NB, we don't need to worry about freeing any references
- * to other resources as they will be freed when that
+ * to other resources as they will be freed when that
* resource chain is traversed. Mainly we worry about freeing
* allocated strings (names).
*/
res = NULL;
break;
default:
- Dmsg1(0, "Unknown resource type %d\n", type);
+ Dmsg1(0, "Unknown resource type %d\n", type);
break;
}
/* Common stuff again -- free the resource, recurse to next one */
int i, size;
int error = 0;
- /*
+ /*
* Ensure that all required items are present
*/
for (i=0; items[i].name; i++) {
if (items[i].flags & ITEM_REQUIRED) {
- if (!bit_is_set(i, res_all.res_dir.hdr.item_present)) {
- Emsg2(M_ERROR_TERM, 0, _("\"%s\" item is required in \"%s\" resource, but not found.\n"),
+ if (!bit_is_set(i, res_all.res_dir.hdr.item_present)) {
+ Emsg2(M_ERROR_TERM, 0, _("\"%s\" item is required in \"%s\" resource, but not found.\n"),
items[i].name, resources[rindex]);
}
}
/* If this triggers, take a look at lib/parse_conf.h */
if (i >= MAX_RES_ITEMS) {
- Emsg1(M_ERROR_TERM, 0, _("Too many items in \"%s\" resource\n"), resources[rindex]);
+ Emsg1(M_ERROR_TERM, 0, _("Too many items in \"%s\" resource\n"), resources[rindex]);
}
}
/* Resources containing a resource */
case R_STORAGE:
if ((res = (URES *)GetResWithName(R_STORAGE, res_all.res_dir.hdr.name)) == NULL) {
- Emsg1(M_ERROR_TERM, 0, "Cannot find Storage resource \"%s\"\n", res_all.res_dir.hdr.name);
+ Emsg1(M_ERROR_TERM, 0, "Cannot find Storage resource \"%s\"\n", res_all.res_dir.hdr.name);
}
res->res_store.messages = res_all.res_store.messages;
break;
default:
- printf("Unknown resource type %d\n", type);
+ printf("Unknown resource type %d\n", type);
error = 1;
break;
}
size = sizeof(DEVRES);
break;
case R_MSGS:
- size = sizeof(MSGS);
+ size = sizeof(MSGS);
break;
default:
- printf("Unknown resource type %d\n", type);
+ printf("Unknown resource type %d\n", type);
error = 1;
size = 1;
break;
for (next=res_head[rindex]; next->next; next=next->next) {
if (strcmp(next->name, res->res_dir.hdr.name) == 0) {
Emsg2(M_ERROR_TERM, 0,
- _("Attempt to define second \"%s\" resource named \"%s\" is not permitted.\n"),
+ _("Attempt to define second \"%s\" resource named \"%s\" is not permitted.\n"),
resources[rindex].name, res->res_dir.hdr.name);
}
}
next->next = (RES *)res;
- Dmsg2(90, "Inserting %s res: %s\n", res_to_str(type),
+ Dmsg2(90, "Inserting %s res: %s\n", res_to_str(type),
res->res_dir.hdr.name);
}
}
/*
- * Resource codes -- they must be sequential for indexing
+ * Resource codes -- they must be sequential for indexing
*
* Version $Id$
*/
www.engelschall.com
Kern Sibbald, July 2001
-
+
Version $Id$
-
+
*/
#ifdef APCUPSD
/*
- * examine message from server
+ * examine message from server
*/
static void get_response(void)
{
if (len > 0) {
buf[len-1] = 0;
}
- Dmsg2(10, "%s --> %s\n", mailhost, buf);
- if (!isdigit((int)buf[0]) || buf[0] > '3') {
- Pmsg2(0, "Fatal malformed reply from %s: %s\n", mailhost, buf);
+ Dmsg2(10, "%s --> %s\n", mailhost, buf);
+ if (!isdigit((int)buf[0]) || buf[0] > '3') {
+ Pmsg2(0, "Fatal malformed reply from %s: %s\n", mailhost, buf);
exit(1);
}
- if (buf[3] != '-') {
+ if (buf[3] != '-') {
break;
}
}
va_start(ap, fmt);
vfprintf(sfp, fmt, ap);
if (debug_level >= 10) {
- fprintf(stdout, "%s --> ", my_hostname);
+ fprintf(stdout, "%s --> ", my_hostname);
vfprintf(stdout, fmt, ap);
}
va_end(ap);
-
+
fflush(sfp);
if (debug_level >= 10) {
fflush(stdout);
" -f set the From: field\n"
" -h use mailhost:port as the SMTP server\n"
" -s set the Subject: field\n"
-" -? print this message.\n"
+" -? print this message.\n"
"\n", MY_NAME);
exit(1);
while ((ch = getopt(argc, argv, "c:d:f:h:r:s:?")) != -1) {
switch (ch) {
- case 'c':
- Dmsg1(20, "cc=%s\n", optarg);
+ case 'c':
+ Dmsg1(20, "cc=%s\n", optarg);
cc_addr = optarg;
break;
case 'd': /* set debug level */
debug_level = atoi(optarg);
if (debug_level <= 0) {
- debug_level = 1;
+ debug_level = 1;
}
- Dmsg1(20, "Debug level = %d\n", debug_level);
+ Dmsg1(20, "Debug level = %d\n", debug_level);
break;
case 'f': /* from */
break;
case 'h': /* smtp host */
- Dmsg1(20, "host=%s\n", optarg);
- p = strchr(optarg, ':');
+ Dmsg1(20, "host=%s\n", optarg);
+ p = strchr(optarg, ':');
if (p) {
*p++ = 0;
mailport = atoi(p);
break;
case 's': /* subject */
- Dmsg1(20, "subject=%s\n", optarg);
+ Dmsg1(20, "subject=%s\n", optarg);
subject = optarg;
break;
default:
usage();
- }
+ }
}
argc -= optind;
argv += optind;
if ((cp = getenv("SMTPSERVER")) != NULL) {
mailhost = cp;
} else {
- mailhost = "localhost";
+ mailhost = "localhost";
}
}
/*
- * Find out my own host name for HELO;
+ * Find out my own host name for HELO;
* if possible, get the fully qualified domain name
*/
if (gethostname(my_hostname, sizeof(my_hostname) - 1) < 0) {
*/
if (from_addr == NULL) {
if ((pwd = getpwuid(getuid())) == 0) {
- sprintf(buf, "userid-%d@%s", (int)getuid(), my_hostname);
+ sprintf(buf, "userid-%d@%s", (int)getuid(), my_hostname);
} else {
- sprintf(buf, "%s@%s", pwd->pw_name, my_hostname);
+ sprintf(buf, "%s@%s", pwd->pw_name, my_hostname);
}
from_addr = bstrdup(buf);
}
Pmsg2(0, "Error unknown mail host \"%s\": ERR=%s\n", mailhost,
strerror(errno));
if (strcasecmp(mailhost, "localhost") != 0) {
- Pmsg0(0, "Retrying connection using \"localhost\".\n");
- mailhost = "localhost";
+ Pmsg0(0, "Retrying connection using \"localhost\".\n");
+ mailhost = "localhost";
goto hp;
}
exit(1);
exit(1);
}
- /*
+ /*
* Send SMTP headers
*/
get_response(); /* banner */
Dmsg0(20, "Data\n");
chat("data\r\n");
- /*
+ /*
* Send message header
*/
fprintf(sfp, "From: %s\r\n", from_addr);
fprintf(sfp, "\r\n");
- /*
- * Send message body
+ /*
+ * Send message body
*/
while (fgets(buf, sizeof(buf), stdin)) {
buf[strlen(buf)-1] = 0;
if (strcmp(buf, ".") == 0) { /* quote lone dots */
- fprintf(sfp, "..\r\n");
+ fprintf(sfp, "..\r\n");
} else { /* pass body through unchanged */
- fprintf(sfp, "%s\r\n", buf);
+ fprintf(sfp, "%s\r\n", buf);
}
}
- /*
+ /*
* Send SMTP quit command
*/
chat(".\r\n");
chat("quit\r\n");
- /*
+ /*
* Go away gracefully ...
*/
exit(0);
/*
*
* Program to check a Bacula database for consistency and to
- * make repairs
+ * make repairs
*
* Kern E. Sibbald, August 2002
*
case 'd': /* debug level */
debug_level = atoi(optarg);
if (debug_level <= 0)
- debug_level = 1;
+ debug_level = 1;
break;
case 'f': /* fix inconsistencies */
case '?':
default:
usage();
- }
+ }
}
argc -= optind;
argv += optind;
CAT *catalog = NULL;
int found = 0;
if (argc > 0) {
- Pmsg0(0, _("Warning skipping the additional parameters for working directory/dbname/user/password/host.\n"));
+ Pmsg0(0, _("Warning skipping the additional parameters for working directory/dbname/user/password/host.\n"));
}
parse_config(configfile);
LockRes();
foreach_res(catalog, R_CATALOG) {
- if (catalogname && !strcmp(catalog->hdr.name, catalogname)) {
+ if (catalogname && !strcmp(catalog->hdr.name, catalogname)) {
++found;
break;
} else if (!catalogname) { // stop on first if no catalogname is given
UnlockRes();
if (!found) {
if (catalogname) {
- Pmsg2(0, "Error can not find the Catalog name[%s] in the given config file [%s]\n", catalogname, configfile);
+ Pmsg2(0, "Error can not find the Catalog name[%s] in the given config file [%s]\n", catalogname, configfile);
} else {
- Pmsg1(0, "Error there is no Catalog section in the given config file [%s]\n", configfile);
+ Pmsg1(0, "Error there is no Catalog section in the given config file [%s]\n", configfile);
}
exit(1);
} else {
director = (DIRRES *)GetNextRes(R_DIRECTOR, NULL);
UnlockRes();
if (!director) {
- Pmsg0(0, "Error no Director resource defined.\n");
+ Pmsg0(0, "Error no Director resource defined.\n");
exit(1);
}
set_working_directory(director->working_directory);
}
} else {
if (argc > 5) {
- Pmsg0(0, _("Wrong number of arguments.\n"));
+ Pmsg0(0, _("Wrong number of arguments.\n"));
usage();
}
if (argc < 1) {
- Pmsg0(0, _("Working directory not supplied.\n"));
+ Pmsg0(0, _("Working directory not supplied.\n"));
usage();
}
bool quit = false;
const char *cmd;
- printf("Hello, this is the database check/correct program.\n\
-Modify database is %s. Verbose is %s.\n\
-Please select the fuction you want to perform.\n",
- fix?"On":"Off", verbose?"On":"Off");
+ printf("Hello, this is the database check/correct program.\n"
+"Modify database is %s. Verbose is %s.\n"
+"Please select the fuction you want to perform.\n",
+ fix?"On":"Off", verbose?"On":"Off");
while (!quit) {
if (fix) {
- printf(_("\n\
- 1) Toggle modify database flag\n\
- 2) Toggle verbose flag\n\
- 3) Repair bad Filename records\n\
- 4) Repair bad Path records\n\
- 5) Eliminate duplicate Filename records\n\
- 6) Eliminate duplicate Path records\n\
- 7) Eliminate orphaned Jobmedia records\n\
- 8) Eliminate orphaned File records\n\
- 9) Eliminate orphaned Path records\n\
- 10) Eliminate orphaned Filename records\n\
- 11) Eliminate orphaned FileSet records\n\
- 12) Eliminate orphaned Client records\n\
- 13) Eliminate orphaned Job records\n\
- 14) Eliminate all Admin records\n\
- 15) Eliminate all Restore records\n\
- 16) All (3-15)\n\
- 17) Quit\n"));
+ printf(_("\n"
+" 1) Toggle modify database flag\n"
+" 2) Toggle verbose flag\n"
+" 3) Repair bad Filename records\n"
+" 4) Repair bad Path records\n"
+" 5) Eliminate duplicate Filename records\n"
+" 6) Eliminate duplicate Path records\n"
+" 7) Eliminate orphaned Jobmedia records\n"
+" 8) Eliminate orphaned File records\n"
+" 9) Eliminate orphaned Path records\n"
+" 10) Eliminate orphaned Filename records\n"
+" 11) Eliminate orphaned FileSet records\n"
+" 12) Eliminate orphaned Client records\n"
+" 13) Eliminate orphaned Job records\n"
+" 14) Eliminate all Admin records\n"
+" 15) Eliminate all Restore records\n"
+" 16) All (3-15)\n"
+" 17) Quit\n"));
} else {
- printf(_("\n\
- 1) Toggle modify database flag\n\
- 2) Toggle verbose flag\n\
- 3) Check for bad Filename records\n\
- 4) Check for bad Path records\n\
- 5) Check for duplicate Filename records\n\
- 6) Check for duplicate Path records\n\
- 7) Check for orphaned Jobmedia records\n\
- 8) Check for orphaned File records\n\
- 9) Check for orphaned Path records\n\
- 10) Check for orphaned Filename records\n\
- 11) Check for orphaned FileSet records\n\
- 12) Check for orphaned Client records\n\
- 13) Check for orphaned Job records\n\
- 14) Check for all Admin records\n\
- 15) Check for all Restore records\n\
- 16) All (3-15)\n\
- 17) Quit\n"));
+ printf(_("\n"
+" 1) Toggle modify database flag\n"
+" 2) Toggle verbose flag\n"
+" 3) Check for bad Filename records\n"
+" 4) Check for bad Path records\n"
+" 5) Check for duplicate Filename records\n"
+" 6) Check for duplicate Path records\n"
+" 7) Check for orphaned Jobmedia records\n"
+" 8) Check for orphaned File records\n"
+" 9) Check for orphaned Path records\n"
+" 10) Check for orphaned Filename records\n"
+" 11) Check for orphaned FileSet records\n"
+" 12) Check for orphaned Client records\n"
+" 13) Check for orphaned Job records\n"
+" 14) Check for all Admin records\n"
+" 15) Check for all Restore records\n"
+" 16) All (3-15)\n"
+" 17) Quit\n"));
}
cmd = get_cmd(_("Select function number: "));
switch (item) {
case 1:
fix = !fix;
- printf(_("Database will %sbe modified.\n"), fix?"":_("NOT "));
+ printf(_("Database will %sbe modified.\n"), fix?"":_("NOT "));
break;
case 2:
verbose = verbose?0:1;
- printf(_("Verbose is %s\n"), verbose?_("On"):_("Off"));
+ printf(_("Verbose is %s\n"), verbose?_("On"):_("Off"));
break;
case 3:
repair_bad_filenames();
static int print_job_handler(void *ctx, int num_fields, char **row)
{
- printf(_("JobId=%s Name=\"%s\" StartTime=%s\n"),
+ printf(_("JobId=%s Name=\"%s\" StartTime=%s\n"),
NPRT(row[0]), NPRT(row[1]), NPRT(row[2]));
return 0;
}
static int print_jobmedia_handler(void *ctx, int num_fields, char **row)
{
- printf(_("Orphaned JobMediaId=%s JobId=%s Volume=\"%s\"\n"),
+ printf(_("Orphaned JobMediaId=%s JobId=%s Volume=\"%s\"\n"),
NPRT(row[0]), NPRT(row[1]), NPRT(row[2]));
return 0;
}
static int print_file_handler(void *ctx, int num_fields, char **row)
{
- printf(_("Orphaned FileId=%s JobId=%s Volume=\"%s\"\n"),
+ printf(_("Orphaned FileId=%s JobId=%s Volume=\"%s\"\n"),
NPRT(row[0]), NPRT(row[1]), NPRT(row[2]));
return 0;
}
static int print_fileset_handler(void *ctx, int num_fields, char **row)
{
- printf(_("Orphaned FileSetId=%s FileSet=\"%s\" MD5=%s\n"),
+ printf(_("Orphaned FileSetId=%s FileSet=\"%s\" MD5=%s\n"),
NPRT(row[0]), NPRT(row[1]), NPRT(row[2]));
return 0;
}
static int print_client_handler(void *ctx, int num_fields, char **row)
{
- printf(_("Orphaned ClientId=%s Name=\"%s\"\n"),
+ printf(_("Orphaned ClientId=%s Name=\"%s\"\n"),
NPRT(row[0]), NPRT(row[1]));
return 0;
}
-
+
/*
* Called here with each id to be added to the list
*/
{
ID_LIST *lst = (ID_LIST *)ctx;
- if (lst->num_ids == MAX_ID_LIST_LEN) {
+ if (lst->num_ids == MAX_ID_LIST_LEN) {
return 1;
}
if (lst->num_ids == lst->max_ids) {
}
/*
- * Delete all entries in the list
+ * Delete all entries in the list
*/
static int delete_id_list(const char *query, ID_LIST *id_list)
-{
+{
for (int i=0; i < id_list->num_ids; i++) {
bsnprintf(buf, sizeof(buf), query, id_list->Id[i]);
if (verbose) {
- printf("Deleting: %s\n", buf);
+ printf("Deleting: %s\n", buf);
}
db_sql_query(db, buf, NULL, NULL);
}
{
NAME_LIST *name = (NAME_LIST *)ctx;
- if (name->num_ids == MAX_ID_LIST_LEN) {
+ if (name->num_ids == MAX_ID_LIST_LEN) {
return 1;
}
if (name->num_ids == name->max_ids) {
* Print names in the list
*/
static void print_name_list(NAME_LIST *name_list)
-{
+{
for (int i=0; i < name_list->num_ids; i++) {
printf("%s\n", name_list->name[i]);
}
* Free names in the list
*/
static void free_name_list(NAME_LIST *name_list)
-{
+{
for (int i=0; i < name_list->num_ids; i++) {
free(name_list->name[i]);
}
char esc_name[5000];
printf("Checking for duplicate Filename entries.\n");
-
+
/* Make list of duplicated names */
query = "SELECT Name, count(Name) as Count FROM Filename GROUP BY Name "
- "HAVING count(Name) > 1";
+ "HAVING count(Name) > 1";
if (!make_name_list(query, &name_list)) {
exit(1);
for (int i=0; i<name_list.num_ids; i++) {
/* Get all the Ids of each name */
db_escape_string(esc_name, name_list.name[i], strlen(name_list.name[i]));
- bsnprintf(buf, sizeof(buf), "SELECT FilenameId FROM Filename WHERE Name='%s'", esc_name);
+ bsnprintf(buf, sizeof(buf), "SELECT FilenameId FROM Filename WHERE Name='%s'", esc_name);
if (verbose > 1) {
- printf("%s\n", buf);
+ printf("%s\n", buf);
}
if (!make_id_list(buf, &id_list)) {
exit(1);
}
if (verbose) {
- printf("Found %d for: %s\n", id_list.num_ids, name_list.name[i]);
+ printf("Found %d for: %s\n", id_list.num_ids, name_list.name[i]);
}
/* Force all records to use the first id then delete the other ids */
for (int j=1; j<id_list.num_ids; j++) {
- bsnprintf(buf, sizeof(buf), "UPDATE File SET FilenameId=%u WHERE FilenameId=%u",
+ bsnprintf(buf, sizeof(buf), "UPDATE File SET FilenameId=%u WHERE FilenameId=%u",
id_list.Id[0], id_list.Id[j]);
if (verbose > 1) {
- printf("%s\n", buf);
+ printf("%s\n", buf);
}
db_sql_query(db, buf, NULL, NULL);
- bsnprintf(buf, sizeof(buf), "DELETE FROM Filename WHERE FilenameId=%u",
+ bsnprintf(buf, sizeof(buf), "DELETE FROM Filename WHERE FilenameId=%u",
id_list.Id[j]);
if (verbose > 2) {
- printf("%s\n", buf);
+ printf("%s\n", buf);
}
db_sql_query(db, buf, NULL, NULL);
}
char esc_name[5000];
printf(_("Checking for duplicate Path entries.\n"));
-
+
/* Make list of duplicated names */
query = "SELECT Path, count(Path) as Count FROM Path "
- "GROUP BY Path HAVING count(Path) > 1";
+ "GROUP BY Path HAVING count(Path) > 1";
if (!make_name_list(query, &name_list)) {
exit(1);
for (int i=0; i<name_list.num_ids; i++) {
/* Get all the Ids of each name */
db_escape_string(esc_name, name_list.name[i], strlen(name_list.name[i]));
- bsnprintf(buf, sizeof(buf), "SELECT PathId FROM Path WHERE Path='%s'", esc_name);
+ bsnprintf(buf, sizeof(buf), "SELECT PathId FROM Path WHERE Path='%s'", esc_name);
if (verbose > 1) {
- printf("%s\n", buf);
+ printf("%s\n", buf);
}
if (!make_id_list(buf, &id_list)) {
exit(1);
}
if (verbose) {
- printf("Found %d for: %s\n", id_list.num_ids, name_list.name[i]);
+ printf("Found %d for: %s\n", id_list.num_ids, name_list.name[i]);
}
/* Force all records to use the first id then delete the other ids */
for (int j=1; j<id_list.num_ids; j++) {
- bsnprintf(buf, sizeof(buf), "UPDATE File SET PathId=%u WHERE PathId=%u",
+ bsnprintf(buf, sizeof(buf), "UPDATE File SET PathId=%u WHERE PathId=%u",
id_list.Id[0], id_list.Id[j]);
if (verbose > 1) {
- printf("%s\n", buf);
+ printf("%s\n", buf);
}
db_sql_query(db, buf, NULL, NULL);
- bsnprintf(buf, sizeof(buf), "DELETE FROM Path WHERE PathId=%u",
+ bsnprintf(buf, sizeof(buf), "DELETE FROM Path WHERE PathId=%u",
id_list.Id[j]);
if (verbose > 2) {
- printf("%s\n", buf);
+ printf("%s\n", buf);
}
db_sql_query(db, buf, NULL, NULL);
}
printf("Checking for orphaned JobMedia entries.\n");
query = "SELECT JobMedia.JobMediaId,Job.JobId FROM JobMedia "
- "LEFT OUTER JOIN Job ON (JobMedia.JobId=Job.JobId) "
- "WHERE Job.JobId IS NULL";
+ "LEFT OUTER JOIN Job ON (JobMedia.JobId=Job.JobId) "
+ "WHERE Job.JobId IS NULL";
if (!make_id_list(query, &id_list)) {
exit(1);
}
printf("Found %d orphaned JobMedia records.\n", id_list.num_ids);
if (id_list.num_ids && verbose && yes_no("Print them? (yes/no): ")) {
for (int i=0; i < id_list.num_ids; i++) {
- bsnprintf(buf, sizeof(buf),
+ bsnprintf(buf, sizeof(buf),
"SELECT JobMedia.JobMediaId,JobMedia.JobId,Media.VolumeName FROM JobMedia,Media "
"WHERE JobMedia.JobMediaId=%u AND Media.MediaId=JobMedia.MediaId", id_list.Id[i]);
if (!db_sql_query(db, buf, print_jobmedia_handler, NULL)) {
- printf("%s\n", db_strerror(db));
+ printf("%s\n", db_strerror(db));
}
}
}
-
+
if (fix && id_list.num_ids > 0) {
printf("Deleting %d orphaned JobMedia records.\n", id_list.num_ids);
delete_id_list("DELETE FROM JobMedia WHERE JobMediaId=%u", &id_list);
printf("Checking for orphaned File entries. This may take some time!\n");
query = "SELECT File.FileId,Job.JobId FROM File "
- "LEFT OUTER JOIN Job ON (File.JobId=Job.JobId) "
- "WHERE Job.JobId IS NULL";
+ "LEFT OUTER JOIN Job ON (File.JobId=Job.JobId) "
+ "WHERE Job.JobId IS NULL";
if (verbose > 1) {
printf("%s\n", query);
}
"SELECT File.FileId,File.JobId,Filename.Name FROM File,Filename "
"WHERE File.FileId=%u AND File.FilenameId=Filename.FilenameId", id_list.Id[i]);
if (!db_sql_query(db, buf, print_file_handler, NULL)) {
- printf("%s\n", db_strerror(db));
+ printf("%s\n", db_strerror(db));
}
}
}
-
+
if (fix && id_list.num_ids > 0) {
printf("Deleting %d orphaned File records.\n", id_list.num_ids);
delete_id_list("DELETE FROM File WHERE FileId=%u", &id_list);
printf("Checking for orphaned Path entries. This may take some time!\n");
query = "SELECT DISTINCT Path.PathId,File.PathId FROM Path "
- "LEFT OUTER JOIN File ON (Path.PathId=File.PathId) "
- "WHERE File.PathId IS NULL";
+ "LEFT OUTER JOIN File ON (Path.PathId=File.PathId) "
+ "WHERE File.PathId IS NULL";
if (verbose > 1) {
printf("%s\n", query);
}
printf("Found %d orphaned Path records.\n", id_list.num_ids);
if (id_list.num_ids && verbose && yes_no("Print them? (yes/no): ")) {
for (int i=0; i < id_list.num_ids; i++) {
- bsnprintf(buf, sizeof(buf), "SELECT Path FROM Path WHERE PathId=%u", id_list.Id[i]);
+ bsnprintf(buf, sizeof(buf), "SELECT Path FROM Path WHERE PathId=%u", id_list.Id[i]);
db_sql_query(db, buf, print_name_handler, NULL);
}
}
-
+
if (fix && id_list.num_ids > 0) {
printf("Deleting %d orphaned Path records.\n", id_list.num_ids);
delete_id_list("DELETE FROM Path WHERE PathId=%u", &id_list);
printf("Checking for orphaned Filename entries. This may take some time!\n");
query = "SELECT Filename.FilenameId,File.FilenameId FROM Filename "
- "LEFT OUTER JOIN File ON (Filename.FilenameId=File.FilenameId) "
- "WHERE File.FilenameId IS NULL";
+ "LEFT OUTER JOIN File ON (Filename.FilenameId=File.FilenameId) "
+ "WHERE File.FilenameId IS NULL";
if (verbose > 1) {
printf("%s\n", query);
}
printf("Found %d orphaned Filename records.\n", id_list.num_ids);
if (id_list.num_ids && verbose && yes_no("Print them? (yes/no): ")) {
for (int i=0; i < id_list.num_ids; i++) {
- bsnprintf(buf, sizeof(buf), "SELECT Name FROM Filename WHERE FilenameId=%u", id_list.Id[i]);
+ bsnprintf(buf, sizeof(buf), "SELECT Name FROM Filename WHERE FilenameId=%u", id_list.Id[i]);
db_sql_query(db, buf, print_name_handler, NULL);
}
}
-
+
if (fix && id_list.num_ids > 0) {
printf("Deleting %d orphaned Filename records.\n", id_list.num_ids);
delete_id_list("DELETE FROM Filename WHERE FilenameId=%u", &id_list);
printf("Checking for orphaned FileSet entries. This takes some time!\n");
query = "SELECT FileSet.FileSetId,Job.FileSetId FROM FileSet "
- "LEFT OUTER JOIN Job ON (FileSet.FileSetId=Job.FileSetId) "
- "WHERE Job.FileSetId IS NULL";
+ "LEFT OUTER JOIN Job ON (FileSet.FileSetId=Job.FileSetId) "
+ "WHERE Job.FileSetId IS NULL";
if (verbose > 1) {
printf("%s\n", query);
}
printf("Found %d orphaned FileSet records.\n", id_list.num_ids);
if (id_list.num_ids && verbose && yes_no("Print them? (yes/no): ")) {
for (int i=0; i < id_list.num_ids; i++) {
- bsnprintf(buf, sizeof(buf), "SELECT FileSetId,FileSet,MD5 FROM FileSet "
- "WHERE FileSetId=%u", id_list.Id[i]);
+ bsnprintf(buf, sizeof(buf), "SELECT FileSetId,FileSet,MD5 FROM FileSet "
+ "WHERE FileSetId=%u", id_list.Id[i]);
if (!db_sql_query(db, buf, print_fileset_handler, NULL)) {
- printf("%s\n", db_strerror(db));
+ printf("%s\n", db_strerror(db));
}
}
}
-
+
if (fix && id_list.num_ids > 0) {
printf("Deleting %d orphaned FileSet records.\n", id_list.num_ids);
delete_id_list("DELETE FROM FileSet WHERE FileSetId=%u", &id_list);
* i.e. Job.Client is NULL
*/
query = "SELECT Client.ClientId,Client.Name FROM Client "
- "LEFT OUTER JOIN Job ON (Client.ClientId=Job.ClientId) "
- "WHERE Job.ClientId IS NULL";
+ "LEFT OUTER JOIN Job ON (Client.ClientId=Job.ClientId) "
+ "WHERE Job.ClientId IS NULL";
if (verbose > 1) {
printf("%s\n", query);
}
printf("Found %d orphaned Client records.\n", id_list.num_ids);
if (id_list.num_ids && verbose && yes_no("Print them? (yes/no): ")) {
for (int i=0; i < id_list.num_ids; i++) {
- bsnprintf(buf, sizeof(buf), "SELECT ClientId,Name FROM Client "
- "WHERE ClientId=%u", id_list.Id[i]);
+ bsnprintf(buf, sizeof(buf), "SELECT ClientId,Name FROM Client "
+ "WHERE ClientId=%u", id_list.Id[i]);
if (!db_sql_query(db, buf, print_client_handler, NULL)) {
- printf("%s\n", db_strerror(db));
+ printf("%s\n", db_strerror(db));
}
}
}
-
+
if (fix && id_list.num_ids > 0) {
printf("Deleting %d orphaned Client records.\n", id_list.num_ids);
delete_id_list("DELETE FROM Client WHERE ClientId=%u", &id_list);
* i.e. Client.Name is NULL
*/
query = "SELECT Job.JobId,Job.Name FROM Job "
- "LEFT OUTER JOIN Client ON (Job.ClientId=Client.ClientId) "
- "WHERE Client.Name IS NULL";
+ "LEFT OUTER JOIN Client ON (Job.ClientId=Client.ClientId) "
+ "WHERE Client.Name IS NULL";
if (verbose > 1) {
printf("%s\n", query);
}
printf("Found %d orphaned Job records.\n", id_list.num_ids);
if (id_list.num_ids && verbose && yes_no("Print them? (yes/no): ")) {
for (int i=0; i < id_list.num_ids; i++) {
- bsnprintf(buf, sizeof(buf), "SELECT JobId,Name,StartTime FROM Job "
- "WHERE JobId=%u", id_list.Id[i]);
+ bsnprintf(buf, sizeof(buf), "SELECT JobId,Name,StartTime FROM Job "
+ "WHERE JobId=%u", id_list.Id[i]);
if (!db_sql_query(db, buf, print_job_handler, NULL)) {
- printf("%s\n", db_strerror(db));
+ printf("%s\n", db_strerror(db));
}
}
}
-
+
if (fix && id_list.num_ids > 0) {
printf("Deleting %d orphaned Job records.\n", id_list.num_ids);
delete_id_list("DELETE FROM Job WHERE JobId=%u", &id_list);
printf("Checking for Admin Job entries.\n");
query = "SELECT Job.JobId FROM Job "
- "WHERE Job.Type='D'";
+ "WHERE Job.Type='D'";
if (verbose > 1) {
printf("%s\n", query);
}
printf("Found %d Admin Job records.\n", id_list.num_ids);
if (id_list.num_ids && verbose && yes_no("Print them? (yes/no): ")) {
for (int i=0; i < id_list.num_ids; i++) {
- bsnprintf(buf, sizeof(buf), "SELECT JobId,Name,StartTime FROM Job "
- "WHERE JobId=%u", id_list.Id[i]);
+ bsnprintf(buf, sizeof(buf), "SELECT JobId,Name,StartTime FROM Job "
+ "WHERE JobId=%u", id_list.Id[i]);
if (!db_sql_query(db, buf, print_job_handler, NULL)) {
- printf("%s\n", db_strerror(db));
+ printf("%s\n", db_strerror(db));
}
}
}
-
+
if (fix && id_list.num_ids > 0) {
printf("Deleting %d Admin Job records.\n", id_list.num_ids);
delete_id_list("DELETE FROM Job WHERE JobId=%u", &id_list);
printf("Checking for Restore Job entries.\n");
query = "SELECT Job.JobId FROM Job "
- "WHERE Job.Type='R'";
+ "WHERE Job.Type='R'";
if (verbose > 1) {
printf("%s\n", query);
}
printf("Found %d Restore Job records.\n", id_list.num_ids);
if (id_list.num_ids && verbose && yes_no("Print them? (yes/no): ")) {
for (int i=0; i < id_list.num_ids; i++) {
- bsnprintf(buf, sizeof(buf), "SELECT JobId,Name,StartTime FROM Job "
- "WHERE JobId=%u", id_list.Id[i]);
+ bsnprintf(buf, sizeof(buf), "SELECT JobId,Name,StartTime FROM Job "
+ "WHERE JobId=%u", id_list.Id[i]);
if (!db_sql_query(db, buf, print_job_handler, NULL)) {
- printf("%s\n", db_strerror(db));
+ printf("%s\n", db_strerror(db));
}
}
}
-
+
if (fix && id_list.num_ids > 0) {
printf("Deleting %d Restore Job records.\n", id_list.num_ids);
delete_id_list("DELETE FROM Job WHERE JobId=%u", &id_list);
printf("Checking for Filenames with a trailing slash\n");
query = "SELECT FilenameId,Name from Filename "
- "WHERE Name LIKE '%/'";
+ "WHERE Name LIKE '%/'";
if (verbose > 1) {
printf("%s\n", query);
}
printf("Found %d bad Filename records.\n", id_list.num_ids);
if (id_list.num_ids && verbose && yes_no("Print them? (yes/no): ")) {
for (i=0; i < id_list.num_ids; i++) {
- bsnprintf(buf, sizeof(buf),
- "SELECT Name FROM Filename WHERE FilenameId=%u", id_list.Id[i]);
+ bsnprintf(buf, sizeof(buf),
+ "SELECT Name FROM Filename WHERE FilenameId=%u", id_list.Id[i]);
if (!db_sql_query(db, buf, print_name_handler, NULL)) {
- printf("%s\n", db_strerror(db));
+ printf("%s\n", db_strerror(db));
}
}
}
-
+
if (fix && id_list.num_ids > 0) {
POOLMEM *name = get_pool_memory(PM_FNAME);
char esc_name[5000];
printf("Reparing %d bad Filename records.\n", id_list.num_ids);
for (i=0; i < id_list.num_ids; i++) {
int len;
- bsnprintf(buf, sizeof(buf),
- "SELECT Name FROM Filename WHERE FilenameId=%u", id_list.Id[i]);
+ bsnprintf(buf, sizeof(buf),
+ "SELECT Name FROM Filename WHERE FilenameId=%u", id_list.Id[i]);
if (!db_sql_query(db, buf, get_name_handler, name)) {
- printf("%s\n", db_strerror(db));
+ printf("%s\n", db_strerror(db));
}
/* Strip trailing slash(es) */
- for (len=strlen(name); len > 0 && name[len-1]=='/'; len--)
+ for (len=strlen(name); len > 0 && name[len-1]=='/'; len--)
{ }
if (len == 0) {
len = 1;
- esc_name[0] = ' ';
+ esc_name[0] = ' ';
esc_name[1] = 0;
} else {
name[len-1] = 0;
db_escape_string(esc_name, name, len);
}
- bsnprintf(buf, sizeof(buf),
- "UPDATE Filename SET Name='%s' WHERE FilenameId=%u",
+ bsnprintf(buf, sizeof(buf),
+ "UPDATE Filename SET Name='%s' WHERE FilenameId=%u",
esc_name, id_list.Id[i]);
if (verbose > 1) {
- printf("%s\n", buf);
+ printf("%s\n", buf);
}
db_sql_query(db, buf, NULL, NULL);
}
printf("Checking for Paths without a trailing slash\n");
query = "SELECT PathId,Path from Path "
- "WHERE Path NOT LIKE '%/'";
+ "WHERE Path NOT LIKE '%/'";
if (verbose > 1) {
printf("%s\n", query);
}
printf("Found %d bad Path records.\n", id_list.num_ids);
if (id_list.num_ids && verbose && yes_no("Print them? (yes/no): ")) {
for (i=0; i < id_list.num_ids; i++) {
- bsnprintf(buf, sizeof(buf),
- "SELECT Path FROM Path WHERE PathId=%u", id_list.Id[i]);
+ bsnprintf(buf, sizeof(buf),
+ "SELECT Path FROM Path WHERE PathId=%u", id_list.Id[i]);
if (!db_sql_query(db, buf, print_name_handler, NULL)) {
- printf("%s\n", db_strerror(db));
+ printf("%s\n", db_strerror(db));
}
}
}
-
+
if (fix && id_list.num_ids > 0) {
POOLMEM *name = get_pool_memory(PM_FNAME);
char esc_name[5000];
printf("Reparing %d bad Filename records.\n", id_list.num_ids);
for (i=0; i < id_list.num_ids; i++) {
int len;
- bsnprintf(buf, sizeof(buf),
- "SELECT Path FROM Path WHERE PathId=%u", id_list.Id[i]);
+ bsnprintf(buf, sizeof(buf),
+ "SELECT Path FROM Path WHERE PathId=%u", id_list.Id[i]);
if (!db_sql_query(db, buf, get_name_handler, name)) {
- printf("%s\n", db_strerror(db));
+ printf("%s\n", db_strerror(db));
}
/* Strip trailing blanks */
- for (len=strlen(name); len > 0 && name[len-1]==' '; len--) {
+ for (len=strlen(name); len > 0 && name[len-1]==' '; len--) {
name[len-1] = 0;
}
/* Add trailing slash */
- len = pm_strcat(&name, "/");
+ len = pm_strcat(&name, "/");
db_escape_string(esc_name, name, len);
- bsnprintf(buf, sizeof(buf), "UPDATE Path SET Path='%s' WHERE PathId=%u",
+ bsnprintf(buf, sizeof(buf), "UPDATE Path SET Path='%s' WHERE PathId=%u",
esc_name, id_list.Id[i]);
if (verbose > 1) {
- printf("%s\n", buf);
+ printf("%s\n", buf);
}
db_sql_query(db, buf, NULL, NULL);
}
static int yes_no(const char *prompt)
{
- char *cmd;
+ char *cmd;
cmd = get_cmd(prompt);
return strcasecmp(cmd, "yes") == 0;
}
-/*
+/*
* Program for determining file system type
*
* Written by Preben 'Peppe' Guldberg, December MMIV
- *
+ *
* Version $Id$
- *
+ *
*/
/*
- Copyright (C) 2004 Kern Sibbald
+ Copyright (C) 2004 Kern Sibbald
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
while ((ch = getopt(argc, argv, "v?")) != -1) {
switch (ch) {
- case 'v':
+ case 'v':
verbose = 1;
break;
- case '?':
+ case '?':
default:
usage();
- }
+ }
}
argc -= optind;
argv += optind;
for (i = 0; i < argc; --argc, ++argv) {
if ((fs = fstype(*argv)) != NULL) {
if (verbose) {
- printf("%s: %s\n", *argv, fs);
+ printf("%s: %s\n", *argv, fs);
} else {
puts(fs);
}
free(fs);
} else {
- fprintf(stderr, "%s: unknown\n", *argv);
+ fprintf(stderr, "%s: unknown\n", *argv);
status = 1;
}
}
-/*
+/*
* Test program for find files
*/
while ((ch = getopt(argc, argv, "ad:e:i:?")) != -1) {
switch (ch) {
- case 'a': /* print extended attributes *debug* */
+ case 'a': /* print extended attributes *debug* */
attrs = 1;
break;
- case 'd': /* set debug level */
+ case 'd': /* set debug level */
debug_level = atoi(optarg);
if (debug_level <= 0) {
- debug_level = 1;
+ debug_level = 1;
}
break;
- case 'e': /* exclude patterns */
+ case 'e': /* exclude patterns */
exc = optarg;
break;
- case 'i': /* include patterns */
+ case 'i': /* include patterns */
inc = optarg;
break;
- case '?':
+ case '?':
default:
usage();
- }
+ }
}
argc -= optind;
argv += optind;
ff = init_find_files();
if (argc == 0 && !inc) {
add_fname_to_include_list(ff, 0, "/"); /* default to / */
- } else {
+ } else {
for (i=0; i < argc; i++) {
- if (strcmp(argv[i], "-") == 0) {
+ if (strcmp(argv[i], "-") == 0) {
while (fgets(name, sizeof(name)-1, stdin)) {
strip_trailing_junk(name);
- add_fname_to_include_list(ff, 0, name);
+ add_fname_to_include_list(ff, 0, name);
}
continue;
}
- add_fname_to_include_list(ff, 0, argv[i]);
+ add_fname_to_include_list(ff, 0, argv[i]);
}
}
if (inc) {
fd = fopen(inc, "r");
if (!fd) {
- printf("Could not open include file: %s\n", inc);
+ printf("Could not open include file: %s\n", inc);
exit(1);
}
while (fgets(name, sizeof(name)-1, fd)) {
if (exc) {
fd = fopen(exc, "r");
if (!fd) {
- printf("Could not open exclude file: %s\n", exc);
+ printf("Could not open exclude file: %s\n", exc);
exit(1);
}
while (fgets(name, sizeof(name)-1, fd)) {
}
find_files(jcr, ff, print_file, NULL);
hard_links = term_find_files(ff);
-
- printf(_("\
-Total files : %d\n\
-Max file length: %d\n\
-Max path length: %d\n\
-Files truncated: %d\n\
-Paths truncated: %d\n\
-Hard links : %d\n"),
+
+ printf(_(""
+"Total files : %d\n"
+"Max file length: %d\n"
+"Max path length: %d\n"
+"Files truncated: %d\n"
+"Paths truncated: %d\n"
+"Hard links : %d\n"),
num_files, max_file_len, max_path_len,
trunc_fname, trunc_path, hard_links);
-
+
free_jcr(jcr);
close_memory_pool();
sm_dump(false);
switch (ff->type) {
case FT_LNKSAVED:
if (debug_level == 1) {
- printf("%s\n", ff->fname);
+ printf("%s\n", ff->fname);
} else if (debug_level > 1) {
- printf("Lnka: %s -> %s\n", ff->fname, ff->link);
+ printf("Lnka: %s -> %s\n", ff->fname, ff->link);
}
break;
case FT_REGE:
if (debug_level == 1) {
- printf("%s\n", ff->fname);
+ printf("%s\n", ff->fname);
} else if (debug_level > 1) {
- printf("Empty: %s\n", ff->fname);
+ printf("Empty: %s\n", ff->fname);
}
count_files(ff);
- break;
+ break;
case FT_REG:
if (debug_level == 1) {
- printf("%s\n", ff->fname);
+ printf("%s\n", ff->fname);
} else if (debug_level > 1) {
- printf("Reg: %s\n", ff->fname);
+ printf("Reg: %s\n", ff->fname);
}
count_files(ff);
break;
case FT_LNK:
if (debug_level == 1) {
- printf("%s\n", ff->fname);
+ printf("%s\n", ff->fname);
} else if (debug_level > 1) {
- printf("Lnk: %s -> %s\n", ff->fname, ff->link);
+ printf("Lnk: %s -> %s\n", ff->fname, ff->link);
}
count_files(ff);
break;
break;
case FT_SPEC:
if (debug_level == 1) {
- printf("%s\n", ff->fname);
+ printf("%s\n", ff->fname);
} else if (debug_level > 1) {
- printf("Spec: %s\n", ff->fname);
+ printf("Spec: %s\n", ff->fname);
}
count_files(ff);
break;
char attr[200];
encode_attribsEx(NULL, attr, ff);
if (*attr != 0) {
- printf("AttrEx=%s\n", attr);
+ printf("AttrEx=%s\n", attr);
}
// set_attribsEx(NULL, ff->fname, NULL, NULL, ff->type, attr);
}
return 1;
}
-static void count_files(FF_PKT *ar)
+static void count_files(FF_PKT *ar)
{
int fnl, pnl;
char *l, *p;
num_files++;
- /* Find path without the filename.
+ /* Find path without the filename.
* I.e. everything after the last / is a "filename".
* OK, maybe it is a directory name, but we treat it like
* a filename. If we don't find a / then the whole name
}
/* If filename doesn't exist (i.e. root directory), we
- * simply create a blank name consisting of a single
+ * simply create a blank name consisting of a single
* space. This makes handling zero length filenames
* easier.
*/
file[1] = 0;
}
- pnl = l - ar->fname;
+ pnl = l - ar->fname;
if (pnl > max_path_len) {
max_path_len = pnl;
}
-/*
+/*
* Test program for listing files during regression testing
*/
case 'd': /* set debug level */
debug_level = atoi(optarg);
if (debug_level <= 0) {
- debug_level = 1;
+ debug_level = 1;
}
break;
default:
usage();
- }
+ }
}
argc -= optind;
argv += optind;
ff = init_find_files();
if (argc == 0 && !inc) {
add_fname_to_include_list(ff, 0, "/"); /* default to / */
- } else {
+ } else {
for (i=0; i < argc; i++) {
- if (strcmp(argv[i], "-") == 0) {
+ if (strcmp(argv[i], "-") == 0) {
while (fgets(name, sizeof(name)-1, stdin)) {
strip_trailing_junk(name);
- add_fname_to_include_list(ff, 0, name);
+ add_fname_to_include_list(ff, 0, name);
}
continue;
}
- add_fname_to_include_list(ff, 0, argv[i]);
+ add_fname_to_include_list(ff, 0, argv[i]);
}
}
if (inc) {
fd = fopen(inc, "r");
if (!fd) {
- printf("Could not open include file: %s\n", inc);
+ printf("Could not open include file: %s\n", inc);
exit(1);
}
while (fgets(name, sizeof(name)-1, fd)) {
if (exc) {
fd = fopen(exc, "r");
if (!fd) {
- printf("Could not open exclude file: %s\n", exc);
+ printf("Could not open exclude file: %s\n", exc);
exit(1);
}
while (fgets(name, sizeof(name)-1, fd)) {
}
find_files(jcr, ff, print_file, NULL);
hard_links = term_find_files(ff);
-
+
free_jcr(jcr);
close_memory_pool();
sm_dump(false);
static void print_ls_output(char *fname, char *link, int type, struct stat *statp)
{
- char buf[1000];
+ char buf[1000];
char ec1[30];
char *p, *f;
int n;
p += n;
if (S_ISCHR(statp->st_mode) || S_ISBLK(statp->st_mode)) {
n = sprintf(p, "%4x ", (int)statp->st_rdev);
- } else {
+ } else {
n = sprintf(p, " ");
}
p += n;
#undef DEBUG
#define DEBUG 1
#define TRACEBACK 1
-#define SMCHECK
-#define TRACE_FILE 1
+#define SMCHECK
+#define TRACE_FILE 1
/* If this is set stdout will not be closed on startup */
#define DEVELOPER 1