diff options
-rw-r--r-- | include/inspircd.h | 3 | ||||
-rw-r--r-- | src/inspircd.cpp | 19 |
2 files changed, 15 insertions, 7 deletions
diff --git a/include/inspircd.h b/include/inspircd.h index 86853a94f..d5e749193 100644 --- a/include/inspircd.h +++ b/include/inspircd.h @@ -47,6 +47,7 @@ #endif // Required system headers. +#include <csignal> #include <ctime> #include <cstdarg> #include <algorithm> @@ -454,7 +455,7 @@ class CoreExport InspIRCd /** Set to the current signal recieved */ - int s_signal; + static sig_atomic_t s_signal; /** Protocol interface, overridden by server protocol modules */ diff --git a/src/inspircd.cpp b/src/inspircd.cpp index 9516449a0..9d92888a3 100644 --- a/src/inspircd.cpp +++ b/src/inspircd.cpp @@ -63,7 +63,6 @@ #include "testsuite.h" InspIRCd* ServerInstance = NULL; -int* mysig = NULL; /** Seperate from the other casemap tables so that code *can* still exclusively rely on RFC casemapping * if it must. @@ -244,13 +243,20 @@ void InspIRCd::QuickExit(int status) exit(status); } +// Required for returning the proper value of EXIT_SUCCESS for the parent process +static void VoidSignalHandler(int signalreceived) +{ + exit(0); +} + bool InspIRCd::DaemonSeed() { #ifdef _WIN32 std::cout << "InspIRCd Process ID: " << con_green << GetCurrentProcessId() << con_reset << std::endl; return true; #else - signal(SIGTERM, InspIRCd::QuickExit); + // Do not use QuickExit here: It will exit with status SIGTERM which would break e.g. daemon scripts + signal(SIGTERM, VoidSignalHandler); int childpid; if ((childpid = fork ()) < 0) @@ -847,10 +853,10 @@ int InspIRCd::Run() GlobalCulls.Apply(); AtomicActions.Run(); - if (this->s_signal) + if (s_signal) { this->SignalHandler(s_signal); - this->s_signal = 0; + s_signal = 0; } } @@ -874,9 +880,11 @@ bool InspIRCd::AllModulesReportReady(LocalUser* user) return (res == MOD_RES_PASSTHRU); } +sig_atomic_t InspIRCd::s_signal = 0; + void InspIRCd::SetSignal(int signal) { - *mysig = signal; + s_signal = signal; } /* On posix systems, the flow of the program starts right here, with @@ -888,7 +896,6 @@ void InspIRCd::SetSignal(int signal) ENTRYPOINT { new InspIRCd(argc, argv); - mysig = &ServerInstance->s_signal; ServerInstance->Run(); delete ServerInstance; return 0; |