From 3829cd06105e114cf722b9f22aee61f6a7fde6f9 Mon Sep 17 00:00:00 2001
From: g0dil <g0dil@wiback.org>
Date: Fri, 4 Apr 2008 23:12:19 +0000
Subject: [PATCH] Utils/Daemon: Add Daemon::removeDaemonArgs()

---
 Utils/Daemon/Daemon.cc | 18 ++++++++++++++++++
 Utils/Daemon/Daemon.hh |  1 +
 2 files changed, 19 insertions(+)

diff --git a/Utils/Daemon/Daemon.cc b/Utils/Daemon/Daemon.cc
index 079b383f..9457d8c4 100644
--- a/Utils/Daemon/Daemon.cc
+++ b/Utils/Daemon/Daemon.cc
@@ -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) {
diff --git a/Utils/Daemon/Daemon.hh b/Utils/Daemon/Daemon.hh
index 76e10e73..89e2d53f 100644
--- a/Utils/Daemon/Daemon.hh
+++ b/Utils/Daemon/Daemon.hh
@@ -158,6 +158,7 @@ namespace senf {
 
         int argc();                     ///< Access command line parameter count
         char ** argv();                 ///< Access command line parameters
+        void removeDaemonArgs();        ///< Remove the daemon arguments from argc()/argv()
 
         static void exit(unsigned code=0); ///< Terminate daemon with failure
 
-- 
GitLab