From 71b486fa671579431a852aeed34aa639f5cbc275 Mon Sep 17 00:00:00 2001 From: Robert Nelson Date: Wed, 11 Oct 2006 09:18:29 +0000 Subject: [PATCH] Fix Windows' daemons so that messages print to stdout if not running as a service. Add daemon name to trace file name (eg bacula-dir.trace). Fix environment variable expansion in directory names on Windows. Fix autochanger support in fill command. Update SQL scripts. Fix daemon usage displays. Cleanup bacula-dir.conf template. Install openssl.cnf. git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@3544 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/lib/message.c | 8 +++----- bacula/src/lib/util.c | 12 +++++++++++ bacula/src/stored/btape.c | 42 ++++++++++++++++++-------------------- bacula/src/stored/device.c | 3 ++- 4 files changed, 37 insertions(+), 28 deletions(-) diff --git a/bacula/src/lib/message.c b/bacula/src/lib/message.c index 9e9d219e1b..03074b5487 100755 --- a/bacula/src/lib/message.c +++ b/bacula/src/lib/message.c @@ -162,6 +162,7 @@ void init_msg(JCR *jcr, MSGS *msg) { DEST *d, *dnew, *temp_chain = NULL; + int i; if (jcr == NULL && msg == NULL) { init_last_jobs_list(); @@ -176,7 +177,6 @@ init_msg(JCR *jcr, MSGS *msg) * */ int fd; - int i; fd = open("/dev/null", O_RDONLY, 0644); if (fd > 2) { close(fd); @@ -193,11 +193,9 @@ init_msg(JCR *jcr, MSGS *msg) if (msg == NULL) { daemon_msgs = (MSGS *)malloc(sizeof(MSGS)); memset(daemon_msgs, 0, sizeof(MSGS)); -#if !defined(HAVE_WIN32) for (i=1; i<=M_MAX; i++) { add_msg_dest(daemon_msgs, MD_STDOUT, i, NULL, NULL); } -#endif Dmsg1(050, "Create daemon global message resource %p\n", daemon_msgs); return; } @@ -823,7 +821,7 @@ d_msg(const char *file, int line, int level, const char *fmt,...) if (trace) { if (!trace_fd) { char fn[200]; - bsnprintf(fn, sizeof(fn), "%s/bacula.trace", working_directory ? working_directory : "."); + bsnprintf(fn, sizeof(fn), "%s/%s.trace", working_directory ? working_directory : ".", my_name); trace_fd = fopen(fn, "a+b"); } if (trace_fd) { @@ -919,7 +917,7 @@ t_msg(const char *file, int line, int level, const char *fmt,...) if (level <= debug_level) { if (!trace_fd) { - bsnprintf(buf, sizeof(buf), "%s/bacula.trace", working_directory); + bsnprintf(buf, sizeof(buf), "%s/%s.trace", working_directory ? working_directory : ".", my_name); trace_fd = fopen(buf, "a+b"); } diff --git a/bacula/src/lib/util.c b/bacula/src/lib/util.c index b6c76a0822..8a48d8514d 100644 --- a/bacula/src/lib/util.c +++ b/bacula/src/lib/util.c @@ -380,7 +380,18 @@ char *encode_mode(mode_t mode, char *buf) return cp; } +#if defined(HAVE_WIN32) +int do_shell_expansion(char *name, int name_len) +{ + char *src = bstrdup(name); + + ExpandEnvironmentStrings(src, name, name_len); + + free(src); + return 1; +} +#else int do_shell_expansion(char *name, int name_len) { static char meta[] = "~\\$[]*?`'<>\""; @@ -426,6 +437,7 @@ int do_shell_expansion(char *name, int name_len) } return 1; } +#endif /* MAKESESSIONKEY -- Generate session key with optional start diff --git a/bacula/src/stored/btape.c b/bacula/src/stored/btape.c index cf1f065730..6ebe43b620 100644 --- a/bacula/src/stored/btape.c +++ b/bacula/src/stored/btape.c @@ -385,6 +385,7 @@ static void labelcmd() } } dev->rewind(dcr); + dev->weof(1); write_new_volume_label_to_dev(dcr, cmd, "Default", false,/*no relabel*/ true /* label dvd now */); Pmsg1(-1, _("Wrote Volume label for volume \"%s\".\n"), cmd); } @@ -1848,14 +1849,7 @@ static void fillcmd() min_block_size = dev->min_block_size; dev->min_block_size = dev->max_block_size; set_volume_name("TestVolume1", 1); - - if (!dev->rewind(dcr)) { - Pmsg0(000, _("Rewind failed.\n")); - } - if (!dev->weof(1)) { - Pmsg0(000, _("Write EOF failed.\n")); - } - labelcmd(); + dir_ask_sysop_to_create_appendable_volume(dcr); dev->set_append(); /* force volume to be relabeled */ /* @@ -1892,7 +1886,7 @@ static void fillcmd() * Put some random data in the record */ fd = open("/dev/urandom", O_RDONLY); - if (fd) { + if (fd != -1) { read(fd, rec.data, rec.data_len); close(fd); } else { @@ -2127,6 +2121,19 @@ static void do_unfill() last_file = last_file1; last_block = last_block1; + free_restore_volume_list(jcr); + jcr->bsr = NULL; + bstrncpy(dcr->VolumeName, "TestVolume1|TestVolume2", sizeof(dcr->VolumeName)); + create_restore_volume_list(jcr); + if (jcr->VolList != NULL) { + jcr->VolList->Slot = 1; + if (jcr->VolList->next != NULL) { + jcr->VolList->next->Slot = 2; + } + } + + set_volume_name("TestVolume1", 1); + if (!simple) { /* Multiple Volume tape */ /* Close device so user can use autochanger if desired */ @@ -2140,11 +2147,6 @@ static void do_unfill() } } - free_restore_volume_list(jcr); - jcr->dcr = new_dcr(jcr, dev); - set_volume_name("TestVolume1", 1); - jcr->bsr = NULL; - create_restore_volume_list(jcr); dev->close(); dev->num_writers = 0; if (!acquire_device_for_read(dcr)) { @@ -2198,10 +2200,8 @@ static void do_unfill() dev->offline(); } - free_restore_volume_list(jcr); set_volume_name("TestVolume2", 2); - jcr->bsr = NULL; - create_restore_volume_list(jcr); + autochanger = autoload_device(dcr, 1, NULL); if (!autochanger) { dev->close(); @@ -2743,7 +2743,6 @@ bool dir_ask_sysop_to_create_appendable_volume(DCR *dcr) dev->close(); getchar(); } - open_device(dcr); labelcmd(); VolumeName = NULL; BlockNumber = 0; @@ -2778,11 +2777,9 @@ static bool my_mount_next_read_volume(DCR *dcr) return false; } - free_restore_volume_list(jcr); - dev->close(); set_volume_name("TestVolume2", 2); - jcr->bsr = NULL; - create_restore_volume_list(jcr); + + dev->close(); if (!acquire_device_for_read(dcr)) { Pmsg2(0, _("Cannot open Dev=%s, Vol=%s\n"), dev->print_name(), dcr->VolumeName); return false; @@ -2799,4 +2796,5 @@ static void set_volume_name(const char *VolName, int volnum) bstrncpy(dcr->VolCatInfo.VolCatName, VolName, sizeof(dcr->VolCatInfo.VolCatName)); bstrncpy(dcr->VolumeName, VolName, sizeof(dcr->VolumeName)); dcr->VolCatInfo.Slot = volnum; + dcr->VolCatInfo.InChanger = true; } diff --git a/bacula/src/stored/device.c b/bacula/src/stored/device.c index 1229daeec3..26f42c72bc 100644 --- a/bacula/src/stored/device.c +++ b/bacula/src/stored/device.c @@ -63,7 +63,8 @@ * We enter with device locked, and * exit with device locked. * - * Note, we are called only from one place in block.c + * Note, we are called only from one place in block.c for the daemons. + * The btape utility calls it from btape.c. * * Returns: true on success * false on failure -- 2.39.5