From: Victor Julien Date: Mon, 25 May 2015 09:40:42 +0000 (+0200) Subject: counters: split API init X-Git-Tag: suricata-3.0RC1~377 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=33756abd87856fb95e06c1a41909cfd77943ca44;p=thirdparty%2Fsuricata.git counters: split API init Split into early ctx initialization and post-config setup. --- diff --git a/src/counters.c b/src/counters.c index b0b565a1ba..ad11c3c7af 100644 --- a/src/counters.c +++ b/src/counters.c @@ -212,12 +212,6 @@ static ConfNode *GetConfig(void) { static void SCPerfInitOPCtx(void) { SCEnter(); - if ( (sc_perf_op_ctx = SCMalloc(sizeof(StatsGlobalContext))) == NULL) { - SCLogError(SC_ERR_FATAL, "Fatal error encountered in SCPerfInitOPCtx. Exiting..."); - exit(EXIT_FAILURE); - } - memset(sc_perf_op_ctx, 0, sizeof(StatsGlobalContext)); - ConfNode *stats = GetConfig(); if (stats != NULL) { const char *enabled = ConfNodeLookupChildValue(stats, "enabled"); @@ -797,11 +791,19 @@ TmEcode SCPerfOutputCounterSocket(json_t *cmd, * \brief Initializes the perf counter api. Things are hard coded currently. * More work to be done when we implement multiple interfaces */ -void SCPerfInitCounterApi(void) +void StatsInit(void) { - SCPerfInitOPCtx(); + BUG_ON(sc_perf_op_ctx != NULL); + if ( (sc_perf_op_ctx = SCMalloc(sizeof(StatsGlobalContext))) == NULL) { + SCLogError(SC_ERR_FATAL, "Fatal error encountered in SCPerfInitOPCtx. Exiting..."); + exit(EXIT_FAILURE); + } + memset(sc_perf_op_ctx, 0, sizeof(StatsGlobalContext)); +} - return; +void StatsSetupPostConfig(void) +{ + SCPerfInitOPCtx(); } /** diff --git a/src/counters.h b/src/counters.h index 527c011be9..8d9113f684 100644 --- a/src/counters.h +++ b/src/counters.h @@ -111,7 +111,8 @@ typedef struct SCPerfPrivateContext_ { } SCPerfPrivateContext; /* the initialization functions */ -void SCPerfInitCounterApi(void); +void StatsInit(void); +void StatsSetupPostConfig(void); void SCPerfSpawnThreads(void); void SCPerfRegisterTests(void); diff --git a/src/runmode-unix-socket.c b/src/runmode-unix-socket.c index 42f836cf22..a7331bb9c6 100644 --- a/src/runmode-unix-socket.c +++ b/src/runmode-unix-socket.c @@ -344,6 +344,7 @@ TmEcode UnixSocketPcapFilesCheck(void *data) return TM_ECODE_FAILED; } PcapFilesFree(cfile); + StatsInit(); #ifdef PROFILING SCProfilingRulesGlobalInit(); SCProfilingKeywordsGlobalInit(); @@ -354,7 +355,7 @@ TmEcode UnixSocketPcapFilesCheck(void *data) IPPairInitConfig(FLOW_QUIET); StreamTcpInitConfig(STREAM_VERBOSE); RunModeInitializeOutputs(); - SCPerfInitCounterApi(); + StatsSetupPostConfig(); RunModeDispatch(RUNMODE_PCAP_FILE, NULL); FlowManagerThreadSpawn(); FlowRecyclerThreadSpawn(); diff --git a/src/suricata.c b/src/suricata.c index 6a8f067950..4e55c31857 100644 --- a/src/suricata.c +++ b/src/suricata.c @@ -2203,6 +2203,7 @@ int main(int argc, char **argv) GlobalInits(); TimeInit(); SupportFastPatternForSigMatchTypes(); + StatsInit(); if (conf_filename == NULL) conf_filename = DEFAULT_CONF_FILE; @@ -2302,7 +2303,7 @@ int main(int argc, char **argv) if (suri.run_mode != RUNMODE_UNIX_SOCKET) { RunModeInitializeOutputs(); - SCPerfInitCounterApi(); + StatsSetupPostConfig(); } if (ParseInterfacesList(suri.run_mode, suri.pcap_dev) != TM_ECODE_OK) {