From: Oleksandr Stepanov -X (ostepano - SOFTSERVE INC at Cisco) Date: Thu, 1 Aug 2024 19:44:05 +0000 (+0000) Subject: Pull request #4405: control: handle control commands after packet treads are fully... X-Git-Tag: 3.3.3.0~11 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dbf1716a3f53faf4151ce0eb80a9804fae2406ca;p=thirdparty%2Fsnort3.git Pull request #4405: control: handle control commands after packet treads are fully initialised Merge in SNORT/snort3 from ~OSTEPANO/snort3:main_socket_control to master Squashed commit of the following: commit 9c08c5d51d32c030eea66946b6e7999a2b9f8d3f Author: Oleksandr Stepanov Date: Wed Jul 31 07:16:04 2024 -0400 control: handle control commands after packet treads are fully initialised --- diff --git a/src/main.cc b/src/main.cc index f48e1789f..690f95b22 100644 --- a/src/main.cc +++ b/src/main.cc @@ -76,6 +76,7 @@ bool exit_requested = false; static int main_exit_code = 0; static bool paused = false; static bool pthreads_started = false; +static bool pthreads_running = false; static std::queue orphan_commands; static std::mutex poke_mutex; @@ -284,6 +285,7 @@ void Pig::reap_commands() static bool* pigs_started = nullptr; +static bool* pigs_running = nullptr; static Pig* pigs = nullptr; static unsigned max_pigs = 0; static unsigned pigs_failed = 0; @@ -899,7 +901,7 @@ static bool house_keeping() static void service_check() { #ifdef SHELL - if (pthreads_started && ControlMgmt::service_users()) + if (pthreads_running && ControlMgmt::service_users()) return; #endif @@ -1107,9 +1109,14 @@ static void main_loop() if ( pig.analyzer ) { handle(pig, swine, pending_privileges); - if (!pigs_started[idx] && pig.analyzer && (pig.analyzer->get_state() == - Analyzer::State::STARTED)) + + if (!pigs_started[idx] && pig.analyzer && ((pig.analyzer->get_state() == Analyzer::State::STARTED))) pigs_started[idx] = true; + + if (!pigs_running[idx] && pig.analyzer && ((pig.analyzer->get_state() == Analyzer::State::PAUSED) || + (pig.analyzer->get_state() == Analyzer::State::RUNNING))) + pigs_running[idx] = true; + if (pigs_started[idx] && (!pig.analyzer || pig.analyzer->get_state() == Analyzer::State::FAILED)) pigs_started[idx] = false; @@ -1134,12 +1141,12 @@ static void main_loop() } pthreads_started = pigs_started_count && num_threads <= pigs_started_count + pigs_failed; - + +#ifdef REG_TEST if (pthreads_started) { -#ifdef REG_TEST LogMessage("All pthreads started\n"); -#endif + #ifdef SHELL if (use_shell(SnortConfig::get_conf())) { @@ -1148,7 +1155,24 @@ static void main_loop() } #endif } +#endif + } + +#ifdef SHELL + if(!pthreads_running) + { + const unsigned num_threads = (!Trough::has_next()) ? max_swine : max_pigs; + unsigned pigs_running_count = 0; + + for (unsigned i = 0; i < num_threads; i++) + { + if(pigs_running[i]) + pigs_running_count++; + } + + pthreads_running = pigs_running_count && num_threads <= pigs_running_count + pigs_failed; } +#endif if ( !exit_requested and (swine < max_pigs) and (src = Trough::get_next()) ) { @@ -1184,12 +1208,14 @@ static void snort_main() pig_poke = new Ring((max_pigs*max_grunts)+1); pigs = new Pig[max_pigs]; pigs_started = new bool[max_pigs]; + pigs_running = new bool[max_pigs]; for (unsigned idx = 0; idx < max_pigs; idx++) { Pig& pig = pigs[idx]; pig.set_index(idx); pigs_started[idx] = false; + pigs_running[idx] = false; } main_loop(); @@ -1199,6 +1225,8 @@ static void snort_main() pigs = nullptr; delete[] pigs_started; pigs_started = nullptr; + delete[] pigs_running; + pigs_running = nullptr; #ifdef SHELL ControlMgmt::socket_term();