/* Global variables */
+static STORES *me;
static DEVICE *dev = NULL;
static B_DB *db;
static JCR *bjcr; /* jcr for bscan */
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;
char *configfile;
+
static void usage()
{
fprintf(stderr, _(
" -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);
}
int main (int argc, char *argv[])
{
int ch;
+ struct stat stat_buf;
my_name_is(argc, argv, "bscan");
init_msg(NULL, NULL);
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 */
}
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");
if (read_access) {
if (!acquire_device_for_read(jcr, dev, block)) {
- Emsg0(M_ERROR, 0, dev->errmsg);
free_block(block);
return NULL;
}
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);
}
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);
}
}
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;
/* */
#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