]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Merge pull request #2297 in SNORT/snort3 from ~OKHOMIAK/snort3:trace_print_instance_i...
authorBhagya Tholpady (bbantwal) <bbantwal@cisco.com>
Thu, 2 Jul 2020 14:40:08 +0000 (14:40 +0000)
committerBhagya Tholpady (bbantwal) <bbantwal@cisco.com>
Thu, 2 Jul 2020 14:40:08 +0000 (14:40 +0000)
Squashed commit of the following:

commit 83da91a0bf7dcc47eb2bcdde87860a240229f78b
Author: Oleksii Khomiakovskyi <okhomiak@cisco.com>
Date:   Tue Jun 30 18:43:12 2020 +0300

    main: set thread type for main thread

commit 00065f327ea2f5555fedc514f7ab2434e7e3086c
Author: Oleksii Khomiakovskyi <okhomiak@cisco.com>
Date:   Thu Jun 18 14:00:25 2020 +0300

    trace: add thread type and thread instance id to each log message for stdout logger

doc/trace.txt
src/main.cc
src/main/thread_config.cc
src/trace/trace_log.cc

index 4efa1ff15c6831d7bf0c0ca5e9ea428fc6e2e11e..e5443d59d8fbfc5cd9c2b549b5dad10632236f29 100644 (file)
@@ -190,6 +190,16 @@ Each tracing message has a standard format:
 
     <module_name>:<option_name>:<message_log_level>: <particular_message>
 
+The stdout logger also prints thread type and thread instance ID at the beginning
+of each trace message in a colon-separated manner.
+
+The capital letter at the beginning of the trace message indicates the thread type.
+
+Possible thread types:
+C – main (control) thread
+P – packet thread
+O – other thread
+
 ==== Example - Debugging rules using detection trace
 
 The detection engine is responsible for rule evaluation. Turning on the
index e9ac830400eff7d940d32aed388fe89c9efcee29..dff06ac125170287f53ef964fcc6978da7ce600a 100644 (file)
@@ -1034,6 +1034,8 @@ int main(int argc, char* argv[])
     if ( s )
         prompt = s;
 
+    set_thread_type(STHREAD_TYPE_MAIN);
+
     Snort::setup(argc, argv);
 
     if ( set_mode() )
index d44997ce1b3ac30eb17ff0988b92ad16004f1549..e7859b140c97b44f932bd6322bb517e35be08386 100644 (file)
@@ -319,7 +319,7 @@ TEST_CASE("Named thread affinity with type configured", "[ThreadConfig]")
 
         // Configure type affinity, but not the named thread affinity.
         hwloc_bitmap_singlify(type_cpuset->cpuset);
-        tc.set_thread_affinity(STHREAD_TYPE_OTHER, ThreadConfig::DEFAULT_THREAD_ID, type_cpuset);
+        tc.set_thread_affinity(STHREAD_TYPE_MAIN, ThreadConfig::DEFAULT_THREAD_ID, type_cpuset);
 
         // The named thread should inherit the type affinity.
         tc.implement_named_thread_affinity("not found, type other");
index 968d1b09c9446eb2f01f756e4b800aa2befca470..6f52714a009431a7cafe0f38c73d2aed7b9b04d4 100644 (file)
@@ -26,6 +26,8 @@
 #include <cstdio>
 #include <syslog.h>
 
+#include "main/thread.h"
+
 using namespace snort;
 
 //-----------------------------------------------
@@ -44,16 +46,32 @@ public:
 
 private:
     FILE* file;
+    char thread_type;
+    unsigned instance_id;
 };
 
 StdoutTraceLogger::StdoutTraceLogger()
-    : file(stdout)
-{ }
+    : file(stdout), instance_id(get_instance_id())
+{
+    auto t = get_thread_type();
+    switch (t)
+    {
+    case STHREAD_TYPE_PACKET:
+        thread_type = 'P';
+        break;
+    case STHREAD_TYPE_MAIN:
+        thread_type = 'C';
+        break;
+    default:
+        thread_type = 'O';
+    }
+}
 
 void StdoutTraceLogger::log(const char* log_msg, const char* name,
     uint8_t log_level, const char* trace_option, const Packet*)
 {
-    fprintf(file, "%s:%s:%d: %s", name, trace_option, log_level, log_msg);
+    fprintf(file, "%c%u:%s:%s:%d: %s", thread_type, instance_id, name,
+        trace_option, log_level, log_msg);
 }
 
 // Syslog