]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
minor update to oops_handler. Main thread can perform different action during segfault
authorJosh <jrosenba@cisco.com>
Mon, 22 Sep 2014 19:25:29 +0000 (15:25 -0400)
committerJosh <jrosenba@cisco.com>
Mon, 22 Sep 2014 19:25:29 +0000 (15:25 -0400)
src/helpers/process.cc
src/helpers/process.h
src/main.cc
src/main/snort.cc
src/protocols/packet_manager.cc

index 7f8c7df7fbe64b861b96da0e51847d491b8a7283..73fbb83567cdb5271abc236aca2303a990727bcb 100644 (file)
@@ -32,6 +32,7 @@ using namespace std;
 
 #include "utils/util.h"
 #include "main/analyzer.h"
+#include "main/thread.h"
 #include "snort.h"
 #include "utils/ring.h"
 
@@ -63,6 +64,7 @@ const char* pig_sig_names[PIG_SIG_MAX] =
 
 static Ring<PigSignal> sig_ring(4);
 static volatile sig_atomic_t child_ready_signal = 0;
+static THREAD_LOCAL volatile bool is_main_thread = false;
 
 typedef void (*sighandler_t)(int);
 static int add_signal(int sig, sighandler_t, int check_needed);
@@ -72,6 +74,9 @@ static bool exit_pronto = true;
 void set_quick_exit(bool b)
 { exit_pronto = b; }
 
+void init_main_thread_sig()
+{ is_main_thread = true; }
+
 static void exit_handler(int signal)
 {
     PigSignal s;
@@ -127,7 +132,10 @@ static void child_ready_handler(int /*signal*/)
 
 static void oops_handler(int signal)
 {
-    CapturePacket();
+    // FIXIT-L what should we capture if this is the main thread?
+    if (!is_main_thread)
+        CapturePacket();
+
     add_signal(signal, SIG_DFL, 0);
     raise(signal);
 }
index ab9993b8e880aab2b0975be8b5a087042a9403dc..e9c1e4a241f91907800997ef3643fb5ec55c5916 100644 (file)
@@ -48,6 +48,7 @@ void help_signals();
 
 void daemonize();
 void set_quick_exit(bool);
+void init_main_thread_sig();
 
 #endif
 
index a96ba073030bea7fa27c4471c2acf3aedf951937..a769b944d0c9f71856dabe067e5cf6a5b6802a65 100644 (file)
@@ -671,6 +671,7 @@ static inline bool dont_stop()
 static void main_loop()
 {
     unsigned idx = max_pigs, swine = 0;
+    init_main_thread_sig();
 
     while ( !exit_logged && (dont_stop() || swine) )
     {
index ac0cec03738f0898aaa6a08dd099fac7e60af299..5923c36a031ccf627463f3974dad6e8a936aff49 100644 (file)
@@ -715,7 +715,10 @@ void CapturePacket()
         s_pkth = *s_packet.pkth;
 
         if ( s_packet.pkt )
+        {
             memcpy(s_data, s_packet.pkt, 0xFFFF & s_packet.pkth->caplen);
+            s_packet.pkt = s_data;
+        }
     }
 }
 
index def4eb0179224df9b23cce05c04fc83b6dce2a46..9ec1df09ba590bae646b361b3a63ddebd8248bbc 100644 (file)
@@ -142,7 +142,6 @@ static_assert(CODEC_ENCAP_LAYER == (CODEC_UNSURE_ENCAP | CODEC_SAVE_LAYER),
     "If this is an encapsulated layer, you must also set UNSURE_ENCAP"
     " and SAVE_LAYER");
 
-
 //-------------------------------------------------------------------------
 // Encode/Decode functions
 //-------------------------------------------------------------------------
@@ -154,10 +153,6 @@ void PacketManager::decode(
     uint8_t mapped_prot = CodecManager::grinder;
     uint16_t prev_prot_id = FINISHED_DECODE;
 
-
-//    assert(!(p->packet_flags & PKT_REBUILT_STREAM));
-
-
     // initialize all Packet information
     memset(p, 0, PKT_ZERO_LEN);
     p->pkth = pkthdr;