From: Eric Bollengier Date: Sun, 30 Apr 2006 17:14:27 +0000 (+0000) Subject: - fix : reload a bad configuration file doesn't kill director any more X-Git-Tag: Release-2.0.0~891 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=38968fcbc46d46096f95662efdb4e4d307369efe;p=bacula%2Fbacula - fix : reload a bad configuration file doesn't kill director any more 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 --- diff --git a/bacula/src/dird/dird.c b/bacula/src/dird/dird.c index a6e4563849..57b5fee1ed 100644 --- a/bacula/src/dird/dird.c +++ b/bacula/src/dird/dird.c @@ -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()) { diff --git a/bacula/src/lib/lex.c b/bacula/src/lib/lex.c index ce5f519423..0df090f09b 100644 --- a/bacula/src/lib/lex.c +++ b/bacula/src/lib/lex.c @@ -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; diff --git a/bacula/src/lib/lex.h b/bacula/src/lib/lex.h index e293a3a70a..c4ab324346 100644 --- a/bacula/src/lib/lex.h +++ b/bacula/src/lib/lex.h @@ -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; diff --git a/bacula/src/lib/parse_conf.c b/bacula/src/lib/parse_conf.c index 23288ead62..204a5b937d 100755 --- a/bacula/src/lib/parse_conf.c +++ b/bacula/src/lib/parse_conf.c @@ -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) { diff --git a/bacula/src/lib/parse_conf.h b/bacula/src/lib/parse_conf.h index 4943f6abe6..1c4f2e3923 100644 --- a/bacula/src/lib/parse_conf.h +++ b/bacula/src/lib/parse_conf.h @@ -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(); diff --git a/bacula/src/lib/protos.h b/bacula/src/lib/protos.h index ede58ef234..6f6c1ed4cd 100644 --- a/bacula/src/lib/protos.h +++ b/bacula/src/lib/protos.h @@ -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);