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
OutputModule *om = SCCalloc(1, sizeof(*om));
if (om == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "calloc() failed");
- continue;
+ goto error;
}
om->name = MODULE_NAME;
} 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
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) {
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;
}
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) {
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
#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);