X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Utils%2FDaemon%2FDaemon.cc;h=8cbf98fbbfb6d72fdb0e0b597ae83bcd3ee7adea;hb=f2f5d59e83863f3b513950173baee1b6da2aee3c;hp=d6b8d917dbb5b410c578072317f029912077a4a2;hpb=9348e1098d66ac2684c8e280abf8d7143c887982;p=senf.git diff --git a/Utils/Daemon/Daemon.cc b/Utils/Daemon/Daemon.cc index d6b8d91..8cbf98f 100644 --- a/Utils/Daemon/Daemon.cc +++ b/Utils/Daemon/Daemon.cc @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -88,7 +89,7 @@ prefix_ int senf::Daemon::argc() return argc_; } -prefix_ char ** senf::Daemon::argv() +prefix_ char const ** senf::Daemon::argv() { return argv_; } @@ -106,7 +107,7 @@ namespace { prefix_ void senf::Daemon::removeDaemonArgs() { - char ** last (std::remove_if(argv_+1, argv_+argc_, IsDaemonOpt())); + char const ** last (std::remove_if(argv_+1, argv_+argc_, IsDaemonOpt())); *last = 0; argc_ = last - argv_; } @@ -131,8 +132,11 @@ prefix_ void senf::Daemon::openLog() << " Could not open \"" << stdoutLog_ << "\" for redirecting stdout."; stdout_ = fd; } - if (stderrLog_ == stdoutLog_) - stderr_ = fd; + if (stderrLog_ == stdoutLog_) { + stderr_ = ::dup(fd); + if (stderr_ < 0) + SENF_THROW_SYSTEM_EXCEPTION("::dup()"); + } else if (! stderrLog_.empty()) { fd = ::open(stdoutLog_.c_str(), O_WRONLY | O_APPEND | O_CREAT, 0666); if (fd < 0) @@ -237,7 +241,7 @@ prefix_ void senf::Daemon::exit(unsigned code) throw DaemonExitException(code); } -prefix_ int senf::Daemon::start(int argc, char ** argv) +prefix_ int senf::Daemon::start(int argc, char const ** argv) { argc_ = argc; argv_ = argv; @@ -306,6 +310,7 @@ senf::Daemon * senf::Daemon::instance_ (0); prefix_ void senf::Daemon::configure() { + // int i (not unsigned) since argc_ is int ... for (int i (1); i