From 922060688d3d28531b86b48b3d1b02ecd202d7e4 Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Wed, 2 Jun 2004 20:00:22 +0000 Subject: [PATCH] Misc bug fixes git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@1382 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/dird/dird.c | 3 + bacula/src/dird/query.sql | 2 +- bacula/src/stored/block.c | 2 +- bacula/src/stored/btape.c | 4 +- bacula/src/stored/butil.c | 4 ++ bacula/src/stored/stored_conf.c | 10 +-- bacula/src/tools/Makefile.in | 6 +- bacula/src/tools/dbcheck.c | 109 ++++++++++++++++++++++++-------- bacula/src/version.h | 4 +- 9 files changed, 103 insertions(+), 41 deletions(-) diff --git a/bacula/src/dird/dird.c b/bacula/src/dird/dird.c index b8ff96b8ac..2e3843a2b3 100644 --- a/bacula/src/dird/dird.c +++ b/bacula/src/dird/dird.c @@ -349,6 +349,9 @@ void reload_config(int sig) int njobs = 0; int table, rtable; + Jmsg(NULL, M_ERROR, 0, _("Command not implemented\n")); + return; + if (already_here) { abort(); /* Oops, recursion -> die */ } diff --git a/bacula/src/dird/query.sql b/bacula/src/dird/query.sql index 9495f2c1f4..a145cc6d2c 100644 --- a/bacula/src/dird/query.sql +++ b/bacula/src/dird/query.sql @@ -128,7 +128,7 @@ INSERT INTO temp2 SELECT Job.JobId,Job.StartTime,Media.VolumeName, AND JobMedia.MediaId=Media.MediaId GROUP BY Job.JobId; # list results -SELECT * from temp2; +SELECT DISTINCT VolumeName from temp2; !DROP TABLE temp; !DROP TABLE temp2; # 10 diff --git a/bacula/src/stored/block.c b/bacula/src/stored/block.c index 85f92eed33..cd33bf46b6 100644 --- a/bacula/src/stored/block.c +++ b/bacula/src/stored/block.c @@ -689,7 +689,7 @@ int read_block_from_dev(JCR *jcr, DEVICE *dev, DEV_BLOCK *block, bool check_bloc DCR *dcr = jcr->dcr; if (!dcr) { - Jmsg(jcr, M_ABORT, 0, _("DCR is NULL!\n")); + Jmsg0(jcr, M_ABORT, 0, _("DCR is NULL!\n")); } if (dev_state(dev, ST_EOT)) { return 0; diff --git a/bacula/src/stored/btape.c b/bacula/src/stored/btape.c index 1515549408..6521425ecf 100644 --- a/bacula/src/stored/btape.c +++ b/bacula/src/stored/btape.c @@ -1890,8 +1890,8 @@ This may take a long time -- hours! ...\n\n"); strerror(errno)); } - /* Release the device */ - if (!release_device(jcr)) { + /* Release the device if multiple tapes being used */ + if (!simple && !release_device(jcr)) { Pmsg0(-1, _("Error in release_device\n")); ok = false; } diff --git a/bacula/src/stored/butil.c b/bacula/src/stored/butil.c index 4d439b5048..9f811f2892 100644 --- a/bacula/src/stored/butil.c +++ b/bacula/src/stored/butil.c @@ -100,6 +100,10 @@ DEVICE *setup_to_access_device(JCR *jcr, int read_access) pm_strcpy(&jcr->dev_name, device->device_name); dev = init_dev(NULL, device); + if (!dev) { + Jmsg1(jcr, M_FATAL, 0, _("Cannot init device %s\n"), jcr->dev_name); + return NULL; + } jcr->device->dev = dev; new_dcr(jcr, dev); if (!dev || !first_open_device(dev)) { diff --git a/bacula/src/stored/stored_conf.c b/bacula/src/stored/stored_conf.c index ebdc1a6f63..7f619e9c6a 100644 --- a/bacula/src/stored/stored_conf.c +++ b/bacula/src/stored/stored_conf.c @@ -146,7 +146,7 @@ void dump_resource(int type, RES *reshdr, void sendit(void *sock, char *fmt, ... char buf[MAXSTRING]; int recurse = 1; if (res == NULL) { - sendit(sock, _("Warning: no %s resource (%d) defined.\n"), res_to_str(type), type); + sendit(sock, _("Warning: no \"%s\" resource (%d) defined.\n"), res_to_str(type), type); return; } sendit(sock, "dump_resource type=%d\n", type); @@ -342,13 +342,13 @@ void save_resource(int type, RES_ITEM *items, int pass) 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"), + 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_ABORT, 0, _("Too many items in %s resource\n"), resources[rindex]); + Emsg1(M_ERROR_TERM, 0, _("Too many items in \"%s\" resource\n"), resources[rindex]); } } @@ -368,7 +368,7 @@ void save_resource(int type, RES_ITEM *items, int pass) /* Resources containing a resource */ case R_STORAGE: if ((res = (URES *)GetResWithName(R_STORAGE, res_all.res_dir.hdr.name)) == NULL) { - Emsg1(M_ABORT, 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; @@ -422,7 +422,7 @@ void save_resource(int type, RES_ITEM *items, int pass) for (next=resources[rindex].res_head; 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); } } diff --git a/bacula/src/tools/Makefile.in b/bacula/src/tools/Makefile.in index ced8002607..739c71f43c 100644 --- a/bacula/src/tools/Makefile.in +++ b/bacula/src/tools/Makefile.in @@ -28,6 +28,8 @@ FINDOBJS = testfind.o # these are the objects that are changed by the .configure process EXTRAOBJS = @OBJLIST@ +DIRCONFOBJS = ../dird/dird_conf.o ../dird/run_conf.o ../dird/inc_conf.o + .SUFFIXES: .c .o .PHONY: .DONTCARE: @@ -43,8 +45,8 @@ all: Makefile bsmtp dbcheck testfind testls bsmtp: bsmtp.o ../lib/libbac.a $(CXX) $(LDFLAGS) -L../lib -o $@ bsmtp.o -lbac -lm $(LIBS) $(DLIB) -dbcheck: dbcheck.o ../lib/libbac.a ../cats/libsql.a - $(CXX) $(LDFLAGS) -L../lib -L../cats -o $@ dbcheck.o -lsql -lbac -lm $(LIBS) $(DB_LIBS) +dbcheck: dbcheck.o ../lib/libbac.a ../cats/libsql.a $(DIRCONFOBJS) + $(CXX) $(LDFLAGS) -L../lib -L../cats -o $@ dbcheck.o $(DIRCONFOBJS) -lsql -lbac -lm $(LIBS) $(DB_LIBS) testfind: ../findlib/libfind.a ../lib/libbac.a $(FINDOBJS) $(CXX) -g $(LDFLAGS) -L. -L../lib -L../findlib -o $@ $(FINDOBJS) \ diff --git a/bacula/src/tools/dbcheck.c b/bacula/src/tools/dbcheck.c index 86df726e8e..875072ab09 100644 --- a/bacula/src/tools/dbcheck.c +++ b/bacula/src/tools/dbcheck.c @@ -9,7 +9,7 @@ * */ /* - Copyright (C) 2000-2003 Kern Sibbald and John Walker + Copyright (C) 2000-2004 Kern Sibbald and John Walker This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as @@ -30,6 +30,7 @@ #include "bacula.h" #include "cats/cats.h" +#include "dird/dird_conf.h" typedef struct s_id_ctx { uint32_t *Id; /* ids to be modified */ @@ -82,8 +83,10 @@ static int yes_no(char *prompt); static void usage() { fprintf(stderr, -"Usage: dbcheck [-d debug_level] \n" +"Usage: dbcheck [-c config] [-C catalogname] [-d debug_level] []\n" " -b batch mode\n" +" -C catalogname in the director configfile\n" +" -c director configfilename\n" " -dnn set debug level to nn\n" " -f fix inconsistencies\n" " -v verbose\n" @@ -94,7 +97,9 @@ static void usage() int main (int argc, char *argv[]) { int ch; - char *user, *password, *db_name; + char *user, *password, *db_name, *dbhost; + char *configfile = NULL; + char *catalogname = NULL; my_name_is(argc, argv, "dbcheck"); init_msg(NULL, NULL); /* setup message handler */ @@ -103,12 +108,20 @@ int main (int argc, char *argv[]) memset(&name_list, 0, sizeof(name_list)); - while ((ch = getopt(argc, argv, "bd:fv?")) != -1) { + while ((ch = getopt(argc, argv, "bc:C:d:fv?")) != -1) { switch (ch) { case 'b': /* batch */ batch = true; break; + case 'C': /* CatalogName */ + catalogname = optarg; + break; + + case 'c': /* configfile */ + configfile = optarg; + break; + case 'd': /* debug level */ debug_level = atoi(optarg); if (debug_level <= 0) @@ -131,38 +144,78 @@ int main (int argc, char *argv[]) argc -= optind; argv += optind; - if (argc > 4) { - Pmsg0(0, _("Wrong number of arguments.\n")); - usage(); - } - - if (argc < 1) { - Pmsg0(0, _("Working directory not supplied.\n")); - usage(); - } + if (configfile) { + CAT *catalog = NULL; + int found = 0; + if (argc > 0) { + 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)) { + ++found; + break; + } else if (!catalogname) { // stop on first if no catalogname is given + ++found; + break; + } + } + UnlockRes(); + if (!found) { + if (catalogname) { + 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); + } + return 1; + } else { + db_name = catalog->db_name; + user = catalog->db_user; + password = catalog->db_password; + dbhost = (catalog->db_address[0] == '\0') ? NULL : catalog->db_address; + } + } else { + if (argc > 5) { + Pmsg0(0, _("Wrong number of arguments.\n")); + usage(); + } - /* This is needed by SQLite to find the db */ - working_directory = argv[0]; - db_name = "bacula"; - user = db_name; - password = ""; + if (argc < 1) { + Pmsg0(0, _("Working directory not supplied.\n")); + usage(); + } - if (argc == 2) { - db_name = argv[1]; + /* This is needed by SQLite to find the db */ + working_directory = argv[0]; + db_name = "bacula"; user = db_name; - } else if (argc == 3) { - db_name = argv[1]; - user = argv[2]; - } else if (argc == 4) { - db_name = argv[1]; - user = argv[2]; - password = argv[3]; + password = ""; + dbhost = NULL; + + if (argc == 2) { + db_name = argv[1]; + user = db_name; + } else if (argc == 3) { + db_name = argv[1]; + user = argv[2]; + } else if (argc == 4) { + db_name = argv[1]; + user = argv[2]; + password = argv[3]; + } else if (argc == 5) { + db_name = argv[1]; + user = argv[2]; + password = argv[3]; + dbhost = argv[4]; + } } /* Open database */ - db = db_init_database(NULL, db_name, user, password, NULL, 0, NULL); + db = db_init_database(NULL, db_name, user, password, dbhost, 0, NULL); if (!db_open_database(NULL, db)) { Emsg1(M_FATAL, 0, "%s", db_strerror(db)); + return 1; } if (batch) { diff --git a/bacula/src/version.h b/bacula/src/version.h index 70903504ac..f07b7fd32d 100644 --- a/bacula/src/version.h +++ b/bacula/src/version.h @@ -2,8 +2,8 @@ #undef VERSION #define VERSION "1.34.3" #define VSTRING "1" -#define BDATE "01 June 2004" -#define LSMDATE "01Jun04" +#define BDATE "02 June 2004" +#define LSMDATE "02Jun04" /* Debug flags */ #undef DEBUG -- 2.39.5