]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
init: InitGlobal function
authorPhilippe Antoine <contact@catenacyber.fr>
Thu, 16 Jan 2020 07:49:19 +0000 (08:49 +0100)
committerVictor Julien <victor@inliniac.net>
Fri, 14 Feb 2020 09:09:21 +0000 (10:09 +0100)
To be reused by fuzz targets

src/suricata.c
src/suricata.h

index 477eddd83a2f623784d6779539b5f1ac8631ca05..99b39c437a00e3ba3980b84738b5e858d2e03abc 100644 (file)
@@ -2925,11 +2925,15 @@ static void SuricataMainLoop(SCInstance *suri)
     }
 }
 
-int main(int argc, char **argv)
-{
-    SCInstanceInit(&suricata, argv[0]);
+SuricataContext context;
+
+/**
+ * \brief Global initialization common to all runmodes.
+ *
+ * This can be used by fuzz targets.
+ */
 
-    SuricataContext context;
+int InitGlobal(void) {
     context.SCLogMessage = SCLogMessage;
     context.DetectEngineStateFree = DetectEngineStateFree;
     context.AppLayerDecoderEventsSetEventRaw =
@@ -2961,13 +2965,27 @@ int main(int argc, char **argv)
     UtilSignalHandlerSetup(SIGUSR2, SIG_IGN);
     if (UtilSignalBlock(SIGUSR2)) {
         SCLogError(SC_ERR_INITIALIZATION, "SIGUSR2 initialization error");
-        exit(EXIT_FAILURE);
+        return EXIT_FAILURE;
     }
 #endif
 
     ParseSizeInit();
     RunModeRegisterRunModes();
 
+    /* Initialize the configuration module. */
+    ConfInit();
+
+    return 0;
+}
+
+int main(int argc, char **argv)
+{
+    SCInstanceInit(&suricata, argv[0]);
+
+    if (InitGlobal() != 0) {
+        exit(EXIT_FAILURE);
+    }
+
 #ifdef OS_WIN32
     /* service initialization */
     if (WindowsInitService(argc, argv) != 0) {
@@ -2975,9 +2993,6 @@ int main(int argc, char **argv)
     }
 #endif /* OS_WIN32 */
 
-    /* Initialize the configuration module. */
-    ConfInit();
-
     if (ParseCommandLine(argc, argv, &suricata) != TM_ECODE_OK) {
         exit(EXIT_FAILURE);
     }
index a15b20a2c212607c704024a7bf7e5c4150f9e6b2..f90b17ae773311d37fdfeadd157b3f1e4f7467f1 100644 (file)
@@ -188,6 +188,8 @@ int SuriHasSigFile(void);
 
 extern int run_mode;
 
+int InitGlobal(void);
+
 void PreRunInit(const int runmode);
 void PreRunPostPrivsDropInit(const int runmode);
 void PostRunDeinit(const int runmode, struct timeval *start_time);