]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Merge pull request #826 in SNORT/snort3 from quiet_daemon to master
authorRuss Combs (rucombs) <rucombs@cisco.com>
Wed, 1 Mar 2017 02:05:05 +0000 (21:05 -0500)
committerRuss Combs (rucombs) <rucombs@cisco.com>
Wed, 1 Mar 2017 02:05:05 +0000 (21:05 -0500)
Squashed commit of the following:

commit db5d675a41a376734931ec2b3cea3dfa805b052b
Author: Carter Waxman <cwaxman@cisco.com>
Date:   Mon Feb 27 11:25:19 2017 -0500

    pid file is created regardless of priv drop settings

src/main.cc
src/main/snort.cc
src/main/snort.h

index 4893097f95130e4338aa1baffb2a6c29d0fede5c..8ad08c582d7a887467ec2b205f440bec18ac261a 100644 (file)
@@ -828,10 +828,15 @@ static void handle(Pig& pig, unsigned& swine, unsigned& pending_privileges)
             // FIXIT-L Make this call and the one below exit more gracefully upon error
             if (!Snort::drop_privileges())
                 FatalError("Failed to drop privileges!\n");
+
+            Snort::do_pidfile();
             broadcast(new ACStart());
         }
         else
+        {
+            Snort::do_pidfile();
             pig.queue_command(new ACStart());
+        }
         break;
 
     case Analyzer::State::STARTED:
@@ -845,12 +850,18 @@ static void handle(Pig& pig, unsigned& swine, unsigned& pending_privileges)
             }
             if (pending_privileges)
                 break;
+
             if (!Snort::drop_privileges())
                 FatalError("Failed to drop privileges!\n");
+
+            Snort::do_pidfile();
             broadcast(new ACRun());
         }
         else
+        {
+            Snort::do_pidfile();
             pig.queue_command(new ACRun());
+        }
         break;
 
     case Analyzer::State::STOPPED:
index 2bb87726d5994b822f3a1db2716ea8c796e329c7..8f41998eb01923e685f580a4db5dc19409744214 100644 (file)
@@ -355,15 +355,23 @@ bool Snort::drop_privileges()
             return false;
     }
 
-    if (SnortConfig::create_pid_file())
-        CreatePidFile(snort_main_thread_pid);
-
     initializing = false;
     privileges_dropped = true;
 
     return true;
 }
 
+void Snort::do_pidfile()
+{
+    static bool pid_file_created = false;
+
+    if (SnortConfig::create_pid_file() && !pid_file_created)
+    {
+        CreatePidFile(snort_main_thread_pid);
+        pid_file_created = true;
+    }
+}
+
 //-------------------------------------------------------------------------
 // termination
 //-------------------------------------------------------------------------
index 5f0c9abfac2c35f0f26e4f8c0ea20437bc955ce4..301542527ee61135ff0882319f4ec896c8cbfec1 100644 (file)
@@ -39,6 +39,7 @@ public:
     static SnortConfig* get_reload_config(const char* fname);
     static void setup(int argc, char* argv[]);
     static bool drop_privileges();
+    static void do_pidfile();
     static void cleanup();
 
     static bool is_starting();