]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Merge pull request #1487 in SNORT/snort3 from ~MDAGON/snort3:packet_thread_start...
authorTom Peters (thopeter) <thopeter@cisco.com>
Fri, 18 Jan 2019 20:42:45 +0000 (15:42 -0500)
committerTom Peters (thopeter) <thopeter@cisco.com>
Fri, 18 Jan 2019 20:42:45 +0000 (15:42 -0500)
Squashed commit of the following:

commit 1e58687aaa264f82289d73c5bbc69f9c14aeccbc
Author: Maya Dagon <mdagon@cisco.com>
Date:   Wed Jan 9 16:13:18 2019 -0500

    main: log message when all pthreads started (REG_TEST only)

src/main.cc

index b703888a3ddc965089856e2fceab26ab4ca4a0c7..22cfc64ca545a15758273d2f2ecd92b84e4e2433 100644 (file)
@@ -239,6 +239,9 @@ void Pig::reap_commands()
     } while (commands_to_reap > 1);
 }
 
+#ifdef REG_TEST
+static bool* pigs_started = nullptr;
+#endif
 static Pig* pigs = nullptr;
 static unsigned max_pigs = 0;
 
@@ -850,6 +853,10 @@ static void main_loop()
 {
     unsigned swine = 0, pending_privileges = 0;
 
+#ifdef REG_TEST
+    static bool all_pthreads_started = false;
+#endif
+
     if (SnortConfig::change_privileges())
         pending_privileges = max_pigs;
 
@@ -873,8 +880,14 @@ static void main_loop()
             Pig& pig = pigs[idx];
 
             if ( pig.analyzer )
+            {
                 handle(pig, swine, pending_privileges);
-
+#ifdef REG_TEST
+                if (!pigs_started[idx] && (pig.analyzer->get_state() ==
+                    Analyzer::State::STARTED))
+                    pigs_started[idx] = true;
+#endif
+            }
             else if ( pending_privileges )
                 pending_privileges--;
 
@@ -883,6 +896,19 @@ static void main_loop()
 
             continue;
         }
+
+#ifdef REG_TEST
+        if (!all_pthreads_started)
+        {
+            all_pthreads_started = true;
+            const unsigned num_threads = (!Trough::has_next()) ? swine : max_pigs;
+            for (unsigned i = 0; i < num_threads; i++)
+                all_pthreads_started &= pigs_started[i];
+            if (all_pthreads_started)
+                LogMessage("All pthreads started\n");
+        }
+#endif
+
         if ( !exit_requested and (swine < max_pigs) and (src = Trough::get_next()) )
         {
             Pig* pig = get_lazy_pig(max_pigs);
@@ -908,11 +934,17 @@ static void snort_main()
 
     pig_poke = new Ring<unsigned>((max_pigs*max_grunts)+1);
     pigs = new Pig[max_pigs];
+#ifdef REG_TEST
+    pigs_started = new bool[max_pigs];
+#endif
 
     for (unsigned idx = 0; idx < max_pigs; idx++)
     {
         Pig& pig = pigs[idx];
         pig.set_index(idx);
+#ifdef REG_TEST
+        pigs_started[idx] = false;
+#endif
     }
 
     main_loop();
@@ -920,6 +952,10 @@ static void snort_main()
     delete pig_poke;
     delete[] pigs;
     pigs = nullptr;
+#ifdef REG_TEST
+    delete[] pigs_started;
+    pigs_started = nullptr;
+#endif
 
 #ifdef SHELL
     ControlMgmt::socket_term();