diff --git a/src/log-maintenance.c b/src/log-maintenance.c index 170103754b..0e158e6677 100644 --- a/src/log-maintenance.c +++ b/src/log-maintenance.c @@ -81,8 +81,17 @@ static void *LogMaintenanceThread(void *arg) int flush_counter = 0; uint64_t rotation_check_count = 0; uint64_t worker_flush_count = 0; + bool completed_slice = false; bool run = TmThreadsWaitForUnpause(tv_local); while (run) { + /* killed before completing the first slice: skip it - the fixed + * sleep would only delay shutdown, no rotation or flush can + * happen on this pass. A kill arriving later keeps the normal + * behaviour: the current slice still runs its rotation/flush. */ + if (!completed_slice && TmThreadsCheckFlag(tv_local, THV_KILL)) { + break; + } + SleepMsec(maintenance_sleep_time); /* Check rotation every 1 second */ @@ -99,6 +108,8 @@ static void *LogMaintenanceThread(void *arg) flush_counter = 0; } + completed_slice = true; + if (TmThreadsCheckFlag(tv_local, THV_KILL)) { break; } diff --git a/src/tm-threads.c b/src/tm-threads.c index e8345c7193..5862507bf5 100644 --- a/src/tm-threads.c +++ b/src/tm-threads.c @@ -359,7 +359,14 @@ error: } /** - * Also returns if the kill flag is set. + * Wait for the thread to be unpaused. + * + * A thread killed while still in the initial pause skips its main loop, + * except mgmt threads (TVT_MGMT): they run one pass to do final work + * (e.g. the last stats output) - their loops test THV_KILL and exit + * after the pass. RX/worker loops have no top KILL test and would do + * real work during teardown (a pcap-file pass dispatches into a pipeline + * being torn down), so they keep skipping. */ bool TmThreadsWaitForUnpause(ThreadVars *tv) { @@ -369,8 +376,10 @@ bool TmThreadsWaitForUnpause(ThreadVars *tv) while (TmThreadsCheckFlag(tv, THV_PAUSE)) { SleepUsec(100); - if (TmThreadsCheckFlag(tv, THV_KILL)) - return false; + if (TmThreadsCheckFlag(tv, THV_KILL)) { + TmThreadsUnsetFlag(tv, THV_PAUSED); + return tv->type == TVT_MGMT; + } } TmThreadsUnsetFlag(tv, THV_PAUSED); diff --git a/src/tm-threads.h b/src/tm-threads.h index 97e57c9fe6..161548e82a 100644 --- a/src/tm-threads.h +++ b/src/tm-threads.h @@ -298,8 +298,12 @@ bool SCTmThreadsSlotPacketLoopFinish(ThreadVars *tv); * Check if a thread should wait to be unpaused and wait if so, or * until the thread kill flag is set. * - * \returns true if the thread was unpaused, false if killed. + * \returns true normally, and for mgmt threads killed while still in + * the initial pause (their main loop runs one final pass). Other thread + * types return false in that case and skip the main loop, as before. */ bool TmThreadsWaitForUnpause(ThreadVars *tv); +void TmThreadsRegisterTests(void); + #endif /* SURICATA_TM_THREADS_H */