]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
threads: remove EngineKill & SURICATA_KILL
authorVictor Julien <victor@inliniac.net>
Thu, 14 Jul 2016 08:36:54 +0000 (10:36 +0200)
committerVictor Julien <victor@inliniac.net>
Mon, 19 Sep 2016 10:51:09 +0000 (12:51 +0200)
EngineStop and EngineKill were effectively doing the same, so
removed the kill variant.

src/source-af-packet.c
src/source-erf-dag.c
src/source-erf-file.c
src/source-napatech.c
src/source-pcap-file.c
src/source-pcap.c
src/source-pfring.c
src/suricata.c
src/suricata.h
src/tm-threads.c
src/unix-manager.c

index 2721ed47f6b230749b431330e561e81a54edae85..1909cdcbf6dfc53844ad72c255875cd300bd0da9 100644 (file)
@@ -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");
index 76f5fe3d83e2498cfa60da1128a6ebf766b6ad60..db6b3d9f6459f7e43159272255b70624bfd699ec 100644 (file)
@@ -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);
         }
 
index 5d8af87f75631a61f572dd0f16bcdcba92855b4c..29e59358c8d3a0e6fe3c83dc99ed6c249bc88896 100644 (file)
@@ -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);
         }
 
index 5566e4022794644157361ea28f4c7cacff7327b6..1348eaf99e16e1f1a59ba2cd260d15443c81ac40 100644 (file)
@@ -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();
index 6a587e2b22c7dad9f24b31c8aaeaa3561b801327..51515b7c8523f4d5c8ac033f83e4a6cb2659b5ab 100644 (file)
@@ -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);
index 97fcd72e6f93993c11c93fb065c292ab61579502..ac7d3a35a89e4d98a63de03317bc8494131796e9 100644 (file)
@@ -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);
         }
 
index 4b4715d313f881b56616daf71036c7779f8b4bdf..d8583f5f18e67e04ae3b0df267bd47993f80a0e5 100644 (file)
@@ -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);
             }
 
index 708d1640c13af256f448b9e426971d3fec39c355..4c1c6a67594ddb1d5b3be8d7d882c2311c37cab8 100644 (file)
@@ -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;
         }
index b38e65274b49bd1dda1c519fe13e9cc45ec8db42..4273ecb6e96bef006c28b40f620def6254df9d40 100644 (file)
@@ -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);
index c5699e82ad4cfb5210090c4a5a4d77d0b7f7d355..9df10ff9370ab6a953eb2caaab60f4506c0a2329 100644 (file)
@@ -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;
index bb6eef6756b0de1762d040beb790b7bf306e6f4b..86f619676364c203e321b6c679fe3ff2b3d9d7bf 100644 (file)
@@ -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);
         }