From c0294521dd3124bd0795bdb009f6eef1892017d1 Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Fri, 29 May 2015 14:41:44 +0200 Subject: [PATCH] startup: move more into PostConfLoadedSetup --- src/runmodes.c | 14 +++++++++ src/suricata.c | 83 +++++++++++++++++++++++--------------------------- 2 files changed, 52 insertions(+), 45 deletions(-) diff --git a/src/runmodes.c b/src/runmodes.c index d4eda057af..ee93b0c05e 100644 --- a/src/runmodes.c +++ b/src/runmodes.c @@ -51,6 +51,11 @@ #include "tmqh-flow.h" +#ifdef __SC_CUDA_SUPPORT__ +#include "util-cuda-buffer.h" +#include "util-mpm-ac.h" +#endif + int debuglog_enabled = 0; /** @@ -379,6 +384,15 @@ void RunModeDispatch(int runmode, const char *custom_mode) if (local_custom_mode != NULL) SCFree(local_custom_mode); + +#ifdef __SC_CUDA_SUPPORT__ + if (PatternMatchDefaultMatcher() == MPM_AC_CUDA) + SCACCudaStartDispatcher(); +#endif + + /* Check if the alloted queues have at least 1 reader and writer */ + TmValidateQueueState(); + return; } diff --git a/src/suricata.c b/src/suricata.c index f5ed5136e1..7311561345 100644 --- a/src/suricata.c +++ b/src/suricata.c @@ -920,12 +920,12 @@ void RegisterAllModules() } -TmEcode LoadYamlConfig(char *conf_filename) +static TmEcode LoadYamlConfig(void) { SCEnter(); if (conf_filename == NULL) - SCReturnInt(TM_ECODE_OK); + conf_filename = DEFAULT_CONF_FILE; if (ConfYamlLoadFile(conf_filename) != 0) { /* Error already displayed. */ @@ -1974,6 +1974,9 @@ static int FinalizeRunMode(SCInstance *suri, char **argv) /* Set the global run mode */ run_mode = suri->run_mode; + if (!CheckValidDaemonModes(suri->daemon, suri->run_mode)) { + return TM_ECODE_FAILED; + } return TM_ECODE_OK; } @@ -2202,6 +2205,33 @@ static int PostConfLoadedSetup(SCInstance *suri) TmModuleRunInit(); PcapLogProfileSetup(); + + if (MayDaemonize(suri) != TM_ECODE_OK) + SCReturnInt(TM_ECODE_FAILED); + + if (InitSignalHandler(suri) != TM_ECODE_OK) + SCReturnInt(TM_ECODE_FAILED); + +#ifdef HAVE_NSS + /* init NSS for md5 */ + PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0); + NSS_NoDB_Init(NULL); +#endif + + if (suri->disabled_detect) { + /* disable raw reassembly */ + (void)ConfSetFinal("stream.reassembly.raw", "false"); + } + + HostInitConfig(HOST_VERBOSE); + + if (MagicInit() != 0) + SCReturnInt(TM_ECODE_FAILED); + + SCAsn1LoadConfig(); + + CoredumpLoadConfig(); + SCReturnInt(TM_ECODE_OK); } @@ -2262,10 +2292,6 @@ int main(int argc, char **argv) CudaBufferInit(); #endif - if (!CheckValidDaemonModes(suri.daemon, suri.run_mode)) { - exit(EXIT_FAILURE); - } - /* Initializations for global vars, queues, etc (memsets, mutex init..) */ GlobalInits(); TimeInit(); @@ -2274,12 +2300,8 @@ int main(int argc, char **argv) StatsInit(); } - if (conf_filename == NULL) - conf_filename = DEFAULT_CONF_FILE; - - /** \todo we need an api for these */ /* Load yaml configuration file if provided. */ - if (LoadYamlConfig(conf_filename) != TM_ECODE_OK) { + if (LoadYamlConfig() != TM_ECODE_OK) { exit(EXIT_FAILURE); } @@ -2304,24 +2326,6 @@ int main(int argc, char **argv) exit(EXIT_FAILURE); } - if (MayDaemonize(&suri) != TM_ECODE_OK) - exit(EXIT_FAILURE); - - if (InitSignalHandler(&suri) != TM_ECODE_OK) - exit(EXIT_FAILURE); - -#ifdef HAVE_NSS - /* init NSS for md5 */ - PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0); - NSS_NoDB_Init(NULL); -#endif - - if (suri.disabled_detect) { - /* disable raw reassembly */ - (void)ConfSetFinal("stream.reassembly.raw", "false"); - } - - HostInitConfig(HOST_VERBOSE); if (suri.run_mode != RUNMODE_UNIX_SOCKET) { FlowInitConfig(FLOW_VERBOSE); StreamTcpInitConfig(STREAM_VERBOSE); @@ -2329,9 +2333,6 @@ int main(int argc, char **argv) AppLayerRegisterGlobalCounters(); } - if (MagicInit() != 0) - exit(EXIT_FAILURE); - DetectEngineCtx *de_ctx = NULL; if (!suri.disabled_detect) { SCClassConfInit(); @@ -2378,10 +2379,6 @@ int main(int argc, char **argv) RegisterAppLayerGetActiveTxIdFunc(AppLayerTransactionGetActiveLogOnly); } - SCAsn1LoadConfig(); - - CoredumpLoadConfig(); - SCSetStartTime(&suri); SCDropMainThreadCaps(suri.userid, suri.groupid); @@ -2391,7 +2388,11 @@ int main(int argc, char **argv) StatsSetupPostConfig(); } - if(suri.run_mode == RUNMODE_CONF_TEST){ + if (ParseInterfacesList(suri.run_mode, suri.pcap_dev) != TM_ECODE_OK) { + exit(EXIT_FAILURE); + } + + if (suri.run_mode == RUNMODE_CONF_TEST){ SCLogNotice("Configuration provided was successfully loaded. Exiting."); exit(EXIT_SUCCESS); } @@ -2418,14 +2419,6 @@ int main(int argc, char **argv) StatsSpawnThreads(); } -#ifdef __SC_CUDA_SUPPORT__ - if (PatternMatchDefaultMatcher() == MPM_AC_CUDA) - SCACCudaStartDispatcher(); -#endif - - /* Check if the alloted queues have at least 1 reader and writer */ - TmValidateQueueState(); - /* Wait till all the threads have been initialized */ if (TmThreadWaitOnThreadInit() == TM_ECODE_FAILED) { SCLogError(SC_ERR_INITIALIZATION, "Engine initialization failed, " -- 2.47.2