diff options
author | Adam <Adam@anope.org> | 2011-10-22 11:20:50 -0400 |
---|---|---|
committer | Adam <Adam@anope.org> | 2011-10-22 11:20:50 -0400 |
commit | ad2ef75cbed4804f9f1d24419b9bc77fbe75a27a (patch) | |
tree | 5b153a345df5dff2de4a540a8bb1996f7c7b8a14 /src | |
parent | 6ce9010324f7394fc31eba8a3fc938c03b134025 (diff) |
Fixed a race condition with installing signal handlers and forking
Diffstat (limited to 'src')
-rw-r--r-- | src/init.cpp | 23 | ||||
-rw-r--r-- | src/main.cpp | 2 |
2 files changed, 16 insertions, 9 deletions
diff --git a/src/init.cpp b/src/init.cpp index 3177720c6..e63f6793b 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -256,7 +256,8 @@ class SignalForkExit : public Signal void OnNotify() { - exit(0); + quitting = true; + return_code = 0; } }; @@ -267,11 +268,12 @@ class SignalSigChld : public Signal void OnNotify() { - int status = 0, ret = -1; + quitting = true; + return_code = -1; + int status = 0; wait(&status); if (WIFEXITED(status)) - ret = WEXITSTATUS(status); - exit(ret); + return_code = WEXITSTATUS(status); } }; #endif @@ -407,21 +409,26 @@ void Init(int ac, char **av) #else if (!nofork && AtTerm()) { + SignalForkExit *sfe = new SignalForkExit(); + SignalSigChld *ssc = new SignalSigChld(); int i = fork(); if (i > 0) { - new SignalForkExit(); - new SignalSigChld(); while (!quitting) { Log(LOG_DEBUG_3) << "Top of fork() process loop"; SocketEngine::Process(); } - /* Should not be reached */ - exit(-1); + SocketEngine::Shutdown(); + exit(return_code); } else if (i == -1) + { Log() << "Error, unable to fork: " << Anope::LastError(); + /* On a successful fork, the parents socket engine shutdown will eat these */ + delete sfe; + delete ssc; + } } #endif diff --git a/src/main.cpp b/src/main.cpp index 26d4c29c0..b115137ea 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -46,7 +46,6 @@ bool nothird = false; /* -nothrid */ bool noexpire = false; /* -noexpire */ bool protocoldebug = false; /* -protocoldebug */ Anope::string binary_dir; /* Used to store base path for Anope */ -static int return_code = 0; #ifdef _WIN32 # include <process.h> @@ -55,6 +54,7 @@ static int return_code = 0; /* Set to 1 if we are to quit */ bool quitting = false; +int return_code = 0; /* Set to true if we are restarting */ bool restarting = false; |