From: Victor Julien Date: Thu, 14 Jul 2016 08:36:54 +0000 (+0200) Subject: threads: remove EngineKill & SURICATA_KILL X-Git-Tag: suricata-3.2beta1~395 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=85db260eed58c006ecac17277ccb016c5499f926;p=thirdparty%2Fsuricata.git threads: remove EngineKill & SURICATA_KILL EngineStop and EngineKill were effectively doing the same, so removed the kill variant. --- diff --git a/src/source-af-packet.c b/src/source-af-packet.c index 2721ed47f6..1909cdcbf6 100644 --- a/src/source-af-packet.c +++ b/src/source-af-packet.c @@ -1335,9 +1335,6 @@ TmEcode ReceiveAFPLoop(ThreadVars *tv, void *data, void *slot) switch (-r) { case AFP_FATAL_ERROR: SCLogError(SC_ERR_AFP_CREATE, "Couldn't init AF_PACKET socket, fatal error"); - /* fatal is fatal, we want suri to exit */ - EngineKill(); - //tv->aof = THV_ENGINE_EXIT; SCReturnInt(TM_ECODE_FAILED); case AFP_RECOVERABLE_ERROR: SCLogWarning(SC_ERR_AFP_CREATE, "Couldn't init AF_PACKET socket, retrying soon"); diff --git a/src/source-erf-dag.c b/src/source-erf-dag.c index 76f5fe3d83..db6b3d9f64 100644 --- a/src/source-erf-dag.c +++ b/src/source-erf-dag.c @@ -342,7 +342,7 @@ ReceiveErfDagLoop(ThreadVars *tv, void *data, void *slot) dtv->slot = s->slot_next; while (1) { - if (suricata_ctl_flags & (SURICATA_STOP | SURICATA_KILL)) { + if (suricata_ctl_flags & SURICATA_STOP) { SCReturnInt(TM_ECODE_OK); } diff --git a/src/source-erf-file.c b/src/source-erf-file.c index 5d8af87f75..29e59358c8 100644 --- a/src/source-erf-file.c +++ b/src/source-erf-file.c @@ -117,7 +117,7 @@ TmEcode ReceiveErfFileLoop(ThreadVars *tv, void *data, void *slot) etv->slot = ((TmSlot *)slot)->slot_next; while (1) { - if (suricata_ctl_flags & (SURICATA_STOP | SURICATA_KILL)) { + if (suricata_ctl_flags & SURICATA_STOP) { SCReturnInt(TM_ECODE_OK); } diff --git a/src/source-napatech.c b/src/source-napatech.c index 5566e40227..1348eaf99e 100644 --- a/src/source-napatech.c +++ b/src/source-napatech.c @@ -206,7 +206,7 @@ TmEcode NapatechStreamLoop(ThreadVars *tv, void *data, void *slot) TmSlot *s = (TmSlot *)slot; ntv->slot = s->slot_next; - while (!(suricata_ctl_flags & (SURICATA_STOP | SURICATA_KILL))) { + while (!(suricata_ctl_flags & SURICATA_STOP)) { /* make sure we have at least one packet in the packet pool, to prevent * us from alloc'ing packets at line rate */ PacketPoolWait(); diff --git a/src/source-pcap-file.c b/src/source-pcap-file.c index 6a587e2b22..51515b7c85 100644 --- a/src/source-pcap-file.c +++ b/src/source-pcap-file.c @@ -199,7 +199,7 @@ TmEcode ReceivePcapFileLoop(ThreadVars *tv, void *data, void *slot) ptv->cb_result = TM_ECODE_OK; while (1) { - if (suricata_ctl_flags & (SURICATA_STOP | SURICATA_KILL)) { + if (suricata_ctl_flags & SURICATA_STOP) { SCReturnInt(TM_ECODE_OK); } @@ -213,10 +213,11 @@ TmEcode ReceivePcapFileLoop(ThreadVars *tv, void *data, void *slot) if (unlikely(r == -1)) { SCLogError(SC_ERR_PCAP_DISPATCH, "error code %" PRId32 " %s", r, pcap_geterr(pcap_g.pcap_handle)); - if (! RunModeUnixSocketIsActive()) { - /* in the error state we just kill the engine */ - EngineKill(); + if (ptv->cb_result == TM_ECODE_FAILED) { SCReturnInt(TM_ECODE_FAILED); + } + if (! RunModeUnixSocketIsActive()) { + EngineStop(); } else { pcap_close(pcap_g.pcap_handle); pcap_g.pcap_handle = NULL; @@ -237,7 +238,6 @@ TmEcode ReceivePcapFileLoop(ThreadVars *tv, void *data, void *slot) } else if (ptv->cb_result == TM_ECODE_FAILED) { SCLogError(SC_ERR_PCAP_DISPATCH, "Pcap callback PcapFileCallbackLoop failed"); if (! RunModeUnixSocketIsActive()) { - EngineKill(); SCReturnInt(TM_ECODE_FAILED); } else { pcap_close(pcap_g.pcap_handle); diff --git a/src/source-pcap.c b/src/source-pcap.c index 97fcd72e6f..ac7d3a35a8 100644 --- a/src/source-pcap.c +++ b/src/source-pcap.c @@ -305,7 +305,7 @@ TmEcode ReceivePcapLoop(ThreadVars *tv, void *data, void *slot) ptv->cb_result = TM_ECODE_OK; while (1) { - if (suricata_ctl_flags & (SURICATA_STOP | SURICATA_KILL)) { + if (suricata_ctl_flags & SURICATA_STOP) { SCReturnInt(TM_ECODE_OK); } diff --git a/src/source-pfring.c b/src/source-pfring.c index 4b4715d313..d8583f5f18 100644 --- a/src/source-pfring.c +++ b/src/source-pfring.c @@ -318,7 +318,7 @@ TmEcode ReceivePfringLoop(ThreadVars *tv, void *data, void *slot) } while(1) { - if (suricata_ctl_flags & (SURICATA_STOP | SURICATA_KILL)) { + if (suricata_ctl_flags & SURICATA_STOP) { SCReturnInt(TM_ECODE_OK); } @@ -374,7 +374,7 @@ TmEcode ReceivePfringLoop(ThreadVars *tv, void *data, void *slot) last_dump = p->ts.tv_sec; } } else if (unlikely(r == 0)) { - if (suricata_ctl_flags & (SURICATA_STOP | SURICATA_KILL)) { + if (suricata_ctl_flags & SURICATA_STOP) { SCReturnInt(TM_ECODE_OK); } diff --git a/src/suricata.c b/src/suricata.c index 708d1640c1..4c1c6a6759 100644 --- a/src/suricata.c +++ b/src/suricata.c @@ -367,19 +367,14 @@ void GlobalInits() CreateLowercaseTable(); } -/* XXX hack: make sure threads can stop the engine by calling this - function. Purpose: pcap file mode needs to be able to tell the - engine the file eof is reached. */ +/** \brief make sure threads can stop the engine by calling this + * function. Purpose: pcap file mode needs to be able to tell the + * engine the file eof is reached. */ void EngineStop(void) { suricata_ctl_flags |= SURICATA_STOP; } -void EngineKill(void) -{ - suricata_ctl_flags |= SURICATA_KILL; -} - /** * \brief Used to indicate that the current task is done. * @@ -2667,13 +2662,11 @@ int main(int argc, char **argv) int engine_retval = EXIT_SUCCESS; while(1) { - if (sigterm_count) { - suricata_ctl_flags |= SURICATA_KILL; - } else if (sigint_count) { + if (sigterm_count || sigint_count) { suricata_ctl_flags |= SURICATA_STOP; } - if (suricata_ctl_flags & (SURICATA_KILL | SURICATA_STOP)) { + if (suricata_ctl_flags & SURICATA_STOP) { SCLogNotice("Signal Received. Stopping engine."); break; } diff --git a/src/suricata.h b/src/suricata.h index b38e65274b..4273ecb6e9 100644 --- a/src/suricata.h +++ b/src/suricata.h @@ -88,8 +88,6 @@ /* runtime engine control flags */ #define SURICATA_STOP (1 << 0) /**< gracefully stop the engine: process all outstanding packets first */ -#define SURICATA_KILL (1 << 1) /**< shut down asap, discarding outstanding - packets. */ #define SURICATA_DONE (1 << 2) /**< packets capture ended */ /* Engine stage/status*/ @@ -181,7 +179,6 @@ uint8_t g_u8_lowercasetable[256]; #define u8_tolower(c) tolower((uint8_t)(c)) void EngineStop(void); -void EngineKill(void); void EngineDone(void); int RunmodeIsUnittests(void); diff --git a/src/tm-threads.c b/src/tm-threads.c index c5699e82ad..9df10ff937 100644 --- a/src/tm-threads.c +++ b/src/tm-threads.c @@ -283,8 +283,6 @@ void *TmThreadsSlotPktAcqLoop(void *td) " PktAcqLoop=%p, tmqh_in=%p," " tmqh_out=%p", s, s ? s->PktAcqLoop : NULL, tv->tmqh_in, tv->tmqh_out); - EngineKill(); - TmThreadsSetFlag(tv, THV_CLOSED | THV_RUNNING_DONE); pthread_exit((void *) -1); return NULL; @@ -300,7 +298,6 @@ void *TmThreadsSlotPktAcqLoop(void *td) TmThreadsSetFlag(tv, THV_CLOSED | THV_INIT_DONE | THV_RUNNING_DONE); goto error; } else { - EngineKill(); TmThreadsSetFlag(tv, THV_CLOSED | THV_RUNNING_DONE); goto error; } @@ -336,8 +333,11 @@ void *TmThreadsSlotPktAcqLoop(void *td) r = s->PktAcqLoop(tv, SC_ATOMIC_GET(s->slot_data), s); - if (r == TM_ECODE_FAILED || TmThreadsCheckFlag(tv, THV_KILL_PKTACQ) - || suricata_ctl_flags) { + if (r == TM_ECODE_FAILED) { + TmThreadsSetFlag(tv, THV_FAILED); + run = 0; + } + if (TmThreadsCheckFlag(tv, THV_KILL_PKTACQ) || suricata_ctl_flags) { run = 0; } if (r == TM_ECODE_DONE) { @@ -408,8 +408,6 @@ void *TmThreadsSlotPktAcqLoopAFL(void *td) " PktAcqLoop=%p, tmqh_in=%p," " tmqh_out=%p", s, s ? s->PktAcqLoop : NULL, tv->tmqh_in, tv->tmqh_out); - EngineKill(); - TmThreadsSetFlag(tv, THV_CLOSED | THV_RUNNING_DONE); return NULL; } @@ -424,7 +422,6 @@ void *TmThreadsSlotPktAcqLoopAFL(void *td) TmThreadsSetFlag(tv, THV_CLOSED | THV_INIT_DONE | THV_RUNNING_DONE); goto error; } else { - EngineKill(); TmThreadsSetFlag(tv, THV_CLOSED | THV_RUNNING_DONE); goto error; } @@ -456,8 +453,11 @@ void *TmThreadsSlotPktAcqLoopAFL(void *td) r = s->PktAcqLoop(tv, SC_ATOMIC_GET(s->slot_data), s); - if (r == TM_ECODE_FAILED || TmThreadsCheckFlag(tv, THV_KILL_PKTACQ) - || suricata_ctl_flags) { + if (r == TM_ECODE_FAILED) { + TmThreadsSetFlag(tv, THV_FAILED); + run = 0; + } + if (TmThreadsCheckFlag(tv, THV_KILL_PKTACQ) || suricata_ctl_flags) { run = 0; } if (r == TM_ECODE_DONE) { @@ -530,8 +530,6 @@ void *TmThreadsSlotVar(void *td) /* check if we are setup properly */ if (s == NULL || tv->tmqh_in == NULL || tv->tmqh_out == NULL) { - EngineKill(); - TmThreadsSetFlag(tv, THV_CLOSED | THV_RUNNING_DONE); pthread_exit((void *) -1); return NULL; @@ -542,8 +540,6 @@ void *TmThreadsSlotVar(void *td) void *slot_data = NULL; r = s->SlotThreadInit(tv, s->slot_initdata, &slot_data); if (r != TM_ECODE_OK) { - EngineKill(); - TmThreadsSetFlag(tv, THV_CLOSED | THV_RUNNING_DONE); goto error; } @@ -697,8 +693,6 @@ static void *TmThreadsManagement(void *td) void *slot_data = NULL; r = s->SlotThreadInit(tv, s->slot_initdata, &slot_data); if (r != TM_ECODE_OK) { - EngineKill(); - TmThreadsSetFlag(tv, THV_CLOSED | THV_RUNNING_DONE); pthread_exit((void *) -1); return NULL; diff --git a/src/unix-manager.c b/src/unix-manager.c index bb6eef6756..86f6196763 100644 --- a/src/unix-manager.c +++ b/src/unix-manager.c @@ -579,7 +579,7 @@ int UnixMain(UnixCommand * this) return 0; } - if (suricata_ctl_flags & (SURICATA_STOP | SURICATA_KILL)) { + if (suricata_ctl_flags & SURICATA_STOP) { TAILQ_FOREACH_SAFE(uclient, &this->clients, next, tclient) { UnixCommandClose(this, uclient->fd); }