From: g0dil Date: Fri, 4 Apr 2008 23:12:19 +0000 (+0000) Subject: Utils/Daemon: Add Daemon::removeDaemonArgs() X-Git-Url: http://g0dil.de/git?a=commitdiff_plain;h=2c6294b3a810ee64e117df1b0da01d6b120534bb;p=senf.git Utils/Daemon: Add Daemon::removeDaemonArgs() git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@786 270642c3-0616-0410-b53a-bc976706d245 --- diff --git a/Utils/Daemon/Daemon.cc b/Utils/Daemon/Daemon.cc index 079b383..9457d8c 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 76e10e7..89e2d53 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