]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
counters: split API init
authorVictor Julien <victor@inliniac.net>
Mon, 25 May 2015 09:40:42 +0000 (11:40 +0200)
committerVictor Julien <victor@inliniac.net>
Tue, 26 May 2015 20:05:45 +0000 (22:05 +0200)
Split into early ctx initialization and post-config setup.

src/counters.c
src/counters.h
src/runmode-unix-socket.c
src/suricata.c

index b0b565a1ba3427b1348347bb6fb69b0784fdb5bd..ad11c3c7af12cdbb633338fa843be0edf1039eaa 100644 (file)
@@ -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();
 }
 
 /**
index 527c011be9dcc2dad9b5c5a0e2aa81fb596f09ff..8d9113f68490e5ff471cf92ee9a5b9aa9fc424ed 100644 (file)
@@ -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);
 
index 42f836cf22ab670356649cdbea51344ebbbf83af..a7331bb9c69cebf1eca7b723f3fee5c2a422b69b 100644 (file)
@@ -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();
index 6a8f0679508d4d29bbb60571f3090d990ff08046..4e55c318578507fe266cef2030c93806fc12b3b4 100644 (file)
@@ -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) {