logging: fix modules ordering during logging

With the previous code the order of the logging modules in the
YAML were determining which module was run first. This was not
wished and a consequences was that the EVE fileinfo module was
not correctly displaying the key 'stored' because it was
depending on a flag set alter by the filestore module.

This patch adds a priority file to the TmModule structure. The
higher the priority is set, the sooner the module is run in the
logging process. The RunModeOutput structure has also been
updated to contain the name of the original TmModule. Thus allowing
to define a priority for a RunModeOutput.

Currently only the filestore has a priority set. The rest of them is
set to the default value of zero.
pull/1523/head
Eric Leblond 10 years ago committed by Victor Julien
parent be07620a60
commit d837562441

@ -485,6 +485,7 @@ void TmModuleLogFilestoreRegister (void)
tmm_modules[TMM_FILESTORE].RegisterTests = NULL; tmm_modules[TMM_FILESTORE].RegisterTests = NULL;
tmm_modules[TMM_FILESTORE].cap_flags = 0; tmm_modules[TMM_FILESTORE].cap_flags = 0;
tmm_modules[TMM_FILESTORE].flags = TM_FLAG_LOGAPI_TM; tmm_modules[TMM_FILESTORE].flags = TM_FLAG_LOGAPI_TM;
tmm_modules[TMM_FILESTORE].priority = 10;
OutputRegisterFiledataModule(MODULE_NAME, "file", LogFilestoreLogInitCtx, OutputRegisterFiledataModule(MODULE_NAME, "file", LogFilestoreLogInitCtx,
LogFilestoreLogger); LogFilestoreLogger);

@ -72,6 +72,7 @@ typedef struct RunModes_ {
* A list of output modules that will be active for the run mode. * A list of output modules that will be active for the run mode.
*/ */
typedef struct RunModeOutput_ { typedef struct RunModeOutput_ {
const char *name;
TmModule *tm_module; TmModule *tm_module;
OutputCtx *output_ctx; OutputCtx *output_ctx;
@ -506,6 +507,32 @@ static void AddOutputToFreeList(OutputModule *module, OutputCtx *output_ctx)
TAILQ_INSERT_TAIL(&output_free_list, fl_output, entries); TAILQ_INSERT_TAIL(&output_free_list, fl_output, entries);
} }
static int GetRunModeOutputPriority(RunModeOutput *module)
{
TmModule *tm = TmModuleGetByName(module->name);
if (tm == NULL)
return 0;
return tm->priority;
}
static void InsertInRunModeOutputs(RunModeOutput *runmode_output)
{
RunModeOutput *r_output = NULL;
int output_priority = GetRunModeOutputPriority(runmode_output);
TAILQ_FOREACH(r_output, &RunModeOutputs, entries) {
if (GetRunModeOutputPriority(r_output) < output_priority)
break;
}
if (r_output) {
TAILQ_INSERT_BEFORE(r_output, runmode_output, entries);
} else {
TAILQ_INSERT_TAIL(&RunModeOutputs, runmode_output, entries);
}
}
/** \brief Turn output into thread module */ /** \brief Turn output into thread module */
static void SetupOutput(const char *name, OutputModule *module, OutputCtx *output_ctx) static void SetupOutput(const char *name, OutputModule *module, OutputCtx *output_ctx)
{ {
@ -546,9 +573,10 @@ static void SetupOutput(const char *name, OutputModule *module, OutputCtx *outpu
RunModeOutput *runmode_output = SCCalloc(1, sizeof(RunModeOutput)); RunModeOutput *runmode_output = SCCalloc(1, sizeof(RunModeOutput));
if (unlikely(runmode_output == NULL)) if (unlikely(runmode_output == NULL))
return; return;
runmode_output->name = module->name;
runmode_output->tm_module = pkt_logger_module; runmode_output->tm_module = pkt_logger_module;
runmode_output->output_ctx = NULL; runmode_output->output_ctx = NULL;
TAILQ_INSERT_TAIL(&RunModeOutputs, runmode_output, entries); InsertInRunModeOutputs(runmode_output);
SCLogDebug("__packet_logger__ added"); SCLogDebug("__packet_logger__ added");
} }
} else if (module->TxLogFunc) { } else if (module->TxLogFunc) {
@ -568,9 +596,10 @@ static void SetupOutput(const char *name, OutputModule *module, OutputCtx *outpu
RunModeOutput *runmode_output = SCCalloc(1, sizeof(RunModeOutput)); RunModeOutput *runmode_output = SCCalloc(1, sizeof(RunModeOutput));
if (unlikely(runmode_output == NULL)) if (unlikely(runmode_output == NULL))
return; return;
runmode_output->name = module->name;
runmode_output->tm_module = tx_logger_module; runmode_output->tm_module = tx_logger_module;
runmode_output->output_ctx = NULL; runmode_output->output_ctx = NULL;
TAILQ_INSERT_TAIL(&RunModeOutputs, runmode_output, entries); InsertInRunModeOutputs(runmode_output);
SCLogDebug("__tx_logger__ added"); SCLogDebug("__tx_logger__ added");
} }
} else if (module->FiledataLogFunc) { } else if (module->FiledataLogFunc) {
@ -589,9 +618,10 @@ static void SetupOutput(const char *name, OutputModule *module, OutputCtx *outpu
RunModeOutput *runmode_output = SCCalloc(1, sizeof(RunModeOutput)); RunModeOutput *runmode_output = SCCalloc(1, sizeof(RunModeOutput));
if (unlikely(runmode_output == NULL)) if (unlikely(runmode_output == NULL))
return; return;
runmode_output->name = module->name;
runmode_output->tm_module = filedata_logger_module; runmode_output->tm_module = filedata_logger_module;
runmode_output->output_ctx = NULL; runmode_output->output_ctx = NULL;
TAILQ_INSERT_TAIL(&RunModeOutputs, runmode_output, entries); InsertInRunModeOutputs(runmode_output);
SCLogDebug("__filedata_logger__ added"); SCLogDebug("__filedata_logger__ added");
} }
} else if (module->FileLogFunc) { } else if (module->FileLogFunc) {
@ -610,9 +640,10 @@ static void SetupOutput(const char *name, OutputModule *module, OutputCtx *outpu
RunModeOutput *runmode_output = SCCalloc(1, sizeof(RunModeOutput)); RunModeOutput *runmode_output = SCCalloc(1, sizeof(RunModeOutput));
if (unlikely(runmode_output == NULL)) if (unlikely(runmode_output == NULL))
return; return;
runmode_output->name = module->name;
runmode_output->tm_module = file_logger_module; runmode_output->tm_module = file_logger_module;
runmode_output->output_ctx = NULL; runmode_output->output_ctx = NULL;
TAILQ_INSERT_TAIL(&RunModeOutputs, runmode_output, entries); InsertInRunModeOutputs(runmode_output);
SCLogDebug("__file_logger__ added"); SCLogDebug("__file_logger__ added");
} }
} else if (module->StreamingLogFunc) { } else if (module->StreamingLogFunc) {
@ -632,9 +663,10 @@ static void SetupOutput(const char *name, OutputModule *module, OutputCtx *outpu
RunModeOutput *runmode_output = SCCalloc(1, sizeof(RunModeOutput)); RunModeOutput *runmode_output = SCCalloc(1, sizeof(RunModeOutput));
if (unlikely(runmode_output == NULL)) if (unlikely(runmode_output == NULL))
return; return;
runmode_output->name = module->name;
runmode_output->tm_module = streaming_logger_module; runmode_output->tm_module = streaming_logger_module;
runmode_output->output_ctx = NULL; runmode_output->output_ctx = NULL;
TAILQ_INSERT_TAIL(&RunModeOutputs, runmode_output, entries); InsertInRunModeOutputs(runmode_output);
SCLogDebug("__streaming_logger__ added"); SCLogDebug("__streaming_logger__ added");
} }
} else { } else {
@ -643,9 +675,10 @@ static void SetupOutput(const char *name, OutputModule *module, OutputCtx *outpu
RunModeOutput *runmode_output = SCCalloc(1, sizeof(RunModeOutput)); RunModeOutput *runmode_output = SCCalloc(1, sizeof(RunModeOutput));
if (unlikely(runmode_output == NULL)) if (unlikely(runmode_output == NULL))
return; return;
runmode_output->name = module->name;
runmode_output->tm_module = tm_module; runmode_output->tm_module = tm_module;
runmode_output->output_ctx = output_ctx; runmode_output->output_ctx = output_ctx;
TAILQ_INSERT_TAIL(&RunModeOutputs, runmode_output, entries); InsertInRunModeOutputs(runmode_output);
} }
} }

@ -61,6 +61,8 @@ typedef struct TmModule_ {
the given TmModule */ the given TmModule */
/* Other flags used by the module */ /* Other flags used by the module */
uint8_t flags; uint8_t flags;
/* priority in the logging order, higher priority is runned first */
uint8_t priority;
} TmModule; } TmModule;
TmModule tmm_modules[TMM_SIZE]; TmModule tmm_modules[TMM_SIZE];

Loading…
Cancel
Save