-From bacula-users-admin@lists.sourceforge.net Mon Oct 20 23:44:13 2003
-Return-Path: <bacula-users-admin@lists.sourceforge.net>
-Received: from sc8-sf-list2.sourceforge.net (lists.sourceforge.net
- [66.35.250.206]) by matou.sibbald.com (8.11.6/8.11.6) with ESMTP id
- h9KLiDY13657 for <kern@sibbald.com>; Mon, 20 Oct 2003 23:44:13 +0200
-Received: from sc8-sf-list1-b.sourceforge.net ([10.3.1.13]
- helo=sc8-sf-list1.sourceforge.net) by sc8-sf-list2.sourceforge.net with
- esmtp (Exim 3.31-VA-mm2 #1 (Debian)) id 1ABhpS-00013k-00; Mon, 20 Oct 2003
- 14:44:42 -0700
-Received: from sc8-sf-mx1-b.sourceforge.net ([10.3.1.11]
- helo=sc8-sf-mx1.sourceforge.net) by sc8-sf-list1.sourceforge.net with esmtp
- (Cipher TLSv1:DES-CBC3-SHA:168) (Exim 3.31-VA-mm2 #1 (Debian)) id
- 1ABhnp-0007qu-00 for <bacula-users@lists.sourceforge.net>; Mon, 20 Oct 2003
- 14:43:01 -0700
-Received: from bast.unixathome.org ([66.11.174.150] ident=postfix) by
- sc8-sf-mx1.sourceforge.net with esmtp (Exim 4.22) id 1ABfiR-0002Iv-Q8 for
- bacula-users@lists.sourceforge.net; Mon, 20 Oct 2003 12:29:19 -0700
-Received: from wocker (wocker.unixathome.org [192.168.0.99]) by
- bast.unixathome.org (Postfix) with ESMTP id 258913F53 for
- <bacula-users@lists.sourceforge.net>; Mon, 20 Oct 2003 15:25:33 -0400 (EDT)
From: "Dan Langille" <dan@langille.org>
To: bacula-users@lists.sourceforge.net
-MIME-Version: 1.0
-Message-ID: <3F93FF4E.14552.13ACB682@localhost>
-Priority: normal
-X-mailer: Pegasus Mail for Windows (v4.02a)
-Content-type: text/plain; charset=US-ASCII
-Content-description: Mail message body
-X-Spam-Score: 0.0 (/)
-X-Spam-Report: 0.0/5.0 Spam Filtering performed by sourceforge.net. See
- http://spamassassin.org/tag/ for more details. Report problems to
- https://sf.net/tracker/?func=add&group_id=1&atid=200001
Subject: [Bacula-users] FreeBSD - large backups to tape
-Sender: bacula-users-admin@lists.sourceforge.net
-Errors-To: bacula-users-admin@lists.sourceforge.net
-X-BeenThere: bacula-users@lists.sourceforge.net
-X-Mailman-Version: 2.0.9-sf.net
-Precedence: bulk
-List-Help: <mailto:bacula-users-request@lists.sourceforge.net?subject=help>
-List-Post: <mailto:bacula-users@lists.sourceforge.net>
-List-Subscribe:
- <https://lists.sourceforge.net/lists/listinfo/bacula-users>,
- <mailto:bacula-users-request@lists.sourceforge.net?subject=subscribe>
-List-Id: Bacula user's email list for support and discussions
- <bacula-users.lists.sourceforge.net>
-List-Unsubscribe:
- <https://lists.sourceforge.net/lists/listinfo/bacula-users>,
- <mailto:bacula-users-request@lists.sourceforge.net?subject=unsubscribe>
-List-Archive:
- <http://sourceforge.net/mailarchive/forum.php?forum=bacula-users>
Date: Mon, 20 Oct 2003 15:29:18 -0400
-Content-Transfer-Encoding: 8bit
Kern and I have been working on a FreeBSD/Bacula problem.
He's asked me to post this to the list. The problem was within the
conducting a backup which spans two tapes. Restore the data
and compare to the original. If not identical, please let us know.
-Thanks
-
---
-Dan Langille : http://www.langille.org/
-
-
-
--------------------------------------------------------
-This SF.net email is sponsored by OSDN developer relations
-Here's your chance to show off your extensive product knowledge
-We want to know what you know. Tell us and you have a chance to win $100
-http://www.zoomerang.com/survey.zgi?HRPT1X3RYQNC5V4MLNSV3E54
-_______________________________________________
-Bacula-users mailing list
-Bacula-users@lists.sourceforge.net
-https://lists.sourceforge.net/lists/listinfo/bacula-users
--- /dev/null
+/*
+ *
+ * Program to test loss of data at EOM on
+ * FreeBSD systems.
+ *
+ * Kern Sibbald, August 2003
+ *
+ * If you build this program with:
+ *
+ * c++ -g -O2 -Wall -c tapetest.c
+ * c++ -g -O2 -Wall tapetest.o -o tapetest
+ *
+ * Procedure for testing tape
+ * ./tapetest /dev/your-tape-device
+ * rewind
+ * rawfill
+ * rewind
+ * scan
+ *
+ * The output will be:
+ *
+ * ========
+ * Rewound /dev/nsa0
+ * *Begin writing blocks of 64512 bytes.
+ * ++++++++++++++++++++ ...
+ * Write failed. Last block written=17294. stat=0 ERR=Unknown error: 0
+ * weof_dev
+ * Wrote EOF to /dev/nsa0
+ * *Rewound /dev/nsa0
+ * *Starting scan at file 0
+ * 17294 blocks of 64512 bytes in file 0
+ * End of File mark.
+ * End of File mark.
+ * End of tape
+ * Total files=1, blocks=17294, bytes = 1115670528
+ * ========
+ *
+ * which is correct. Notice that the return status is
+ * 0, while in the example below, which fails, the return
+ * status is -1.
+ *
+
+ * If you build this program with:
+ *
+ * c++ -g -O2 -Wall -pthread -c tapetest.c
+ * c++ -g -O2 -Wall -pthread tapetest.o -o tapetest
+ * Note, we simply added -pthread compared to the
+ * previous example.
+ *
+ * Procedure for testing tape
+ * ./tapetest /dev/your-tape-device
+ * rewind
+ * rawfill
+ * rewind
+ * scan
+ *
+ * The output will be:
+ *
+ * ========
+ * Rewound /dev/nsa0
+ * *Begin writing blocks of 64512 bytes.
+ * +++++++++++++++++++++++++++++ ...
+ * Write failed. Last block written=17926. stat=-1 ERR=No space left on device
+ * weof_dev
+ * Wrote EOF to /dev/nsa0
+ * *Rewound /dev/nsa0
+ * *Starting scan at file 0
+ * 17913 blocks of 64512 bytes in file 0
+ * End of File mark.
+ * End of File mark.
+ * End of tape
+ * Total files=1, blocks=17913, bytes = 1155603456
+ * ========
+ *
+ * which is incroorect because it wrote 17,926 blocks but read
+ * back only 17,913 blocks.
+ *
+ *
+ */
+
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <errno.h>
+#include <sys/ioctl.h>
+#include <string.h>
+#include <strings.h>
+#include <sys/mtio.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <ctype.h>
+
+#define FALSE 0
+#define TRUE 1
+
+#define dev_state(dev, state) ((dev)->state & (state))
+
+/* Device state bits */
+#define ST_OPENED (1<<0) /* set when device opened */
+#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 */
+#define ST_LABEL (1<<5) /* label found */
+#define ST_MALLOC (1<<6) /* dev packet malloc'ed in init_dev() */
+#define ST_APPEND (1<<7) /* ready for Bacula append */
+#define ST_READ (1<<8) /* ready for Bacula read */
+#define ST_EOT (1<<9) /* at end of tape */
+#define ST_WEOT (1<<10) /* Got EOT on write */
+#define ST_EOF (1<<11) /* Read EOF i.e. zero bytes */
+#define ST_NEXTVOL (1<<12) /* Start writing on next volume */
+#define ST_SHORT (1<<13) /* Short block read */
+
+#define BLOCK_SIZE (512 * 126)
+
+
+/* Exported variables */
+int quit = 0;
+char buf[100000];
+int verbose = 0;
+int debug_level = 0;
+int fd = 0;
+
+struct DEVICE {
+ int fd;
+ int dev_errno;
+ int file;
+ int block_num;
+ int state;
+ char *buf;
+ int buf_len;
+ char *dev_name;
+ int file_addr;
+};
+
+DEVICE *dev;
+
+#define uint32_t unsigned long
+#define uint64_t unsigned long long
+
+/* Forward referenced subroutines */
+static void do_tape_cmds();
+static void helpcmd();
+static void scancmd();
+static void rewindcmd();
+static void rawfill_cmd();
+
+
+/* Static variables */
+
+static char cmd[1000];
+
+static void usage();
+int get_cmd(char *prompt);
+
+
+/*********************************************************************
+ *
+ * Main Bacula Pool Creation Program
+ *
+ */
+int main(int argc, char *argv[])
+{
+ int ch;
+
+ while ((ch = getopt(argc, argv, "d:v?")) != -1) {
+ switch (ch) {
+ case 'd': /* set debug level */
+ debug_level = atoi(optarg);
+ if (debug_level <= 0) {
+ debug_level = 1;
+ }
+ break;
+
+ case 'v':
+ verbose++;
+ break;
+
+ case '?':
+ default:
+ helpcmd();
+ exit(0);
+
+ }
+ }
+ argc -= optind;
+ argv += optind;
+
+
+ /* See if we can open a device */
+ if (argc == 0) {
+ printf("No archive name specified.\n");
+ usage();
+ exit(1);
+ } else if (argc != 1) {
+ printf("Improper number of arguments specified.\n");
+ usage();
+ exit(1);
+ }
+
+ fd = open(argv[0], O_RDWR);
+ if (fd < 0) {
+ printf("Error opening %s ERR=%s\n", argv[0], strerror(errno));
+ exit(1);
+ }
+ dev = (DEVICE *)malloc(sizeof(DEVICE));
+ memset(dev, 0, sizeof(DEVICE));
+ dev->fd = fd;
+ dev->dev_name = strdup(argv[0]);
+ dev->buf_len = BLOCK_SIZE;
+ dev->buf = (char *)malloc(BLOCK_SIZE);
+
+ do_tape_cmds();
+ return 0;
+}
+
+
+int rewind_dev(DEVICE *dev)
+{
+ struct mtop mt_com;
+
+ if (dev->fd < 0) {
+ dev->dev_errno = EBADF;
+ printf("Bad call to rewind_dev. Device %s not open\n",
+ dev->dev_name);
+ return 0;
+ }
+ dev->state &= ~(ST_APPEND|ST_READ|ST_EOT|ST_EOF|ST_WEOT); /* remove EOF/EOT flags */
+ dev->block_num = dev->file = 0;
+ mt_com.mt_op = MTREW;
+ mt_com.mt_count = 1;
+ if (ioctl(dev->fd, MTIOCTOP, (char *)&mt_com) < 0) {
+ dev->dev_errno = errno;
+ printf("Rewind error on %s. ERR=%s.\n",
+ dev->dev_name, strerror(dev->dev_errno));
+ return 0;
+ }
+ return 1;
+}
+
+/*
+ * Write an end of file on the device
+ * Returns: 0 on success
+ * non-zero on failure
+ */
+int
+weof_dev(DEVICE *dev, int num)
+{
+ struct mtop mt_com;
+ int stat;
+
+ if (dev->fd < 0) {
+ dev->dev_errno = EBADF;
+ printf("Bad call to fsf_dev. Archive not open\n");
+ return -1;
+ }
+
+ dev->state &= ~(ST_EOT | ST_EOF); /* remove EOF/EOT flags */
+ dev->block_num = 0;
+ printf("weof_dev\n");
+ mt_com.mt_op = MTWEOF;
+ mt_com.mt_count = num;
+ stat = ioctl(dev->fd, MTIOCTOP, (char *)&mt_com);
+ if (stat == 0) {
+ dev->file++;
+ dev->file_addr = 0;
+ } else {
+ dev->dev_errno = errno;
+ printf("ioctl MTWEOF error on %s. ERR=%s.\n",
+ dev->dev_name, strerror(dev->dev_errno));
+ }
+ return stat;
+}
+
+
+
+
+
+void quitcmd()
+{
+ quit = 1;
+}
+
+
+/*
+ * Rewind the tape.
+ */
+static void rewindcmd()
+{
+ if (!rewind_dev(dev)) {
+ printf("Bad status from rewind. ERR=%s\n", strerror(dev->dev_errno));
+ } else {
+ printf("Rewound %s\n", dev->dev_name);
+ }
+}
+
+/*
+ * Write and end of file on the tape
+ */
+static void weofcmd()
+{
+ int stat;
+
+ if ((stat = weof_dev(dev, 1)) < 0) {
+ printf("Bad status from weof %d. ERR=%s\n", stat, strerror(dev->dev_errno));
+ return;
+ } else {
+ printf("Wrote EOF to %s\n", dev->dev_name);
+ }
+}
+
+
+/*
+ * Read a record from the tape
+ */
+static void rrcmd()
+{
+ char *buf;
+ int stat, len;
+
+ if (!get_cmd("Enter length to read: ")) {
+ return;
+ }
+ len = atoi(cmd);
+ if (len < 0 || len > 1000000) {
+ printf("Bad length entered, using default of 1024 bytes.\n");
+ len = 1024;
+ }
+ buf = (char *)malloc(len);
+ stat = read(fd, buf, len);
+ if (stat > 0 && stat <= len) {
+ errno = 0;
+ }
+ printf("Read of %d bytes gives stat=%d. ERR=%s\n",
+ len, stat, strerror(errno));
+ free(buf);
+}
+
+/*
+ * Write a record to the tape
+ */
+static void wrcmd()
+{
+ int stat;
+ int rfd;
+
+ rfd = open("/dev/urandom", O_RDONLY);
+ if (rfd) {
+ read(rfd, dev->buf, dev->buf_len);
+ } else {
+ printf("Cannot open /dev/urandom.\n");
+ return;
+ }
+ printf("Write one block of %u bytes.\n", dev->buf_len);
+ stat = write(dev->fd, dev->buf, dev->buf_len);
+ if (stat != (int)dev->buf_len) {
+ if (stat == -1) {
+ printf("Bad status from write. ERR=%s\n", strerror(errno));
+ } else {
+ printf("Expected to write %d bytes but wrote only %d.\n",
+ dev->buf_len, stat);
+ }
+ }
+}
+
+
+
+/*
+ * Scan tape by reading block by block. Report what is
+ * on the tape. Note, this command does raw reads, and as such
+ * will not work with fixed block size devices.
+ */
+static void scancmd()
+{
+ int stat;
+ int blocks, tot_blocks, tot_files;
+ int block_size;
+ uint64_t bytes;
+
+
+ blocks = block_size = tot_blocks = 0;
+ bytes = 0;
+ if (dev->state & ST_EOT) {
+ printf("End of tape\n");
+ return;
+ }
+ tot_files = dev->file;
+ printf("Starting scan at file %u\n", dev->file);
+ for (;;) {
+ if ((stat = read(dev->fd, buf, sizeof(buf))) < 0) {
+ dev->dev_errno = errno;
+ printf("Bad status from read %d. ERR=%s\n", stat, strerror(dev->dev_errno));
+ if (blocks > 0)
+ printf("%d block%s of %d bytes in file %d\n",
+ blocks, blocks>1?"s":"", block_size, dev->file);
+ return;
+ }
+ if (stat != block_size) {
+ if (blocks > 0) {
+ 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 */
+ printf("End of File mark.\n");
+ /* Two reads of zero means end of tape */
+ if (dev->state & ST_EOF)
+ dev->state |= ST_EOT;
+ else {
+ dev->state |= ST_EOF;
+ dev->file++;
+ }
+ if (dev->state & ST_EOT) {
+ printf("End of tape\n");
+ break;
+ }
+ } else { /* Got data */
+ dev->state &= ~ST_EOF;
+ blocks++;
+ tot_blocks++;
+ bytes += stat;
+ }
+ }
+ tot_files = dev->file - tot_files;
+ printf("Total files=%d, blocks=%d, bytes = %d\n", tot_files, tot_blocks,
+ (int)bytes);
+}
+
+
+static void rawfill_cmd()
+{
+ int stat;
+ int rfd;
+ uint32_t block_num = 0;
+ uint32_t *p;
+ int my_errno;
+
+ rfd = open("/dev/urandom", O_RDONLY);
+ if (rfd) {
+ read(rfd, dev->buf, dev->buf_len);
+ } else {
+ printf("Cannot open /dev/urandom.\n");
+ return;
+ }
+ p = (uint32_t *)dev->buf;
+ printf("Begin writing blocks of %u bytes.\n", dev->buf_len);
+ for ( ;; ) {
+ *p = block_num;
+ stat = write(dev->fd, dev->buf, dev->buf_len);
+ if (stat == (int)dev->buf_len) {
+ if ((block_num++ % 100) == 0) {
+ printf("+");
+ fflush(stdout);
+ }
+ continue;
+ }
+ break;
+ }
+ my_errno = errno;
+ printf("\n");
+ weofcmd();
+ printf("Write failed. Last block written=%d. stat=%d ERR=%s\n", (int)block_num, stat,
+ strerror(my_errno));
+
+}
+
+/* Strip any trailing junk from the command */
+void strip_trailing_junk(char *cmd)
+{
+ char *p;
+ p = cmd + strlen(cmd) - 1;
+
+ /* strip trailing junk from command */
+ while ((p >= cmd) && (*p == '\n' || *p == '\r' || *p == ' '))
+ *p-- = 0;
+}
+
+/* folded search for string - case insensitive */
+int
+fstrsch(char *a, char *b) /* folded case search */
+{
+ register char *s1,*s2;
+ register char c1=0, c2=0;
+
+ s1=a;
+ s2=b;
+ while (*s1) { /* do it the fast way */
+ if ((*s1++ | 0x20) != (*s2++ | 0x20))
+ return 0; /* failed */
+ }
+ while (*a) { /* do it over the correct slow way */
+ if (isupper(c1 = *a)) {
+ c1 = tolower((int)c1);
+ }
+ if (isupper(c2 = *b)) {
+ c2 = tolower((int)c2);
+ }
+ if (c1 != c2) {
+ return 0;
+ }
+ a++;
+ b++;
+ }
+ return 1;
+}
+
+
+struct cmdstruct { char *key; void (*func)(); char *help; };
+static struct cmdstruct commands[] = {
+ {"help", helpcmd, "print this command"},
+ {"quit", quitcmd, "quit tapetest"},
+ {"rawfill", rawfill_cmd, "use write() to fill tape"},
+ {"rewind", rewindcmd, "rewind the tape"},
+ {"rr", rrcmd, "raw read the tape"},
+ {"wr", wrcmd, "raw write one block to the tape"},
+ {"scan", scancmd, "read() tape block by block to EOT and report"},
+ {"weof", weofcmd, "write an EOF on the tape"},
+ };
+#define comsize (sizeof(commands)/sizeof(struct cmdstruct))
+
+static void
+do_tape_cmds()
+{
+ unsigned int i;
+ int found;
+
+ while (get_cmd("*")) {
+ found = 0;
+ for (i=0; i<comsize; i++) /* search for command */
+ if (fstrsch(cmd, commands[i].key)) {
+ (*commands[i].func)(); /* go execute command */
+ found = 1;
+ break;
+ }
+ if (!found) {
+ printf("%s is an illegal command\n", cmd);
+ }
+ if (quit) {
+ break;
+ }
+ }
+}
+
+static void helpcmd()
+{
+ unsigned int i;
+ usage();
+ printf(" Command Description\n ======= ===========\n");
+ for (i=0; i<comsize; i++)
+ printf(" %-10s %s\n", commands[i].key, commands[i].help);
+ printf("\n");
+}
+
+static void usage()
+{
+ fprintf(stderr,
+"Usage: tapetest [-d debug_level] [device_name]\n"
+" -dnn set debug level to nn\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
+get_cmd(char *prompt)
+{
+ int i = 0;
+ int ch;
+ fprintf(stdout, prompt);
+
+ /* We really should turn off echoing and pretty this
+ * up a bit.
+ */
+ cmd[i] = 0;
+ while ((ch = fgetc(stdin)) != EOF) {
+ if (ch == '\n') {
+ strip_trailing_junk(cmd);
+ return 1;
+ } else if (ch == 4 || ch == 0xd3 || ch == 0x8) {
+ if (i > 0)
+ cmd[--i] = 0;
+ continue;
+ }
+
+ cmd[i++] = ch;
+ cmd[i] = 0;
+ }
+ quit = 1;
+ return 0;
+}
#ifndef _BACULA_H
#define _BACULA_H 1
+#ifdef HAVE_WIN32
+#include "winconfig.h"
+#include "winhost.h"
+#else
#include "config.h"
#include "host.h"
+#endif
+
#define _REENTRANT 1
#define _THREAD_SAFE 1
#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif
+#ifdef HAVE_WIN32
+#include <winsock2.h>
+#else
#include <sys/stat.h>
+#endif
#include <sys/time.h>
#if HAVE_SYS_WAIT_H
#include <sys/wait.h>
/* Interrupt caught here */
static void sigintcatcher(int sig)
{
- brkflg = 1;
+ brkflg++;
signal(SIGINT, sigintcatcher);
}
}
if (tty_input) {
stat = get_cmd(input, prompt, UA_sock, 30);
- clrbrk();
+ if (usrbrk() == 1) {
+ clrbrk();
+ }
+ if (usrbrk()) {
+ break;
+ }
} else {
+ /* Reading input from a file */
int len = sizeof_pool_memory(UA_sock->msg) - 1;
- if (fgets(UA_sock->msg, len, input) == NULL || usrbrk()) {
+ if (usrbrk()) {
+ break;
+ }
+ if (fgets(UA_sock->msg, len, input) == NULL) {
stat = -1;
} else {
sendit(UA_sock->msg); /* echo to terminal */
sendit(UA_sock->msg);
}
}
+ if (usrbrk() > 1) {
+ break;
+ } else {
+ clrbrk();
+ }
if (!stop) {
fflush(stdout);
}
char TERM_msg[] = "2999 Terminate\n";
-#ifdef HAVE_CYGWIN
-int win32_client = 1;
+#if defined(HAVE_CYGWIN) || defined(HAVE_WIN32)
+const int win32_client = 1;
#else
-int win32_client = 0;
+const int win32_client = 0;
#endif
* Main Bacula Unix Client Program
*
*/
-#ifdef HAVE_CYGWIN
+#if defined(HAVE_CYGWIN) || defined(HAVE_WIN32)
#define main BaculaMain
#endif
+
int main (int argc, char *argv[])
{
int ch;
#define uLongf uint32_t
#endif
-extern int win32_client; /* Are we running on Windows? */
+extern const int win32_client; /* Are we running on Windows? */
extern CLIENT *me; /* "Global" Client resource */
* then move it to allocated memory when the resource
* scan is complete.
*/
+#if defined(HAVE_WIN32) && !defined(HAVE_CYGWIN)
+extern "C" { // work around visual compiler mangling variables
+ URES res_all;
+ int res_all_size = sizeof(res_all);
+}
+#else
URES res_all;
int res_all_size = sizeof(res_all);
+#endif
/* Definition of records permitted within each
* resource with the routine to process the record
#include "bacula.h"
#include "filed.h"
-#ifdef HAVE_CYGWIN
+#if defined(HAVE_CYGWIN) || defined(HAVE_WIN32)
/* pthread_kill() dies on Cygwin, so disable it */
#define pthread_kill(x, y)
/* Use shorter wait interval on Cygwin because no kill */
static char OKrestore[] = "2000 OK restore\n";
static char OKsession[] = "2000 OK session\n";
static char OKstore[] = "2000 OK storage\n";
-static char OKjob[] = "2000 OK Job " HOST_OS "," DISTNAME "," DISTVER;
+static char OKjob[] = "2000 OK Job %s,%s,%s";
static char OKsetdebug[] = "2000 OK setdebug=%d\n";
static char BADjob[] = "2901 Bad Job\n";
static char EndJob[] = "2800 End Job TermCode=%d JobFiles=%u ReadBytes=%s JobBytes=%s Errors=%u\n";
P(cjcr->mutex);
cjcr->store_bsock->timed_out = 1;
cjcr->store_bsock->terminated = 1;
-#ifndef HAVE_CYGWIN
+#if !defined(HAVE_CYGWIN) && !defined(HAVE_WIN32)
pthread_kill(cjcr->my_thread_id, TIMEOUT_SIGNAL);
#endif
V(cjcr->mutex);
jcr->sd_auth_key = bstrdup(sd_auth_key);
free_pool_memory(sd_auth_key);
Dmsg2(120, "JobId=%d Auth=%s\n", jcr->JobId, jcr->sd_auth_key);
- return bnet_fsend(dir, OKjob);
+ return bnet_fsend(dir, OKjob, HOST_OS, DISTNAME, DISTVER);
}
static int runbefore_cmd(JCR *jcr)
static char *level_to_str(int level);
-#ifdef HAVE_CYGWIN
+#if defined(HAVE_CYGWIN) || defined(HAVE_WIN32)
static int privs = 0;
#endif
len = Mmsg(&msg, _("Daemon started %s, %d Job%s run.\n"), dt, last_job.NumJobs,
last_job.NumJobs == 1 ? "" : "s");
sendit(msg, len, arg);
-#ifdef HAVE_CYGWIN
+#if defined(HAVE_CYGWIN) || defined(HAVE_WIN32)
if (debug_level > 0) {
if (!privs) {
privs = enable_backup_privileges(NULL, 1);
}
-#ifdef HAVE_CYGWIN
+#if defined(HAVE_CYGWIN) || defined(HAVE_WIN32)
#include <windows.h>
static char buf[100];
struct s_win32_arg *arg = (struct s_win32_arg *)marg;
if (len > 0 && msg[len-1] == '\n') {
- msg[len-1] = 0; /* eliminate newline */
+ // 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);
+ strncpy(_msg, msg, len-1);
+ _msg[len-1] = 0;
+ msg = _msg;
}
SendDlgItemMessage(arg->hwnd, arg->idlist, LB_ADDSTRING, 0, (LONG)msg);
// WinUPS header file
-#define STRICT
+#define STRICT 1
#include <windows.h>
#include <stdio.h>
#include <process.h>
Copyright (2000) Kern E. Sibbald
*/
+#ifndef HAVE_WIN32
#define HAVE_CYGWIN 1
+#endif
#include <unistd.h>
#include <lmcons.h>
#include <pthread.h>
#include "../../findlib/winapi.h"
-extern int BaculaMain(int argc, char **argv);
+extern int BaculaMain(int argc, char *argv[]);
extern int terminate_filed(int sig);
extern DWORD g_error;
extern BOOL ReportStatus(DWORD state, DWORD exitcode, DWORD waithint);
{
// DWORD dwThreadID;
pthread_t tid;
-
+#ifdef HAVE_WIN32
+ WSA_Init();
+#endif
HINSTANCE hLib = LoadLibrary("KERNEL32.DLL");
if (hLib) {
p_GetFileAttributesEx = (t_GetFileAttributesEx)
// Create a thread to handle the Windows messages
// (void)CreateThread(NULL, 0, Main_Msg_Loop, NULL, 0, &dwThreadID);
- pthread_create(&tid, NULL, Main_Msg_Loop, (void *)0);
+ pthread_create(&tid, NULL, Main_Msg_Loop, (void *)0);
// Call the "real" Bacula
BaculaMain(num_command_args, command_args);
DEFPUSHBUTTON "OK",IDOK,190,120,50,15
// CONTROL "\3", IDC_BACULABMP,"Static",SS_ICON | SS_CENTERIMAGE |
// SS_SUNKEN,7,5,73,65
- CONTROL "a", IDB_BACULABMP,"Static",SS_BITMAP|SS_SUNKEN,7,5,73,65
- LTEXT "Bacula Version " VERSION " (" BDATE ")", IDC_VERSION,90,10,239,10
- LTEXT " by Kern Sibbald",IDC_NAME,90,20,239,10
- LTEXT "For more information, see:",
- IDC_WWW,90,40,239,10
- LTEXT " www.sibbald.com/bacula",
- IDC_WWW,90,50,239,10
- LTEXT " ",
- IDC_WWW,90,60,239,10
- LTEXT " ",
- IDC_WWW,90,70,239,10
- LTEXT "Copyright (C) 1999-2004, Kern Sibbald",
- IDC_COPYRIGHT,7,120,175,10
- LTEXT "Licensed under GNU GPL 2.0.",
- IDC_TRADEMARK,7,130,175,10
+ CONTROL IDB_BACULABMP,IDB_BACULABMP,"Static",SS_BITMAP|SS_SUNKEN,7,5,32,32
+
+ LTEXT " by Kern Sibbald",IDC_NAME,134,38,78,10
+ LTEXT "For more information, see:",-1,115,60,100,10
+ LTEXT " www.sibbald.com/bacula",IDC_WWW,115,70,100,10
+// LTEXT " ",-1,69,81,100,10
+// LTEXT " ",-1,90,70,100,10
+ LTEXT "Copyright (C) 1999-2003, Kern Sibbald",IDC_COPYRIGHT,7,120,175,10
+ LTEXT "Licensed under GNU GPL 2.0.",IDC_TRADEMARK,7,130,175,10
+ RTEXT "Build Date:",-1,108,24,42,8
+ RTEXT "Bacula Version:",-1,100,9,50,8
+ LTEXT VERSION,IDC_VERSION,159,10,65,8
+ LTEXT BDATE,-1,159,24,65,10
+
END
/////////////////////////////////////////////////////////////////////////////
}
// And find the RegisterServiceProcess function
- DWORD WINAPI (*RegisterService)(DWORD, DWORD);
- RegisterService = (DWORD (*)(DWORD, DWORD))
+ DWORD (WINAPI *RegisterService)(DWORD, DWORD);
+ RegisterService = (DWORD (WINAPI *)(DWORD, DWORD))
GetProcAddress(kerneldll, "RegisterServiceProcess");
if (RegisterService == NULL) {
MessageBox(NULL, "Registry service not found: Bacula service not started",
// Append the service-start flag to the end of the path:
if ((int)strlen(path) + 20 + (int)strlen(BaculaRunService) < pathlength) {
- sprintf(servicecmd, "\"%s\" %s -c %s", path, BaculaRunService, path);
+ sprintf(servicecmd, "\"%s\" %s -c \"%s\"", path, BaculaRunService, path);
len = strlen(servicecmd) - 1;
for ( ; len > 0; len--) {
if (servicecmd[len] == '\\') {
}
LocalFree(msg);
}
-typedef BOOL WINAPI (*WinAPI)(SC_HANDLE, DWORD, LPVOID);
+typedef BOOL (WINAPI * WinAPI)(SC_HANDLE, DWORD, LPVOID);
void set_service_description(SC_HANDLE hSCManager, SC_HANDLE hService,
LPSTR lpDesc)
#include "bacula.h"
#include "find.h"
-#ifdef HAVE_CYGWIN
+#if defined(HAVE_CYGWIN) || defined(HAVE_WIN32)
/* Forward referenced subroutines */
static int set_win32_attributes(JCR *jcr, ATTR *attr, BFILE *ofd);
mode_t old_mask;
int stat = 1;
-#ifdef HAVE_CYGWIN
+#if defined(HAVE_CYGWIN) || defined(HAVE_WIN32)
if (attr->data_stream == STREAM_WIN32_DATA ||
attr->data_stream == STREAM_WIN32_GZIP_DATA) {
if (is_bopen(ofd)) {
/* */
/*=============================================================*/
-#ifndef HAVE_CYGWIN
+#if !defined(HAVE_CYGWIN) && !defined(HAVE_WIN32)
/*
* It is possible to piggyback additional data e.g. ACLs on
/* */
/*=============================================================*/
-#ifdef HAVE_CYGWIN
+#if defined(HAVE_CYGWIN) || defined(HAVE_WIN32)
int encode_attribsEx(JCR *jcr, char *attribsEx, FF_PKT *ff_pkt)
{
* ===============================================================
*/
-#ifdef HAVE_CYGWIN
+#if defined(HAVE_CYGWIN) || defined(HAVE_WIN32)
void unix_name_to_win32(POOLMEM **win32_name, char *name);
extern "C" HANDLE get_osfhandle(int fd);
} else if (flags & O_WRONLY) { /* Open existing for write */
if (bfd->use_backup_api) {
- dwaccess = GENERIC_WRITE|FILE_ALL_ACCESS|WRITE_OWNER|WRITE_DAC|ACCESS_SYSTEM_SECURITY;
+#ifdef HAVE_WIN32
+ dwaccess = GENERIC_WRITE|/*FILE_ALL_ACCESS|*/WRITE_OWNER|WRITE_DAC/*|ACCESS_SYSTEM_SECURITY*/;
+#else
+ dwaccess = GENERIC_WRITE|FILE_ALL_ACCESS|WRITE_OWNER|WRITE_DAC|ACCESS_SYSTEM_SECURITY;
+#endif
dwflags = FILE_FLAG_BACKUP_SEMANTICS;
} else {
dwaccess = GENERIC_WRITE;
#ifndef __BFILE_H
#define __BFILE_H
-#ifdef HAVE_CYGWIN
+#if defined(HAVE_CYGWIN) || defined(HAVE_WIN32)
#include <windows.h>
#include "winapi.h"
return CF_ERROR;
}
return CF_EXTRACT;
-
+#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:
return CF_ERROR;
}
return CF_CREATED;
-
+#endif
} /* End inner switch */
case FT_DIR:
/* */
/*=============================================================*/
-#ifndef HAVE_CYGWIN
+#if !defined(HAVE_CYGWIN) && !defined(WIN32)
int enable_backup_privileges(JCR *jcr, int ignore_errors)
{ return 0; }
/* */
/*=============================================================*/
-#ifdef HAVE_CYGWIN
+#if defined(HAVE_CYGWIN) || defined(WIN32)
void win_error(JCR *jcr, char *prefix, DWORD lerror);
return fail;
}
+/* return non-zero if path is absolute or zero if relative. */
+
+int
+isAbsolute(const char *path)
+{
+#if defined(HAVE_CYGWIN) || defined(WIN32)
+ return path[1] == ':' || *path == '/' || *path == '\\'; /* drivespec:/blah is absolute */
+#else
+ return *path == '/';
+#endif
+}
+
/* Ensure that the directory ARGPATH exists.
Remove any trailing slashes from ARGPATH before calling this function.
re_protect = 0;
}
-#ifdef HAVE_CYGWIN
+#if defined(HAVE_CYGWIN)
/* Because of silly Win32 security, we allow everything */
tmp_mode = S_IRWXUGO;
re_protect = 0;
/* 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. */
- if (cwd.do_chdir && *dirpath == '/' && chdir ("/") < 0) {
+ if (cwd.do_chdir && isAbsolute(dirpath) && chdir ("/") < 0) {
cwd.do_chdir = 0;
}
#undef bmalloc
#define bmalloc(x) sm_malloc(__FILE__, __LINE__, x)
-#ifdef HAVE_CYGWIN
-static int win32_client = 1;
-#else
-static int win32_client = 0;
-#endif
-
+extern const int win32_client;
/*
* Initialize structures for filename matching
break;
}
}
-#ifdef HAVE_CYGWIN
+#if defined(HAVE_CYGWIN) || defined(HAVE_WIN32)
/* Convert any \'s into /'s */
for (p=inc->fname; *p; p++) {
if (*p == '\\') {
int len;
struct s_excluded_file *exc, **list;
-#ifdef HAVE_CYGWIN
+#if defined(HAVE_CYGWIN) || defined(HAVE_WIN32)
/* Convert any \'s into /'s */
for (char *p=fname; *p; p++) {
if (*p == '\\') {
MA 02111-1307, USA.
*/
-
/* from attribs.c */
void encode_stat (char *buf, FF_PKT *ff_pkt, int data_stream);
int decode_stat (char *buf, struct stat *statp, int32_t *LinkFI);
}
if (!have_working_fchdir) {
- POOLMEM *buf = get_pool_memory(PM_FNAME);
+#ifdef HAVE_WIN32
+ POOLMEM *buf = get_memory(MAX_PATH);
+#else
+ POOLMEM *buf = get_memory(5000);
+#endif
cwd->name = (POOLMEM *)getcwd(buf, sizeof_pool_memory(buf));
if (cwd->name == NULL) {
Emsg1(M_ERROR, 0, "Cannot get current directory: %s\n", strerror(errno));
#include "bacula.h"
#include "find.h"
-#ifdef HAVE_CYGWIN
+#if defined(HAVE_CYGWIN) || defined(HAVE_WIN32)
/* API Pointers */
#ifndef __WINAPI_H
#define __WINAPI_H
-
-#ifdef HAVE_CYGWIN
+#if defined(HAVE_WIN32)
+#include <native.h>
+#include <windef.h>
+#endif
+#if defined(HAVE_CYGWIN) || defined(HAVE_WIN32)
/* In ADVAPI32.DLL */
-typedef BOOL WINAPI (*t_OpenProcessToken)(HANDLE, DWORD, PHANDLE);
-typedef BOOL WINAPI (*t_AdjustTokenPrivileges)(HANDLE, BOOL,
+
+typedef BOOL (WINAPI * t_OpenProcessToken)(HANDLE, DWORD, PHANDLE);
+typedef BOOL (WINAPI * t_AdjustTokenPrivileges)(HANDLE, BOOL,
PTOKEN_PRIVILEGES, DWORD, PTOKEN_PRIVILEGES, PDWORD);
-typedef BOOL WINAPI (*t_LookupPrivilegeValue)(LPCTSTR, LPCTSTR, PLUID);
+typedef BOOL (WINAPI * t_LookupPrivilegeValue)(LPCTSTR, LPCTSTR, PLUID);
extern t_OpenProcessToken p_OpenProcessToken;
extern t_AdjustTokenPrivileges p_AdjustTokenPrivileges;
extern t_LookupPrivilegeValue p_LookupPrivilegeValue;
/* In KERNEL32.DLL */
-typedef BOOL WINAPI (*t_GetFileAttributesEx)(LPCTSTR, GET_FILEEX_INFO_LEVELS,
+typedef BOOL (WINAPI * t_GetFileAttributesEx)(LPCTSTR, GET_FILEEX_INFO_LEVELS,
LPVOID);
-typedef BOOL WINAPI (*t_SetProcessShutdownParameters)(DWORD, DWORD);
-typedef BOOL WINAPI (*t_BackupRead)(HANDLE,LPBYTE,DWORD,LPDWORD,BOOL,BOOL,LPVOID*);
-typedef BOOL WINAPI (*t_BackupWrite)(HANDLE,LPBYTE,DWORD,LPDWORD,BOOL,BOOL,LPVOID*);
+typedef BOOL (WINAPI * t_SetProcessShutdownParameters)(DWORD, DWORD);
+typedef BOOL (WINAPI * t_BackupRead)(HANDLE,LPBYTE,DWORD,LPDWORD,BOOL,BOOL,LPVOID*);
+typedef BOOL (WINAPI * t_BackupWrite)(HANDLE,LPBYTE,DWORD,LPDWORD,BOOL,BOOL,LPVOID*);
extern t_GetFileAttributesEx p_GetFileAttributesEx;
extern t_SetProcessShutdownParameters p_SetProcessShutdownParameters;
extern t_BackupRead p_BackupRead;
extern t_BackupWrite p_BackupWrite;
+
#endif
#endif /* __WINAPI_H */
#include "bacula.h"
#include "jcr.h"
-extern int win32_client;
+extern const int win32_client;
ATTR *new_attr()
{
#define ENODATA EPIPE
#endif
-
+#ifdef HAVE_WIN32
+#define socketRead(fd, buf, len) recv(fd, buf, len, 0)
+#define socketWrite(fd, buf, len) send(fd, buf, len, 0)
+#else
+#define socketRead(fd, buf, len) read(fd, buf, len)
+#define socketWrite(fd, buf, len) write(fd, buf, len)
+#endif
/*
while (nleft > 0) {
do {
errno = 0;
- nread = read(bsock->fd, ptr, nleft);
+ nread = socketRead(bsock->fd, ptr, nleft);
if (bsock->timed_out || bsock->terminated) {
return nread;
}
while (nleft > 0) {
do {
errno = 0;
- nwritten = write(bsock->fd, ptr, nleft);
+ nwritten = socketWrite(bsock->fd, ptr, nleft);
if (bsock->timed_out || bsock->terminated) {
return nwritten;
}
#define NO_DATA 4 /* Valid name, no data record of requested type. */
#endif
+#ifndef HAVE_WIN32
extern int h_errno; /* On error has one of the above */
-
+#endif
/*
* Get human readable error for gethostbyname()
*/
BPIPE *open_bpipe(char *prog, int wait, char *mode)
{
char *bargv[MAX_ARGV];
- int bargc;
+ int bargc, i;
int readp[2], writep[2];
POOLMEM *tprog;
int mode_read, mode_write;
build_argc_argv(mp_chr(tprog), &bargc, bargv, MAX_ARGV);
#ifdef xxxxxx
printf("argc=%d\n", bargc);
- int i;
for (i=0; i<bargc; i++) {
printf("argc=%d argv=%s:\n", i, bargv[i]);
}
dup2(readp[1], 1); /* dup our read to his stdout */
dup2(readp[1], 2); /* and his stderr */
}
- for (int i=3; i<=32; i++) { /* close any open file descriptors */
+ for (i=3; i<=32; i++) { /* close any open file descriptors */
close(i);
}
execvp(bargv[0], bargv); /* call the program */
#include "bacula.h"
-#ifndef HAVE_CYGWIN
+#if !defined(HAVE_CYGWIN) && !defined(HAVE_WIN32)
#ifdef NEED_SHARED_MEMORY
#define SHM_KEY 0x0BACB01 /* key for shared memory */
#endif /* HAVE_LOCALTIME_R */
#ifndef HAVE_READDIR_R
-
+#ifndef HAVE_WIN32
#include <dirent.h>
int readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result)
}
V(mutex);
return stat;
-}
+}
+#endif
#endif /* HAVE_READDIR_R */
#ifdef xxxxxxxxxx_STRERROR_R
}
#endif /* DEBUG_MUTEX */
-#ifndef HAVE_CYGWIN
+#if !defined(HAVE_CYGWIN) && !defined(HAVE_WIN32)
static int del_pid_file_ok = FALSE;
#endif
*/
void create_pid_file(char *dir, char *progname, int port)
{
-#ifndef HAVE_CYGWIN
+#if !defined(HAVE_CYGWIN) && !defined(HAVE_WIN32)
int pidfd, len;
int oldpid;
char pidbuf[20];
*/
int delete_pid_file(char *dir, char *progname, int port)
{
-#ifndef HAVE_CYGWIN
+#if !defined(HAVE_CYGWIN) && !defined(HAVE_WIN32)
POOLMEM *fname = get_pool_memory(PM_FNAME);
if (!del_pid_file_ok) {
void
daemon_start()
{
-#ifndef HAVE_CYGWIN
+#if !defined(HAVE_CYGWIN) && !defined(HAVE_WIN32)
int i;
pid_t cpid;
mode_t oldmask;
/* In case you want to specifically specify the offset to the link */
#define OFFSET(item, link) ((char *)(link) - (char *)(item))
-
+#ifdef HAVE_WIN32
+/* Extra ***& workaround for VisualC Studio */
+#define foreach_dlist(var, list) \
+ for((var)=NULL; (*((void **)&(var))=(void*)((list)->next(var))); )
+#else
/*
* Loop var through each member of list
*/
#define foreach_dlist(var, list) \
for((var)=NULL; (((void *)(var))=(list)->next(var)); )
+#endif
struct dlink {
void *next;
void *prev;
};
+
class dlist {
void *head;
void *tail;
if (errno != 0 || value < 0) {
return 0;
}
+#if defined(HAVE_WIN32)
+ /* work around microsofts non handling of uint64 to double cvt*/
+ *rtn_value = (uint64_t)(value * (__int64)mult[i]);
+ Dmsg2(400, "Full value = %lf %" lld "\n", value * (__int64)mult[i],
+ (uint64_t)(value * (__int64)mult[i]));
+#else
*rtn_value = (uint64_t)(value * mult[i]);
Dmsg2(400, "Full value = %lf %" lld "\n", value * mult[i],
(uint64_t)(value * mult[i]));
+#endif
return 1;
}
#endif /* IMPLEMENTED */
-#ifdef HAVE_CYGWIN
+#if defined(HAVE_CYGWIN) || defined(HAVE_WIN32)
#include <windows.h>
pwent = getpwuid(uid);
tail = (struct userid *)malloc(sizeof (struct userid));
tail->id.u = uid;
+#ifndef HAVE_WIN32
if (pwent == 0 || strcmp(pwent->pw_name, "????????") == 0) {
sprintf(usernum_string, "%u", (uint32_t)uid);
tail->name = bstrdup(usernum_string);
} else {
tail->name = bstrdup(pwent->pw_name);
}
+#else
+ sprintf(usernum_string, "%u", (uint32_t)uid);
+ tail->name = bstrdup(usernum_string);
+#endif
/* Add to the head of the list, so most recently used is first. */
tail->next = user_alist;
grent = getgrgid(gid);
tail = (struct userid *)malloc(sizeof (struct userid));
tail->id.g = gid;
+#ifndef HAVE_WIN32
if (grent == 0 || strcmp(grent->gr_name, "????????") == 0) {
sprintf (groupnum_string, "%u", (uint32_t)gid);
tail->name = bstrdup(groupnum_string);
} else {
tail->name = bstrdup(grent->gr_name);
}
-
+#else
+ sprintf (groupnum_string, "%u", (uint32_t)gid);
+ tail->name = bstrdup(groupnum_string);
+#endif
/* Add to the head of the list, so most recently used is first. */
tail->next = group_alist;
group_alist = tail;
void init_last_jobs_list()
{
int errstat;
- struct s_last_job *job_entry;
+ struct s_last_job *job_entry = NULL;
if (!last_jobs) {
last_jobs = new dlist(job_entry, &job_entry->link);
memset(&last_job, 0, sizeof(last_job));
#endif
#endif
-char *host_os = HOST_OS;
-char *distname = DISTNAME;
-char *distver = DISTVER;
+const char *host_os = HOST_OS;
+const char *distname = DISTNAME;
+const char *distver = DISTVER;
/* Forward referenced functions */
l++;
} else {
l = argv[0];
-#ifdef HAVE_CYGWIN
+#if defined(HAVE_CYGWIN) || defined(HAVE_WIN32)
/* On Windows allow c: junk */
if (l[1] == ':') {
l += 2;
init_msg(JCR *jcr, MSGS *msg)
{
DEST *d, *dnew, *temp_chain = NULL;
- int i, fd;
+ int i;
if (jcr == NULL && msg == NULL) {
init_last_jobs_list();
}
+#ifndef HAVE_WIN32
/*
* Make sure we have fd's 0, 1, 2 open
* If we don't do this one of our sockets may open
* send total garbage to our socket.
*
*/
+ int fd;
fd = open("/dev/null", O_RDONLY, 0644);
if (fd > 2) {
close(fd);
}
}
-
+#endif
/*
* If msg is NULL, initialize global chain for STDOUT and syslog
*/
}
if (level <= debug_level) {
+#ifdef HAVE_WIN32
+#define SEND_DMSG_TO_FILE
+#endif
#ifdef SEND_DMSG_TO_FILE
if (!trace_fd) {
- bsnprintf(buf, sizeof(buf), "%s/bacula.trace", working_directory);
+ bsnprintf(buf, sizeof(buf), "%s/bacula.trace", working_directory ? working_directory : ".");
trace_fd = fopen(buf, "a+");
- if (!trace_fd) {
- Emsg2(M_ABORT, 0, _("Cannot open trace file \"%s\": ERR=%s\n"),
- buf, strerror(errno));
- }
}
#endif
#ifdef FULL_LOCATION
if (details) {
+ /* visual studio passes the whole path to the file as well
+ * which makes for very long lines
+ */
+ char *f = strrchr(file, '\\');
+ if (f) file = f + 1;
len = bsnprintf(buf, sizeof(buf), "%s: %s:%d ", my_name, file, line);
} else {
len = 0;
va_end(arg_ptr);
#ifdef SEND_DMSG_TO_FILE
- fputs(buf, trace_fd);
- fflush(trace_fd);
+ if (trace_fd) {
+ fputs(buf, trace_fd);
+ fflush(trace_fd);
+ }
#else
fputs(buf, stdout);
#endif
if (!trace_fd) {
bsnprintf(buf, sizeof(buf), "%s/bacula.trace", working_directory);
trace_fd = fopen(buf, "a+");
- if (!trace_fd) {
- Emsg2(M_ABORT, 0, _("Cannot open trace file \"%s\": ERR=%s\n"),
- buf, strerror(errno));
- }
}
#ifdef FULL_LOCATION
va_start(arg_ptr, fmt);
bvsnprintf(buf+len, sizeof(buf)-len, (char *)fmt, arg_ptr);
va_end(arg_ptr);
-
- fputs(buf, trace_fd);
- fflush(trace_fd);
- }
+ if (trace_fd != NULL) {
+ fputs(buf, trace_fd);
+ fflush(trace_fd);
+ }
+ }
}
extern int r_last;
extern pthread_mutex_t res_mutex;
extern struct s_res resources[];
-extern CURES res_all;
+#ifdef HAVE_WIN32
+// work around visual studio name manling preventing external linkage since res_all
+// is declared as a different type when instantiated.
+extern "C" CURES res_all;
+extern "C" int res_all_size;
+#else
+extern CURES res_all;
extern int res_all_size;
+#endif
+
static bool res_locked = false; /* set when resource chains locked */
void save_resource(int type, struct res_items *item, int pass);
char *res_to_str(int rcode);
/* Loop through each resource of type, returning in var */
+#ifdef HAVE_WIN32
+#define foreach_res(var, type) \
+ for(var=NULL; *((void **)&(var))=(void *)GetNextRes((type), (RES *)var);)
+#else
#define foreach_res(var, type) \
for((var)=NULL; (((void *)(var))=GetNextRes((type), (RES *)var));)
-
+#endif
void store_str(LEX *lc, struct res_items *item, int index, int pass);
*/
-
+#ifndef HAVE_WIN32
#include "bacula.h"
#ifndef _NSIG
sigaction(SIGLOST, &sighandle, NULL);
#endif
}
+#endif
char *p, *str;
char add[20];
char name[MAX_NAME_LENGTH];
+ int i;
*omsg = 0;
Dmsg1(200, "edit_job_codes: %s\n", imsg);
case 'n':
bstrncpy(name, jcr->Job, sizeof(name));
/* There are three periods after the Job name */
- for (int i=0; i<3; i++) {
+ for (i=0; i<3; i++) {
if ((str=strrchr(name, '.')) != NULL) {
*str = 0;
}
*/
-
+#ifndef HAVE_WIN32
#include "bacula.h"
#if defined(HAVE_PCREPOSIX)
# include <pcreposix.h>
}
return str;
}
+#endif
#include "stored.h"
#include "findlib/find.h"
-#ifdef HAVE_CYGWIN
+#if defined(HAVE_CYGWIN) || defined(HAVE_WIN32)
int win32_client = 1;
#else
int win32_client = 0;
#endif
-
static void do_extract(char *fname);
static int record_cb(JCR *jcr, DEVICE *dev, DEV_BLOCK *block, DEV_RECORD *rec);
#include "stored.h"
#include "findlib/find.h"
-#ifdef HAVE_CYGWIN
+#if defined(HAVE_CYGWIN) || defined(HAVE_WIN32)
int win32_client = 1;
#else
int win32_client = 0;
#endif
-
static void do_blocks(char *infname);
static void do_jobs(char *infname);
static void do_ls(char *fname);
/* Global variables */
STORES *me;
-#ifdef HAVE_CYGWIN
+#if defined(HAVE_CYGWIN) || defined(HAVE_WIN32)
int win32_client = 1;
#else
int win32_client = 0;
#include "findlib/find.h"
+#if defined(HAVE_CYGWIN) || defined(HAVE_WIN32)
+int win32_client = 1;
+#else
+int win32_client = 0;
+#endif
+
+
/* Global variables */
static int num_files = 0;
static int max_file_len = 0;
#include "bacula.h"
#include "findlib/find.h"
+#if defined(HAVE_CYGWIN) || defined(HAVE_WIN32)
+int win32_client = 1;
+#else
+int win32_client = 0;
+#endif
+
/* Global variables */
int attrs = 0;