From 8978266a91b2aac3b78f54bb5debb5ac064930df Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Tue, 12 Apr 2011 11:28:49 +0200 Subject: [PATCH] If shutdown doesn't complete processing all packets that are already in the engine within 30 seconds, force quit. --- src/suricata.c | 20 ++++++++++++++++++++ src/util-error.c | 1 + src/util-error.h | 1 + 3 files changed, 22 insertions(+) diff --git a/src/suricata.c b/src/suricata.c index d9c3da399d..1921d8b8c5 100644 --- a/src/suricata.c +++ b/src/suricata.c @@ -1362,6 +1362,12 @@ int main(int argc, char **argv) SCLogInfo("signal received"); if (suricata_ctl_flags & SURICATA_STOP) { + struct timeval ts_start; + struct timeval ts_cur; + + memset(&ts_start, 0x00, sizeof(ts_start)); + gettimeofday(&ts_start, NULL); + SCLogInfo("EngineStop received"); /* Stop the engine so it quits after processing the pcap file @@ -1378,6 +1384,20 @@ int main(int argc, char **argv) done = 1; if (done == 0) { + memset(&ts_cur, 0x00, sizeof(ts_cur)); + gettimeofday(&ts_cur, NULL); + + if (ts_cur.tv_sec - ts_start.tv_sec >= 30) { + SCLogError(SC_ERR_SHUTDOWN, "shutdown taking too " + "long, likely a bug! (%"PRIuMAX + " != %"PRIuMAX").", (uintmax_t)PacketPoolSize(), + (uintmax_t)max_pending_packets); +#ifdef DEBUG + BUG_ON(1); +#endif + break; + } + usleep(100); } } while (done == 0); diff --git a/src/util-error.c b/src/util-error.c index 3951568c82..e2f6ffd012 100644 --- a/src/util-error.c +++ b/src/util-error.c @@ -204,6 +204,7 @@ const char * SCErrorToString(SCError err) CASE_CODE (SC_ERR_LOGPCAP_SGUIL_BASE_DIR_MISSING); CASE_CODE (SC_ERR_UNKNOWN_DECODE_EVENT); CASE_CODE (SC_ERR_RUNMODE); + CASE_CODE (SC_ERR_SHUTDOWN); default: return "UNKNOWN_ERROR"; diff --git a/src/util-error.h b/src/util-error.h index 578da1d192..ec07bef9ad 100644 --- a/src/util-error.h +++ b/src/util-error.h @@ -215,6 +215,7 @@ typedef enum { SC_ERR_LOGPCAP_SGUIL_BASE_DIR_MISSING, SC_ERR_UNKNOWN_DECODE_EVENT, SC_ERR_RUNMODE, + SC_ERR_SHUTDOWN, } SCError; const char *SCErrorToString(SCError);