From a400aabdd394a3ac24668454baf3e128186b74ab Mon Sep 17 00:00:00 2001 From: Michal Rakowski Date: Fri, 14 May 2021 13:55:46 +0200 Subject: [PATCH] Fix #7628 About 'reload' command crashing the director This issue was not seen when trying to start the director with the same, broken config file. It's because we use different error codes for config parsing when the dir is being started and when we do the reload. For the startup, we use M_ERROR_TERM which in the end just stops the director. In case of reload we use M_ERROR (since we don't want the dir to stop in case of trying to load broken config), so the error from parsing config was not propagated anywhere (err msg was printed, but the parser's caller could be unaware about it). New field was added to inform about the error, besides printing err message. --- bacula/src/lib/ini.c | 2 ++ bacula/src/lib/lex.c | 2 ++ bacula/src/lib/lex.h | 3 +++ bacula/src/lib/parse_conf.c | 4 ++++ bacula/src/stored/parse_bsr.c | 2 ++ 5 files changed, 13 insertions(+) diff --git a/bacula/src/lib/ini.c b/bacula/src/lib/ini.c index f79f3b1dd..2a0c86f00 100644 --- a/bacula/src/lib/ini.c +++ b/bacula/src/lib/ini.c @@ -112,6 +112,8 @@ static void s_err(const char *file, int line, LEX *lc, const char *msg, ...) " : Line %d, col %d of file %s\n%s\n"), buf, lc->line_no, lc->col_no, lc->fname, lc->line); } + + lc->last_result = -1; } /* Reset free items */ diff --git a/bacula/src/lib/lex.c b/bacula/src/lib/lex.c index b58a79738..33a9b638f 100644 --- a/bacula/src/lib/lex.c +++ b/bacula/src/lib/lex.c @@ -104,6 +104,8 @@ static void s_err(const char *file, int line, LEX *lc, const char *msg, ...) } else { e_msg(file, line, lc->err_type, 0, _("Config error: %s\n"), buf); } + + lc->last_result = -1; } void lex_set_default_error_handler(LEX *lf) diff --git a/bacula/src/lib/lex.h b/bacula/src/lib/lex.h index f9b2f163d..e0568e5a0 100644 --- a/bacula/src/lib/lex.h +++ b/bacula/src/lib/lex.h @@ -113,6 +113,9 @@ typedef struct s_lex_context { uint64_t pint64_val2; void (*scan_error)(const char *file, int line, struct s_lex_context *lc, const char *msg, ...); int err_type; /* message level for scan_error (M_..) */ + /* TODO change the config scanning helpers to be non-void, add handling of it's return value */ + int last_result; /* Result of last scanning. Error code is set whenerver any of the + 'scan_err' macros is called. */ void *caller_ctx; /* caller private data */ BPIPE *bpipe; /* set if we are piping */ } LEX; diff --git a/bacula/src/lib/parse_conf.c b/bacula/src/lib/parse_conf.c index e7dbb63ed..ab5235b02 100644 --- a/bacula/src/lib/parse_conf.c +++ b/bacula/src/lib/parse_conf.c @@ -1630,6 +1630,10 @@ bool CONFIG::parse_config() Dmsg1(800, "calling handler for %s\n", items[i].name); /* Call item handler */ items[i].handler(lc, &items[i], i, pass); + if (lc->last_result != 0) { + /* Error during parsing, message has already been printed, now we have to bail out */ + goto bail_out; + } i = -1; break; } diff --git a/bacula/src/stored/parse_bsr.c b/bacula/src/stored/parse_bsr.c index bb5c41992..1214a542c 100644 --- a/bacula/src/stored/parse_bsr.c +++ b/bacula/src/stored/parse_bsr.c @@ -1068,4 +1068,6 @@ static void s_err(const char *file, int line, LEX *lc, const char *msg, ...) " : Line %d, col %d of file %s\n%s\n"), buf, lc->line_no, lc->col_no, lc->fname, lc->line); } + + lc->last_result = -1; } -- 2.47.3