unix-manager: block live reload when -s/-S is specified

Currently, when live reload is executed through
unix-socket, suri prints in the console the following
error message:
"Live rule reload not possible if -s or -S option used at runtime."

Instead, prints "done" in unix socket,
when the live reload is not executed.
pull/2871/merge
Giuseppe Longo 10 years ago committed by Victor Julien
parent f1d372a505
commit e7392a0780

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

@ -193,6 +193,8 @@ int RunmodeIsUnittests(void);
int RunmodeGetCurrent(void); int RunmodeGetCurrent(void);
int IsRuleReloadSet(int quiet); int IsRuleReloadSet(int quiet);
int SuriHasSigFile(void);
extern int run_mode; extern int run_mode;
void PreRunInit(const int runmode); void PreRunInit(const int runmode);

@ -659,6 +659,14 @@ static TmEcode UnixManagerCaptureModeCommand(json_t *cmd,
static TmEcode UnixManagerReloadRulesWrapper(json_t *cmd, json_t *server_msg, void *data, int do_wait) static TmEcode UnixManagerReloadRulesWrapper(json_t *cmd, json_t *server_msg, void *data, int do_wait)
{ {
SCEnter(); SCEnter();
if (SuriHasSigFile()) {
json_object_set_new(server_msg, "message",
json_string("Live rule reload not possible if -s "
"or -S option used at runtime."));
SCReturnInt(TM_ECODE_FAILED);
}
int r = DetectEngineReloadStart(); int r = DetectEngineReloadStart();
if (r == 0 && do_wait) { if (r == 0 && do_wait) {

Loading…
Cancel
Save