aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Sadie Powell2022-07-19 17:00:23 +0100
committerGravatar Sadie Powell2022-07-19 17:00:23 +0100
commitb763b1e69e58de3d7895354682b9f8e484d7e981 (patch)
treee0f978e310f05cf3293c82ebae461fc469ab6756
parentAllow remote servers to specify the context of a message. (diff)
parentAlso use binary exit codes in places that terminate abruptly. (diff)
Merge branch 'insp3' into master.
-rw-r--r--include/inspircd.h8
-rw-r--r--make/template/logrotate7
-rw-r--r--src/inspircd.cpp14
-rw-r--r--src/server.cpp12
-rw-r--r--src/socketengine.cpp2
5 files changed, 32 insertions, 11 deletions
diff --git a/include/inspircd.h b/include/inspircd.h
index 0c6f85eaf..7cdad2e31 100644
--- a/include/inspircd.h
+++ b/include/inspircd.h
@@ -357,6 +357,14 @@ public:
[[noreturn]]
void Exit(int status);
+ /** Causes the server to exit immediately.
+ *
+ * @param status The exit code to give to the operating system
+ * (See the ExitStatus enum for valid values)
+ */
+ [[noreturn]]
+ static void QuickExit(int status);
+
/** Formats the input string with the specified arguments.
* @param formatString The string to format
* @param ... A variable number of format arguments.
diff --git a/make/template/logrotate b/make/template/logrotate
index a80d2b5a3..ccef31fbe 100644
--- a/make/template/logrotate
+++ b/make/template/logrotate
@@ -18,7 +18,7 @@
# To use this file move it to /etc/logrotate.d/inspircd
-@LOG_DIR@/* {
+@LOG_DIR@/*.log {
compress
create 0644 @USER@ @GROUP@
dateext
@@ -28,7 +28,10 @@
rotate 8
weekly
postrotate
- if [ -d /lib/systemd ]
+ if [ -r "@RUNTIME_DIR@/inspircd.pid" ]
+ then
+ kill -HUP $(cat "@RUNTIME_DIR@/inspircd.pid")
+ elif [ -d /lib/systemd ]
then
if systemctl --quiet is-active inspircd
then
diff --git a/src/inspircd.cpp b/src/inspircd.cpp
index 3b6e3c3e7..ddad6cfc7 100644
--- a/src/inspircd.cpp
+++ b/src/inspircd.cpp
@@ -157,20 +157,20 @@ namespace
if (setgroups(0, NULL) == -1)
{
ServerInstance->Logs.Normal("STARTUP", "setgroups() failed (wtf?): %s", strerror(errno));
- exit(EXIT_STATUS_CONFIG);
+ InspIRCd::QuickExit(EXIT_STATUS_CONFIG);
}
struct group* g = getgrnam(SetGroup.c_str());
if (!g)
{
ServerInstance->Logs.Normal("STARTUP", "getgrnam(%s) failed (wrong group?): %s", SetGroup.c_str(), strerror(errno));
- exit(EXIT_STATUS_CONFIG);
+ InspIRCd::QuickExit(EXIT_STATUS_CONFIG);
}
if (setgid(g->gr_gid) == -1)
{
ServerInstance->Logs.Normal("STARTUP", "setgid(%d) failed (wrong group?): %s", g->gr_gid, strerror(errno));
- exit(EXIT_STATUS_CONFIG);
+ InspIRCd::QuickExit(EXIT_STATUS_CONFIG);
}
}
@@ -182,13 +182,13 @@ namespace
if (!u)
{
ServerInstance->Logs.Normal("STARTUP", "getpwnam(%s) failed (wrong user?): %s", SetUser.c_str(), strerror(errno));
- exit(EXIT_STATUS_CONFIG);
+ InspIRCd::QuickExit(EXIT_STATUS_CONFIG);
}
if (setuid(u->pw_uid) == -1)
{
ServerInstance->Logs.Normal("STARTUP", "setuid(%d) failed (wrong user?): %s", u->pw_uid, strerror(errno));
- exit(EXIT_STATUS_CONFIG);
+ InspIRCd::QuickExit(EXIT_STATUS_CONFIG);
}
}
#endif
@@ -253,7 +253,7 @@ namespace
// happened and the parent should exit.
while (kill(childpid, 0) != -1)
sleep(1);
- exit(EXIT_STATUS_NOERROR);
+ InspIRCd::QuickExit(EXIT_STATUS_NOERROR);
}
else
{
@@ -400,7 +400,7 @@ namespace
// Required for returning the proper value of EXIT_SUCCESS for the parent process.
void VoidSignalHandler(int)
{
- exit(EXIT_STATUS_NOERROR);
+ InspIRCd::QuickExit(EXIT_STATUS_NOERROR);
}
}
diff --git a/src/server.cpp b/src/server.cpp
index fe26485a1..acf0f3241 100644
--- a/src/server.cpp
+++ b/src/server.cpp
@@ -56,7 +56,17 @@ void InspIRCd::Exit(int status)
this->Cleanup();
ServerInstance = NULL;
delete this;
- exit (status);
+ QuickExit(status);
+}
+
+void InspIRCd::QuickExit(int status)
+{
+#ifdef INSPIRCD_BINARY_EXIT
+ // Some init systems handle non-binary exit statuses weirdly.
+ exit(status ? EXIT_FAILURE : EXIT_SUCCESS);
+#else
+ exit(status);
+#endif
}
void InspIRCd::Rehash(const std::string& uuid)
diff --git a/src/socketengine.cpp b/src/socketengine.cpp
index dd8c0ad27..a63ea4c0b 100644
--- a/src/socketengine.cpp
+++ b/src/socketengine.cpp
@@ -79,7 +79,7 @@ void EventHandler::OnEventHandlerError(int errornum)
void SocketEngine::InitError()
{
std::cerr << rang::style::bold << rang::fg::red << "FATAL ERROR!" << rang::style::reset << " Socket engine initialization failed. " << strerror(errno) << '.' << std::endl;
- exit(EXIT_STATUS_SOCKETENGINE);
+ InspIRCd::QuickExit(EXIT_STATUS_SOCKETENGINE);
}
void SocketEngine::LookupMaxFds()