[Box Backup-commit] COMMIT r1173 - box/chris/merge/lib/server
boxbackup-dev at fluffy.co.uk
boxbackup-dev at fluffy.co.uk
Sun Nov 26 19:38:07 GMT 2006
Author: chris
Date: 2006-11-26 19:38:07 +0000 (Sun, 26 Nov 2006)
New Revision: 1173
Modified:
box/chris/merge/lib/server/Daemon.cpp
Log:
* 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)
Modified: box/chris/merge/lib/server/Daemon.cpp
===================================================================
--- box/chris/merge/lib/server/Daemon.cpp 2006-11-26 16:23:03 UTC (rev 1172)
+++ box/chris/merge/lib/server/Daemon.cpp 2006-11-26 19:38:07 UTC (rev 1173)
@@ -48,11 +48,11 @@
//
// --------------------------------------------------------------------------
Daemon::Daemon()
- : mpConfiguration(0),
+ : mpConfiguration(NULL),
mReloadConfigWanted(false),
mTerminateWanted(false)
{
- if(spDaemon != 0)
+ if(spDaemon != NULL)
{
THROW_EXCEPTION(ServerException, AlreadyDaemonConstructed)
}
@@ -79,6 +79,9 @@
delete mpConfiguration;
mpConfiguration = 0;
}
+
+ ASSERT(spDaemon == this);
+ spDaemon = NULL;
}
// --------------------------------------------------------------------------
@@ -183,18 +186,6 @@
// 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 @@
default:
// parent
- _exit(0);
+ // _exit(0);
return 0;
break;
@@ -269,8 +260,21 @@
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);
More information about the Boxbackup-commit
mailing list