X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Utils%2FDaemon%2FDaemon.cc;h=13668eec5b648a20efdeff29c73fb3bb2b26bfd8;hb=034f9bec0a66d26314fb6ebc83dedf1618a2c19d;hp=c60939ab77908e96bfe5e28400beca60b704fbc8;hpb=cb2920bff3d35e88f195be7f5e03c217b9cf484c;p=senf.git diff --git a/Utils/Daemon/Daemon.cc b/Utils/Daemon/Daemon.cc index c60939a..13668ee 100644 --- a/Utils/Daemon/Daemon.cc +++ b/Utils/Daemon/Daemon.cc @@ -46,8 +46,11 @@ #define prefix_ ///////////////////////////////cc.p//////////////////////////////////////// -#define LIBC_CALL(fn, args) if (fn args < 0) throw SystemException(#fn "()") -#define LIBC_CALL_RV(var, fn, args) int var (fn args); if (var < 0) throw SystemException(#fn "()") +#define LIBC_CALL(fn, args) if (fn args < 0) \ + SENF_THROW_SYSTEM_EXCEPTION(#fn "()") + +#define LIBC_CALL_RV(var, fn, args) \ + int var (fn args); if (var < 0) SENF_THROW_SYSTEM_EXCEPTION(#fn "()") /////////////////////////////////////////////////////////////////////////// // senf::Daemon @@ -57,9 +60,9 @@ prefix_ senf::Daemon::~Daemon() if (! pidfile_.empty()) { try { LIBC_CALL( ::unlink, (pidfile_.c_str()) ); - } catch (SystemException e) { - e << "; could not unlink " << pidfile_.c_str(); - throw; + } catch (Exception e) { + // e << "; could not unlink " << pidfile_.c_str(); + // throw; } } } @@ -98,7 +101,8 @@ prefix_ void senf::Daemon::openLog() if (! stdoutLog_.empty()) { fd = ::open(stdoutLog_.c_str(), O_WRONLY | O_APPEND | O_CREAT, 0666); if (fd < 0) - throw SystemException("::open()"); + SENF_THROW_SYSTEM_EXCEPTION("") + << " Could not open \"" << stdoutLog_ << "\" for redirecting stdout."; stdout_ = fd; } if (stderrLog_ == stdoutLog_) @@ -106,7 +110,8 @@ prefix_ void senf::Daemon::openLog() else if (! stderrLog_.empty()) { fd = ::open(stdoutLog_.c_str(), O_WRONLY | O_APPEND | O_CREAT, 0666); if (fd < 0) - throw SystemException("::open()"); + SENF_THROW_SYSTEM_EXCEPTION("") + << " Could not open \"" << stderrLog_ << "\" for redirecting stderr."; stderr_ = fd; } } @@ -154,7 +159,7 @@ prefix_ void senf::Daemon::detach() while (! signaled) { ::sigsuspend(&waitsig); if (errno != EINTR) - throw SystemException("::sigsuspend()"); + SENF_THROW_SYSTEM_EXCEPTION("::sigsuspend()"); } LIBC_CALL( ::sigaction, (SIGUSR1, &oldact, 0) ); @@ -323,7 +328,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%\""); + boost::format linkErrorFormat(" Could not link \"%1%\" to \"%2%\"."); { char hostname[HOST_NAME_MAX+1]; @@ -337,13 +342,18 @@ prefix_ bool senf::Daemon::pidfileCreate() while (1) { { std::ofstream pidf (tempname.c_str()); + if (! pidf) + SENF_THROW_SYSTEM_EXCEPTION("") + << " Could not open pidfile \"" << tempname << "\" for output."; pidf << ::getpid() << std::endl; + if (! pidf) + SENF_THROW_SYSTEM_EXCEPTION("") + << " Could not write to pidfile \"" << tempname << "\"."; } if (::link(tempname.c_str(), pidfile_.c_str()) < 0) { if (errno != EEXIST) - throw SystemException("::link()") - << linkErrorFormat % pidfile_.c_str() % tempname.c_str(); + SENF_THROW_SYSTEM_EXCEPTION("") << linkErrorFormat % pidfile_ % tempname; } else { struct ::stat s; @@ -374,8 +384,7 @@ 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()") - << linkErrorFormat % tempname.c_str() % pidfile_.c_str(); + SENF_THROW_SYSTEM_EXCEPTION("") << linkErrorFormat % tempname % pidfile_; // Hmm ... the pidfile mysteriously disappeared ... try again. continue; } @@ -438,7 +447,7 @@ prefix_ void senf::detail::DaemonWatcher::pipeClosed(int id) if (sigChld_) childDied(); // does not return if (::kill(childPid_, SIGUSR1) < 0) - if (errno != ESRCH) throw SystemException("::kill()"); + if (errno != ESRCH) SENF_THROW_SYSTEM_EXCEPTION("::kill()"); Scheduler::instance().timeout( Scheduler::instance().eventTime() + ClockService::seconds(1), senf::membind(&DaemonWatcher::childOk, this)); @@ -455,7 +464,7 @@ prefix_ void senf::detail::DaemonWatcher::sigChld() prefix_ void senf::detail::DaemonWatcher::childDied() { int status (0); - if (::waitpid(childPid_,&status,0) < 0) throw SystemException("::waitpid()"); + if (::waitpid(childPid_,&status,0) < 0) SENF_THROW_SYSTEM_EXCEPTION("::waitpid()"); if (WIFSIGNALED(status)) { ::signal(WTERMSIG(status),SIG_DFL); ::kill(::getpid(), WTERMSIG(status)); @@ -506,7 +515,7 @@ prefix_ void senf::detail::DaemonWatcher::Forwarder::readData(Scheduler::EventId while (1) { n = ::read(src_,buf,1024); if (n<0) { - if (errno != EINTR) throw SystemException("::read()"); + if (errno != EINTR) SENF_THROW_SYSTEM_EXCEPTION("::read()"); } else break; } @@ -550,7 +559,7 @@ prefix_ void senf::detail::DaemonWatcher::Forwarder::writeData(Scheduler::EventI int w (::write(target->fd, buf, n)); if (w < 0) { - if (errno != EINTR) throw SystemException("::write()"); + if (errno != EINTR) SENF_THROW_SYSTEM_EXCEPTION("::write()"); return; } target->offset += w;