@ -230,6 +230,14 @@ int g_disable_randomness = 0;
int g_disable_randomness = 1 ;
# endif
/** Suricata instance */
SCInstance suricata ;
int SuriHasSigFile ( void )
{
return ( suricata . sig_file ! = NULL ) ;
}
int EngineModeIsIPS ( void )
{
return ( g_engine_mode = = ENGINE_MODE_IPS ) ;
@ -2801,8 +2809,7 @@ static void SuricataMainLoop(SCInstance *suri)
int main ( int argc , char * * argv )
{
SCInstance suri ;
SCInstanceInit ( & suri , argv [ 0 ] ) ;
SCInstanceInit ( & suricata , argv [ 0 ] ) ;
# ifdef HAVE_RUST
SuricataContext context ;
@ -2843,15 +2850,15 @@ int main(int argc, char **argv)
/* Initialize the configuration module. */
ConfInit ( ) ;
if ( ParseCommandLine ( argc , argv , & suri ) ! = TM_ECODE_OK ) {
if ( ParseCommandLine ( argc , argv , & suri cata ) ! = TM_ECODE_OK ) {
exit ( EXIT_FAILURE ) ;
}
if ( FinalizeRunMode ( & suri , argv ) ! = TM_ECODE_OK ) {
if ( FinalizeRunMode ( & suri cata , argv ) ! = TM_ECODE_OK ) {
exit ( EXIT_FAILURE ) ;
}
switch ( StartInternalRunMode ( & suri , argc , argv ) ) {
switch ( StartInternalRunMode ( & suri cata , argc , argv ) ) {
case TM_ECODE_DONE :
exit ( EXIT_SUCCESS ) ;
case TM_ECODE_FAILED :
@ -2862,35 +2869,35 @@ int main(int argc, char **argv)
GlobalsInitPreConfig ( ) ;
/* Load yaml configuration file if provided. */
if ( LoadYamlConfig ( & suri ) ! = TM_ECODE_OK ) {
if ( LoadYamlConfig ( & suri cata ) ! = TM_ECODE_OK ) {
exit ( EXIT_FAILURE ) ;
}
if ( suri . run_mode = = RUNMODE_DUMP_CONFIG ) {
if ( suri cata . run_mode = = RUNMODE_DUMP_CONFIG ) {
ConfDump ( ) ;
exit ( EXIT_SUCCESS ) ;
}
/* Since our config is now loaded we can finish configurating the
* logging module . */
SCLogLoadConfig ( suri . daemon , suri . verbose ) ;
SCLogLoadConfig ( suri cata . daemon , suri cata . verbose ) ;
LogVersion ( ) ;
UtilCpuPrintSummary ( ) ;
if ( ParseInterfacesList ( suri . run_mode , suri . pcap_dev ) ! = TM_ECODE_OK ) {
if ( ParseInterfacesList ( suri cata . run_mode , suri cata . pcap_dev ) ! = TM_ECODE_OK ) {
exit ( EXIT_FAILURE ) ;
}
if ( PostConfLoadedSetup ( & suri ) ! = TM_ECODE_OK ) {
if ( PostConfLoadedSetup ( & suri cata ) ! = TM_ECODE_OK ) {
exit ( EXIT_FAILURE ) ;
}
PostConfLoadedDetectSetup ( & suri ) ;
PostConfLoadedDetectSetup ( & suri cata ) ;
SCDropMainThreadCaps ( suri . userid , suri . groupid ) ;
PreRunPostPrivsDropInit ( suri . run_mode ) ;
SCDropMainThreadCaps ( suri cata . userid , suri cata . groupid ) ;
PreRunPostPrivsDropInit ( suri cata . run_mode ) ;
if ( suri . run_mode = = RUNMODE_CONF_TEST ) {
if ( suri cata . run_mode = = RUNMODE_CONF_TEST ) {
SCLogNotice ( " Configuration provided was successfully loaded. Exiting. " ) ;
# ifdef HAVE_MAGIC
MagicDeinit ( ) ;
@ -2898,9 +2905,9 @@ int main(int argc, char **argv)
exit ( EXIT_SUCCESS ) ;
}
SCSetStartTime ( & suri ) ;
RunModeDispatch ( suri . run_mode , suri . runmode_custom_mode ) ;
if ( suri . run_mode ! = RUNMODE_UNIX_SOCKET ) {
SCSetStartTime ( & suri cata ) ;
RunModeDispatch ( suri cata . run_mode , suri cata . runmode_custom_mode ) ;
if ( suri cata . run_mode ! = RUNMODE_UNIX_SOCKET ) {
UnixManagerThreadSpawnNonRunmode ( ) ;
}
@ -2917,7 +2924,7 @@ int main(int argc, char **argv)
/* Un-pause all the paused threads */
TmThreadContinueThreads ( ) ;
PostRunStartedDetectSetup ( & suri ) ;
PostRunStartedDetectSetup ( & suri cata ) ;
# ifdef DBG_MEM_ALLOC
SCLogInfo ( " Memory used at startup: % " PRIdMAX , ( intmax_t ) global_mem ) ;
@ -2926,17 +2933,17 @@ int main(int argc, char **argv)
# endif
# endif
SuricataMainLoop ( & suri ) ;
SuricataMainLoop ( & suri cata ) ;
/* Update the engine stage/status flag */
( void ) SC_ATOMIC_CAS ( & engine_stage , SURICATA_RUNTIME , SURICATA_DEINIT ) ;
UnixSocketKillSocketThread ( ) ;
PostRunDeinit ( suri . run_mode , & suri . start_time ) ;
PostRunDeinit ( suri cata . run_mode , & suri cata . start_time ) ;
/* kill remaining threads */
TmThreadKillThreads ( ) ;
GlobalsDestroy ( & suri ) ;
GlobalsDestroy ( & suri cata ) ;
exit ( EXIT_SUCCESS ) ;
}