diff --git a/Utils/Daemon/Daemon.cc b/Utils/Daemon/Daemon.cc index 079b383f44cc062f24323c902f8768c48a905063..9457d8c43c9b5d98e70a8e564c12116de6c62c43 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 76e10e732186158778c6bf073df67a73055b6b9c..89e2d53fe27273ae931c5102e93f0720d6ce56c5 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