diff options
author | Rainer Gerhards <rgerhards@adiscon.com> | 2011-07-12 12:14:47 +0200 |
---|---|---|
committer | Rainer Gerhards <rgerhards@adiscon.com> | 2011-07-12 12:14:47 +0200 |
commit | a5bc2a8b4bdf8b7834326ae6410c3bc7285fa1e8 (patch) | |
tree | ea303676c318c2161a4a89606cbb6449bb40a88e | |
parent | 80701b698802efe1bcecac09afcd393dd4bd3d5c (diff) | |
download | rsyslog-a5bc2a8b4bdf8b7834326ae6410c3bc7285fa1e8.tar.gz rsyslog-a5bc2a8b4bdf8b7834326ae6410c3bc7285fa1e8.tar.xz rsyslog-a5bc2a8b4bdf8b7834326ae6410c3bc7285fa1e8.zip |
removed emergency config, do error reporting on fatal config file error
-rw-r--r-- | grammar/lexer.l | 8 | ||||
-rw-r--r-- | grammar/parserif.h | 1 | ||||
-rw-r--r-- | runtime/rsconf.c | 101 | ||||
-rw-r--r-- | runtime/rsyslog.h | 1 | ||||
-rw-r--r-- | tests/testsuites/imtcp_conndrop.conf | 2 | ||||
-rw-r--r-- | tools/syslogd.c | 2 |
6 files changed, 24 insertions, 91 deletions
diff --git a/grammar/lexer.l b/grammar/lexer.l index d56b4fc2..0c82a4af 100644 --- a/grammar/lexer.l +++ b/grammar/lexer.l @@ -75,7 +75,7 @@ struct bufstack { es_str_t *estr; } *currbs = NULL; -char *currfn; /* name of currently processed file */ +char *cnfcurrfn; /* name of currently processed file */ int popfile(void); int cnfSetLexFile(char *fname); @@ -220,7 +220,7 @@ cnfParseBuffer(char *buf, unsigned lenBuf) bs->bs = yy_scan_buffer(buf, lenBuf); bs->estr = NULL; currbs = bs; - currfn = bs->fn; + cnfcurrfn = bs->fn; yylineno = 1; done: return r; } @@ -259,7 +259,7 @@ cnfSetLexFile(char *fname) bs->bs = yy_scan_buffer((char*)es_getBufAddr(str), es_strlen(str)); bs->estr = str; /* needed so we can free it later */ currbs = bs; - currfn = bs->fn; + cnfcurrfn = bs->fn; yylineno = 1; done: @@ -294,6 +294,6 @@ popfile(void) yy_switch_to_buffer(currbs->bs); yylineno = currbs->lineno; - currfn = currbs->fn; + cnfcurrfn = currbs->fn; return 0; } diff --git a/grammar/parserif.h b/grammar/parserif.h index bebb1dfb..58b8fbdd 100644 --- a/grammar/parserif.h +++ b/grammar/parserif.h @@ -4,6 +4,7 @@ int cnfSetLexFile(char*); int yyparse(); int yydebug; +char *cnfcurrfn; void dbgprintf(char *fmt, ...) __attribute__((format(printf, 1, 2))); void parser_errmsg(char *fmt, ...) __attribute__((format(printf, 1, 2))); diff --git a/runtime/rsconf.c b/runtime/rsconf.c index 2f0287c2..5df4c2c8 100644 --- a/runtime/rsconf.c +++ b/runtime/rsconf.c @@ -335,13 +335,14 @@ void parser_errmsg(char *fmt, ...) { va_list ap; + char errBuf[1024]; + va_start(ap, fmt); - // TODO: create useful code ;) 2011-07-06 - errmsg.LogError(0, NO_ERRCODE, "error during parsing on or before line %d", - yylineno); -dbgprintf("error on or before line %d: ", yylineno); - vprintf(fmt, ap); - printf("\n"); + if(vsnprintf(errBuf, sizeof(errBuf), fmt, ap) == sizeof(errBuf)) + errBuf[1024] = '\0'; + errmsg.LogError(0, RS_RET_CONF_PARSE_ERROR, + "error during parsing file %s, on or before line %d: %s", + cnfcurrfn, yylineno, errBuf); va_end(ap); } @@ -1206,56 +1207,6 @@ validateConf(void) } -#if 0 -/* create an emergency rule */ -static inline rsRetVal -createEmergRule(char *PRIFilt, char *legact) -{ - rule_t *pRule; - action_t *pAction; - DEFiRet; - - CHKiRet(rule.Construct(&pRule)); /* create "fresh" selector */ - CHKiRet(rule.SetAssRuleset(pRule, ruleset.GetCurrent(loadConf))); - CHKiRet(rule.ConstructFinalize(pRule)); - CHKiRet(cflineProcessTradPRIFilter((uchar**)&PRIFilt, pRule)); - iRet = cflineDoAction(loadConf, (uchar**)&legact, &pAction); - iRet = llAppend(&(pRule)->llActList, NULL, (void*) pAction); - CHKiRet(ruleset.AddRule(loadConf, rule.GetAssRuleset(pRule), &pRule)); - -finalize_it: - RETiRet; -} - - -/* start up an rsyslog emergency configuration. This is recovery if - * the config failed. - */ -static inline rsRetVal -createEmergConf(void) -{ - DEFiRet; - errmsg.LogError(0, NO_ERRCODE, "EMERGENCY CONFIGURATION ACTIVATED - " - "fix rsyslog config file!"); - /* - CHKiRet(rsconfConstruct(&loadConf)); -ourConf = loadConf; // TODO: remove, once ourConf is gone! - CHKiRet(loadBuildInModules()); - CHKiRet(initLegacyConf()); - */ - ruleset.SetDefaultRuleset(loadConf, (uchar*) "RSYSLOG_DefaultRuleset"); - - CHKiRet(createEmergRule("*.err", _PATH_CONSOLE)); - CHKiRet(createEmergRule("syslog.*", _PATH_CONSOLE)); - CHKiRet(createEmergRule("*.panic", ":omusrmsg:*")); - CHKiRet(createEmergRule("syslog.*", ":omusrmsg:root")); -CHKiRet(createEmergRule("*.*", "/tmp/emerg")); -finalize_it: - RETiRet; -} -#endif - - /* Load a configuration. This will do all necessary steps to create * the in-memory representation of the configuration, including support * for multiple configuration languages. @@ -1266,9 +1217,7 @@ finalize_it: rsRetVal load(rsconf_t **cnf, uchar *confFile) { - rsRetVal localRet; int iNbrActions; - int bHadConfigErr = 0; int r; DEFiRet; @@ -1286,37 +1235,19 @@ ourConf = loadConf; // TODO: remove, once ourConf is gone! } if(r == 1) { - errmsg.LogError(0, localRet, "CONFIG ERROR: could not interpret master config file '%s'.", confFile); - bHadConfigErr = 1; + errmsg.LogError(0, RS_RET_CONF_PARSE_ERROR, + "CONFIG ERROR: could not interpret master " + "config file '%s'.", confFile); + ABORT_FINALIZE(RS_RET_CONF_PARSE_ERROR); } else if(iNbrActions == 0) { - errmsg.LogError(0, RS_RET_NO_ACTIONS, "CONFIG ERROR: there are no active actions configured. Inputs will " - "run, but no output whatsoever is created."); - bHadConfigErr = 1; - } - - if(r == 1 || iNbrActions == 0) { - /* rgerhards: this code is executed to set defaults when the - * config file could not be opened. We might think about - * abandoning the run in this case - but this, too, is not - * very clever... So we stick with what we have. - * We ignore any errors while doing this - we would be lost anyhow... - */ - // TODO: think about this! iRet = createEmergConf(); - if(1) { //if(iRet != RS_RET_OK) { - fprintf(stderr, "rsyslogd: could not even activate emergency " - "conf - terminating\n"); - exit(1); - } + errmsg.LogError(0, RS_RET_NO_ACTIONS, "CONFIG ERROR: there are no " + "active actions configured. Inputs will " + "run, but no output whatsoever is created."); + ABORT_FINALIZE(RS_RET_NO_ACTIONS); } CHKiRet(validateConf()); - - /* return warning state if we had some acceptable problems */ - if(bHadConfigErr) { - iRet = RS_RET_NONFATAL_CONFIG_ERR; - } - /* we are done checking the config - now validate if we should actually run or not. * If not, terminate. -- rgerhards, 2008-07-25 * TODO: iConfigVerify -- should it be pulled from the config, or leave as is (option)? @@ -1331,7 +1262,7 @@ ourConf = loadConf; // TODO: remove, once ourConf is gone! *cnf = loadConf; // TODO: enable this once all config code is moved to here! loadConf = NULL; - dbgprintf("rsyslog finished loading initial config %p\n", loadConf); + dbgprintf("rsyslog finished loading master config %p\n", loadConf); rsconfDebugPrint(loadConf); finalize_it: diff --git a/runtime/rsyslog.h b/runtime/rsyslog.h index d1290aeb..05f45565 100644 --- a/runtime/rsyslog.h +++ b/runtime/rsyslog.h @@ -359,6 +359,7 @@ enum rsRetVal_ /** return value. All methods return this if not specified oth RS_RET_CMD_GONE_AWAY = -2204,/**< config directive existed, but no longer supported */ RS_RET_ERR_SCHED_PARAMS = -2205,/**< there is a problem with configured thread scheduling params */ RS_RET_SOCKNAME_MISSING = -2206,/**< no socket name configured where one is required */ + RS_RET_CONF_PARSE_ERROR = -2207,/**< (fatal) error parsing config file */ /* RainerScript error messages (range 1000.. 1999) */ RS_RET_SYSVAR_NOT_FOUND = 1001, /**< system variable could not be found (maybe misspelled) */ diff --git a/tests/testsuites/imtcp_conndrop.conf b/tests/testsuites/imtcp_conndrop.conf index de41bc43..c1508525 100644 --- a/tests/testsuites/imtcp_conndrop.conf +++ b/tests/testsuites/imtcp_conndrop.conf @@ -12,4 +12,4 @@ $template dynfile,"rsyslog.out.log" # trick to use relative path names! $OMFileFlushOnTXEnd off $OMFileFlushInterval 2 $OMFileIOBufferSize 256k -local0.* ?dynfile;outfmt +0local0.* ?dynfile;outfmt diff --git a/tools/syslogd.c b/tools/syslogd.c index 45abf1a7..72c0bdb3 100644 --- a/tools/syslogd.c +++ b/tools/syslogd.c @@ -2243,7 +2243,7 @@ finalize_it: if(iRet == RS_RET_VALIDATION_RUN) { fprintf(stderr, "rsyslogd: End of config validation run. Bye.\n"); } else if(iRet != RS_RET_OK) { - fprintf(stderr, "rsyslogd run failed with error %d (see rsyslog.h " + fprintf(stderr, "rsyslogd: run failed with error %d (see rsyslog.h " "or try http://www.rsyslog.com/e/%d to learn what that number means)\n", iRet, iRet*-1); } |