]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
Fix #7628 About 'reload' command crashing the director
authorMichal Rakowski <michal.rakowski@baculasystems.com>
Fri, 14 May 2021 11:55:46 +0000 (13:55 +0200)
committerEric Bollengier <eric@baculasystems.com>
Thu, 24 Mar 2022 08:03:02 +0000 (09:03 +0100)
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
bacula/src/lib/lex.c
bacula/src/lib/lex.h
bacula/src/lib/parse_conf.c
bacula/src/stored/parse_bsr.c

index f79f3b1dd05db49fe906f59887b99ff586dda01a..2a0c86f00192357881b51085551a0d22f8d46724 100644 (file)
@@ -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 */
index b58a7973855f2a60aacd0e02033cd5af679442cf..33a9b638f84f3bd2a3c19773f84ec32f2c520f3b 100644 (file)
@@ -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)
index f9b2f163d145e73c2b38c7b4b1aed6542734ebdd..e0568e5a01c35e335d326c2fa8e72eb3ab3c0a08 100644 (file)
@@ -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;
index e7dbb63ed007742bfc4785d426dc25f05b6356d3..ab5235b02112a2585ce2cf8f4671cbddd1e95ba0 100644 (file)
@@ -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;
                   }
index bb5c419924c36b045618c5a19ea9e58925b65330..1214a542c078da2c0460d9c2c7c0dba3532bb6d1 100644 (file)
@@ -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;
 }