From db89a28f4529ad91649589499fb785ffeb5fdb1c Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Tue, 21 Dec 2004 17:29:45 +0000 Subject: [PATCH] - Fix Bacula so that it does not exit if there is a syntax error in its conf file during a reload command. Bug 182. git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@1771 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/patches/1.36.1-reload.patch | 50 ++++++++++++++++++++++++++++++ bacula/patches/patches-1.36.1 | 8 +++-- bacula/src/dird/dird.c | 44 +++++++++++++------------- 3 files changed, 79 insertions(+), 23 deletions(-) create mode 100644 bacula/patches/1.36.1-reload.patch diff --git a/bacula/patches/1.36.1-reload.patch b/bacula/patches/1.36.1-reload.patch new file mode 100644 index 0000000000..022ee33b59 --- /dev/null +++ b/bacula/patches/1.36.1-reload.patch @@ -0,0 +1,50 @@ + This patch fixes Bacula so that it does not exit if there + is a syntax error in its conf file during a reload command. + Apply the patch to 1.36.1 with: + + cd + patch -p0 <1.36.1-reload.patch + make + make install + +--- ../branch-1.36.1/src/dird/dird.c 2004-11-11 18:30:32.000000000 +0100 ++++ src/dird/dird.c 2004-12-21 18:15:10.625754501 +0100 +@@ -372,6 +375,7 @@ + JCR *jcr; + int njobs = 0; /* number of running jobs */ + int table, rtable; ++ bool ok; + + if (already_here) { + abort(); /* Oops, recursion -> die */ +@@ -396,16 +400,17 @@ + reload_table[table].res_table = save_config_resources(); + Dmsg1(100, "Saved old config in table %d\n", table); + +- parse_config(configfile); ++ ok = parse_config(configfile, 0); /* no exit on error */ + + Dmsg0(100, "Reloaded config file\n"); +- if (!check_resources()) { ++ if (!ok || !check_resources()) { + rtable = find_free_reload_table_entry(); /* save new, bad table */ + if (rtable < 0) { + Jmsg(NULL, M_ERROR, 0, _("Please correct configuration file: %s\n"), configfile); + Jmsg(NULL, M_ERROR_TERM, 0, _("Out of reload table entries. Giving up.\n")); + } else { + Jmsg(NULL, M_ERROR, 0, _("Please correct configuration file: %s\n"), configfile); ++ Jmsg(NULL, M_ERROR, 0, _("Resetting previous configuration.\n")); + } + reload_table[rtable].res_table = save_config_resources(); + /* Now restore old resoure values */ +@@ -465,8 +470,8 @@ + job = (JOB *)GetNextRes(R_JOB, NULL); + director = (DIRRES *)GetNextRes(R_DIRECTOR, NULL); + if (!director) { +- Jmsg(NULL, M_FATAL, 0, _("No Director resource defined in %s\n\ +-Without that I don't know who I am :-(\n"), configfile); ++ Jmsg(NULL, M_FATAL, 0, _("No Director resource defined in %s\n" ++"Without that I don't know who I am :-(\n"), configfile); + OK = false; + } else { + set_working_directory(director->working_directory); diff --git a/bacula/patches/patches-1.36.1 b/bacula/patches/patches-1.36.1 index 0480335f72..23bfed574f 100644 --- a/bacula/patches/patches-1.36.1 +++ b/bacula/patches/patches-1.36.1 @@ -8,13 +8,17 @@ This patch should fix "update slots" with two different magazines in different pools by checking the pool when zapping the InChanger. -18Dec04 +18Dec04 1.36.1-spool.patch This patch fixes the despooling size printed in the Job report. Previously, it reported the total size for the device. This patch makes it report the size for the job. -21Dec04 +21Dec04 1.36.1-store.patch This patch fixes a problem with overriding storage daemon specifications. Previously they were not always honored. This implements more uniform handling. It also eliminates an orphaned buffer situation using JobDefs. + +21Dec04 1.36.1-reload.patch + This patch fixes Bacula so that it does not exit if there + is a syntax error in its conf file during a reload command. diff --git a/bacula/src/dird/dird.c b/bacula/src/dird/dird.c index e9a680feb8..e3484c79db 100644 --- a/bacula/src/dird/dird.c +++ b/bacula/src/dird/dird.c @@ -128,7 +128,7 @@ int main (int argc, char *argv[]) if (debug_level <= 0) { debug_level = 1; } - Dmsg1(0, "Debug level = %d\n", debug_level); + Dmsg1(0, "Debug level = %d\n", debug_level); break; case 'f': /* run in foreground */ @@ -375,6 +375,7 @@ void reload_config(int sig) JCR *jcr; int njobs = 0; /* number of running jobs */ int table, rtable; + bool ok; if (already_here) { abort(); /* Oops, recursion -> die */ @@ -399,16 +400,17 @@ void reload_config(int sig) reload_table[table].res_table = save_config_resources(); Dmsg1(100, "Saved old config in table %d\n", table); - parse_config(configfile); + ok = parse_config(configfile, 0); /* no exit on error */ Dmsg0(100, "Reloaded config file\n"); - if (!check_resources()) { + if (!ok || !check_resources()) { rtable = find_free_reload_table_entry(); /* save new, bad table */ if (rtable < 0) { - Jmsg(NULL, M_ERROR, 0, _("Please correct configuration file: %s\n"), configfile); - Jmsg(NULL, M_ERROR_TERM, 0, _("Out of reload table entries. Giving up.\n")); + Jmsg(NULL, M_ERROR, 0, _("Please correct configuration file: %s\n"), configfile); + Jmsg(NULL, M_ERROR_TERM, 0, _("Out of reload table entries. Giving up.\n")); } else { - Jmsg(NULL, M_ERROR, 0, _("Please correct configuration file: %s\n"), configfile); + Jmsg(NULL, M_ERROR, 0, _("Please correct configuration file: %s\n"), configfile); + Jmsg(NULL, M_ERROR, 0, _("Resetting previous configuration.\n")); } reload_table[rtable].res_table = save_config_resources(); /* Now restore old resoure values */ @@ -476,12 +478,12 @@ static int check_resources() if (!director->messages) { /* If message resource not specified */ director->messages = (MSGS *)GetNextRes(R_MSGS, NULL); if (!director->messages) { - Jmsg(NULL, M_FATAL, 0, _("No Messages resource defined in %s\n"), configfile); + Jmsg(NULL, M_FATAL, 0, _("No Messages resource defined in %s\n"), configfile); OK = false; } } if (GetNextRes(R_DIRECTOR, (RES *)director) != NULL) { - Jmsg(NULL, M_FATAL, 0, _("Only one Director resource permitted in %s\n"), + Jmsg(NULL, M_FATAL, 0, _("Only one Director resource permitted in %s\n"), configfile); OK = false; } @@ -514,14 +516,14 @@ static int check_resources() int64_t *def_lvalue, *lvalue; /* 64 bit values */ uint32_t offset; - Dmsg4(400, "Job \"%s\", field \"%s\" bit=%d def=%d\n", + Dmsg4(400, "Job \"%s\", field \"%s\" bit=%d def=%d\n", job->hdr.name, job_items[i].name, bit_is_set(i, job->hdr.item_present), bit_is_set(i, job->jobdefs->hdr.item_present)); if (!bit_is_set(i, job->hdr.item_present) && bit_is_set(i, job->jobdefs->hdr.item_present)) { - Dmsg2(400, "Job \"%s\", field \"%s\": getting default.\n", + Dmsg2(400, "Job \"%s\", field \"%s\": getting default.\n", job->hdr.name, job_items[i].name); offset = (char *)(job_items[i].value) - (char *)&res_all; /* @@ -530,11 +532,11 @@ static int check_resources() if (job_items[i].handler == store_str || job_items[i].handler == store_dir) { def_svalue = (char **)((char *)(job->jobdefs) + offset); - Dmsg5(400, "Job \"%s\", field \"%s\" def_svalue=%s item %d offset=%u\n", + Dmsg5(400, "Job \"%s\", field \"%s\" def_svalue=%s item %d offset=%u\n", job->hdr.name, job_items[i].name, *def_svalue, i, offset); svalue = (char **)((char *)job + offset); if (*svalue) { - Pmsg1(000, "Hey something is wrong. p=0x%lu\n", *svalue); + Pmsg1(000, "Hey something is wrong. p=0x%lu\n", *svalue); } *svalue = bstrdup(*def_svalue); set_bit(i, job->hdr.item_present); @@ -543,11 +545,11 @@ static int check_resources() */ } else if (job_items[i].handler == store_res) { def_svalue = (char **)((char *)(job->jobdefs) + offset); - Dmsg4(400, "Job \"%s\", field \"%s\" item %d offset=%u\n", + Dmsg4(400, "Job \"%s\", field \"%s\" item %d offset=%u\n", job->hdr.name, job_items[i].name, i, offset); svalue = (char **)((char *)job + offset); if (*svalue) { - Pmsg1(000, "Hey something is wrong. p=0x%lu\n", *svalue); + Pmsg1(000, "Hey something is wrong. p=0x%lu\n", *svalue); } *svalue = *def_svalue; set_bit(i, job->hdr.item_present); @@ -569,7 +571,7 @@ static int check_resources() job_items[i].handler == store_pint || job_items[i].handler == store_replace) { def_ivalue = (int *)((char *)(job->jobdefs) + offset); - Dmsg5(400, "Job \"%s\", field \"%s\" def_ivalue=%d item %d offset=%u\n", + Dmsg5(400, "Job \"%s\", field \"%s\" def_ivalue=%d item %d offset=%u\n", job->hdr.name, job_items[i].name, *def_ivalue, i, offset); ivalue = (int *)((char *)job + offset); *ivalue = *def_ivalue; @@ -581,7 +583,7 @@ static int check_resources() job_items[i].handler == store_size || job_items[i].handler == store_int64) { def_lvalue = (int64_t *)((char *)(job->jobdefs) + offset); - Dmsg5(400, "Job \"%s\", field \"%s\" def_lvalue=%" lld " item %d offset=%u\n", + Dmsg5(400, "Job \"%s\", field \"%s\" def_lvalue=%" lld " item %d offset=%u\n", job->hdr.name, job_items[i].name, *def_lvalue, i, offset); lvalue = (int64_t *)((char *)job + offset); *lvalue = *def_lvalue; @@ -596,14 +598,14 @@ static int check_resources() for (i=0; job_items[i].name; i++) { if (job_items[i].flags & ITEM_REQUIRED) { if (!bit_is_set(i, job->hdr.item_present)) { - Jmsg(NULL, M_FATAL, 0, "\"%s\" directive in Job \"%s\" resource is required, but not found.\n", + Jmsg(NULL, M_FATAL, 0, "\"%s\" directive in Job \"%s\" resource is required, but not found.\n", job_items[i].name, job->hdr.name); OK = false; } } /* If this triggers, take a look at lib/parse_conf.h */ if (i >= MAX_RES_ITEMS) { - Emsg0(M_ERROR_TERM, 0, "Too many items in Job resource\n"); + Emsg0(M_ERROR_TERM, 0, "Too many items in Job resource\n"); } } } /* End loop over Job res */ @@ -621,10 +623,10 @@ static int check_resources() catalog->db_port, catalog->db_socket, catalog->mult_db_connections); if (!db || !db_open_database(NULL, db)) { - Jmsg(NULL, M_FATAL, 0, _("Could not open database \"%s\".\n"), + Jmsg(NULL, M_FATAL, 0, _("Could not open database \"%s\".\n"), catalog->db_name); if (db) { - Jmsg(NULL, M_FATAL, 0, _("%s"), db_strerror(db)); + Jmsg(NULL, M_FATAL, 0, _("%s"), db_strerror(db)); } OK = false; continue; @@ -655,7 +657,7 @@ static int check_resources() if (db_create_counter_record(NULL, db, &cr)) { counter->CurrentValue = cr.CurrentValue; counter->created = true; - Dmsg2(100, "Create counter %s val=%d\n", counter->hdr.name, counter->CurrentValue); + Dmsg2(100, "Create counter %s val=%d\n", counter->hdr.name, counter->CurrentValue); } } if (!counter->created) { -- 2.39.5