From: Jason Ish Date: Fri, 27 May 2016 18:55:50 +0000 (-0600) Subject: logging: convert file data logging to non-thread module X-Git-Tag: suricata-3.2beta1~368 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=60b6ccc3c40696cae23ae3a49bd2aa46b6ac565e;p=thirdparty%2Fsuricata.git logging: convert file data logging to non-thread module --- diff --git a/src/log-filestore.c b/src/log-filestore.c index 15c7c9a586..80c32dfd0a 100644 --- a/src/log-filestore.c +++ b/src/log-filestore.c @@ -481,20 +481,12 @@ static OutputCtx *LogFilestoreLogInitCtx(ConfNode *conf) void TmModuleLogFilestoreRegister (void) { - tmm_modules[TMM_FILESTORE].name = MODULE_NAME; - tmm_modules[TMM_FILESTORE].ThreadInit = LogFilestoreLogThreadInit; - tmm_modules[TMM_FILESTORE].Func = NULL; - tmm_modules[TMM_FILESTORE].ThreadExitPrintStats = LogFilestoreLogExitPrintStats; - tmm_modules[TMM_FILESTORE].ThreadDeinit = LogFilestoreLogThreadDeinit; - tmm_modules[TMM_FILESTORE].RegisterTests = NULL; - tmm_modules[TMM_FILESTORE].cap_flags = 0; - tmm_modules[TMM_FILESTORE].flags = TM_FLAG_LOGAPI_TM; - tmm_modules[TMM_FILESTORE].priority = 10; - OutputRegisterFiledataModule(MODULE_NAME, "file", LogFilestoreLogInitCtx, - LogFilestoreLogger); - OutputRegisterFiledataModule(MODULE_NAME, "file-store", LogFilestoreLogInitCtx, - LogFilestoreLogger); + LogFilestoreLogger, LogFilestoreLogThreadInit, + LogFilestoreLogThreadDeinit, LogFilestoreLogExitPrintStats); + OutputRegisterFiledataModule(MODULE_NAME, "file-store", + LogFilestoreLogInitCtx, LogFilestoreLogger, LogFilestoreLogThreadInit, + LogFilestoreLogThreadDeinit, LogFilestoreLogExitPrintStats); SCLogDebug("registered"); } diff --git a/src/output-filedata.c b/src/output-filedata.c index 43f36c0664..828dac2384 100644 --- a/src/output-filedata.c +++ b/src/output-filedata.c @@ -52,6 +52,9 @@ typedef struct OutputFiledataLogger_ { struct OutputFiledataLogger_ *next; const char *name; TmmId module_id; + ThreadInitFunc ThreadInit; + ThreadDeinitFunc ThreadDeinit; + ThreadExitPrintStatsFunc ThreadExitPrintStats; } OutputFiledataLogger; static OutputFiledataLogger *list = NULL; @@ -60,11 +63,16 @@ static SCMutex g_waldo_mutex = SCMUTEX_INITIALIZER; static int g_waldo_init = 0; static int g_waldo_deinit = 0; -int OutputRegisterFiledataLogger(const char *name, FiledataLogger LogFunc, OutputCtx *output_ctx) +int OutputRegisterFiledataLogger(const char *name, FiledataLogger LogFunc, + OutputCtx *output_ctx, ThreadInitFunc ThreadInit, + ThreadDeinitFunc ThreadDeinit, + ThreadExitPrintStatsFunc ThreadExitPrintStats) { +#if 0 int module_id = TmModuleGetIdByName(name); if (module_id < 0) return -1; +#endif OutputFiledataLogger *op = SCMalloc(sizeof(*op)); if (op == NULL) @@ -74,7 +82,12 @@ int OutputRegisterFiledataLogger(const char *name, FiledataLogger LogFunc, Outpu op->LogFunc = LogFunc; op->output_ctx = output_ctx; op->name = name; +#if 0 op->module_id = (TmmId) module_id; +#endif + op->ThreadInit = ThreadInit; + op->ThreadDeinit = ThreadDeinit; + op->ThreadExitPrintStats = ThreadExitPrintStats; if (list == NULL) list = op; @@ -299,16 +312,9 @@ static TmEcode OutputFiledataLogThreadInit(ThreadVars *tv, void *initdata, void OutputFiledataLogger *logger = list; while (logger) { - TmModule *tm_module = TmModuleGetByName((char *)logger->name); - if (tm_module == NULL) { - SCLogError(SC_ERR_INVALID_ARGUMENT, - "TmModuleGetByName for %s failed", logger->name); - exit(EXIT_FAILURE); - } - - if (tm_module->ThreadInit) { + if (logger->ThreadInit) { void *retptr = NULL; - if (tm_module->ThreadInit(tv, (void *)logger->output_ctx, &retptr) == TM_ECODE_OK) { + if (logger->ThreadInit(tv, (void *)logger->output_ctx, &retptr) == TM_ECODE_OK) { OutputLoggerThreadStore *ts = SCMalloc(sizeof(*ts)); /* todo */ BUG_ON(ts == NULL); memset(ts, 0x00, sizeof(*ts)); @@ -391,15 +397,8 @@ static TmEcode OutputFiledataLogThreadDeinit(ThreadVars *tv, void *thread_data) OutputFiledataLogger *logger = list; while (logger && store) { - TmModule *tm_module = TmModuleGetByName((char *)logger->name); - if (tm_module == NULL) { - SCLogError(SC_ERR_INVALID_ARGUMENT, - "TmModuleGetByName for %s failed", logger->name); - exit(EXIT_FAILURE); - } - - if (tm_module->ThreadDeinit) { - tm_module->ThreadDeinit(tv, store->thread_data); + if (logger->ThreadDeinit) { + logger->ThreadDeinit(tv, store->thread_data); } OutputLoggerThreadStore *next_store = store->next; @@ -429,15 +428,8 @@ static void OutputFiledataLogExitPrintStats(ThreadVars *tv, void *thread_data) OutputFiledataLogger *logger = list; while (logger && store) { - TmModule *tm_module = TmModuleGetByName((char *)logger->name); - if (tm_module == NULL) { - SCLogError(SC_ERR_INVALID_ARGUMENT, - "TmModuleGetByName for %s failed", logger->name); - exit(EXIT_FAILURE); - } - - if (tm_module->ThreadExitPrintStats) { - tm_module->ThreadExitPrintStats(tv, store->thread_data); + if (logger->ThreadExitPrintStats) { + logger->ThreadExitPrintStats(tv, store->thread_data); } logger = logger->next; diff --git a/src/output-filedata.h b/src/output-filedata.h index 3a0a5d4341..c9478990aa 100644 --- a/src/output-filedata.h +++ b/src/output-filedata.h @@ -41,7 +41,9 @@ typedef int (*FiledataLogger)(ThreadVars *, void *thread_data, const Packet *, */ //typedef int (*TxLogCondition)(ThreadVars *, const Packet *); -int OutputRegisterFiledataLogger(const char *name, FiledataLogger LogFunc, OutputCtx *); +int OutputRegisterFiledataLogger(const char *name, FiledataLogger LogFunc, + OutputCtx *, ThreadInitFunc ThreadInit, ThreadDeinitFunc ThreadDeinit, + ThreadExitPrintStatsFunc ThreadExitPrintStats); void TmModuleFiledataLoggerRegister (void); diff --git a/src/output.c b/src/output.c index b1262c06a4..1650995d86 100644 --- a/src/output.c +++ b/src/output.c @@ -424,7 +424,9 @@ error: */ void OutputRegisterFiledataModule(const char *name, const char *conf_name, - OutputCtx *(*InitFunc)(ConfNode *), FiledataLogger FiledataLogFunc) + OutputCtx *(*InitFunc)(ConfNode *), FiledataLogger FiledataLogFunc, + ThreadInitFunc ThreadInit, ThreadDeinitFunc ThreadDeinit, + ThreadExitPrintStatsFunc ThreadExitPrintStats) { if (unlikely(FiledataLogFunc == NULL)) { goto error; @@ -439,6 +441,9 @@ OutputRegisterFiledataModule(const char *name, const char *conf_name, module->conf_name = conf_name; module->InitFunc = InitFunc; module->FiledataLogFunc = FiledataLogFunc; + module->ThreadInit = ThreadInit; + module->ThreadDeinit = ThreadDeinit; + module->ThreadExitPrintStats = ThreadExitPrintStats; TAILQ_INSERT_TAIL(&output_modules, module, entries); SCLogDebug("Filedata logger \"%s\" registered.", name); @@ -459,7 +464,9 @@ error: void OutputRegisterFiledataSubModule(const char *parent_name, const char *name, const char *conf_name, OutputCtx *(*InitFunc)(ConfNode *, OutputCtx *), - FiledataLogger FiledataLogFunc) + FiledataLogger FiledataLogFunc, ThreadInitFunc ThreadInit, + ThreadDeinitFunc ThreadDeinit, + ThreadExitPrintStatsFunc ThreadExitPrintStats) { if (unlikely(FiledataLogFunc == NULL)) { goto error; @@ -475,6 +482,9 @@ OutputRegisterFiledataSubModule(const char *parent_name, const char *name, module->parent_name = parent_name; module->InitSubFunc = InitFunc; module->FiledataLogFunc = FiledataLogFunc; + module->ThreadInit = ThreadInit; + module->ThreadDeinit = ThreadDeinit; + module->ThreadExitPrintStats = ThreadExitPrintStats; TAILQ_INSERT_TAIL(&output_modules, module, entries); SCLogDebug("Filedata logger \"%s\" registered.", name); diff --git a/src/output.h b/src/output.h index 72f89c89d7..007031bc91 100644 --- a/src/output.h +++ b/src/output.h @@ -127,10 +127,14 @@ void OutputRegisterFileSubModule(const char *parent_name, const char *name, ThreadExitPrintStatsFunc ThreadExitPrintStats); void OutputRegisterFiledataModule(const char *name, const char *conf_name, - OutputCtx *(*InitFunc)(ConfNode *), FiledataLogger FiledataLogFunc); + OutputCtx *(*InitFunc)(ConfNode *), FiledataLogger FiledataLogFunc, + ThreadInitFunc ThreadInit, ThreadDeinitFunc ThreadDeinit, + ThreadExitPrintStatsFunc ThreadExitPrintStats); void OutputRegisterFiledataSubModule(const char *parent_name, const char *name, const char *conf_name, OutputCtx *(*InitFunc)(ConfNode *, OutputCtx *), - FiledataLogger FiledataLogFunc); + FiledataLogger FiledataLogFunc, ThreadInitFunc ThreadInit, + ThreadDeinitFunc ThreadDeinit, + ThreadExitPrintStatsFunc ThreadExitPrintStats); void OutputRegisterFlowModule(const char *name, const char *conf_name, OutputCtx *(*InitFunc)(ConfNode *), FlowLogger FlowLogFunc, diff --git a/src/runmodes.c b/src/runmodes.c index f55dea3ce3..903f9a99a3 100644 --- a/src/runmodes.c +++ b/src/runmodes.c @@ -662,7 +662,9 @@ static void SetupOutput(const char *name, OutputModule *module, OutputCtx *outpu } } else if (module->FiledataLogFunc) { SCLogDebug("%s is a filedata logger", module->name); - OutputRegisterFiledataLogger(module->name, module->FiledataLogFunc, output_ctx); + OutputRegisterFiledataLogger(module->name, module->FiledataLogFunc, + output_ctx, module->ThreadInit, module->ThreadDeinit, + module->ThreadExitPrintStats); /* need one instance of the tx logger module */ if (filedata_logger_module == NULL) { diff --git a/src/tm-modules.c b/src/tm-modules.c index 8175a5e651..341488b411 100644 --- a/src/tm-modules.c +++ b/src/tm-modules.c @@ -216,7 +216,6 @@ const char * TmModuleTmmIdToString(TmmId id) CASE_CODE (TMM_LOGTLSLOG); CASE_CODE (TMM_LOGTCPDATALOG); CASE_CODE (TMM_PCAPLOG); - CASE_CODE (TMM_FILESTORE); CASE_CODE (TMM_DECODEIPFW); CASE_CODE (TMM_VERDICTIPFW); CASE_CODE (TMM_RECEIVEIPFW); diff --git a/src/tm-threads-common.h b/src/tm-threads-common.h index 76b357a5ea..5850673748 100644 --- a/src/tm-threads-common.h +++ b/src/tm-threads-common.h @@ -47,7 +47,6 @@ typedef enum { TMM_LOGTCPDATALOG, TMM_OUTPUTJSON, TMM_PCAPLOG, - TMM_FILESTORE, TMM_DECODEIPFW, TMM_VERDICTIPFW, TMM_RECEIVEIPFW,