Utils/Logger: Fix the bugfix .. outch ...
[senf.git] / Utils / Daemon / Daemon.cc
index 079b383..94d95ea 100644 (file)
@@ -92,6 +92,24 @@ prefix_ char ** senf::Daemon::argv()
     return argv_;
 }
 
+namespace {
+
+    struct IsDaemonOpt {
+        bool operator()(std::string const & str) const {
+            return str == "--no-daemon"
+                || boost::starts_with(str, std::string("--pid-file="))
+                || boost::starts_with(str, std::string("--console-log="));
+        }
+    };
+}
+
+prefix_ void senf::Daemon::removeDaemonArgs()
+{
+    char ** last (std::remove_if(argv_+1, argv_+argc_, IsDaemonOpt()));
+    *last = 0;
+    argc_ = last - argv_;
+}
+
 prefix_ void senf::Daemon::consoleLog(std::string const & path, StdStream which)
 {
     switch (which) {
@@ -523,6 +541,9 @@ prefix_ void senf::Daemon::installSighandlers()
 
     ::sigaction(SIGHUP,   &sa, NULL);
 
+    sa.sa_handler = SIG_IGN;
+    ::sigaction(SIGPIPE, &sa, NULL);
+
 #ifdef SENF_DEBUG
     sa.sa_sigaction = &fatalSignalsHandler;
     sa.sa_flags = SA_RESTART | SA_SIGINFO;