From: Kern Sibbald Date: Tue, 19 Apr 2005 09:49:20 +0000 (+0000) Subject: Cleanup Python build so that Python is not dragged X-Git-Tag: Release-1.38.0~555 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=6fc016ea3c4f5698462494319733199e2de9a9af;p=bacula%2Fbacula Cleanup Python build so that Python is not dragged into programs that don't use it. git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@1936 91ce42f0-d328-0410-95d8-f526ca767f89 --- diff --git a/bacula/examples/python/EndJob.py b/bacula/examples/python/EndJob.py index adcd49729a..f32df1f2f4 100644 --- a/bacula/examples/python/EndJob.py +++ b/bacula/examples/python/EndJob.py @@ -1,11 +1,11 @@ import bacula def EndJob(jcr): - jobid = jcr.get("JobId") - client = jcr.get("Client") - jcr.set(JobReport="Python EndJob output: JobId=%d Client=%s.\n" % (jobid, client)) - if (jobid < 2) : - startid = bacula.run("run kernsave") - print "Python started new Job: jobid=", startid + jobid = jcr.get("JobId") + client = jcr.get("Client") + jcr.set(JobReport="Python EndJob output: JobId=%d Client=%s.\n" % (jobid, client)) + if (jobid < 2) : + startid = bacula.run("run kernsave") + print "Python started new Job: jobid=", startid - return 1 + return 1 diff --git a/bacula/kernstodo b/bacula/kernstodo index d8ef55de0d..31055d0381 100644 --- a/bacula/kernstodo +++ b/bacula/kernstodo @@ -28,6 +28,8 @@ Autochangers: all Volumes from other drives. "update slots all-drives"? For 1.37: +- Look at dird_conf.c:1000: warning: `int size' + might be used uninitialized in this function - Make a callback when Rerun failed levels is called. - Give Python program access to Scheduled jobs. - Implement some way to turn off automatic pruning in Jobs. diff --git a/bacula/src/console/console.c b/bacula/src/console/console.c index 8bf17863fd..850bc21a12 100644 --- a/bacula/src/console/console.c +++ b/bacula/src/console/console.c @@ -59,7 +59,8 @@ extern int rl_catch_signals; /* Imported functions */ int authenticate_director(JCR *jcr, DIRRES *director, CONRES *cons); - +/* Dummy functions */ +int generate_daemon_event(JCR *jcr, const char *event) { return 1; } /* Forward referenced functions */ static void terminate_console(int sig); @@ -79,7 +80,7 @@ static char *configfile = NULL; static BSOCK *UA_sock = NULL; static DIRRES *dir; static FILE *output = stdout; -static bool tee = false; /* output to output and stdout */ +static bool tee = false; /* output to output and stdout */ static bool stop = false; static int argc; static POOLMEM *args; @@ -159,7 +160,7 @@ static struct cmdstruct commands[] = { { N_("version"), versioncmd, _("print Console's version")}, { N_("exit"), quitcmd, _("exit = quit")}, { N_("zed_keyst"), zed_keyscmd, _("zed_keys = use zed keys instead of bash keys")}, - }; + }; #define comsize (sizeof(commands)/sizeof(struct cmdstruct)) static int do_a_command(FILE *input, BSOCK *UA_sock) @@ -183,11 +184,11 @@ static int do_a_command(FILE *input, BSOCK *UA_sock) return 1; } len = strlen(cmd); - for (i=0; imsg) - 1; - if (usrbrk()) { - break; - } - if (fgets(UA_sock->msg, len, input) == NULL) { - stat = -1; - } else { - sendit(UA_sock->msg); /* echo to terminal */ - strip_trailing_junk(UA_sock->msg); - UA_sock->msglen = strlen(UA_sock->msg); - stat = 1; - } + /* Reading input from a file */ + int len = sizeof_pool_memory(UA_sock->msg) - 1; + if (usrbrk()) { + break; + } + if (fgets(UA_sock->msg, len, input) == NULL) { + stat = -1; + } else { + sendit(UA_sock->msg); /* echo to terminal */ + strip_trailing_junk(UA_sock->msg); + UA_sock->msglen = strlen(UA_sock->msg); + stat = 1; + } } if (stat < 0) { - break; /* error or interrupt */ - } else if (stat == 0) { /* timeout */ + break; /* error or interrupt */ + } else if (stat == 0) { /* timeout */ if (strcmp(prompt, "*") == 0) { bnet_fsend(UA_sock, ".messages"); - } else { - continue; - } + } else { + continue; + } } else { - at_prompt = FALSE; - /* @ => internal command for us */ + at_prompt = FALSE; + /* @ => internal command for us */ if (UA_sock->msg[0] == '@') { - parse_args(UA_sock->msg, &args, &argc, argk, argv, MAX_CMD_ARGS); - if (!do_a_command(input, UA_sock)) { - break; - } - continue; - } - if (!bnet_send(UA_sock)) { /* send command */ - break; /* error */ - } + parse_args(UA_sock->msg, &args, &argc, argk, argv, MAX_CMD_ARGS); + if (!do_a_command(input, UA_sock)) { + break; + } + continue; + } + if (!bnet_send(UA_sock)) { /* send command */ + break; /* error */ + } } if (strcmp(UA_sock->msg, ".quit") == 0 || strcmp(UA_sock->msg, ".exit") == 0) { - break; + break; } while ((stat = bnet_recv(UA_sock)) >= 0) { - if (at_prompt) { - if (!stop) { + if (at_prompt) { + if (!stop) { sendit("\n"); - } - at_prompt = false; - } - /* Suppress output if running in background or user hit ctl-c */ - if (!stop && !usrbrk()) { - sendit(UA_sock->msg); - } + } + at_prompt = false; + } + /* Suppress output if running in background or user hit ctl-c */ + if (!stop && !usrbrk()) { + sendit(UA_sock->msg); + } } if (usrbrk() > 1) { - break; + break; } else { - clrbrk(); + clrbrk(); } if (!stop) { - fflush(stdout); + fflush(stdout); } if (is_bnet_stop(UA_sock)) { - break; /* error or term */ + break; /* error or term */ } else if (stat == BNET_SIGNAL) { - if (UA_sock->msglen == BNET_PROMPT) { - at_prompt = true; - } + if (UA_sock->msglen == BNET_PROMPT) { + at_prompt = true; + } Dmsg1(100, "Got poll %s\n", bnet_sig_to_ascii(UA_sock)); } } @@ -295,7 +296,7 @@ static void read_and_process_input(FILE *input, BSOCK *UA_sock) /********************************************************************* * - * Main Bacula Console -- User Interface Program + * Main Bacula Console -- User Interface Program * */ int main(int argc, char *argv[]) @@ -316,32 +317,32 @@ int main(int argc, char *argv[]) while ((ch = getopt(argc, argv, "bc:d:r:st?")) != -1) { switch (ch) { case 'c': /* configuration file */ - if (configfile != NULL) { - free(configfile); - } - configfile = bstrdup(optarg); - break; + if (configfile != NULL) { + free(configfile); + } + configfile = bstrdup(optarg); + break; case 'd': - debug_level = atoi(optarg); - if (debug_level <= 0) { - debug_level = 1; - } - break; + debug_level = atoi(optarg); + if (debug_level <= 0) { + debug_level = 1; + } + break; case 's': /* turn off signals */ - no_signals = true; - break; + no_signals = true; + break; case 't': - test_config = true; - break; + test_config = true; + break; case '?': default: - usage(); - con_term(); - exit(1); + usage(); + con_term(); + exit(1); } } argc -= optind; @@ -393,7 +394,7 @@ int main(int argc, char *argv[]) memset(&jcr, 0, sizeof(jcr)); - (void)WSA_Init(); /* Initialize Windows sockets */ + (void)WSA_Init(); /* Initialize Windows sockets */ if (ndir > 1) { struct sockaddr client_addr; @@ -405,22 +406,22 @@ try_again: ndir = 0; foreach_res(dir, R_DIRECTOR) { senditf( _("%d %s at %s:%d\n"), 1+ndir++, dir->hdr.name, dir->address, - dir->DIRport); + dir->DIRport); } UnlockRes(); if (get_cmd(stdin, _("Select Director: "), UA_sock, 600) < 0) { - (void)WSACleanup(); /* Cleanup Windows sockets */ - return 1; + (void)WSACleanup(); /* Cleanup Windows sockets */ + return 1; } item = atoi(UA_sock->msg); if (item < 0 || item > ndir) { senditf(_("You must enter a number between 1 and %d\n"), ndir); - goto try_again; + goto try_again; } LockRes(); dir = NULL; for (i=0; iaddress,dir->DIRport); UA_sock = bnet_connect(NULL, 5, 15, "Director daemon", dir->address, - NULL, dir->DIRport, 0); + NULL, dir->DIRport, 0); if (UA_sock == NULL) { terminate_console(0); return 1; @@ -461,8 +462,8 @@ try_again: pm_strcat(&UA_sock->msg, "/.bconsolerc"); fd = fopen(UA_sock->msg, "r"); if (fd) { - read_and_process_input(fd, UA_sock); - fclose(fd); + read_and_process_input(fd, UA_sock); + fclose(fd); } } @@ -484,13 +485,13 @@ static void terminate_console(int sig) static bool already_here = false; - if (already_here) { /* avoid recursive temination problems */ + if (already_here) { /* avoid recursive temination problems */ exit(1); } already_here = true; free_pool_memory(args); con_term(); - (void)WSACleanup(); /* Cleanup Windows sockets */ + (void)WSACleanup(); /* Cleanup Windows sockets */ if (sig != 0) { exit(1); } @@ -509,7 +510,7 @@ get_cmd(FILE *input, const char *prompt, BSOCK *sock, int sec) { char *line; - rl_catch_signals = 0; /* do it ourselves */ + rl_catch_signals = 0; /* do it ourselves */ line = readline((char *)prompt); /* cast needed for old readlines */ if (!line) { @@ -528,8 +529,8 @@ get_cmd(FILE *input, const char *prompt, BSOCK *sock, int sec) /* * Returns: 1 if data available - * 0 if timeout - * -1 if error + * 0 if timeout + * -1 if error */ static int wait_for_data(int fd, int sec) @@ -546,15 +547,15 @@ wait_for_data(int fd, int sec) FD_ZERO(&fdset); FD_SET((unsigned)fd, &fdset); switch(select(fd + 1, &fdset, NULL, NULL, &tv)) { - case 0: /* timeout */ - return 0; + case 0: /* timeout */ + return 0; case -1: - if (errno == EINTR || errno == EAGAIN) { - continue; - } - return -1; /* error return */ + if (errno == EINTR || errno == EAGAIN) { + continue; + } + return -1; /* error return */ default: - return 1; + return 1; } } } @@ -563,8 +564,8 @@ wait_for_data(int fd, int sec) * Get next input command from terminal. * * Returns: 1 if got input - * 0 if timeout - * -1 if EOF or error + * 0 if timeout + * -1 if EOF or error */ int get_cmd(FILE *input, const char *prompt, BSOCK *sock, int sec) @@ -572,29 +573,29 @@ get_cmd(FILE *input, const char *prompt, BSOCK *sock, int sec) int len; if (!stop) { if (output == stdout || tee) { - sendit(prompt); + sendit(prompt); } } again: switch (wait_for_data(fileno(input), sec)) { case 0: - return 0; /* timeout */ + return 0; /* timeout */ case -1: - return -1; /* error */ + return -1; /* error */ default: len = sizeof_pool_memory(sock->msg) - 1; if (stop) { - sleep(1); - goto again; + sleep(1); + goto again; } #ifdef HAVE_CONIO if (isatty(fileno(input))) { - input_line(sock->msg, len); - break; + input_line(sock->msg, len); + break; } #endif if (fgets(sock->msg, len, input) == NULL) { - return -1; + return -1; } break; } @@ -630,7 +631,7 @@ static int inputcmd(FILE *input, BSOCK *UA_sock) fd = fopen(argk[1], "r"); if (!fd) { senditf(_("Cannot open file %s for input. ERR=%s\n"), - argk[1], strerror(errno)); + argk[1], strerror(errno)); return 1; } read_and_process_input(fd, UA_sock); @@ -664,9 +665,9 @@ static int do_outputcmd(FILE *input, BSOCK *UA_sock) } if (argc == 1) { if (output != stdout) { - fclose(output); - output = stdout; - tee = false; + fclose(output); + output = stdout; + tee = false; } return 1; } @@ -676,7 +677,7 @@ static int do_outputcmd(FILE *input, BSOCK *UA_sock) fd = fopen(argk[1], mode); if (!fd) { senditf(_("Cannot open file %s for output. ERR=%s\n"), - argk[1], strerror(errno)); + argk[1], strerror(errno)); return 1; } output = fd; @@ -729,18 +730,18 @@ void sendit(const char *buf) char *p, *q; /* * Here, we convert every \n into \r\n because the - * terminal is in raw mode when we are using - * conio. - */ + * terminal is in raw mode when we are using + * conio. + */ for (p=q=buf; (p=strchr(q, '\n')); ) { - if (p-q > 0) { - t_sendl(q, p-q); - } + if (p-q > 0) { + t_sendl(q, p-q); + } t_sendl("\r\n", 2); q = ++p; /* point after \n */ } if (*q) { - t_send(q); + t_send(q); } } if (output != stdout) { diff --git a/bacula/src/dird/newvol.c b/bacula/src/dird/newvol.c index 1d8d04b979..e82d2ebdf2 100644 --- a/bacula/src/dird/newvol.c +++ b/bacula/src/dird/newvol.c @@ -84,6 +84,8 @@ bool newVolume(JCR *jcr, MEDIA_DBR *mr) goto bail_out; } } + } else { + goto bail_out; } pr.NumVols++; if (db_create_media_record(jcr, jcr->db, mr) && diff --git a/bacula/src/dird/python.c b/bacula/src/dird/python.c index 926c877e42..e717b1271e 100644 --- a/bacula/src/dird/python.c +++ b/bacula/src/dird/python.c @@ -9,7 +9,7 @@ */ /* - Copyright (C) 2000-2005 Kern Sibbald + Copyright (C) 2004-2005 Kern Sibbald This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as @@ -42,8 +42,7 @@ static PyObject *jcr_get(PyObject *self, PyObject *args); static PyObject *jcr_write(PyObject *self, PyObject *args); static PyObject *jcr_set(PyObject *self, PyObject *args, PyObject *keyw); static PyObject *set_jcr_events(PyObject *self, PyObject *args); - -PyObject *bacula_run(PyObject *self, PyObject *args); +static PyObject *jcr_run(PyObject *self, PyObject *args); /* Define Job entry points */ PyMethodDef JobMethods[] = { @@ -52,7 +51,7 @@ PyMethodDef JobMethods[] = { "Set Job variables."}, {"set_events", set_jcr_events, METH_VARARGS, "Define Job events."}, {"write", jcr_write, METH_VARARGS, "Write output."}, -// {"run", (PyCFunction)bacula_run, METH_VARARGS, "Run a Bacula command."}, + {"run", (PyCFunction)jcr_run, METH_VARARGS, "Run a Bacula command."}, {NULL, NULL, 0, NULL} /* last item */ }; @@ -60,7 +59,6 @@ PyMethodDef JobMethods[] = { static PyObject *open_method = NULL; static PyObject *read_method = NULL; static PyObject *close_method = NULL; -static PyObject *volname_method = NULL; struct s_vars { const char *name; @@ -178,7 +176,6 @@ static PyObject *set_jcr_events(PyObject *self, PyObject *args) open_method = find_method(eObject, open_method, "open"); read_method = find_method(eObject, read_method, "read"); close_method = find_method(eObject, close_method, "close"); - volname_method = find_method(eObject, volname_method, "VolumeName"); Py_INCREF(Py_None); return Py_None; } @@ -199,11 +196,36 @@ static PyObject *jcr_write(PyObject *self, PyObject *args) return Py_None; } +/* Run a Bacula command */ +static PyObject *jcr_run(PyObject *self, PyObject *args) +{ + JCR *jcr; + char *item; + int stat; + + if (!PyArg_ParseTuple(args, "s:get", &item)) { + return NULL; + } + jcr = get_jcr_from_PyObject(self); + UAContext *ua = new_ua_context(jcr); + ua->batch = true; + pm_strcpy(ua->cmd, item); /* copy command */ + parse_ua_args(ua); /* parse command */ + stat = run_cmd(ua, ua->cmd); + free_ua_context(ua); + return Py_BuildValue("i", stat); +} + + int generate_job_event(JCR *jcr, const char *event) { +#ifdef xxx + PyObject *eObject, *method; PyEval_AcquireLock(); - PyObject *result = PyObject_CallFunction(open_method, "s", "m.py"); + method = find_method(eObject, method, event); + + PyObject *result = PyObject_CallFunction(method, "s", "m.py"); if (result == NULL) { PyErr_Print(); PyErr_Clear(); @@ -211,36 +233,14 @@ int generate_job_event(JCR *jcr, const char *event) Py_XDECREF(result); PyEval_ReleaseLock(); +#endif return 1; } #else /* Dummy if Python not configured */ -int generate_job_event(JCR *jcr, const char *event) -{ return 1; } +int generate_job_event(JCR *jcr, const char *event) { return 1; } #endif /* HAVE_PYTHON */ - -#ifdef xxx -/* Run a Bacula command */ -PyObject *bacula_run(PyObject *self, PyObject *args) -{ - JCR *jcr; - char *item; - int stat; - - if (!PyArg_ParseTuple(args, "s:get", &item)) { - return NULL; - } - jcr = get_jcr_from_PyObject(self); - UAContext *ua = new_ua_context(jcr); - ua->batch = true; - pm_strcpy(ua->cmd, item); /* copy command */ - parse_ua_args(ua); /* parse command */ - stat = run_cmd(ua, ua->cmd); - free_ua_context(ua); - return Py_BuildValue("i", stat); -} -#endif diff --git a/bacula/src/gnome2-console/console.c b/bacula/src/gnome2-console/console.c index d3feea0ecf..df4f4dfb65 100644 --- a/bacula/src/gnome2-console/console.c +++ b/bacula/src/gnome2-console/console.c @@ -35,24 +35,27 @@ int authenticate_director(JCR *jcr, DIRRES *director, CONRES *cons); void select_restore_setup(); +/* Dummy functions */ +int generate_daemon_event(JCR *jcr, const char *event) { return 1; } + /* Exported variables */ GtkWidget *console; /* application window */ -GtkWidget *text1; /* text window */ -GtkWidget *entry1; /* entry box */ -GtkWidget *status1; /* status bar */ -GtkWidget *combo1; /* director combo */ -GtkWidget *scroll1; /* main scroll bar */ -GtkWidget *run_dialog; /* run dialog */ -GtkWidget *dir_dialog; /* director selection dialog */ +GtkWidget *text1; /* text window */ +GtkWidget *entry1; /* entry box */ +GtkWidget *status1; /* status bar */ +GtkWidget *combo1; /* director combo */ +GtkWidget *scroll1; /* main scroll bar */ +GtkWidget *run_dialog; /* run dialog */ +GtkWidget *dir_dialog; /* director selection dialog */ GtkWidget *restore_dialog; /* restore dialog */ GtkWidget *restore_file_selection; GtkWidget *dir_select; -GtkWidget *about1; /* about box */ +GtkWidget *about1; /* about box */ GtkWidget *label_dialog; GdkFont *text_font = NULL; PangoFontDescription *font_desc; pthread_mutex_t cmd_mutex = PTHREAD_MUTEX_INITIALIZER; -pthread_cond_t cmd_wait; +pthread_cond_t cmd_wait; char cmd[1000]; int reply; BSOCK *UA_sock = NULL; @@ -101,7 +104,7 @@ static void usage() /********************************************************************* * - * Main Bacula GNOME Console -- User Interface Program + * Main Bacula GNOME Console -- User Interface Program * */ int main(int argc, char *argv[]) @@ -126,7 +129,7 @@ int main(int argc, char *argv[]) if ((stat=pthread_cond_init(&cmd_wait, NULL)) != 0) { Emsg1(M_ABORT, 0, _("Pthread cond init error = %s\n"), - strerror(stat)); + strerror(stat)); } gnome_init("bacula", VERSION, gargc, (char **)&gargv); @@ -134,28 +137,28 @@ int main(int argc, char *argv[]) while ((ch = getopt(argc, argv, "bc:d:r:st?")) != -1) { switch (ch) { case 'c': /* configuration file */ - if (configfile != NULL) - free(configfile); - configfile = bstrdup(optarg); - break; + if (configfile != NULL) + free(configfile); + configfile = bstrdup(optarg); + break; case 'd': - debug_level = atoi(optarg); - if (debug_level <= 0) - debug_level = 1; - break; + debug_level = atoi(optarg); + if (debug_level <= 0) + debug_level = 1; + break; case 's': /* turn off signals */ - no_signals = TRUE; - break; + no_signals = TRUE; + break; case 't': - test_config = TRUE; - break; + test_config = TRUE; + break; case '?': default: - usage(); + usage(); } } argc -= optind; @@ -217,24 +220,24 @@ int main(int argc, char *argv[]) LockRes(); foreach_res(con_font, R_CONSOLE_FONT) { if (!con_font->fontface) { - Dmsg1(400, "No fontface for %s\n", con_font->hdr.name); - continue; + Dmsg1(400, "No fontface for %s\n", con_font->hdr.name); + continue; } text_font = gdk_font_load(con_font->fontface); if (text_font == NULL) { - Dmsg2(400, "Load of requested ConsoleFont \"%s\" (%s) failed!\n", - con_font->hdr.name, con_font->fontface); + Dmsg2(400, "Load of requested ConsoleFont \"%s\" (%s) failed!\n", + con_font->hdr.name, con_font->fontface); } else { - Dmsg2(400, "ConsoleFont \"%s\" (%s) loaded.\n", - con_font->hdr.name, con_font->fontface); - break; + Dmsg2(400, "ConsoleFont \"%s\" (%s) loaded.\n", + con_font->hdr.name, con_font->fontface); + break; } } UnlockRes(); if (text_font == NULL) { Dmsg1(400, "Attempting to load fallback font %s\n", - "-misc-fixed-medium-r-normal-*-*-130-*-*-c-*-iso8859-1"); + "-misc-fixed-medium-r-normal-*-*-130-*-*-c-*-iso8859-1"); text_font = gdk_font_load("-misc-fixed-medium-r-normal-*-*-130-*-*-c-*-iso8859-1"); } font_desc = pango_font_description_from_string("LucidaTypewriter 9"); @@ -356,27 +359,27 @@ int connect_to_director(gpointer data) if (ndir > 1) { LockRes(); foreach_res(dir, R_DIRECTOR) { - dirs = g_list_append(dirs, dir->hdr.name); + dirs = g_list_append(dirs, dir->hdr.name); } UnlockRes(); dir_dialog = create_SelectDirectorDialog(); combo = lookup_widget(dir_dialog, "combo1"); dir_select = lookup_widget(dir_dialog, "dirselect"); if (dirs) { - gtk_combo_set_popdown_strings(GTK_COMBO(combo), dirs); + gtk_combo_set_popdown_strings(GTK_COMBO(combo), dirs); } gtk_widget_show(dir_dialog); gtk_main(); if (reply == OK) { - gchar *ecmd = gtk_editable_get_chars((GtkEditable *)dir_select, 0, -1); - dir = (DIRRES *)GetResWithName(R_DIRECTOR, ecmd); - if (ecmd) { - g_free(ecmd); /* release director name string */ - } + gchar *ecmd = gtk_editable_get_chars((GtkEditable *)dir_select, 0, -1); + dir = (DIRRES *)GetResWithName(R_DIRECTOR, ecmd); + if (ecmd) { + g_free(ecmd); /* release director name string */ + } } if (dirs) { - g_free(dirs); + g_free(dirs); } gtk_widget_destroy(dir_dialog); dir_dialog = NULL; @@ -400,7 +403,7 @@ int connect_to_director(gpointer data) gtk_main_iteration(); } UA_sock = bnet_connect(NULL, 5, 15, "Director daemon", dir->address, - NULL, dir->DIRport, 0); + NULL, dir->DIRport, 0); if (UA_sock == NULL) { return 0; } @@ -481,13 +484,13 @@ void read_director(gpointer data, gint fd, GdkInputCondition condition) stat = bnet_recv(UA_sock); if (stat >= 0) { if (at_prompt) { - set_text("\n", 1); - at_prompt = false; + set_text("\n", 1); + at_prompt = false; } set_text(UA_sock->msg, UA_sock->msglen); return; } - if (is_bnet_stop(UA_sock)) { /* error or term request */ + if (is_bnet_stop(UA_sock)) { /* error or term request */ gtk_main_quit(); return; } @@ -540,7 +543,7 @@ void terminate_console(int sig) { static int already_here = FALSE; - if (already_here) /* avoid recursive temination problems */ + if (already_here) /* avoid recursive temination problems */ exit(1); already_here = TRUE; disconnect_from_director((gpointer)NULL); @@ -550,7 +553,7 @@ void terminate_console(int sig) /* Buffer approx 2000 lines -- assume 60 chars/line */ -#define MAX_TEXT_CHARS (2000 * 60) +#define MAX_TEXT_CHARS (2000 * 60) static int text_chars = 0; static void truncate_text_chars() @@ -637,6 +640,6 @@ static void set_scroll_bar_to_end(void) gtk_text_iter_set_offset(&iter, buf_len); gtk_text_buffer_place_cursor(textbuf, &iter); gtk_text_view_scroll_to_mark(GTK_TEXT_VIEW(text1), - gtk_text_buffer_get_mark(textbuf, "insert"), - 0, TRUE, 0.0, 1.0); + gtk_text_buffer_get_mark(textbuf, "insert"), + 0, TRUE, 0.0, 1.0); } diff --git a/bacula/src/lib/protos.h b/bacula/src/lib/protos.h index 81a9a3e26d..36c7f53c09 100644 --- a/bacula/src/lib/protos.h +++ b/bacula/src/lib/protos.h @@ -179,7 +179,8 @@ typedef int (EVENT_HANDLER)(JCR *jcr, const char *event); void init_python_interpreter(const char *progname, const char *scripts, const char *module); void term_python_interpreter(); -extern EVENT_HANDLER *generate_daemon_event; +//extern EVENT_HANDLER *generate_daemon_event; +int generate_daemon_event(JCR *jcr, const char *event); /* signal.c */ void init_signals (void terminate(int sig)); diff --git a/bacula/src/lib/python.c b/bacula/src/lib/python.c index fd7f23725f..cfc3ebde90 100644 --- a/bacula/src/lib/python.c +++ b/bacula/src/lib/python.c @@ -31,8 +31,6 @@ #include "bacula.h" #include "jcr.h" -EVENT_HANDLER *generate_daemon_event; - #ifdef HAVE_PYTHON #undef _POSIX_C_SOURCE @@ -49,7 +47,6 @@ static PyObject *Exit_method = NULL; static PyObject *set_bacula_events(PyObject *self, PyObject *args); static PyObject *bacula_write(PyObject *self, PyObject *args); -int _generate_daemon_event(JCR *jcr, const char *event); PyObject *find_method(PyObject *eventsObject, PyObject *method, char *name); @@ -61,10 +58,6 @@ static PyMethodDef BaculaMethods[] = { }; -/* Pull in Bacula entry points */ -extern PyMethodDef JobMethods[]; - - /* * This is a Bacula Job type as defined in Python. We store a pointer * to the jcr. That is all we need, but the user's script may keep @@ -153,11 +146,9 @@ void init_python_interpreter(const char *progname, const char *scripts, PyErr_Clear(); } PyEval_ReleaseLock(); - generate_daemon_event = _generate_daemon_event; } - void term_python_interpreter() { Py_XDECREF(StartUp_module); @@ -222,7 +213,7 @@ PyObject *find_method(PyObject *eventsObject, PyObject *method, char *name) * -1 on Python error * 1 OK */ -int _generate_daemon_event(JCR *jcr, const char *event) +int generate_daemon_event(JCR *jcr, const char *event) { PyObject *pJCR; int stat = -1; @@ -357,16 +348,10 @@ bail_out: * No Python configured -- create external entry points and * dummy routines so that library code can call this without * problems even if it is not configured. - */ - -int _generate_daemon_event(JCR *jcr, const char *event) { return 0; } +int generate_daemon_event(JCR *jcr, const char *event) { return 0; } void init_python_interpreter(const char *progname, const char *scripts, - const char *module) -{ - generate_daemon_event = _generate_daemon_event; -} + const char *module) { } void term_python_interpreter() { } - #endif /* HAVE_PYTHON */ diff --git a/bacula/src/stored/Makefile.in b/bacula/src/stored/Makefile.in index b3bb074517..6b87fe59c1 100644 --- a/bacula/src/stored/Makefile.in +++ b/bacula/src/stored/Makefile.in @@ -108,7 +108,7 @@ btape.o: btape.c btape: $(TAPEOBJS) ../lib/libbac.a ../cats/libsql.a $(CXX) $(TTOOL_LDFLAGS) $(LDFLAGS) -L../lib -L../cats -o $@ $(TAPEOBJS) \ - -lsql $(DLIB) -lbac -lm $(PYTHON_LIBS) $(LIBS) + -lsql $(DLIB) -lbac -lm $(LIBS) bls.o: bls.c $(CXX) $(DEFS) $(DEBUG) -c $(CPPFLAGS) $(PYTHON_INC) -I$(srcdir) \ @@ -116,7 +116,7 @@ bls.o: bls.c bls: ../findlib/libfind.a $(BLSOBJS) ../lib/libbac.a $(CXX) $(TTOOL_LDFLAGS) $(LDFLAGS) -L../lib -L../findlib -o $@ $(BLSOBJS) $(DLIB) -lfind \ - -lbac -lm $(PYTHON_LIBS) $(LIBS) + -lbac -lm $(LIBS) bextract.o: bextract.c $(CXX) $(DEFS) $(DEBUG) -c $(CPPFLAGS) $(PYTHON_INC) -I$(srcdir) \ @@ -132,15 +132,15 @@ bscan.o: bscan.c bscan: ../findlib/libfind.a $(SCNOBJS) ../cats/libsql.a $(CXX) $(TTOOL_LDFLAGS) $(LDFLAGS) -L../lib -L../cats -L../findlib -o $@ $(SCNOBJS) \ - -lsql $(DB_LIBS) $(FDLIBS) -lfind -lbac -lm $(PYTHON_LIBS) $(LIBS) + -lsql $(DB_LIBS) $(FDLIBS) -lfind -lbac -lm $(LIBS) bcopy.o: bcopy.c - $(CXX) $(DEFS) $(DEBUG) -c $(CPPFLAGS) $(PYTHON_INC) -I$(srcdir) \ + $(CXX) $(DEFS) $(DEBUG) -c $(CPPFLAGS) -I$(srcdir) \ -I$(basedir) $(DINCLUDE) $(CFLAGS) $< bcopy: $(COPYOBJS) ../findlib/libfind.a ../lib/libbac.a $(CXX) $(TTOOL_LDFLAGS) $(LDFLAGS) -L../lib -L../findlib -o $@ $(COPYOBJS) \ - $(DB_LIBS) $(FDLIBS) -lfind -lbac -lm $(PYTHON_LIBS) $(LIBS) + $(DB_LIBS) $(FDLIBS) -lfind -lbac -lm $(LIBS) Makefile: $(srcdir)/Makefile.in $(topdir)/config.status diff --git a/bacula/src/stored/bcopy.c b/bacula/src/stored/bcopy.c index 74ef4b640c..3ceafca90b 100644 --- a/bacula/src/stored/bcopy.c +++ b/bacula/src/stored/bcopy.c @@ -30,6 +30,9 @@ #include "bacula.h" #include "stored.h" +/* Dummy functions */ +int generate_daemon_event(JCR *jcr, const char *event) { return 1; } + /* Forward referenced functions */ static bool record_cb(DCR *dcr, DEV_RECORD *rec); @@ -37,8 +40,8 @@ static bool record_cb(DCR *dcr, DEV_RECORD *rec); /* Global variables */ static DEVICE *in_dev = NULL; static DEVICE *out_dev = NULL; -static JCR *in_jcr; /* input jcr */ -static JCR *out_jcr; /* output jcr */ +static JCR *in_jcr; /* input jcr */ +static JCR *out_jcr; /* output jcr */ static BSR *bsr = NULL; static const char *wd = "/tmp"; static int list_records = 0; @@ -48,8 +51,8 @@ static DEV_BLOCK *out_block; #define CONFIG_FILE "bacula-sd.conf" char *configfile; -STORES *me = NULL; /* our Global resource */ -bool forge_on = false; /* proceed inspite of I/O errors */ +STORES *me = NULL; /* our Global resource */ +bool forge_on = false; /* proceed inspite of I/O errors */ pthread_mutex_t device_release_mutex = PTHREAD_MUTEX_INITIALIZER; pthread_cond_t wait_device_release = PTHREAD_COND_INITIALIZER; @@ -85,46 +88,46 @@ int main (int argc, char *argv[]) while ((ch = getopt(argc, argv, "b:c:d:i:o:pvw:?")) != -1) { switch (ch) { case 'b': - bsr = parse_bsr(NULL, optarg); - break; + bsr = parse_bsr(NULL, optarg); + break; case 'c': /* specify config file */ - if (configfile != NULL) { - free(configfile); - } - configfile = bstrdup(optarg); - break; + if (configfile != NULL) { + free(configfile); + } + configfile = bstrdup(optarg); + break; case 'd': /* debug level */ - debug_level = atoi(optarg); - if (debug_level <= 0) - debug_level = 1; - break; + debug_level = atoi(optarg); + if (debug_level <= 0) + debug_level = 1; + break; case 'i': /* input Volume name */ - iVolumeName = optarg; - break; + iVolumeName = optarg; + break; case 'o': /* output Volume name */ - oVolumeName = optarg; - break; + oVolumeName = optarg; + break; case 'p': - ignore_label_errors = true; - forge_on = true; - break; + ignore_label_errors = true; + forge_on = true; + break; case 'v': - verbose++; - break; + verbose++; + break; case 'w': - wd = optarg; - break; + wd = optarg; + break; case '?': default: - usage(); + usage(); } } @@ -201,8 +204,8 @@ static bool record_cb(DCR *in_dcr, DEV_RECORD *rec) { if (list_records) { Pmsg5(000, _("Record: SessId=%u SessTim=%u FileIndex=%d Stream=%d len=%u\n"), - rec->VolSessionId, rec->VolSessionTime, rec->FileIndex, - rec->Stream, rec->data_len); + rec->VolSessionId, rec->VolSessionTime, rec->FileIndex, + rec->Stream, rec->data_len); } /* * Check for Start or End of Session Record @@ -211,44 +214,44 @@ static bool record_cb(DCR *in_dcr, DEV_RECORD *rec) if (rec->FileIndex < 0) { if (verbose > 1) { - dump_label_record(in_dcr->dev, rec, 1); + dump_label_record(in_dcr->dev, rec, 1); } switch (rec->FileIndex) { case PRE_LABEL: Pmsg0(000, "Volume is prelabeled. This volume cannot be copied.\n"); - return false; + return false; case VOL_LABEL: Pmsg0(000, "Volume label not copied.\n"); - return true; + return true; case SOS_LABEL: - jobs++; - break; + jobs++; + break; case EOS_LABEL: - while (!write_record_to_block(out_block, rec)) { + while (!write_record_to_block(out_block, rec)) { Dmsg2(150, "!write_record_to_block data_len=%d rem=%d\n", rec->data_len, - rec->remainder); - if (!write_block_to_device(out_jcr->dcr)) { + rec->remainder); + if (!write_block_to_device(out_jcr->dcr)) { Dmsg2(90, "Got write_block_to_dev error on device %s: ERR=%s\n", - out_dev->print_name(), strerror_dev(out_dev)); + out_dev->print_name(), strerror_dev(out_dev)); Jmsg(out_jcr, M_FATAL, 0, _("Cannot fixup device error. %s\n"), - strerror_dev(out_dev)); - } - } - if (!write_block_to_device(out_jcr->dcr)) { + strerror_dev(out_dev)); + } + } + if (!write_block_to_device(out_jcr->dcr)) { Dmsg2(90, "Got write_block_to_dev error on device %s: ERR=%s\n", - out_dev->print_name(), strerror_dev(out_dev)); + out_dev->print_name(), strerror_dev(out_dev)); Jmsg(out_jcr, M_FATAL, 0, _("Cannot fixup device error. %s\n"), - strerror_dev(out_dev)); - } - break; + strerror_dev(out_dev)); + } + break; case EOM_LABEL: Pmsg0(000, "EOM label not copied.\n"); - return true; - case EOT_LABEL: /* end of all tapes */ + return true; + case EOT_LABEL: /* end of all tapes */ Pmsg0(000, "EOT label not copied.\n"); - return true; + return true; default: - break; + break; } } @@ -256,13 +259,13 @@ static bool record_cb(DCR *in_dcr, DEV_RECORD *rec) records++; while (!write_record_to_block(out_block, rec)) { Dmsg2(150, "!write_record_to_block data_len=%d rem=%d\n", rec->data_len, - rec->remainder); + rec->remainder); if (!write_block_to_device(out_jcr->dcr)) { Dmsg2(90, "Got write_block_to_dev error on device %s: ERR=%s\n", - out_dev->print_name(), strerror_dev(out_dev)); + out_dev->print_name(), strerror_dev(out_dev)); Jmsg(out_jcr, M_FATAL, 0, _("Cannot fixup device error. %s\n"), - strerror_dev(out_dev)); - break; + strerror_dev(out_dev)); + break; } } return true; @@ -270,13 +273,13 @@ static bool record_cb(DCR *in_dcr, DEV_RECORD *rec) /* Dummies to replace askdir.c */ -bool dir_get_volume_info(DCR *dcr, enum get_vol_info_rw writing) { return 1;} -bool dir_find_next_appendable_volume(DCR *dcr) { return 1;} -bool dir_update_volume_info(DCR *dcr, bool relabel) { return 1; } -bool dir_create_jobmedia_record(DCR *dcr) { return 1; } -bool dir_ask_sysop_to_create_appendable_volume(DCR *dcr) { return 1; } -bool dir_update_file_attributes(DCR *dcr, DEV_RECORD *rec) { return 1;} -bool dir_send_job_status(JCR *jcr) {return 1;} +bool dir_get_volume_info(DCR *dcr, enum get_vol_info_rw writing) { return 1;} +bool dir_find_next_appendable_volume(DCR *dcr) { return 1;} +bool dir_update_volume_info(DCR *dcr, bool relabel) { return 1; } +bool dir_create_jobmedia_record(DCR *dcr) { return 1; } +bool dir_ask_sysop_to_create_appendable_volume(DCR *dcr) { return 1; } +bool dir_update_file_attributes(DCR *dcr, DEV_RECORD *rec) { return 1;} +bool dir_send_job_status(JCR *jcr) {return 1;} bool dir_ask_sysop_to_mount_volume(DCR *dcr) diff --git a/bacula/src/stored/bls.c b/bacula/src/stored/bls.c index 70b2e5701b..85c6e780a8 100644 --- a/bacula/src/stored/bls.c +++ b/bacula/src/stored/bls.c @@ -34,6 +34,9 @@ int win32_client = 1; int win32_client = 0; #endif +/* Dummy functions */ +int generate_daemon_event(JCR *jcr, const char *event) { return 1; } + static void do_blocks(char *infname); static void do_jobs(char *infname); static void do_ls(char *fname); diff --git a/bacula/src/stored/bscan.c b/bacula/src/stored/bscan.c index 8abda6a5e2..c8d442b13b 100644 --- a/bacula/src/stored/bscan.c +++ b/bacula/src/stored/bscan.c @@ -33,6 +33,9 @@ #include "stored.h" #include "findlib/find.h" #include "cats/cats.h" + +/* Dummy functions */ +int generate_daemon_event(JCR *jcr, const char *event) { return 1; } /* Forward referenced functions */ static void do_scan(void); diff --git a/bacula/src/stored/btape.c b/bacula/src/stored/btape.c index ee09cb4929..60ea8d3c5e 100644 --- a/bacula/src/stored/btape.c +++ b/bacula/src/stored/btape.c @@ -36,6 +36,8 @@ #include "bacula.h" #include "stored.h" +/* Dummy functions */ +int generate_daemon_event(JCR *jcr, const char *event) { return 1; } /* External subroutines */ extern void free_config_resources(); diff --git a/bacula/src/tools/bsmtp.c b/bacula/src/tools/bsmtp.c index 929bed2968..f9135266a7 100644 --- a/bacula/src/tools/bsmtp.c +++ b/bacula/src/tools/bsmtp.c @@ -51,6 +51,9 @@ UPSINFO *core_ups = &myUPS; #endif +/* Dummy functions */ +int generate_daemon_event(JCR *jcr, const char *event) + { return 1; } #ifndef MAXSTRING #define MAXSTRING 254 @@ -79,18 +82,18 @@ static void get_response(void) Dmsg0(50, "Calling fgets on read socket rfp.\n"); buf[3] = 0; while (fgets(buf, sizeof(buf), rfp)) { - int len = strlen(buf); - if (len > 0) { - buf[len-1] = 0; - } - Dmsg2(10, "%s --> %s\n", mailhost, buf); - if (!isdigit((int)buf[0]) || buf[0] > '3') { - Pmsg2(0, "Fatal malformed reply from %s: %s\n", mailhost, buf); - exit(1); - } - if (buf[3] != '-') { - break; - } + int len = strlen(buf); + if (len > 0) { + buf[len-1] = 0; + } + Dmsg2(10, "%s --> %s\n", mailhost, buf); + if (!isdigit((int)buf[0]) || buf[0] > '3') { + Pmsg2(0, "Fatal malformed reply from %s: %s\n", mailhost, buf); + exit(1); + } + if (buf[3] != '-') { + break; + } } return; } @@ -155,44 +158,44 @@ int main (int argc, char *argv[]) while ((ch = getopt(argc, argv, "c:d:f:h:r:s:?")) != -1) { switch (ch) { case 'c': - Dmsg1(20, "cc=%s\n", optarg); - cc_addr = optarg; - break; + Dmsg1(20, "cc=%s\n", optarg); + cc_addr = optarg; + break; case 'd': /* set debug level */ - debug_level = atoi(optarg); - if (debug_level <= 0) { - debug_level = 1; - } - Dmsg1(20, "Debug level = %d\n", debug_level); - break; + debug_level = atoi(optarg); + if (debug_level <= 0) { + debug_level = 1; + } + Dmsg1(20, "Debug level = %d\n", debug_level); + break; case 'f': /* from */ - from_addr = optarg; - break; + from_addr = optarg; + break; case 'h': /* smtp host */ - Dmsg1(20, "host=%s\n", optarg); - p = strchr(optarg, ':'); - if (p) { - *p++ = 0; - mailport = atoi(p); - } - mailhost = optarg; - break; + Dmsg1(20, "host=%s\n", optarg); + p = strchr(optarg, ':'); + if (p) { + *p++ = 0; + mailport = atoi(p); + } + mailhost = optarg; + break; case 's': /* subject */ - Dmsg1(20, "subject=%s\n", optarg); - subject = optarg; - break; + Dmsg1(20, "subject=%s\n", optarg); + subject = optarg; + break; case 'r': /* reply address */ - reply_addr = optarg; - break; + reply_addr = optarg; + break; case '?': default: - usage(); + usage(); } } @@ -210,9 +213,9 @@ int main (int argc, char *argv[]) */ if (mailhost == NULL) { if ((cp = getenv("SMTPSERVER")) != NULL) { - mailhost = cp; + mailhost = cp; } else { - mailhost = "localhost"; + mailhost = "localhost"; } } @@ -226,7 +229,7 @@ int main (int argc, char *argv[]) } if ((hp = gethostbyname(my_hostname)) == NULL) { Pmsg2(0, "Fatal gethostbyname for myself failed \"%s\": ERR=%s\n", my_hostname, - strerror(errno)); + strerror(errno)); exit(1); } strcpy(my_hostname, hp->h_name); @@ -237,9 +240,9 @@ int main (int argc, char *argv[]) */ if (from_addr == NULL) { if ((pwd = getpwuid(getuid())) == 0) { - sprintf(buf, "userid-%d@%s", (int)getuid(), my_hostname); + sprintf(buf, "userid-%d@%s", (int)getuid(), my_hostname); } else { - sprintf(buf, "%s@%s", pwd->pw_name, my_hostname); + sprintf(buf, "%s@%s", pwd->pw_name, my_hostname); } from_addr = bstrdup(buf); } @@ -251,11 +254,11 @@ int main (int argc, char *argv[]) hp: if ((hp = gethostbyname(mailhost)) == NULL) { Pmsg2(0, "Error unknown mail host \"%s\": ERR=%s\n", mailhost, - strerror(errno)); + strerror(errno)); if (strcasecmp(mailhost, "localhost") != 0) { - Pmsg0(0, "Retrying connection using \"localhost\".\n"); - mailhost = "localhost"; - goto hp; + Pmsg0(0, "Retrying connection using \"localhost\".\n"); + mailhost = "localhost"; + goto hp; } exit(1); } @@ -350,9 +353,9 @@ hp: while (fgets(buf, sizeof(buf), stdin)) { buf[strlen(buf)-1] = 0; if (strcmp(buf, ".") == 0) { /* quote lone dots */ - fprintf(sfp, "..\r\n"); - } else { /* pass body through unchanged */ - fprintf(sfp, "%s\r\n", buf); + fprintf(sfp, "..\r\n"); + } else { /* pass body through unchanged */ + fprintf(sfp, "%s\r\n", buf); } } diff --git a/bacula/src/tools/dbcheck.c b/bacula/src/tools/dbcheck.c index b6a74617f6..9411818f38 100644 --- a/bacula/src/tools/dbcheck.c +++ b/bacula/src/tools/dbcheck.c @@ -32,20 +32,24 @@ #include "cats/cats.h" #include "dird/dird_conf.h" +/* Dummy functions */ +int generate_daemon_event(JCR *jcr, const char *event) + { return 1; } + typedef struct s_id_ctx { - uint32_t *Id; /* ids to be modified */ - int num_ids; /* ids stored */ - int max_ids; /* size of array */ - int num_del; /* number deleted */ - int tot_ids; /* total to process */ + uint32_t *Id; /* ids to be modified */ + int num_ids; /* ids stored */ + int max_ids; /* size of array */ + int num_del; /* number deleted */ + int tot_ids; /* total to process */ } ID_LIST; typedef struct s_name_ctx { - char **name; /* list of names */ - int num_ids; /* ids stored */ - int max_ids; /* size of array */ - int num_del; /* number deleted */ - int tot_ids; /* total to process */ + char **name; /* list of names */ + int num_ids; /* ids stored */ + int max_ids; /* size of array */ + int num_del; /* number deleted */ + int tot_ids; /* total to process */ } NAME_LIST; @@ -106,7 +110,7 @@ int main (int argc, char *argv[]) char *catalogname = NULL; my_name_is(argc, argv, "dbcheck"); - init_msg(NULL, NULL); /* setup message handler */ + init_msg(NULL, NULL); /* setup message handler */ memset(&id_list, 0, sizeof(id_list)); memset(&name_list, 0, sizeof(name_list)); @@ -115,34 +119,34 @@ int main (int argc, char *argv[]) while ((ch = getopt(argc, argv, "bc:C:d:fv?")) != -1) { switch (ch) { case 'b': /* batch */ - batch = true; - break; + batch = true; + break; case 'C': /* CatalogName */ - catalogname = optarg; - break; + catalogname = optarg; + break; case 'c': /* configfile */ - configfile = optarg; - break; + configfile = optarg; + break; case 'd': /* debug level */ - debug_level = atoi(optarg); - if (debug_level <= 0) - debug_level = 1; - break; + debug_level = atoi(optarg); + if (debug_level <= 0) + debug_level = 1; + break; case 'f': /* fix inconsistencies */ - fix = true; - break; + fix = true; + break; case 'v': - verbose++; - break; + verbose++; + break; case '?': default: - usage(); + usage(); } } argc -= optind; @@ -152,54 +156,54 @@ int main (int argc, char *argv[]) CAT *catalog = NULL; int found = 0; if (argc > 0) { - Pmsg0(0, _("Warning skipping the additional parameters for working directory/dbname/user/password/host.\n")); + 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; - } + 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); - } - exit(1); + 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); + } + exit(1); } else { - DIRRES *director; - LockRes(); - director = (DIRRES *)GetNextRes(R_DIRECTOR, NULL); - UnlockRes(); - if (!director) { - Pmsg0(0, "Error no Director resource defined.\n"); - exit(1); - } - set_working_directory(director->working_directory); - db_name = catalog->db_name; - user = catalog->db_user; - password = catalog->db_password; - dbhost = catalog->db_address; - if (dbhost && dbhost[0] == 0) { - dbhost = NULL; - } + DIRRES *director; + LockRes(); + director = (DIRRES *)GetNextRes(R_DIRECTOR, NULL); + UnlockRes(); + if (!director) { + Pmsg0(0, "Error no Director resource defined.\n"); + exit(1); + } + set_working_directory(director->working_directory); + db_name = catalog->db_name; + user = catalog->db_user; + password = catalog->db_password; + dbhost = catalog->db_address; + if (dbhost && dbhost[0] == 0) { + dbhost = NULL; + } } } else { if (argc > 5) { - Pmsg0(0, _("Wrong number of arguments.\n")); - usage(); + Pmsg0(0, _("Wrong number of arguments.\n")); + usage(); } if (argc < 1) { - Pmsg0(0, _("Working directory not supplied.\n")); - usage(); + Pmsg0(0, _("Working directory not supplied.\n")); + usage(); } /* This is needed by SQLite to find the db */ @@ -210,20 +214,20 @@ int main (int argc, char *argv[]) dbhost = NULL; if (argc == 2) { - db_name = argv[1]; - user = db_name; + db_name = argv[1]; + user = db_name; } else if (argc == 3) { - db_name = argv[1]; - user = argv[2]; + db_name = argv[1]; + user = argv[2]; } else if (argc == 4) { - db_name = argv[1]; - user = argv[2]; - password = argv[3]; + 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]; + db_name = argv[1]; + user = argv[2]; + password = argv[3]; + dbhost = argv[4]; } } @@ -231,7 +235,7 @@ int main (int argc, char *argv[]) db = db_init_database(NULL, db_name, user, password, dbhost, 0, NULL, 0); if (!db_open_database(NULL, db)) { Emsg1(M_FATAL, 0, "%s", db_strerror(db)); - return 1; + return 1; } if (batch) { @@ -266,11 +270,11 @@ static void do_interactive_mode() printf("Hello, this is the database check/correct program.\n" "Modify database is %s. Verbose is %s.\n" "Please select the fuction you want to perform.\n", - fix?"On":"Off", verbose?"On":"Off"); + fix?"On":"Off", verbose?"On":"Off"); while (!quit) { if (fix) { - printf(_("\n" + printf(_("\n" " 1) Toggle modify database flag\n" " 2) Toggle verbose flag\n" " 3) Repair bad Filename records\n" @@ -289,7 +293,7 @@ static void do_interactive_mode() " 16) All (3-15)\n" " 17) Quit\n")); } else { - printf(_("\n" + printf(_("\n" " 1) Toggle modify database flag\n" " 2) Toggle verbose flag\n" " 3) Check for bad Filename records\n" @@ -311,74 +315,74 @@ static void do_interactive_mode() cmd = get_cmd(_("Select function number: ")); if (cmd) { - int item = atoi(cmd); - switch (item) { - case 1: - fix = !fix; - printf(_("Database will %sbe modified.\n"), fix?"":_("NOT ")); - break; - case 2: - verbose = verbose?0:1; - printf(_("Verbose is %s\n"), verbose?_("On"):_("Off")); - break; - case 3: - repair_bad_filenames(); - break; - case 4: - repair_bad_paths(); - break; - case 5: - eliminate_duplicate_filenames(); - break; - case 6: - eliminate_duplicate_paths(); - break; - case 7: - eliminate_orphaned_jobmedia_records(); - break; - case 8: - eliminate_orphaned_file_records(); - break; - case 9: - eliminate_orphaned_path_records(); - break; - case 10: - eliminate_orphaned_filename_records(); - break; - case 11: - eliminate_orphaned_fileset_records(); - break; - case 12: - eliminate_orphaned_client_records(); - break; - case 13: - eliminate_orphaned_job_records(); - break; - case 14: - eliminate_admin_records(); - break; - case 15: - eliminate_restore_records(); - break; - case 16: - repair_bad_filenames(); - repair_bad_paths(); - eliminate_duplicate_filenames(); - eliminate_duplicate_paths(); - eliminate_orphaned_jobmedia_records(); - eliminate_orphaned_file_records(); - eliminate_orphaned_path_records(); - eliminate_orphaned_filename_records(); - eliminate_orphaned_fileset_records(); - eliminate_orphaned_client_records(); - eliminate_orphaned_job_records(); - eliminate_admin_records(); - eliminate_restore_records(); - break; - case 17: - quit = true; - break; - } + int item = atoi(cmd); + switch (item) { + case 1: + fix = !fix; + printf(_("Database will %sbe modified.\n"), fix?"":_("NOT ")); + break; + case 2: + verbose = verbose?0:1; + printf(_("Verbose is %s\n"), verbose?_("On"):_("Off")); + break; + case 3: + repair_bad_filenames(); + break; + case 4: + repair_bad_paths(); + break; + case 5: + eliminate_duplicate_filenames(); + break; + case 6: + eliminate_duplicate_paths(); + break; + case 7: + eliminate_orphaned_jobmedia_records(); + break; + case 8: + eliminate_orphaned_file_records(); + break; + case 9: + eliminate_orphaned_path_records(); + break; + case 10: + eliminate_orphaned_filename_records(); + break; + case 11: + eliminate_orphaned_fileset_records(); + break; + case 12: + eliminate_orphaned_client_records(); + break; + case 13: + eliminate_orphaned_job_records(); + break; + case 14: + eliminate_admin_records(); + break; + case 15: + eliminate_restore_records(); + break; + case 16: + repair_bad_filenames(); + repair_bad_paths(); + eliminate_duplicate_filenames(); + eliminate_duplicate_paths(); + eliminate_orphaned_jobmedia_records(); + eliminate_orphaned_file_records(); + eliminate_orphaned_path_records(); + eliminate_orphaned_filename_records(); + eliminate_orphaned_fileset_records(); + eliminate_orphaned_client_records(); + eliminate_orphaned_job_records(); + eliminate_admin_records(); + eliminate_restore_records(); + break; + case 17: + quit = true; + break; + } } } } @@ -403,7 +407,7 @@ static int get_name_handler(void *ctx, int num_fields, char **row) static int print_job_handler(void *ctx, int num_fields, char **row) { printf(_("JobId=%s Name=\"%s\" StartTime=%s\n"), - NPRT(row[0]), NPRT(row[1]), NPRT(row[2])); + NPRT(row[0]), NPRT(row[1]), NPRT(row[2])); return 0; } @@ -411,28 +415,28 @@ static int print_job_handler(void *ctx, int num_fields, char **row) static int print_jobmedia_handler(void *ctx, int num_fields, char **row) { printf(_("Orphaned JobMediaId=%s JobId=%s Volume=\"%s\"\n"), - NPRT(row[0]), NPRT(row[1]), NPRT(row[2])); + NPRT(row[0]), NPRT(row[1]), NPRT(row[2])); return 0; } static int print_file_handler(void *ctx, int num_fields, char **row) { printf(_("Orphaned FileId=%s JobId=%s Volume=\"%s\"\n"), - NPRT(row[0]), NPRT(row[1]), NPRT(row[2])); + NPRT(row[0]), NPRT(row[1]), NPRT(row[2])); return 0; } static int print_fileset_handler(void *ctx, int num_fields, char **row) { printf(_("Orphaned FileSetId=%s FileSet=\"%s\" MD5=%s\n"), - NPRT(row[0]), NPRT(row[1]), NPRT(row[2])); + NPRT(row[0]), NPRT(row[1]), NPRT(row[2])); return 0; } static int print_client_handler(void *ctx, int num_fields, char **row) { printf(_("Orphaned ClientId=%s Name=\"%s\"\n"), - NPRT(row[0]), NPRT(row[1])); + NPRT(row[0]), NPRT(row[1])); return 0; } @@ -449,11 +453,11 @@ static int id_list_handler(void *ctx, int num_fields, char **row) } if (lst->num_ids == lst->max_ids) { if (lst->max_ids == 0) { - lst->max_ids = 1000; - lst->Id = (uint32_t *)bmalloc(sizeof(uint32_t) * lst->max_ids); + lst->max_ids = 1000; + lst->Id = (uint32_t *)bmalloc(sizeof(uint32_t) * lst->max_ids); } else { - lst->max_ids = (lst->max_ids * 3) / 2; - lst->Id = (uint32_t *)brealloc(lst->Id, sizeof(uint32_t) * lst->max_ids); + lst->max_ids = (lst->max_ids * 3) / 2; + lst->Id = (uint32_t *)brealloc(lst->Id, sizeof(uint32_t) * lst->max_ids); } } lst->Id[lst->num_ids++] = (uint32_t)strtod(row[0], NULL); @@ -484,7 +488,7 @@ static int delete_id_list(const char *query, ID_LIST *id_list) for (int i=0; i < id_list->num_ids; i++) { bsnprintf(buf, sizeof(buf), query, id_list->Id[i]); if (verbose) { - printf("Deleting: %s\n", buf); + printf("Deleting: %s\n", buf); } db_sql_query(db, buf, NULL, NULL); } @@ -503,11 +507,11 @@ static int name_list_handler(void *ctx, int num_fields, char **row) } if (name->num_ids == name->max_ids) { if (name->max_ids == 0) { - name->max_ids = 1000; - name->name = (char **)bmalloc(sizeof(char *) * name->max_ids); + name->max_ids = 1000; + name->name = (char **)bmalloc(sizeof(char *) * name->max_ids); } else { - name->max_ids = (name->max_ids * 3) / 2; - name->name = (char **)brealloc(name->name, sizeof(char *) * name->max_ids); + name->max_ids = (name->max_ids * 3) / 2; + name->name = (char **)brealloc(name->name, sizeof(char *) * name->max_ids); } } name->name[name->num_ids++] = bstrdup(row[0]); @@ -562,7 +566,7 @@ static void eliminate_duplicate_filenames() /* Make list of duplicated names */ query = "SELECT Name, count(Name) as Count FROM Filename GROUP BY Name " - "HAVING count(Name) > 1"; + "HAVING count(Name) > 1"; if (!make_name_list(query, &name_list)) { exit(1); @@ -574,33 +578,33 @@ static void eliminate_duplicate_filenames() if (fix) { /* Loop through list of duplicate names */ for (int i=0; i 1) { - printf("%s\n", buf); - } - if (!make_id_list(buf, &id_list)) { - exit(1); - } - if (verbose) { - printf("Found %d for: %s\n", id_list.num_ids, name_list.name[i]); - } - /* Force all records to use the first id then delete the other ids */ - for (int j=1; j 1) { - printf("%s\n", buf); - } - db_sql_query(db, buf, NULL, NULL); - bsnprintf(buf, sizeof(buf), "DELETE FROM Filename WHERE FilenameId=%u", - id_list.Id[j]); - if (verbose > 2) { - printf("%s\n", buf); - } - db_sql_query(db, buf, NULL, NULL); - } + /* Get all the Ids of each name */ + db_escape_string(esc_name, name_list.name[i], strlen(name_list.name[i])); + bsnprintf(buf, sizeof(buf), "SELECT FilenameId FROM Filename WHERE Name='%s'", esc_name); + if (verbose > 1) { + printf("%s\n", buf); + } + if (!make_id_list(buf, &id_list)) { + exit(1); + } + if (verbose) { + printf("Found %d for: %s\n", id_list.num_ids, name_list.name[i]); + } + /* Force all records to use the first id then delete the other ids */ + for (int j=1; j 1) { + printf("%s\n", buf); + } + db_sql_query(db, buf, NULL, NULL); + bsnprintf(buf, sizeof(buf), "DELETE FROM Filename WHERE FilenameId=%u", + id_list.Id[j]); + if (verbose > 2) { + printf("%s\n", buf); + } + db_sql_query(db, buf, NULL, NULL); + } } } free_name_list(&name_list); @@ -616,7 +620,7 @@ static void eliminate_duplicate_paths() /* Make list of duplicated names */ query = "SELECT Path, count(Path) as Count FROM Path " - "GROUP BY Path HAVING count(Path) > 1"; + "GROUP BY Path HAVING count(Path) > 1"; if (!make_name_list(query, &name_list)) { exit(1); @@ -628,33 +632,33 @@ static void eliminate_duplicate_paths() if (fix) { /* Loop through list of duplicate names */ for (int i=0; i 1) { - printf("%s\n", buf); - } - if (!make_id_list(buf, &id_list)) { - exit(1); - } - if (verbose) { - printf("Found %d for: %s\n", id_list.num_ids, name_list.name[i]); - } - /* Force all records to use the first id then delete the other ids */ - for (int j=1; j 1) { - printf("%s\n", buf); - } - db_sql_query(db, buf, NULL, NULL); - bsnprintf(buf, sizeof(buf), "DELETE FROM Path WHERE PathId=%u", - id_list.Id[j]); - if (verbose > 2) { - printf("%s\n", buf); - } - db_sql_query(db, buf, NULL, NULL); - } + /* Get all the Ids of each name */ + db_escape_string(esc_name, name_list.name[i], strlen(name_list.name[i])); + bsnprintf(buf, sizeof(buf), "SELECT PathId FROM Path WHERE Path='%s'", esc_name); + if (verbose > 1) { + printf("%s\n", buf); + } + if (!make_id_list(buf, &id_list)) { + exit(1); + } + if (verbose) { + printf("Found %d for: %s\n", id_list.num_ids, name_list.name[i]); + } + /* Force all records to use the first id then delete the other ids */ + for (int j=1; j 1) { + printf("%s\n", buf); + } + db_sql_query(db, buf, NULL, NULL); + bsnprintf(buf, sizeof(buf), "DELETE FROM Path WHERE PathId=%u", + id_list.Id[j]); + if (verbose > 2) { + printf("%s\n", buf); + } + db_sql_query(db, buf, NULL, NULL); + } } } free_name_list(&name_list); @@ -666,20 +670,20 @@ static void eliminate_orphaned_jobmedia_records() printf("Checking for orphaned JobMedia entries.\n"); query = "SELECT JobMedia.JobMediaId,Job.JobId FROM JobMedia " - "LEFT OUTER JOIN Job ON (JobMedia.JobId=Job.JobId) " - "WHERE Job.JobId IS NULL"; + "LEFT OUTER JOIN Job ON (JobMedia.JobId=Job.JobId) " + "WHERE Job.JobId IS NULL"; if (!make_id_list(query, &id_list)) { exit(1); } printf("Found %d orphaned JobMedia records.\n", id_list.num_ids); if (id_list.num_ids && verbose && yes_no("Print them? (yes/no): ")) { for (int i=0; i < id_list.num_ids; i++) { - bsnprintf(buf, sizeof(buf), + bsnprintf(buf, sizeof(buf), "SELECT JobMedia.JobMediaId,JobMedia.JobId,Media.VolumeName FROM JobMedia,Media " "WHERE JobMedia.JobMediaId=%u AND Media.MediaId=JobMedia.MediaId", id_list.Id[i]); - if (!db_sql_query(db, buf, print_jobmedia_handler, NULL)) { - printf("%s\n", db_strerror(db)); - } + if (!db_sql_query(db, buf, print_jobmedia_handler, NULL)) { + printf("%s\n", db_strerror(db)); + } } } @@ -695,8 +699,8 @@ static void eliminate_orphaned_file_records() printf("Checking for orphaned File entries. This may take some time!\n"); query = "SELECT File.FileId,Job.JobId FROM File " - "LEFT OUTER JOIN Job ON (File.JobId=Job.JobId) " - "WHERE Job.JobId IS NULL"; + "LEFT OUTER JOIN Job ON (File.JobId=Job.JobId) " + "WHERE Job.JobId IS NULL"; if (verbose > 1) { printf("%s\n", query); } @@ -706,12 +710,12 @@ static void eliminate_orphaned_file_records() printf("Found %d orphaned File records.\n", id_list.num_ids); if (name_list.num_ids && verbose && yes_no("Print them? (yes/no): ")) { for (int i=0; i < id_list.num_ids; i++) { - bsnprintf(buf, sizeof(buf), + bsnprintf(buf, sizeof(buf), "SELECT File.FileId,File.JobId,Filename.Name FROM File,Filename " "WHERE File.FileId=%u AND File.FilenameId=Filename.FilenameId", id_list.Id[i]); - if (!db_sql_query(db, buf, print_file_handler, NULL)) { - printf("%s\n", db_strerror(db)); - } + if (!db_sql_query(db, buf, print_file_handler, NULL)) { + printf("%s\n", db_strerror(db)); + } } } @@ -727,8 +731,8 @@ static void eliminate_orphaned_path_records() printf("Checking for orphaned Path entries. This may take some time!\n"); query = "SELECT DISTINCT Path.PathId,File.PathId FROM Path " - "LEFT OUTER JOIN File ON (Path.PathId=File.PathId) " - "WHERE File.PathId IS NULL"; + "LEFT OUTER JOIN File ON (Path.PathId=File.PathId) " + "WHERE File.PathId IS NULL"; if (verbose > 1) { printf("%s\n", query); } @@ -738,8 +742,8 @@ static void eliminate_orphaned_path_records() printf("Found %d orphaned Path records.\n", id_list.num_ids); if (id_list.num_ids && verbose && yes_no("Print them? (yes/no): ")) { for (int i=0; i < id_list.num_ids; i++) { - bsnprintf(buf, sizeof(buf), "SELECT Path FROM Path WHERE PathId=%u", id_list.Id[i]); - db_sql_query(db, buf, print_name_handler, NULL); + bsnprintf(buf, sizeof(buf), "SELECT Path FROM Path WHERE PathId=%u", id_list.Id[i]); + db_sql_query(db, buf, print_name_handler, NULL); } } @@ -755,8 +759,8 @@ static void eliminate_orphaned_filename_records() printf("Checking for orphaned Filename entries. This may take some time!\n"); query = "SELECT Filename.FilenameId,File.FilenameId FROM Filename " - "LEFT OUTER JOIN File ON (Filename.FilenameId=File.FilenameId) " - "WHERE File.FilenameId IS NULL"; + "LEFT OUTER JOIN File ON (Filename.FilenameId=File.FilenameId) " + "WHERE File.FilenameId IS NULL"; if (verbose > 1) { printf("%s\n", query); } @@ -766,8 +770,8 @@ static void eliminate_orphaned_filename_records() printf("Found %d orphaned Filename records.\n", id_list.num_ids); if (id_list.num_ids && verbose && yes_no("Print them? (yes/no): ")) { for (int i=0; i < id_list.num_ids; i++) { - bsnprintf(buf, sizeof(buf), "SELECT Name FROM Filename WHERE FilenameId=%u", id_list.Id[i]); - db_sql_query(db, buf, print_name_handler, NULL); + bsnprintf(buf, sizeof(buf), "SELECT Name FROM Filename WHERE FilenameId=%u", id_list.Id[i]); + db_sql_query(db, buf, print_name_handler, NULL); } } @@ -783,8 +787,8 @@ static void eliminate_orphaned_fileset_records() printf("Checking for orphaned FileSet entries. This takes some time!\n"); query = "SELECT FileSet.FileSetId,Job.FileSetId FROM FileSet " - "LEFT OUTER JOIN Job ON (FileSet.FileSetId=Job.FileSetId) " - "WHERE Job.FileSetId IS NULL"; + "LEFT OUTER JOIN Job ON (FileSet.FileSetId=Job.FileSetId) " + "WHERE Job.FileSetId IS NULL"; if (verbose > 1) { printf("%s\n", query); } @@ -794,11 +798,11 @@ static void eliminate_orphaned_fileset_records() printf("Found %d orphaned FileSet records.\n", id_list.num_ids); if (id_list.num_ids && verbose && yes_no("Print them? (yes/no): ")) { for (int i=0; i < id_list.num_ids; i++) { - bsnprintf(buf, sizeof(buf), "SELECT FileSetId,FileSet,MD5 FROM FileSet " - "WHERE FileSetId=%u", id_list.Id[i]); - if (!db_sql_query(db, buf, print_fileset_handler, NULL)) { - printf("%s\n", db_strerror(db)); - } + bsnprintf(buf, sizeof(buf), "SELECT FileSetId,FileSet,MD5 FROM FileSet " + "WHERE FileSetId=%u", id_list.Id[i]); + if (!db_sql_query(db, buf, print_fileset_handler, NULL)) { + printf("%s\n", db_strerror(db)); + } } } @@ -814,15 +818,15 @@ static void eliminate_orphaned_client_records() printf("Checking for orphaned Client entries.\n"); /* In English: - * Wiffle through Client for every Client - * joining with the Job table including every Client even if - * there is not a match in Job (left outer join), then - * filter out only those where no Job points to a Client - * i.e. Job.Client is NULL + * Wiffle through Client for every Client + * joining with the Job table including every Client even if + * there is not a match in Job (left outer join), then + * filter out only those where no Job points to a Client + * i.e. Job.Client is NULL */ query = "SELECT Client.ClientId,Client.Name FROM Client " - "LEFT OUTER JOIN Job ON (Client.ClientId=Job.ClientId) " - "WHERE Job.ClientId IS NULL"; + "LEFT OUTER JOIN Job ON (Client.ClientId=Job.ClientId) " + "WHERE Job.ClientId IS NULL"; if (verbose > 1) { printf("%s\n", query); } @@ -832,11 +836,11 @@ static void eliminate_orphaned_client_records() printf("Found %d orphaned Client records.\n", id_list.num_ids); if (id_list.num_ids && verbose && yes_no("Print them? (yes/no): ")) { for (int i=0; i < id_list.num_ids; i++) { - bsnprintf(buf, sizeof(buf), "SELECT ClientId,Name FROM Client " - "WHERE ClientId=%u", id_list.Id[i]); - if (!db_sql_query(db, buf, print_client_handler, NULL)) { - printf("%s\n", db_strerror(db)); - } + bsnprintf(buf, sizeof(buf), "SELECT ClientId,Name FROM Client " + "WHERE ClientId=%u", id_list.Id[i]); + if (!db_sql_query(db, buf, print_client_handler, NULL)) { + printf("%s\n", db_strerror(db)); + } } } @@ -852,15 +856,15 @@ static void eliminate_orphaned_job_records() printf("Checking for orphaned Job entries.\n"); /* In English: - * Wiffle through Job for every Job - * joining with the Client table including every Job even if - * there is not a match in Client (left outer join), then - * filter out only those where no Client exists - * i.e. Client.Name is NULL + * Wiffle through Job for every Job + * joining with the Client table including every Job even if + * there is not a match in Client (left outer join), then + * filter out only those where no Client exists + * i.e. Client.Name is NULL */ query = "SELECT Job.JobId,Job.Name FROM Job " - "LEFT OUTER JOIN Client ON (Job.ClientId=Client.ClientId) " - "WHERE Client.Name IS NULL"; + "LEFT OUTER JOIN Client ON (Job.ClientId=Client.ClientId) " + "WHERE Client.Name IS NULL"; if (verbose > 1) { printf("%s\n", query); } @@ -870,11 +874,11 @@ static void eliminate_orphaned_job_records() printf("Found %d orphaned Job records.\n", id_list.num_ids); if (id_list.num_ids && verbose && yes_no("Print them? (yes/no): ")) { for (int i=0; i < id_list.num_ids; i++) { - bsnprintf(buf, sizeof(buf), "SELECT JobId,Name,StartTime FROM Job " - "WHERE JobId=%u", id_list.Id[i]); - if (!db_sql_query(db, buf, print_job_handler, NULL)) { - printf("%s\n", db_strerror(db)); - } + bsnprintf(buf, sizeof(buf), "SELECT JobId,Name,StartTime FROM Job " + "WHERE JobId=%u", id_list.Id[i]); + if (!db_sql_query(db, buf, print_job_handler, NULL)) { + printf("%s\n", db_strerror(db)); + } } } @@ -891,7 +895,7 @@ static void eliminate_admin_records() printf("Checking for Admin Job entries.\n"); query = "SELECT Job.JobId FROM Job " - "WHERE Job.Type='D'"; + "WHERE Job.Type='D'"; if (verbose > 1) { printf("%s\n", query); } @@ -901,11 +905,11 @@ static void eliminate_admin_records() printf("Found %d Admin Job records.\n", id_list.num_ids); if (id_list.num_ids && verbose && yes_no("Print them? (yes/no): ")) { for (int i=0; i < id_list.num_ids; i++) { - bsnprintf(buf, sizeof(buf), "SELECT JobId,Name,StartTime FROM Job " - "WHERE JobId=%u", id_list.Id[i]); - if (!db_sql_query(db, buf, print_job_handler, NULL)) { - printf("%s\n", db_strerror(db)); - } + bsnprintf(buf, sizeof(buf), "SELECT JobId,Name,StartTime FROM Job " + "WHERE JobId=%u", id_list.Id[i]); + if (!db_sql_query(db, buf, print_job_handler, NULL)) { + printf("%s\n", db_strerror(db)); + } } } @@ -921,7 +925,7 @@ static void eliminate_restore_records() printf("Checking for Restore Job entries.\n"); query = "SELECT Job.JobId FROM Job " - "WHERE Job.Type='R'"; + "WHERE Job.Type='R'"; if (verbose > 1) { printf("%s\n", query); } @@ -931,11 +935,11 @@ static void eliminate_restore_records() printf("Found %d Restore Job records.\n", id_list.num_ids); if (id_list.num_ids && verbose && yes_no("Print them? (yes/no): ")) { for (int i=0; i < id_list.num_ids; i++) { - bsnprintf(buf, sizeof(buf), "SELECT JobId,Name,StartTime FROM Job " - "WHERE JobId=%u", id_list.Id[i]); - if (!db_sql_query(db, buf, print_job_handler, NULL)) { - printf("%s\n", db_strerror(db)); - } + bsnprintf(buf, sizeof(buf), "SELECT JobId,Name,StartTime FROM Job " + "WHERE JobId=%u", id_list.Id[i]); + if (!db_sql_query(db, buf, print_job_handler, NULL)) { + printf("%s\n", db_strerror(db)); + } } } @@ -955,7 +959,7 @@ static void repair_bad_filenames() printf("Checking for Filenames with a trailing slash\n"); query = "SELECT FilenameId,Name from Filename " - "WHERE Name LIKE '%/'"; + "WHERE Name LIKE '%/'"; if (verbose > 1) { printf("%s\n", query); } @@ -965,11 +969,11 @@ static void repair_bad_filenames() printf("Found %d bad Filename records.\n", id_list.num_ids); if (id_list.num_ids && verbose && yes_no("Print them? (yes/no): ")) { for (i=0; i < id_list.num_ids; i++) { - bsnprintf(buf, sizeof(buf), - "SELECT Name FROM Filename WHERE FilenameId=%u", id_list.Id[i]); - if (!db_sql_query(db, buf, print_name_handler, NULL)) { - printf("%s\n", db_strerror(db)); - } + bsnprintf(buf, sizeof(buf), + "SELECT Name FROM Filename WHERE FilenameId=%u", id_list.Id[i]); + if (!db_sql_query(db, buf, print_name_handler, NULL)) { + printf("%s\n", db_strerror(db)); + } } } @@ -978,30 +982,30 @@ static void repair_bad_filenames() char esc_name[5000]; printf("Reparing %d bad Filename records.\n", id_list.num_ids); for (i=0; i < id_list.num_ids; i++) { - int len; - bsnprintf(buf, sizeof(buf), - "SELECT Name FROM Filename WHERE FilenameId=%u", id_list.Id[i]); - if (!db_sql_query(db, buf, get_name_handler, name)) { - printf("%s\n", db_strerror(db)); - } - /* Strip trailing slash(es) */ - for (len=strlen(name); len > 0 && name[len-1]=='/'; len--) - { } - if (len == 0) { - len = 1; - esc_name[0] = ' '; - esc_name[1] = 0; - } else { - name[len-1] = 0; - db_escape_string(esc_name, name, len); - } - bsnprintf(buf, sizeof(buf), - "UPDATE Filename SET Name='%s' WHERE FilenameId=%u", - esc_name, id_list.Id[i]); - if (verbose > 1) { - printf("%s\n", buf); - } - db_sql_query(db, buf, NULL, NULL); + int len; + bsnprintf(buf, sizeof(buf), + "SELECT Name FROM Filename WHERE FilenameId=%u", id_list.Id[i]); + if (!db_sql_query(db, buf, get_name_handler, name)) { + printf("%s\n", db_strerror(db)); + } + /* Strip trailing slash(es) */ + for (len=strlen(name); len > 0 && name[len-1]=='/'; len--) + { } + if (len == 0) { + len = 1; + esc_name[0] = ' '; + esc_name[1] = 0; + } else { + name[len-1] = 0; + db_escape_string(esc_name, name, len); + } + bsnprintf(buf, sizeof(buf), + "UPDATE Filename SET Name='%s' WHERE FilenameId=%u", + esc_name, id_list.Id[i]); + if (verbose > 1) { + printf("%s\n", buf); + } + db_sql_query(db, buf, NULL, NULL); } } } @@ -1013,7 +1017,7 @@ static void repair_bad_paths() printf("Checking for Paths without a trailing slash\n"); query = "SELECT PathId,Path from Path " - "WHERE Path NOT LIKE '%/'"; + "WHERE Path NOT LIKE '%/'"; if (verbose > 1) { printf("%s\n", query); } @@ -1023,11 +1027,11 @@ static void repair_bad_paths() printf("Found %d bad Path records.\n", id_list.num_ids); if (id_list.num_ids && verbose && yes_no("Print them? (yes/no): ")) { for (i=0; i < id_list.num_ids; i++) { - bsnprintf(buf, sizeof(buf), - "SELECT Path FROM Path WHERE PathId=%u", id_list.Id[i]); - if (!db_sql_query(db, buf, print_name_handler, NULL)) { - printf("%s\n", db_strerror(db)); - } + bsnprintf(buf, sizeof(buf), + "SELECT Path FROM Path WHERE PathId=%u", id_list.Id[i]); + if (!db_sql_query(db, buf, print_name_handler, NULL)) { + printf("%s\n", db_strerror(db)); + } } } @@ -1036,25 +1040,25 @@ static void repair_bad_paths() char esc_name[5000]; printf("Reparing %d bad Filename records.\n", id_list.num_ids); for (i=0; i < id_list.num_ids; i++) { - int len; - bsnprintf(buf, sizeof(buf), - "SELECT Path FROM Path WHERE PathId=%u", id_list.Id[i]); - if (!db_sql_query(db, buf, get_name_handler, name)) { - printf("%s\n", db_strerror(db)); - } - /* Strip trailing blanks */ - for (len=strlen(name); len > 0 && name[len-1]==' '; len--) { - name[len-1] = 0; - } - /* Add trailing slash */ - len = pm_strcat(&name, "/"); - db_escape_string(esc_name, name, len); - bsnprintf(buf, sizeof(buf), "UPDATE Path SET Path='%s' WHERE PathId=%u", - esc_name, id_list.Id[i]); - if (verbose > 1) { - printf("%s\n", buf); - } - db_sql_query(db, buf, NULL, NULL); + int len; + bsnprintf(buf, sizeof(buf), + "SELECT Path FROM Path WHERE PathId=%u", id_list.Id[i]); + if (!db_sql_query(db, buf, get_name_handler, name)) { + printf("%s\n", db_strerror(db)); + } + /* Strip trailing blanks */ + for (len=strlen(name); len > 0 && name[len-1]==' '; len--) { + name[len-1] = 0; + } + /* Add trailing slash */ + len = pm_strcat(&name, "/"); + db_escape_string(esc_name, name, len); + bsnprintf(buf, sizeof(buf), "UPDATE Path SET Path='%s' WHERE PathId=%u", + esc_name, id_list.Id[i]); + if (verbose > 1) { + printf("%s\n", buf); + } + db_sql_query(db, buf, NULL, NULL); } } } diff --git a/bacula/src/tools/fstype.c b/bacula/src/tools/fstype.c index 4003d62f8b..c164292453 100644 --- a/bacula/src/tools/fstype.c +++ b/bacula/src/tools/fstype.c @@ -30,6 +30,10 @@ #include "bacula.h" #include "findlib/find.h" +/* Dummy functions */ +int generate_daemon_event(JCR *jcr, const char *event) + { return 1; } + static void usage() { fprintf(stderr, _( @@ -58,11 +62,11 @@ main (int argc, char *const *argv) while ((ch = getopt(argc, argv, "v?")) != -1) { switch (ch) { case 'v': - verbose = 1; - break; + verbose = 1; + break; case '?': - default: - usage(); + default: + usage(); } } @@ -75,14 +79,14 @@ main (int argc, char *const *argv) for (i = 0; i < argc; --argc, ++argv) { if (fstype(*argv, fs, sizeof(fs))) { - if (verbose) { + if (verbose) { printf("%s: %s\n", *argv, fs); - } else { - puts(fs); - } + } else { + puts(fs); + } } else { fprintf(stderr, "%s: unknown\n", *argv); - status = 1; + status = 1; } } diff --git a/bacula/src/tools/testfind.c b/bacula/src/tools/testfind.c index 44bfde3f26..23af56784d 100644 --- a/bacula/src/tools/testfind.c +++ b/bacula/src/tools/testfind.c @@ -32,6 +32,9 @@ int win32_client = 1; int win32_client = 0; #endif +/* Dummy functions */ +int generate_daemon_event(JCR *jcr, const char *event) { return 1; } +int generate_job_event(JCR *jcr, const char *event) { return 1; } /* Global variables */ static int num_files = 0; diff --git a/bacula/src/tools/testls.c b/bacula/src/tools/testls.c index 087a8be9a0..da1a4db131 100755 --- a/bacula/src/tools/testls.c +++ b/bacula/src/tools/testls.c @@ -31,6 +31,10 @@ int win32_client = 1; int win32_client = 0; #endif +/* Dummy functions */ +int generate_daemon_event(JCR *jcr, const char *event) { return 1; } +int generate_job_event(JCR *jcr, const char *event) { return 1; } + /* Global variables */ int attrs = 0; diff --git a/bacula/src/tray-monitor/tray-monitor.c b/bacula/src/tray-monitor/tray-monitor.c index f626a91b96..2d056a37c6 100644 --- a/bacula/src/tray-monitor/tray-monitor.c +++ b/bacula/src/tray-monitor/tray-monitor.c @@ -8,7 +8,7 @@ */ /* - Copyright (C) 2004 Kern Sibbald and John Walker + Copyright (C) 2004-2005 Kern Sibbald This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -41,6 +41,9 @@ int authenticate_director(JCR *jcr, MONITOR *monitor, DIRRES *director); int authenticate_file_daemon(JCR *jcr, MONITOR *monitor, CLIENT* client); int authenticate_storage_daemon(JCR *jcr, MONITOR *monitor, STORE* store); +/* Dummy functions */ +int generate_daemon_event(JCR *jcr, const char *event) { return 1; } + /* Forward referenced functions */ void writecmd(monitoritem* item, const char* command); int docmd(monitoritem* item, const char* command, GSList** list); @@ -108,7 +111,7 @@ static void usage() } static GtkWidget *new_image_button(const gchar *stock_id, - const gchar *label_text) { + const gchar *label_text) { GtkWidget *button; GtkWidget *box; GtkWidget *label; @@ -157,7 +160,7 @@ void smt_free(gpointer mem) { /********************************************************************* * - * Main Bacula Tray Monitor -- User Interface Program + * Main Bacula Tray Monitor -- User Interface Program * */ int main(int argc, char *argv[]) @@ -196,28 +199,28 @@ int main(int argc, char *argv[]) while ((ch = getopt(argc, argv, "bc:d:th?f:s:")) != -1) { switch (ch) { case 'c': /* configuration file */ - if (configfile != NULL) { - free(configfile); - } - configfile = bstrdup(optarg); - break; + if (configfile != NULL) { + free(configfile); + } + configfile = bstrdup(optarg); + break; case 'd': - debug_level = atoi(optarg); - if (debug_level <= 0) { - debug_level = 1; - } - break; + debug_level = atoi(optarg); + if (debug_level <= 0) { + debug_level = 1; + } + break; case 't': - test_config = true; - break; + test_config = true; + break; case 'h': case '?': default: - usage(); - exit(1); + usage(); + exit(1); } } argc -= optind; @@ -242,7 +245,7 @@ int main(int argc, char *argv[]) if (nitems != 1) { Emsg2(M_ERROR_TERM, 0, - _("Error: %d Monitor resource defined in %s. You must define one and only one Monitor resource.\n"), nitems, configfile); + _("Error: %d Monitor resource defined in %s. You must define one and only one Monitor resource.\n"), nitems, configfile); } nitems = 0; @@ -352,19 +355,19 @@ int main(int argc, char *argv[]) for (int i = 0; i < nitems; i++) { switch (items[i].type) { case R_DIRECTOR: - str = g_string_new(((DIRRES*)(items[i].resource))->hdr.name); - g_string_append(str, _(" (DIR)")); - break; + str = g_string_new(((DIRRES*)(items[i].resource))->hdr.name); + g_string_append(str, _(" (DIR)")); + break; case R_CLIENT: - str = g_string_new(((CLIENT*)(items[i].resource))->hdr.name); - g_string_append(str, _(" (FD)")); - break; + str = g_string_new(((CLIENT*)(items[i].resource))->hdr.name); + g_string_append(str, _(" (FD)")); + break; case R_STORAGE: - str = g_string_new(((STORE*)(items[i].resource))->hdr.name); - g_string_append(str, _(" (SD)")); - break; + str = g_string_new(((STORE*)(items[i].resource))->hdr.name); + g_string_append(str, _(" (SD)")); + break; default: - continue; + continue; } radio = gtk_radio_button_new_with_label(group, str->str); @@ -379,11 +382,11 @@ int main(int argc, char *argv[]) gtk_container_add(GTK_CONTAINER(align), items[i].label); gtk_table_attach(GTK_TABLE(daemon_table), radio, 0, 1, (i*2)+1, (i*2)+2, - GTK_FILL, (GtkAttachOptions)(GTK_EXPAND | GTK_FILL), 0, 0); + GTK_FILL, (GtkAttachOptions)(GTK_EXPAND | GTK_FILL), 0, 0); gtk_table_attach(GTK_TABLE(daemon_table), items[i].image, 1, 2, (i*2)+1, (i*2)+2, - GTK_FILL, (GtkAttachOptions)(GTK_EXPAND | GTK_FILL), 0, 0); + GTK_FILL, (GtkAttachOptions)(GTK_EXPAND | GTK_FILL), 0, 0); gtk_table_attach(GTK_TABLE(daemon_table), align, 2, 3, (i*2)+1, (i*2)+2, - (GtkAttachOptions)(GTK_EXPAND | GTK_FILL), (GtkAttachOptions)(GTK_EXPAND | GTK_FILL), 0, 0); + (GtkAttachOptions)(GTK_EXPAND | GTK_FILL), (GtkAttachOptions)(GTK_EXPAND | GTK_FILL), 0, 0); separator = gtk_hseparator_new(); gtk_table_attach_defaults(GTK_TABLE(daemon_table), separator, 0, 3, (i*2)+2, (i*2)+3); @@ -449,13 +452,13 @@ int main(int argc, char *argv[]) for (i = 0; i < nitems; i++) { if (items[i].D_sock) { - writecmd(&items[i], "quit"); - bnet_sig(items[i].D_sock, BNET_TERMINATE); /* send EOF */ - bnet_close(items[i].D_sock); + writecmd(&items[i], "quit"); + bnet_sig(items[i].D_sock, BNET_TERMINATE); /* send EOF */ + bnet_close(items[i].D_sock); } } - (void)WSACleanup(); /* Cleanup Windows sockets */ + (void)WSACleanup(); /* Cleanup Windows sockets */ //Free xpm_generic_var for (i = 0; i < (int)(sizeof(xpm_generic)/sizeof(const char*)); i++) { @@ -501,8 +504,8 @@ static void MonitorRefresh(GtkWidget *widget, gpointer data) { } static gboolean delete_event( GtkWidget *widget, - GdkEvent *event, - gpointer data ) { + GdkEvent *event, + gpointer data ) { gtk_widget_hide(window); return TRUE; /* do not destroy the window */ } @@ -524,7 +527,7 @@ static void IntervalChanged(GtkWidget *widget, gpointer data) { g_source_remove(timerTag); timerTag = g_timeout_add( (guint)( - gtk_spin_button_get_value(GTK_SPIN_BUTTON(timeoutspinner))*1000/nitems + gtk_spin_button_get_value(GTK_SPIN_BUTTON(timeoutspinner))*1000/nitems ), fd_read, NULL ); } @@ -532,10 +535,10 @@ static void DaemonChanged(GtkWidget *widget, monitoritem* data) { if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) { fullitem = -1; for (int i = 0; i < nitems; i++) { - if (data == &(items[i])) { - fullitem = i; - break; - } + if (data == &(items[i])) { + fullitem = i; + break; + } } g_return_if_fail(fullitem != -1); @@ -594,29 +597,29 @@ static gboolean fd_read(gpointer data) { newbuffer = gtk_text_buffer_new(NULL); if (items[lastupdated].type == R_DIRECTOR) - docmd(&items[lastupdated], "status Director\n", &list); + docmd(&items[lastupdated], "status Director\n", &list); else - docmd(&items[lastupdated], "status\n", &list); + docmd(&items[lastupdated], "status\n", &list); it = list->next; do { - gtk_text_buffer_get_end_iter(newbuffer, &stop); - gtk_text_buffer_insert (newbuffer, &stop, ((GString*)it->data)->str, -1); - if (it->data) g_string_free((GString*)it->data, TRUE); + gtk_text_buffer_get_end_iter(newbuffer, &stop); + gtk_text_buffer_insert (newbuffer, &stop, ((GString*)it->data)->str, -1); + if (it->data) g_string_free((GString*)it->data, TRUE); } while ((it = it->next) != NULL); g_slist_free(list); /* Keep the selection if necessary */ if (gtk_text_buffer_get_selection_bounds(buffer, &start, &stop)) { - gtk_text_buffer_get_iter_at_offset(newbuffer, &nstart, gtk_text_iter_get_offset(&start)); - gtk_text_buffer_get_iter_at_offset(newbuffer, &nstop, gtk_text_iter_get_offset(&stop )); + gtk_text_buffer_get_iter_at_offset(newbuffer, &nstart, gtk_text_iter_get_offset(&start)); + gtk_text_buffer_get_iter_at_offset(newbuffer, &nstop, gtk_text_iter_get_offset(&stop )); #if HAVE_GTK_2_4 - gtk_text_buffer_select_range(newbuffer, &nstart, &nstop); + gtk_text_buffer_select_range(newbuffer, &nstart, &nstop); #else - gtk_text_buffer_move_mark(newbuffer, gtk_text_buffer_get_mark(newbuffer, "insert"), &nstart); - gtk_text_buffer_move_mark(newbuffer, gtk_text_buffer_get_mark(newbuffer, "selection_bound"), &nstop); + gtk_text_buffer_move_mark(newbuffer, gtk_text_buffer_get_mark(newbuffer, "insert"), &nstart); + gtk_text_buffer_move_mark(newbuffer, gtk_text_buffer_get_mark(newbuffer, "selection_bound"), &nstop); #endif } @@ -652,117 +655,117 @@ void getstatus(monitoritem* item, int current, GString** str) { if (current) { if (item->type == R_DIRECTOR) - docmd(&items[lastupdated], ".status dir current\n", &list); + docmd(&items[lastupdated], ".status dir current\n", &list); else - docmd(&items[lastupdated], ".status current\n", &list); + docmd(&items[lastupdated], ".status current\n", &list); } else { if (item->type == R_DIRECTOR) - docmd(&items[lastupdated], ".status dir last\n", &list); + docmd(&items[lastupdated], ".status dir last\n", &list); else - docmd(&items[lastupdated], ".status last\n", &list); + docmd(&items[lastupdated], ".status last\n", &list); } it = list->next; if ((it == NULL) || (sscanf(((GString*)it->data)->str, OKqstatus, &num) != 1)) { g_string_append_printf(*str, ".status error : %s", (it == NULL) ? "" : ((GString*)it->data)->str); while (((*str)->str[(*str)->len-1] == '\n') || ((*str)->str[(*str)->len-1] == '\r')) { - g_string_set_size(*str, (*str)->len-1); + g_string_set_size(*str, (*str)->len-1); } ret = error; } else if ((it = it->next) == NULL) { if (current) { - g_string_append(*str, _("No current job.")); + g_string_append(*str, _("No current job.")); } else { - g_string_append(*str, _("No last job.")); + g_string_append(*str, _("No last job.")); } ret = idle; } else if ((k = sscanf(((GString*)it->data)->str, DotStatusJob, &jobid, &jobstatus, &joberrors)) == 3) { switch (jobstatus) { case JS_Created: - ret = (joberrors > 0) ? warn : running; - g_string_append_printf(*str, _("Job status: Created (%d error%s)"), joberrors, (joberrors > 1) ? "s" : ""); - break; + ret = (joberrors > 0) ? warn : running; + g_string_append_printf(*str, _("Job status: Created (%d error%s)"), joberrors, (joberrors > 1) ? "s" : ""); + break; case JS_Running: - ret = (joberrors > 0) ? warn : running; - g_string_append_printf(*str, _("Job status: Running (%d error%s)"), joberrors, (joberrors > 1) ? "s" : ""); - break; + ret = (joberrors > 0) ? warn : running; + g_string_append_printf(*str, _("Job status: Running (%d error%s)"), joberrors, (joberrors > 1) ? "s" : ""); + break; case JS_Blocked: - g_string_append_printf(*str, _("Job status: Blocked (%d error%s)"), joberrors, (joberrors > 1) ? "s" : ""); - ret = warn; - break; + g_string_append_printf(*str, _("Job status: Blocked (%d error%s)"), joberrors, (joberrors > 1) ? "s" : ""); + ret = warn; + break; case JS_Terminated: - g_string_append_printf(*str, _("Job status: Terminated (%d error%s)"), joberrors, (joberrors > 1) ? "s" : ""); - ret = (joberrors > 0) ? warn : idle; - break; + g_string_append_printf(*str, _("Job status: Terminated (%d error%s)"), joberrors, (joberrors > 1) ? "s" : ""); + ret = (joberrors > 0) ? warn : idle; + break; case JS_ErrorTerminated: - g_string_append_printf(*str, _("Job status: Terminated in error (%d error%s)"), joberrors, (joberrors > 1) ? "s" : ""); - ret = error; - break; + g_string_append_printf(*str, _("Job status: Terminated in error (%d error%s)"), joberrors, (joberrors > 1) ? "s" : ""); + ret = error; + break; case JS_Error: - ret = (joberrors > 0) ? warn : running; - g_string_append_printf(*str, _("Job status: Error (%d error%s)"), joberrors, (joberrors > 1) ? "s" : ""); - break; + ret = (joberrors > 0) ? warn : running; + g_string_append_printf(*str, _("Job status: Error (%d error%s)"), joberrors, (joberrors > 1) ? "s" : ""); + break; case JS_FatalError: - g_string_append_printf(*str, _("Job status: Fatal error (%d error%s)"), joberrors, (joberrors > 1) ? "s" : ""); - ret = error; - break; + g_string_append_printf(*str, _("Job status: Fatal error (%d error%s)"), joberrors, (joberrors > 1) ? "s" : ""); + ret = error; + break; case JS_Differences: - g_string_append_printf(*str, _("Job status: Verify differences (%d error%s)"), joberrors, (joberrors > 1) ? "s" : ""); - ret = warn; - break; + g_string_append_printf(*str, _("Job status: Verify differences (%d error%s)"), joberrors, (joberrors > 1) ? "s" : ""); + ret = warn; + break; case JS_Canceled: - g_string_append_printf(*str, _("Job status: Canceled (%d error%s)"), joberrors, (joberrors > 1) ? "s" : ""); - ret = warn; - break; + g_string_append_printf(*str, _("Job status: Canceled (%d error%s)"), joberrors, (joberrors > 1) ? "s" : ""); + ret = warn; + break; case JS_WaitFD: - g_string_append_printf(*str, _("Job status: Waiting on File daemon (%d error%s)"), joberrors, (joberrors > 1) ? "s" : ""); - ret = warn; - break; + g_string_append_printf(*str, _("Job status: Waiting on File daemon (%d error%s)"), joberrors, (joberrors > 1) ? "s" : ""); + ret = warn; + break; case JS_WaitSD: - g_string_append_printf(*str, _("Job status: Waiting on the Storage daemon (%d error%s)"), joberrors, (joberrors > 1) ? "s" : ""); - ret = warn; - break; + g_string_append_printf(*str, _("Job status: Waiting on the Storage daemon (%d error%s)"), joberrors, (joberrors > 1) ? "s" : ""); + ret = warn; + break; case JS_WaitMedia: - g_string_append_printf(*str, _("Job status: Waiting for new media (%d error%s)"), joberrors, (joberrors > 1) ? "s" : ""); - ret = warn; - break; + g_string_append_printf(*str, _("Job status: Waiting for new media (%d error%s)"), joberrors, (joberrors > 1) ? "s" : ""); + ret = warn; + break; case JS_WaitMount: - g_string_append_printf(*str, _("Job status: Waiting for Mount (%d error%s)"), joberrors, (joberrors > 1) ? "s" : ""); - ret = warn; - break; + g_string_append_printf(*str, _("Job status: Waiting for Mount (%d error%s)"), joberrors, (joberrors > 1) ? "s" : ""); + ret = warn; + break; case JS_WaitStoreRes: - g_string_append_printf(*str, _("Job status: Waiting for storage resource (%d error%s)"), joberrors, (joberrors > 1) ? "s" : ""); - ret = warn; - break; + g_string_append_printf(*str, _("Job status: Waiting for storage resource (%d error%s)"), joberrors, (joberrors > 1) ? "s" : ""); + ret = warn; + break; case JS_WaitJobRes: - g_string_append_printf(*str, _("Job status: Waiting for job resource (%d error%s)"), joberrors, (joberrors > 1) ? "s" : ""); - ret = warn; - break; + g_string_append_printf(*str, _("Job status: Waiting for job resource (%d error%s)"), joberrors, (joberrors > 1) ? "s" : ""); + ret = warn; + break; case JS_WaitClientRes: - g_string_append_printf(*str, _("Job status: Waiting for Client resource (%d error%s)"), joberrors, (joberrors > 1) ? "s" : ""); - ret = warn; - break; + g_string_append_printf(*str, _("Job status: Waiting for Client resource (%d error%s)"), joberrors, (joberrors > 1) ? "s" : ""); + ret = warn; + break; case JS_WaitMaxJobs: - g_string_append_printf(*str, _("Job status: Waiting for maximum jobs (%d error%s)"), joberrors, (joberrors > 1) ? "s" : ""); - ret = warn; - break; + g_string_append_printf(*str, _("Job status: Waiting for maximum jobs (%d error%s)"), joberrors, (joberrors > 1) ? "s" : ""); + ret = warn; + break; case JS_WaitStartTime: - g_string_append_printf(*str, _("Job status: Waiting for start time (%d error%s)"), joberrors, (joberrors > 1) ? "s" : ""); - ret = warn; - break; + g_string_append_printf(*str, _("Job status: Waiting for start time (%d error%s)"), joberrors, (joberrors > 1) ? "s" : ""); + ret = warn; + break; case JS_WaitPriority: - g_string_append_printf(*str, _("Job status: Waiting for higher priority jobs to finish (%d error%s)"), joberrors, (joberrors > 1) ? "s" : ""); - ret = warn; - break; + g_string_append_printf(*str, _("Job status: Waiting for higher priority jobs to finish (%d error%s)"), joberrors, (joberrors > 1) ? "s" : ""); + ret = warn; + break; default: - g_warning("Unknown job status %c.", jobstatus); - g_string_append_printf(*str, _("Job status: Unknown(%c) (%d error%s)"), jobstatus, joberrors, (joberrors > 1) ? "s" : ""); - ret = warn; - break; + g_warning("Unknown job status %c.", jobstatus); + g_string_append_printf(*str, _("Job status: Unknown(%c) (%d error%s)"), jobstatus, joberrors, (joberrors > 1) ? "s" : ""); + ret = warn; + break; } } else { @@ -802,80 +805,80 @@ int docmd(monitoritem* item, const char* command, GSList** list) { switch (item->type) { case R_DIRECTOR: - dird = (DIRRES*)item->resource; - trayMessage("Connecting to Director %s:%d\n", dird->address, dird->DIRport); - changeStatusMessage(item, "Connecting to Director %s:%d", dird->address, dird->DIRport); - item->D_sock = bnet_connect(NULL, 0, 0, "Director daemon", dird->address, NULL, dird->DIRport, 0); - jcr.dir_bsock = item->D_sock; - break; + dird = (DIRRES*)item->resource; + trayMessage("Connecting to Director %s:%d\n", dird->address, dird->DIRport); + changeStatusMessage(item, "Connecting to Director %s:%d", dird->address, dird->DIRport); + item->D_sock = bnet_connect(NULL, 0, 0, "Director daemon", dird->address, NULL, dird->DIRport, 0); + jcr.dir_bsock = item->D_sock; + break; case R_CLIENT: - filed = (CLIENT*)item->resource; - trayMessage("Connecting to Client %s:%d\n", filed->address, filed->FDport); - changeStatusMessage(item, "Connecting to Client %s:%d", filed->address, filed->FDport); - item->D_sock = bnet_connect(NULL, 0, 0, "File daemon", filed->address, NULL, filed->FDport, 0); - jcr.file_bsock = item->D_sock; - break; + filed = (CLIENT*)item->resource; + trayMessage("Connecting to Client %s:%d\n", filed->address, filed->FDport); + changeStatusMessage(item, "Connecting to Client %s:%d", filed->address, filed->FDport); + item->D_sock = bnet_connect(NULL, 0, 0, "File daemon", filed->address, NULL, filed->FDport, 0); + jcr.file_bsock = item->D_sock; + break; case R_STORAGE: - stored = (STORE*)item->resource; - trayMessage("Connecting to Storage %s:%d\n", stored->address, stored->SDport); - changeStatusMessage(item, "Connecting to Storage %s:%d", stored->address, stored->SDport); - item->D_sock = bnet_connect(NULL, 0, 0, "Storage daemon", stored->address, NULL, stored->SDport, 0); - jcr.store_bsock = item->D_sock; - break; + stored = (STORE*)item->resource; + trayMessage("Connecting to Storage %s:%d\n", stored->address, stored->SDport); + changeStatusMessage(item, "Connecting to Storage %s:%d", stored->address, stored->SDport); + item->D_sock = bnet_connect(NULL, 0, 0, "Storage daemon", stored->address, NULL, stored->SDport, 0); + jcr.store_bsock = item->D_sock; + break; default: - printf("Error, currentitem is not a Client, a Storage or a Director..\n"); - gtk_main_quit(); - return 0; + printf("Error, currentitem is not a Client, a Storage or a Director..\n"); + gtk_main_quit(); + return 0; } if (item->D_sock == NULL) { - g_slist_append(*list, g_string_new("Cannot connect to daemon.\n")); - changeStatusMessage(item, "Cannot connect to daemon."); - item->state = error; - item->oldstate = error; - return 0; + g_slist_append(*list, g_string_new("Cannot connect to daemon.\n")); + changeStatusMessage(item, "Cannot connect to daemon."); + item->state = error; + item->oldstate = error; + return 0; } if (!authenticate_daemon(item, &jcr)) { - str = g_string_sized_new(64); - g_string_printf(str, "ERR=%s\n", item->D_sock->msg); - g_slist_append(*list, str); - item->state = error; - item->oldstate = error; - changeStatusMessage(item, "Authentication error : %s", item->D_sock->msg); - item->D_sock = NULL; - return 0; + str = g_string_sized_new(64); + g_string_printf(str, "ERR=%s\n", item->D_sock->msg); + g_slist_append(*list, str); + item->state = error; + item->oldstate = error; + changeStatusMessage(item, "Authentication error : %s", item->D_sock->msg); + item->D_sock = NULL; + return 0; } switch (item->type) { case R_DIRECTOR: - trayMessage("Opened connection with Director daemon.\n"); - changeStatusMessage(item, "Opened connection with Director daemon."); - break; + trayMessage("Opened connection with Director daemon.\n"); + changeStatusMessage(item, "Opened connection with Director daemon."); + break; case R_CLIENT: - trayMessage("Opened connection with File daemon.\n"); - changeStatusMessage(item, "Opened connection with File daemon."); - break; + trayMessage("Opened connection with File daemon.\n"); + changeStatusMessage(item, "Opened connection with File daemon."); + break; case R_STORAGE: - trayMessage("Opened connection with Storage daemon.\n"); - changeStatusMessage(item, "Opened connection with Storage daemon."); - break; + trayMessage("Opened connection with Storage daemon.\n"); + changeStatusMessage(item, "Opened connection with Storage daemon."); + break; default: - printf("Error, currentitem is not a Client, a Storage or a Director..\n"); - gtk_main_quit(); - return 0; - break; + printf("Error, currentitem is not a Client, a Storage or a Director..\n"); + gtk_main_quit(); + return 0; + break; } if (item->type == R_DIRECTOR) { /* Read connection messages... */ - GSList *list, *it; - docmd(item, "", &list); /* Usually invalid, but no matter */ - it = list; - do { - if (it->data) g_string_free((GString*)it->data, TRUE); - } while ((it = it->next) != NULL); - - g_slist_free(list); + GSList *list, *it; + docmd(item, "", &list); /* Usually invalid, but no matter */ + it = list; + do { + if (it->data) g_string_free((GString*)it->data, TRUE); + } while ((it = it->next) != NULL); + + g_slist_free(list); } } @@ -884,46 +887,46 @@ int docmd(monitoritem* item, const char* command, GSList** list) { while(1) { if ((stat = bnet_recv(item->D_sock)) >= 0) { - g_slist_append(*list, g_string_new(item->D_sock->msg)); + g_slist_append(*list, g_string_new(item->D_sock->msg)); } else if (stat == BNET_SIGNAL) { - if (item->D_sock->msglen == BNET_EOD) { - //fprintf(stderr, "<< EOD >>\n"); - return 1; - } - else if (item->D_sock->msglen == BNET_PROMPT) { - //fprintf(stderr, "<< PROMPT >>\n"); - g_slist_append(*list, g_string_new("<< Error: BNET_PROMPT signal received. >>\n")); - return 0; - } - else if (item->D_sock->msglen == BNET_HEARTBEAT) { - bnet_sig(item->D_sock, BNET_HB_RESPONSE); - g_slist_append(*list, g_string_new("<< Heartbeat signal received, answered. >>\n")); - } - else { - str = g_string_sized_new(64); - g_string_printf(str, "<< Unexpected signal received : %s >>\n", bnet_sig_to_ascii(item->D_sock)); - g_slist_append(*list, str); - } + if (item->D_sock->msglen == BNET_EOD) { + //fprintf(stderr, "<< EOD >>\n"); + return 1; + } + else if (item->D_sock->msglen == BNET_PROMPT) { + //fprintf(stderr, "<< PROMPT >>\n"); + g_slist_append(*list, g_string_new("<< Error: BNET_PROMPT signal received. >>\n")); + return 0; + } + else if (item->D_sock->msglen == BNET_HEARTBEAT) { + bnet_sig(item->D_sock, BNET_HB_RESPONSE); + g_slist_append(*list, g_string_new("<< Heartbeat signal received, answered. >>\n")); + } + else { + str = g_string_sized_new(64); + g_string_printf(str, "<< Unexpected signal received : %s >>\n", bnet_sig_to_ascii(item->D_sock)); + g_slist_append(*list, str); + } } else { /* BNET_HARDEOF || BNET_ERROR */ - g_slist_append(*list, g_string_new("\n")); - item->D_sock = NULL; - item->state = error; - item->oldstate = error; - changeStatusMessage(item, "Error : BNET_HARDEOF or BNET_ERROR"); - //fprintf(stderr, "<< ERROR >>\n"); - return 0; + g_slist_append(*list, g_string_new("\n")); + item->D_sock = NULL; + item->state = error; + item->oldstate = error; + changeStatusMessage(item, "Error : BNET_HARDEOF or BNET_ERROR"); + //fprintf(stderr, "<< ERROR >>\n"); + return 0; } if (is_bnet_stop(item->D_sock)) { - g_string_append_printf(str, "\n"); - item->D_sock = NULL; - item->state = error; - item->oldstate = error; - changeStatusMessage(item, "Error : Connection closed."); - //fprintf(stderr, "<< STOP >>\n"); - return 0; /* error or term */ + g_string_append_printf(str, "\n"); + item->D_sock = NULL; + item->state = error; + item->oldstate = error; + changeStatusMessage(item, "Error : Connection closed."); + //fprintf(stderr, "<< STOP >>\n"); + return 0; /* error or term */ } } } @@ -966,41 +969,41 @@ void updateStatusIcon(monitoritem* item) { if (item == NULL) { /* For the current status, select the two worse for blinking, - but never blink a D_Sock == NULL error with idle. */ + but never blink a D_Sock == NULL error with idle. */ stateenum state1, state2, oldstate; gboolean onenull = FALSE; state1 = idle; state2 = idle; oldstate = idle; for (int i = 0; i < nitems; i++) { - if (items[i].D_sock == NULL) onenull = TRUE; - if (items[i].state >= state1) { - state2 = state1; - state1 = items[i].state; - } - else if (items[i].state > state2) { - state2 = items[i].state; - } - if (items[i].oldstate > oldstate) oldstate = items[i].oldstate; + if (items[i].D_sock == NULL) onenull = TRUE; + if (items[i].state >= state1) { + state2 = state1; + state1 = items[i].state; + } + else if (items[i].state > state2) { + state2 = items[i].state; + } + if (items[i].oldstate > oldstate) oldstate = items[i].oldstate; } if ((onenull == TRUE) && (state2 == idle)) { - state2 = error; + state2 = error; } xpm = generateXPM(blinkstate ? state1 : state2, oldstate); } else { if ((blinkstate) && (item->D_sock != NULL)) { - if (item->state > 1) { //Warning or error while running - xpm = generateXPM(running, item->oldstate); - } - else { - xpm = generateXPM(idle, item->oldstate); - } + if (item->state > 1) { //Warning or error while running + xpm = generateXPM(running, item->oldstate); + } + else { + xpm = generateXPM(idle, item->oldstate); + } } else { - xpm = generateXPM(item->state, item->oldstate); + xpm = generateXPM(item->state, item->oldstate); } } diff --git a/bacula/src/version.h b/bacula/src/version.h index 4df9f780a4..f6bdf3001f 100644 --- a/bacula/src/version.h +++ b/bacula/src/version.h @@ -1,8 +1,8 @@ /* */ #undef VERSION -#define VERSION "1.37.12" -#define BDATE "18 April 2005" -#define LSMDATE "18Apr05" +#define VERSION "1.37.13" +#define BDATE "19 April 2005" +#define LSMDATE "19Apr05" /* Debug flags */ #undef DEBUG diff --git a/bacula/src/wx-console/main.cpp b/bacula/src/wx-console/main.cpp index 92779b4e72..a1ebab7800 100644 --- a/bacula/src/wx-console/main.cpp +++ b/bacula/src/wx-console/main.cpp @@ -48,6 +48,11 @@ #include "csprint.h" +/* Dummy functions */ +int generate_daemon_event(JCR *jcr, const char *event) { return 1; } +int generate_job_event(JCR *jcr, const char *event) { return 1; } + + // ---------------------------------------------------------------------------- // resources // ----------------------------------------------------------------------------