introduce fatal error macro's

Add 'FatalError' and 'FatalErrorConditonal' that will take the same
args as SCLogError.

FatalError logs the error using SCLogError and then exits with return
code EXIT_FAILURE.

FatalErrorOnInit does the same only during init and with
--init-errors-fatal enabled, otherwise it just calls SCLogWarning. So
then the macro returns to the caller.

Implement this for output setup.
pull/1600/head
Victor Julien 10 years ago
parent 4dd53c8f03
commit 334e8656bf

@ -736,7 +736,7 @@ static OutputCtx *OutputLuaLogInit(ConfNode *conf)
int r = LuaScriptInit(path, &opts);
if (r != 0) {
SCLogError(SC_ERR_LUA_ERROR, "couldn't initialize scipt");
continue;
goto error;
}
/* create an OutputModule for this script, based
@ -744,7 +744,7 @@ static OutputCtx *OutputLuaLogInit(ConfNode *conf)
OutputModule *om = SCCalloc(1, sizeof(*om));
if (om == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "calloc() failed");
continue;
goto error;
}
om->name = MODULE_NAME;
@ -783,13 +783,22 @@ static OutputCtx *OutputLuaLogInit(ConfNode *conf)
} else {
SCLogError(SC_ERR_LUA_ERROR, "failed to setup thread module");
SCFree(om);
continue;
goto error;
}
TAILQ_INSERT_TAIL(&output_ctx->submodules, om, entries);
}
return output_ctx;
error:
if (output_ctx != NULL) {
if (output_ctx->DeInit && output_ctx->data)
output_ctx->DeInit(output_ctx->data);
SCFree(output_ctx);
}
return NULL;
}
/** \internal

@ -703,9 +703,8 @@ void RunModeInitializeOutputs(void)
output_config = ConfNodeLookupChild(output, output->val);
if (output_config == NULL) {
/* Shouldn't happen. */
SCLogError(SC_ERR_INVALID_ARGUMENT,
"Failed to lookup configuration child node: fast");
exit(1);
FatalError(SC_ERR_INVALID_ARGUMENT,
"Failed to lookup configuration child node: %s", output->val);
}
if (strcmp(output->val, "tls-store") == 0) {
@ -754,8 +753,8 @@ void RunModeInitializeOutputs(void)
OutputModule *module = OutputGetModuleByConfName(output->val);
if (module == NULL) {
SCLogWarning(SC_ERR_INVALID_ARGUMENT,
"No output module named %s, ignoring", output->val);
FatalErrorOnInit(SC_ERR_INVALID_ARGUMENT,
"No output module named %s", output->val);
continue;
}
@ -763,8 +762,7 @@ void RunModeInitializeOutputs(void)
if (module->InitFunc != NULL) {
output_ctx = module->InitFunc(output_config);
if (output_ctx == NULL) {
/* In most cases the init function will have logged the
* error. Maybe we should exit on init errors? */
FatalErrorOnInit(SC_ERR_INVALID_ARGUMENT, "output module setup failed");
continue;
}
} else if (module->InitSubFunc != NULL) {
@ -786,20 +784,18 @@ void RunModeInitializeOutputs(void)
OutputModule *sub_module = OutputGetModuleByConfName(subname);
if (sub_module == NULL) {
SCLogWarning(SC_ERR_INVALID_ARGUMENT,
"No output module named %s, ignoring", subname);
FatalErrorOnInit(SC_ERR_INVALID_ARGUMENT,
"No output module named %s", subname);
continue;
}
if (sub_module->parent_name == NULL ||
strcmp(sub_module->parent_name,output->val) != 0) {
SCLogWarning(SC_ERR_INVALID_ARGUMENT,
"bad parent for %s, ignoring", subname);
continue;
FatalError(SC_ERR_INVALID_ARGUMENT,
"bad parent for %s", subname);
}
if (sub_module->InitSubFunc == NULL) {
SCLogWarning(SC_ERR_INVALID_ARGUMENT,
"bad sub-module for %s, ignoring", subname);
continue;
FatalError(SC_ERR_INVALID_ARGUMENT,
"bad sub-module for %s", subname);
}
ConfNode *sub_output_config = ConfNodeLookupChild(type, type->val);
// sub_output_config may be NULL if no config

@ -507,6 +507,24 @@ extern int sc_log_module_cleaned;
#endif /* DEBUG */
#define FatalError(x, ...) do { \
SCLogError(x, __VA_ARGS__); \
exit(EXIT_FAILURE); \
} while(0)
/** \brief Fatal error IF we're starting up, and configured to consider
* errors to be fatal errors */
#define FatalErrorOnInit(x, ...) do { \
int init_errors_fatal = 0; \
ConfGetBool("engine.init-failure-fatal", &init_errors_fatal); \
if (init_errors_fatal && (SC_ATOMIC_GET(engine_stage) == SURICATA_INIT))\
{ \
SCLogError(x, __VA_ARGS__); \
exit(EXIT_FAILURE); \
} \
SCLogWarning(x, __VA_ARGS__); \
} while(0)
SCLogInitData *SCLogAllocLogInitData(void);

Loading…
Cancel
Save