* support */
bool g_disable_hashing = false;
+/* snapshot of the system's hugepages before system intitialization. */
+SystemHugepageSnapshot *prerun_snap = NULL;
+
/** Suricata instance */
SCInstance suricata;
return 0;
}
-int SuricataMain(int argc, char **argv)
+void SuricataPreInit(const char *progname)
{
- SCInstanceInit(&suricata, argv[0]);
+ SCInstanceInit(&suricata, progname);
if (InitGlobal() != 0) {
exit(EXIT_FAILURE);
}
+}
+void SuricataInit(int argc, char **argv)
+{
#ifdef OS_WIN32
/* service initialization */
if (WindowsInitService(argc, argv) != 0) {
goto out;
}
- SystemHugepageSnapshot *prerun_snap = NULL;
if (run_mode == RUNMODE_DPDK)
prerun_snap = SystemHugepageSnapshotCreate();
UnixManagerThreadSpawnNonRunmode(suricata.unix_socket_enabled);
}
+ return;
+
+out:
+ GlobalsDestroy(&suricata);
+ exit(EXIT_SUCCESS);
+}
+
+void SuricataShutdown(void)
+{
+ /* Update the engine stage/status flag */
+ SC_ATOMIC_SET(engine_stage, SURICATA_DEINIT);
+
+ UnixSocketKillSocketThread();
+ PostRunDeinit(suricata.run_mode, &suricata.start_time);
+ /* kill remaining threads */
+ TmThreadKillThreads();
+}
+
+void SuricataPostInit(void)
+{
/* Wait till all the threads have been initialized */
if (TmThreadWaitOnThreadInit() == TM_ECODE_FAILED) {
+ SystemHugepageSnapshotDestroy(prerun_snap);
FatalError("Engine initialization failed, "
"aborting...");
}
/* Must ensure all threads are fully operational before continuing with init process */
if (TmThreadWaitOnThreadRunning() != TM_ECODE_OK) {
+ SystemHugepageSnapshotDestroy(prerun_snap);
exit(EXIT_FAILURE);
}
SystemHugepageSnapshotDestroy(postrun_snap);
}
SCPledge();
- SuricataMainLoop(&suricata);
+}
- /* Update the engine stage/status flag */
- SC_ATOMIC_SET(engine_stage, SURICATA_DEINIT);
+int SuricataMain(int argc, char **argv)
+{
+ /* Pre-initialization tasks: initialize global context and variables. */
+ SuricataPreInit(argv[0]);
- UnixSocketKillSocketThread();
- PostRunDeinit(suricata.run_mode, &suricata.start_time);
- /* kill remaining threads */
- TmThreadKillThreads();
+ /* Initialization tasks: parse command line options, load yaml, start runmode... */
+ SuricataInit(argc, argv);
-out:
+ /* Post-initialization tasks: wait on thread start/running and get ready for the main loop. */
+ SuricataPostInit();
+
+ SuricataMainLoop(&suricata);
+
+ /* Shutdown engine. */
+ SuricataShutdown();
GlobalsDestroy(&suricata);
exit(EXIT_SUCCESS);