From: Russ Combs (rucombs) Date: Wed, 1 Mar 2017 02:05:05 +0000 (-0500) Subject: Merge pull request #826 in SNORT/snort3 from quiet_daemon to master X-Git-Tag: 3.0.0-233~55 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=29101a153d4553df72eb641a1eb673a64196156d;p=thirdparty%2Fsnort3.git Merge pull request #826 in SNORT/snort3 from quiet_daemon to master Squashed commit of the following: commit db5d675a41a376734931ec2b3cea3dfa805b052b Author: Carter Waxman Date: Mon Feb 27 11:25:19 2017 -0500 pid file is created regardless of priv drop settings --- diff --git a/src/main.cc b/src/main.cc index 4893097f9..8ad08c582 100644 --- a/src/main.cc +++ b/src/main.cc @@ -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: diff --git a/src/main/snort.cc b/src/main/snort.cc index 2bb87726d..8f41998eb 100644 --- a/src/main/snort.cc +++ b/src/main/snort.cc @@ -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 //------------------------------------------------------------------------- diff --git a/src/main/snort.h b/src/main/snort.h index 5f0c9abfa..301542527 100644 --- a/src/main/snort.h +++ b/src/main/snort.h @@ -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();