// $Id$
//
// Copyright (C) 2007
-// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
-// Kompetenzzentrum fuer NETwork research (NET)
+// Fraunhofer Institute for Open Communication Systems (FOKUS)
+// Competence Center NETwork research (NET), St. Augustin, GERMANY
// Stefan Bund <g0dil@berlios.de>
//
// This program is free software; you can redistribute it and/or modify
prefix_ void senf::Daemon::detach()
{
- if (daemonize_) {
+ if (daemonize_ && ! detached_) {
// Wow .. ouch ..
// To ensure all data is written to the console log file in the correct order, we suspend
// execution here until the parent process tells us to continue via SIGUSR1: We block
LIBC_CALL( ::sigaction, (SIGUSR1, &oldact, 0) );
LIBC_CALL( ::sigprocmask, (SIG_SETMASK, &oldsig, 0) );
+
+ detached_ = true;
}
}
+namespace {
+ /* Purposely *not* derived from std::exception */
+ struct DaemonExitException {
+ DaemonExitException(unsigned c) : code(c) {}
+ unsigned code;
+ };
+}
+
+prefix_ void senf::Daemon::exit(unsigned code)
+{
+ throw DaemonExitException(code);
+}
+
prefix_ int senf::Daemon::start(int argc, char const ** argv)
{
argc_ = argc;
argv_ = argv;
-# ifdef NDEBUG
-
try {
-
-# endif
-
configure();
if (daemonize_) {
}
main();
+ }
+ catch (DaemonExitException & e) {
+ return e.code;
+ }
-# ifdef NDEBUG
+#ifdef SENF_NO_DEBUG
- }
catch (std::exception & e) {
std::cerr << "\n*** Fatal exception: " << e.what() << std::endl;
return 1;
std::string::size_type komma (arg.find(','));
if (komma == std::string::npos) {
boost::trim(arg);
- consoleLog(arg);
+ if (arg == std::string("none")) consoleLog("");
+ else if (!arg.empty()) consoleLog(arg);
} else {
std::string arg1 (arg,0,komma);
std::string arg2 (arg,komma+1);