From f3fa07f776e208bb8933b3edb4b47baa886187c0 Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Tue, 19 Jul 2022 16:25:28 +0100 Subject: Allow forcing binary exit codes at compile time. This is useful with some init systems that handle our exit codes strangely. --- src/server.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src/server.cpp') diff --git a/src/server.cpp b/src/server.cpp index 46ed9e9ff..ccc572553 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -56,7 +56,13 @@ void InspIRCd::Exit(int status) this->Cleanup(); ServerInstance = NULL; delete this; - exit (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) -- cgit v1.3.1-10-gc9f91 From 42b1429b37f1365687479764b4524cac913787b7 Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Tue, 19 Jul 2022 16:47:02 +0100 Subject: Also use binary exit codes in places that terminate abruptly. This is a partial reversion of commit 57330e973b3eb1f2a84803c84daf9d6b420859fd. --- include/inspircd.h | 8 ++++++++ src/inspircd.cpp | 14 +++++++------- src/server.cpp | 4 ++++ src/socketengine.cpp | 2 +- 4 files changed, 20 insertions(+), 8 deletions(-) (limited to 'src/server.cpp') diff --git a/include/inspircd.h b/include/inspircd.h index 68cc647f8..4fcc6c4f6 100644 --- a/include/inspircd.h +++ b/include/inspircd.h @@ -417,6 +417,14 @@ class CoreExport InspIRCd */ 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) + */ + 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/src/inspircd.cpp b/src/inspircd.cpp index 0205bd3b6..09cbf99d3 100644 --- a/src/inspircd.cpp +++ b/src/inspircd.cpp @@ -167,20 +167,20 @@ namespace if (setgroups(0, NULL) == -1) { ServerInstance->Logs->Log("STARTUP", LOG_DEFAULT, "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->Log("STARTUP", LOG_DEFAULT, "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->Log("STARTUP", LOG_DEFAULT, "setgid(%d) failed (wrong group?): %s", g->gr_gid, strerror(errno)); - exit(EXIT_STATUS_CONFIG); + InspIRCd::QuickExit(EXIT_STATUS_CONFIG); } } @@ -192,13 +192,13 @@ namespace if (!u) { ServerInstance->Logs->Log("STARTUP", LOG_DEFAULT, "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->Log("STARTUP", LOG_DEFAULT, "setuid(%d) failed (wrong user?): %s", u->pw_uid, strerror(errno)); - exit(EXIT_STATUS_CONFIG); + InspIRCd::QuickExit(EXIT_STATUS_CONFIG); } } #endif @@ -262,7 +262,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 { @@ -399,7 +399,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 ccc572553..1787e4f26 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -56,7 +56,11 @@ void InspIRCd::Exit(int status) this->Cleanup(); ServerInstance = NULL; delete this; + 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); diff --git a/src/socketengine.cpp b/src/socketengine.cpp index 629203710..ac8f56289 100644 --- a/src/socketengine.cpp +++ b/src/socketengine.cpp @@ -77,7 +77,7 @@ void EventHandler::OnEventHandlerError(int errornum) void SocketEngine::InitError() { std::cerr << con_red << "FATAL ERROR!" << con_reset << " Socket engine initialization failed. " << strerror(errno) << '.' << std::endl; - exit(EXIT_STATUS_SOCKETENGINE); + InspIRCd::QuickExit(EXIT_STATUS_SOCKETENGINE); } void SocketEngine::LookupMaxFds() -- cgit v1.3.1-10-gc9f91