summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChrisTX <xpipe@hotmail.de>2013-09-04 14:16:48 +0200
committerattilamolnar <attilamolnar@hush.com>2013-09-08 12:10:01 +0200
commit3f4d54eb031f1cd6b016dfe1f768ed86303e3856 (patch)
tree194c78243eb190c22328b351edf226ef93358b29
parentfb1e17c31cfb4af8f7512a0e6c7d7da81ae1be55 (diff)
Fix a crash when running as systemd service
- Fix a NULL dereference if a signal is raised in the constructor of the class InspIRCd - Resolve the parent's process exit code being SIGTERM=15 and typically not EXIT_SUCCESS thus A combination of the two caused crashes when running as systemd unit.
-rw-r--r--include/inspircd.h3
-rw-r--r--src/inspircd.cpp19
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;