static int main_exit_code = 0;
static bool paused = false;
static bool pthreads_started = false;
+static bool pthreads_running = false;
static std::queue<AnalyzerCommand*> orphan_commands;
static std::mutex poke_mutex;
static bool* pigs_started = nullptr;
+static bool* pigs_running = nullptr;
static Pig* pigs = nullptr;
static unsigned max_pigs = 0;
static unsigned pigs_failed = 0;
static void service_check()
{
#ifdef SHELL
- if (pthreads_started && ControlMgmt::service_users())
+ if (pthreads_running && ControlMgmt::service_users())
return;
#endif
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;
}
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()))
{
}
#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()) )
{
pig_poke = new Ring<unsigned>((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();
pigs = nullptr;
delete[] pigs_started;
pigs_started = nullptr;
+ delete[] pigs_running;
+ pigs_running = nullptr;
#ifdef SHELL
ControlMgmt::socket_term();