diff --git a/src/counters.c b/src/counters.c index dd90b2e57f..b375eff4db 100644 --- a/src/counters.c +++ b/src/counters.c @@ -468,11 +468,11 @@ static void *SCPerfMgmtThread(void *arg) SCPerfOutputCounters(); if (TmThreadsCheckFlag(tv_local, THV_KILL)) { - TmThreadsSetFlag(tv_local, THV_CLOSED); run = 0; } } + TmThreadsSetFlag(tv_local, THV_CLOSED); return NULL; } diff --git a/src/flow.c b/src/flow.c index 085d77682f..3f518d85ba 100644 --- a/src/flow.c +++ b/src/flow.c @@ -1156,6 +1156,7 @@ void *FlowManagerThread(void *td) SCLogInfo("prune_usecnt %"PRIu64, prune_usecnt); #endif + TmThreadsSetFlag(th_v, THV_CLOSED); pthread_exit((void *) 0); } diff --git a/src/suricata.h b/src/suricata.h index 8ee6681ac5..d05d35a47d 100644 --- a/src/suricata.h +++ b/src/suricata.h @@ -66,6 +66,8 @@ SCDQDataQueue data_queues[256]; /* memset to zeros, and mutex init! */ void GlobalInits(); +extern uint8_t suricata_ctl_flags; + /* uppercase to lowercase conversion lookup table */ uint8_t g_u8_lowercasetable[256]; diff --git a/src/threadvars.h b/src/threadvars.h index 31a0627772..c96ad9ed48 100644 --- a/src/threadvars.h +++ b/src/threadvars.h @@ -41,7 +41,7 @@ struct TmSlot_; #define THV_CLOSED 0x20 /** thread done, should be joinable */ /** Thread flags set and read by threads, to control the threads, when they - encounter certain conditions like failure */ + * encounter certain conditions like failure */ #define THV_RESTART_THREAD 0x01 /** restart the thread */ #define THV_ENGINE_EXIT 0x02 /** shut the engine down gracefully */ diff --git a/src/tm-threads.c b/src/tm-threads.c index b15baf5420..6437a4edd9 100644 --- a/src/tm-threads.c +++ b/src/tm-threads.c @@ -1467,12 +1467,17 @@ void TmThreadCheckThreadState(void) while (tv) { if (TmThreadsCheckFlag(tv, THV_FAILED)) { pthread_join(tv->t, NULL); - if ( !(tv_aof & THV_ENGINE_EXIT) && - (tv->aof & THV_RESTART_THREAD) ) { - TmThreadRestartThread(tv); - } else { - TmThreadsSetFlag(tv, THV_CLOSED); + if (tv_aof & THV_ENGINE_EXIT || tv->aof & THV_ENGINE_EXIT) { EngineKill(); + return; + } else { + /* if the engine kill-stop has been received by now, chuck + * restarting and return to kill the engine */ + if (suricata_ctl_flags & SURICATA_KILL || + suricata_ctl_flags & SURICATA_STOP) { + return; + } + TmThreadRestartThread(tv); } } tv = tv->next;