summaryrefslogtreecommitdiff
path: root/src/init.cpp
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2011-10-22 11:20:50 -0400
committerAdam <Adam@anope.org>2011-10-22 11:20:50 -0400
commitad2ef75cbed4804f9f1d24419b9bc77fbe75a27a (patch)
tree5b153a345df5dff2de4a540a8bb1996f7c7b8a14 /src/init.cpp
parent6ce9010324f7394fc31eba8a3fc938c03b134025 (diff)
Fixed a race condition with installing signal handlers and forking
Diffstat (limited to 'src/init.cpp')
-rw-r--r--src/init.cpp23
1 files changed, 15 insertions, 8 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