X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Utils%2FDaemon%2FDaemon.cc;h=152186768576eec4327ae0403a2d17d48fdb47b4;hb=a66bffcc77f006b22190e1c27cbe0cd75fc4501c;hp=73fbf5d4f79f5bf38c9a0da594898a4f7fc32617;hpb=1d247d12d1759ffd77f456efe3a52f03dd289994;p=senf.git diff --git a/Utils/Daemon/Daemon.cc b/Utils/Daemon/Daemon.cc index 73fbf5d..1521867 100644 --- a/Utils/Daemon/Daemon.cc +++ b/Utils/Daemon/Daemon.cc @@ -38,6 +38,7 @@ #include #include #include +#include #include "../Exception.hh" #include "../membind.hh" @@ -53,8 +54,14 @@ prefix_ senf::Daemon::~Daemon() { - if (! pidfile_.empty()) - LIBC_CALL( ::unlink, (pidfile_.c_str()) ); + if (! pidfile_.empty()) { + try { + LIBC_CALL( ::unlink, (pidfile_.c_str()) ); + } catch (Exception e) { + // e << "; could not unlink " << pidfile_.c_str(); + // throw; + } + } } prefix_ void senf::Daemon::daemonize(bool v) @@ -67,6 +74,14 @@ prefix_ bool senf::Daemon::daemon() return daemonize_; } +prefix_ int senf::Daemon::argc() { + return argc_; +} + +prefix_ char const ** senf::Daemon::argv() { + return argv_; +} + prefix_ void senf::Daemon::consoleLog(std::string const & path, StdStream which) { switch (which) { @@ -186,7 +201,7 @@ prefix_ int senf::Daemon::start(int argc, char const ** argv) return e.code; } -#ifdef SENF_NO_DEBUG +#ifndef SENF_DEBUG catch (std::exception & e) { std::cerr << "\n*** Fatal exception: " << e.what() << std::endl; @@ -308,6 +323,7 @@ prefix_ bool senf::Daemon::pidfileCreate() // was some race condition, probably over NFS. std::string tempname; + boost::format linkErrorFormat("; could not link \"%1%\" to \"%2%\"."); { char hostname[HOST_NAME_MAX+1]; @@ -326,7 +342,8 @@ prefix_ bool senf::Daemon::pidfileCreate() if (::link(tempname.c_str(), pidfile_.c_str()) < 0) { if (errno != EEXIST) - throw SystemException("::link()"); + throw SystemException("::link()") + << linkErrorFormat % pidfile_.c_str() % tempname.c_str(); } else { struct ::stat s; @@ -356,7 +373,9 @@ prefix_ bool senf::Daemon::pidfileCreate() LIBC_CALL( ::unlink, (tempname.c_str() )); if (::link(pidfile_.c_str(), tempname.c_str()) < 0) { - if (errno != ENOENT) throw SystemException("::link()"); + if (errno != ENOENT) + throw SystemException("::link()") + << linkErrorFormat % tempname.c_str() % pidfile_.c_str(); // Hmm ... the pidfile mysteriously disappeared ... try again. continue; }