]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
flow recycler: shutdown
authorVictor Julien <victor@inliniac.net>
Wed, 30 Apr 2014 16:49:39 +0000 (18:49 +0200)
committerVictor Julien <victor@inliniac.net>
Mon, 28 Jul 2014 13:47:44 +0000 (15:47 +0200)
Only shut down when all flows in the recycle queue have been processed.

src/flow-manager.c

index eb5e264e0dc6d23fcb2d134c46764da0d4957834..a41addb1d56f1b518b0c87366228316f4870302f 100644 (file)
@@ -684,6 +684,16 @@ void *FlowRecyclerThread(void *td)
     return NULL;
 }
 
+int FlowRecyclerReadyToShutdown(void)
+{
+    uint32_t len = 0;
+    FQLOCK_LOCK(&flow_recycle_q);
+    len = flow_recycle_q.len;
+    FQLOCK_UNLOCK(&flow_recycle_q);
+
+    return ((len == 0));
+}
+
 /** \brief spawn the flow recycler thread */
 void FlowRecyclerThreadSpawn()
 {
@@ -712,6 +722,8 @@ void FlowRecyclerThreadSpawn()
 /**
  * \brief Used to kill flow recycler thread(s).
  *
+ * \note this should only be called when the flow manager is already gone
+ *
  * \todo Kinda hackish since it uses the tv name to identify flow recycler
  *       thread.  We need an all weather identification scheme.
  */
@@ -720,7 +732,11 @@ void FlowKillFlowRecyclerThread(void)
     ThreadVars *tv = NULL;
     int cnt = 0;
 
-    SCCtrlCondSignal(&flow_recycler_ctrl_cond);
+    /* make sure all flows are processed */
+    do {
+        SCCtrlCondSignal(&flow_recycler_ctrl_cond);
+        usleep(10);
+    } while (FlowRecyclerReadyToShutdown() == 0);
 
     SCMutexLock(&tv_root_lock);