diff options
author | Chris Wilson <chris+github@qwirx.com> | 2006-11-26 19:38:07 +0000 |
---|---|---|
committer | Chris Wilson <chris+github@qwirx.com> | 2006-11-26 19:38:07 +0000 |
commit | 1f2de110c9d4e55ee4d76b46857b4e26a2671e73 (patch) | |
tree | 85f632a21a599448a4f364fd49a8f7e5ca2b7fe3 /lib | |
parent | 366574d921bf39a356d558ef8d61d78181a7af9b (diff) |
* Allow Daemons to be created more than once per process
* Don't initialise signal handler until after fork, in case the parent
is actually a unit test or another complex application
* Don't exit(0) in the parent, for the same reason (refs #9)
Diffstat (limited to 'lib')
-rw-r--r-- | lib/server/Daemon.cpp | 36 |
1 files changed, 20 insertions, 16 deletions
diff --git a/lib/server/Daemon.cpp b/lib/server/Daemon.cpp index 2131bdcb..af478320 100644 --- a/lib/server/Daemon.cpp +++ b/lib/server/Daemon.cpp @@ -48,11 +48,11 @@ Daemon *Daemon::spDaemon = 0; // // -------------------------------------------------------------------------- Daemon::Daemon() - : mpConfiguration(0), + : mpConfiguration(NULL), mReloadConfigWanted(false), mTerminateWanted(false) { - if(spDaemon != 0) + if(spDaemon != NULL) { THROW_EXCEPTION(ServerException, AlreadyDaemonConstructed) } @@ -79,6 +79,9 @@ Daemon::~Daemon() delete mpConfiguration; mpConfiguration = 0; } + + ASSERT(spDaemon == this); + spDaemon = NULL; } // -------------------------------------------------------------------------- @@ -183,18 +186,6 @@ int Daemon::Main(const char *DefaultConfigFile, int argc, const char *argv[]) // Let the derived class have a go at setting up stuff in the initial process SetupInInitialProcess(); -#ifndef WIN32 - // Set signal handler - struct sigaction sa; - sa.sa_handler = SignalHandler; - sa.sa_flags = 0; - sigemptyset(&sa.sa_mask); // macro - if(::sigaction(SIGHUP, &sa, NULL) != 0 || ::sigaction(SIGTERM, &sa, NULL) != 0) - { - THROW_EXCEPTION(ServerException, DaemoniseFailed) - } -#endif // !WIN32 - // Server configuration const Configuration &serverConfig( mpConfiguration->GetSubConfiguration("Server")); @@ -232,7 +223,7 @@ int Daemon::Main(const char *DefaultConfigFile, int argc, const char *argv[]) default: // parent - _exit(0); + // _exit(0); return 0; break; @@ -269,7 +260,20 @@ int Daemon::Main(const char *DefaultConfigFile, int argc, const char *argv[]) break; } } -#endif // ! WIN32 + + // Set signal handler + // Don't do this in the parent, since it might be anything + // (e.g. test/bbackupd) + + struct sigaction sa; + sa.sa_handler = SignalHandler; + sa.sa_flags = 0; + sigemptyset(&sa.sa_mask); // macro + if(::sigaction(SIGHUP, &sa, NULL) != 0 || ::sigaction(SIGTERM, &sa, NULL) != 0) + { + THROW_EXCEPTION(ServerException, DaemoniseFailed) + } +#endif // !WIN32 // open the log ::openlog(DaemonName(), LOG_PID, LOG_LOCAL6); |