]> git.sur5r.net Git - bacula/bacula/commitdiff
- fix : reload a bad configuration file doesn't kill director any more
authorEric Bollengier <eric@eb.homelinux.org>
Sun, 30 Apr 2006 17:14:27 +0000 (17:14 +0000)
committerEric Bollengier <eric@eb.homelinux.org>
Sun, 30 Apr 2006 17:14:27 +0000 (17:14 +0000)
o add an extra field to LEX err_type (M_ERROR, M_ERROR_TERM...)
o add lex_set_default_error_handler() to set lex->err_type
o add an extra option (message level) to parse_config()

git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@2989 91ce42f0-d328-0410-95d8-f526ca767f89

bacula/src/dird/dird.c
bacula/src/lib/lex.c
bacula/src/lib/lex.h
bacula/src/lib/parse_conf.c
bacula/src/lib/parse_conf.h
bacula/src/lib/protos.h

index a6e45638490fec3eb4cb02e001a3ec6f9dc019e9..57b5fee1ed324029be9074be3dcef3ce4bd5ea28 100644 (file)
@@ -401,7 +401,7 @@ void reload_config(int sig)
    reload_table[table].res_table = save_config_resources();
    Dmsg1(100, "Saved old config in table %d\n", table);
 
-   ok = parse_config(configfile, 0);  /* no exit on error */
+   ok = parse_config(configfile, 0, M_ERROR);  /* no exit on error */
 
    Dmsg0(100, "Reloaded config file\n");
    if (!ok || !check_resources()) {
index ce5f5194233f7e77926bf3a28f1c52ce97d499f9..0df090f09bb4be972ac8a9e380cc8f04b779c1a7 100644 (file)
@@ -74,6 +74,10 @@ static void s_err(const char *file, int line, LEX *lc, const char *msg, ...)
    bvsnprintf(buf, sizeof(buf), msg, arg_ptr);
    va_end(arg_ptr);
 
+   if (lc->err_type == 0) {    /* M_ERROR_TERM by default */
+      lc->err_type = M_ERROR_TERM;
+   }
+
    if (lc->line_no > lc->begin_line_no) {
       bsnprintf(more, sizeof(more),
                 _("Problem probably begins at line %d.\n"), lc->begin_line_no);
@@ -81,11 +85,11 @@ static void s_err(const char *file, int line, LEX *lc, const char *msg, ...)
       more[0] = 0;
    }  
    if (lc->line_no > 0) {
-      e_msg(file, line, M_ERROR_TERM, 0, _("Config error: %s\n"
+      e_msg(file, line, lc->err_type, 0, _("Config error: %s\n"
 "            : line %d, col %d of file %s\n%s\n%s"),
          buf, lc->line_no, lc->col_no, lc->fname, lc->line, more);
    } else {
-      e_msg(file, line, M_ERROR_TERM, 0, _("Config error: %s\n"), buf);
+      e_msg(file, line, lc->err_type, 0, _("Config error: %s\n"), buf);
    }
 }
 
@@ -94,6 +98,16 @@ void lex_set_default_error_handler(LEX *lf)
    lf->scan_error = s_err;
 }
 
+/*
+ * Set err_type used in error_handler
+ * return the old value
+ */
+int lex_set_error_handler_error_type(LEX *lf, int err_type)
+{
+   int old = lf->err_type;
+   lf->err_type = err_type;
+   return old;
+}
 
 /*
  * Free the current file, and retrieve the contents
@@ -156,6 +170,7 @@ LEX *lex_open_file(LEX *lf, const char *filename, LEX_ERROR_HANDLER *scan_error)
    } else {
       lf = nf;                        /* start new packet */
       memset(lf, 0, sizeof(LEX));
+      lex_set_error_handler_error_type(lf, M_ERROR_TERM);
    }
    if (scan_error) {
       lf->scan_error = scan_error;
index e293a3a70ad85eb6b75e9c8e9b4243cabd77c9be..c4ab32434608bc6fe77fbdb384cf4cfe13956617 100644 (file)
@@ -101,6 +101,7 @@ typedef struct s_lex_context {
    int32_t int32_val;
    int64_t int64_val;
    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_..) */
    void *caller_ctx;                  /* caller private data */
 } LEX;
 
index 23288ead62b05b3f683fcb1d5c47d4d9a0ca272f..204a5b937d9aafc345d8418eb3d6f3e86596ff17 100755 (executable)
@@ -759,7 +759,7 @@ enum parse_state {
  *  scan_error handler is to die on an error.
  */
 int
-parse_config(const char *cf, LEX_ERROR_HANDLER *scan_error)
+parse_config(const char *cf, LEX_ERROR_HANDLER *scan_error, int err_type)
 {
    LEX *lc = NULL;
    int token, i, pass;
@@ -784,6 +784,7 @@ parse_config(const char *cf, LEX_ERROR_HANDLER *scan_error)
          } else {
             lex_set_default_error_handler(lc);
          }
+         lex_set_error_handler_error_type(lc, err_type) ;
          bstrncpy(lc->str, cf, sizeof(lc->str));
          lc->fname = lc->str;
          scan_err2(lc, _("Cannot open config file \"%s\": %s\n"),
@@ -791,6 +792,7 @@ parse_config(const char *cf, LEX_ERROR_HANDLER *scan_error)
          free(lc);
          return 0;
       }
+      lex_set_error_handler_error_type(lc, err_type) ;
       while ((token=lex_get_token(lc, T_ALL)) != T_EOF) {
          Dmsg1(900, "parse got token=%s\n", lex_tok_to_str(token));
          switch (state) {
index 4943f6abe66c195fe025f341687b4376f4b54008..1c4f2e3923a9977a8d6282b87d0100b76efb4432 100644 (file)
@@ -91,7 +91,7 @@ union CURES {
 
 
 /* Configuration routines */
-int   parse_config(const char *cf, LEX_ERROR_HANDLER *scan_error = NULL);
+int   parse_config(const char *cf, LEX_ERROR_HANDLER *scan_error = NULL, int err_type=M_ERROR_TERM);
 void    free_config_resources(void);
 RES   **save_config_resources(void);
 RES   **new_res_head();
index ede58ef2343be3da04447d52610b6418225edc8a..6f6c1ed4cdd17a08491799fe1cf8a942ffbce1d4 100644 (file)
@@ -192,6 +192,7 @@ void      lex_unget_char         (LEX *lf);
 const char *  lex_tok_to_str     (int token);
 int       lex_get_token          (LEX *lf, int expect);
 void      lex_set_default_error_handler (LEX *lf);
+int       lex_set_error_handler_error_type (LEX *lf, int err_type);
 
 /* message.c */
 void       my_name_is            (int argc, char *argv[], const char *name);