From ebed47ad3e2291d0bdb6240d11fbdca5baf36100 Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Sat, 28 Dec 2002 15:28:57 +0000 Subject: [PATCH] Update doc, default working directory bscan git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@250 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/stored/bscan.c | 36 ++++++++++++++++++++++++++++++++---- bacula/src/stored/butil.c | 5 ++--- bacula/src/stored/stored.c | 16 ++++++++-------- bacula/src/version.h | 4 ++-- 4 files changed, 44 insertions(+), 17 deletions(-) diff --git a/bacula/src/stored/bscan.c b/bacula/src/stored/bscan.c index bcf9f223fb..8f3fe3185a 100644 --- a/bacula/src/stored/bscan.c +++ b/bacula/src/stored/bscan.c @@ -54,6 +54,7 @@ static int update_MD5_record(B_DB *db, char *MD5buf, DEV_RECORD *rec); /* Global variables */ +static STORES *me; static DEVICE *dev = NULL; static B_DB *db; static JCR *bjcr; /* jcr for bscan */ @@ -79,7 +80,7 @@ static time_t lasttime = 0; static char *db_name = "bacula"; static char *db_user = "bacula"; static char *db_password = ""; -static char *wd = "/tmp"; +static char *wd = NULL; static int verbose = 0; static int update_db = 0; static int update_vol_info = 0; @@ -90,6 +91,7 @@ static int ignored_msgs = 0; char *configfile; + static void usage() { fprintf(stderr, _( @@ -105,7 +107,7 @@ static void usage() " -r list records\n" " -s synchronize or store in database\n" " -v verbose\n" -" -w dir specify working directory (default /tmp)\n" +" -w dir specify working directory (default from conf file)\n" " -? print this message\n\n")); exit(1); } @@ -113,6 +115,7 @@ static void usage() int main (int argc, char *argv[]) { int ch; + struct stat stat_buf; my_name_is(argc, argv, "bscan"); init_msg(NULL, NULL); @@ -183,13 +186,38 @@ int main (int argc, char *argv[]) usage(); } - working_directory = wd; - if (configfile == NULL) { configfile = bstrdup(CONFIG_FILE); } parse_config(configfile); + LockRes(); + me = (STORES *)GetNextRes(R_STORAGE, NULL); + if (!me) { + UnlockRes(); + 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) { + working_directory = wd; + } else if (!me->working_directory) { + Emsg1(M_ERROR_TERM, 0, _("No Working Directory defined in %s. Cannot continue.\n"), + configfile); + } else { + working_directory = me->working_directory; + } + + /* Check that working directory is good */ + if (stat(working_directory, &stat_buf) != 0) { + Emsg1(M_ERROR_TERM, 0, _("Working Directory: %s not found. Cannot continue.\n"), + working_directory); + } + if (!S_ISDIR(stat_buf.st_mode)) { + Emsg1(M_ERROR_TERM, 0, _("Working Directory: %s is not a directory. Cannot continue.\n"), + working_directory); + } bjcr = setup_jcr("bscan", argv[0], bsr); dev = setup_to_access_device(bjcr, 1); /* read device */ diff --git a/bacula/src/stored/butil.c b/bacula/src/stored/butil.c index 5b114b1f7c..40389710b5 100644 --- a/bacula/src/stored/butil.c +++ b/bacula/src/stored/butil.c @@ -88,14 +88,14 @@ DEVICE *setup_to_access_device(JCR *jcr, int read_access) } if ((device=find_device_res(jcr->dev_name, read_access)) == NULL) { - Emsg2(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"), jcr->dev_name, configfile); return NULL; } dev = init_dev(NULL, device); if (!dev || !open_device(dev)) { - Emsg1(M_FATAL, 0, _("Cannot open %s\n"), jcr->dev_name); + Jmsg1(jcr, M_FATAL, 0, _("Cannot open %s\n"), jcr->dev_name); return NULL; } Dmsg0(90, "Device opened for read.\n"); @@ -106,7 +106,6 @@ DEVICE *setup_to_access_device(JCR *jcr, int read_access) if (read_access) { if (!acquire_device_for_read(jcr, dev, block)) { - Emsg0(M_ERROR, 0, dev->errmsg); free_block(block); return NULL; } diff --git a/bacula/src/stored/stored.c b/bacula/src/stored/stored.c index ebe8cf2419..35d50f4a8a 100644 --- a/bacula/src/stored/stored.c +++ b/bacula/src/stored/stored.c @@ -226,7 +226,7 @@ static void check_config() me = (STORES *)GetNextRes(R_STORAGE, NULL); if (!me) { UnlockRes(); - Emsg1(M_ABORT, 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); } @@ -234,23 +234,23 @@ static void check_config() if (GetNextRes(R_STORAGE, (RES *)me) != NULL) { UnlockRes(); - Emsg1(M_ABORT, 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) { UnlockRes(); - Emsg1(M_ABORT, 0, _("No Director resource defined in %s. Cannot continue.\n"), + Emsg1(M_ERROR_TERM, 0, _("No Director resource defined in %s. Cannot continue.\n"), configfile); } if (GetNextRes(R_DEVICE, NULL) == NULL){ UnlockRes(); - Emsg1(M_ABORT, 0, _("No Device resource defined in %s. Cannot continue.\n"), + Emsg1(M_ERROR_TERM, 0, _("No Device resource defined in %s. Cannot continue.\n"), configfile); } if (!me->messages) { me->messages = (MSGS *)GetNextRes(R_MSGS, NULL); if (!me->messages) { - Emsg1(M_ABORT, 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); } } @@ -260,15 +260,15 @@ static void check_config() UnlockRes(); if (!me->working_directory) { - Emsg1(M_ABORT, 0, _("No Working Directory defined in %s. Cannot continue.\n"), + Emsg1(M_ERROR_TERM, 0, _("No Working Directory defined in %s. Cannot continue.\n"), configfile); } if (stat(me->working_directory, &stat_buf) != 0) { - Emsg1(M_ABORT, 0, _("Working Directory: %s not found. Cannot continue.\n"), + Emsg1(M_ERROR_TERM, 0, _("Working Directory: %s not found. Cannot continue.\n"), me->working_directory); } if (!S_ISDIR(stat_buf.st_mode)) { - Emsg1(M_ABORT, 0, _("Working Directory: %s is not a directory. Cannot continue.\n"), + Emsg1(M_ERROR_TERM, 0, _("Working Directory: %s is not a directory. Cannot continue.\n"), me->working_directory); } working_directory = me->working_directory; diff --git a/bacula/src/version.h b/bacula/src/version.h index 95dbcaf5d1..fe6ffcf823 100644 --- a/bacula/src/version.h +++ b/bacula/src/version.h @@ -1,8 +1,8 @@ /* */ #define VERSION "1.28" #define VSTRING "1" -#define DATE "25 December 2002" -#define LSMDATE "25Dec02" +#define DATE "28 December 2002" +#define LSMDATE "28Dec02" /* Debug flags */ #define DEBUG 1 -- 2.39.5