aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGravatar Sadie Powell2023-07-13 13:31:06 +0100
committerGravatar Sadie Powell2023-07-13 14:07:26 +0100
commitb4e3e973297db456f0ba8d7fdb8bbfc9c8426ea7 (patch)
tree6e642a3690d163861d6d14e86b57ccf300bd3e0c /src
parentError out if CMake is used on non-Windows. (diff)
downloadinspircd++-b4e3e973297db456f0ba8d7fdb8bbfc9c8426ea7.tar.gz
inspircd++-b4e3e973297db456f0ba8d7fdb8bbfc9c8426ea7.tar.bz2
inspircd++-b4e3e973297db456f0ba8d7fdb8bbfc9c8426ea7.zip
Simplify the codes that InspIRCd can exit with.
The custom codes that InspIRCd exits with are not very useful and can confuse init systems like systemd which assume that certain exit codes mean certain things. INSPIRCD_BINARY_EXIT was a workaround for this in v3 but considering thatsers have to check the logs anyway so we may as well just use EXIT_SUCCESS and EXIT_FAILURE.
Diffstat (limited to 'src')
-rw-r--r--src/configreader.cpp3
-rw-r--r--src/coremods/core_oper/cmd_die.cpp4
-rw-r--r--src/inspircd.cpp35
-rw-r--r--src/modulemanager.cpp5
-rw-r--r--src/modules.cpp9
-rw-r--r--src/server.cpp8
-rw-r--r--src/socketengine.cpp3
7 files changed, 27 insertions, 40 deletions
diff --git a/src/configreader.cpp b/src/configreader.cpp
index 110dc9172..3a0b70534 100644
--- a/src/configreader.cpp
+++ b/src/configreader.cpp
@@ -37,7 +37,6 @@
#include "inspircd.h"
#include "configparser.h"
-#include "exitcodes.h"
ServerConfig::ReadResult::ReadResult(const std::string& c, const std::string& e)
: contents(c)
@@ -528,7 +527,7 @@ void ServerConfig::Apply(ServerConfig* old, const std::string& useruid)
{
if (!valid)
{
- ServerInstance->Exit(EXIT_STATUS_CONFIG);
+ ServerInstance->Exit(EXIT_FAILURE);
}
return;
diff --git a/src/coremods/core_oper/cmd_die.cpp b/src/coremods/core_oper/cmd_die.cpp
index 87cf382e7..74b1b60a4 100644
--- a/src/coremods/core_oper/cmd_die.cpp
+++ b/src/coremods/core_oper/cmd_die.cpp
@@ -27,8 +27,6 @@
#include "inspircd.h"
#include "clientprotocolmsg.h"
-#include "exitcodes.h"
-
#include "core_oper.h"
@@ -65,7 +63,7 @@ CmdResult CommandDie::Handle(User* user, const Params& parameters)
const std::string diebuf = "*** DIE command from " + user->GetMask() + ". Terminating.";
ServerInstance->Logs.Error(MODNAME, diebuf);
DieRestart::SendError(diebuf);
- ServerInstance->Exit(EXIT_STATUS_DIE);
+ ServerInstance->Exit(EXIT_FAILURE);
}
else
{
diff --git a/src/inspircd.cpp b/src/inspircd.cpp
index 0372e4058..a4c6c9edc 100644
--- a/src/inspircd.cpp
+++ b/src/inspircd.cpp
@@ -40,7 +40,6 @@
#include <lyra/lyra.hpp>
#include "inspircd.h"
-#include "exitcodes.h"
#include "xline.h"
#ifndef _WIN32
@@ -92,7 +91,7 @@ namespace
{
fmt::println("If you are sure that you need to run as root then you can pass the {}", fmt::styled("--runasroot", fmt::emphasis::bold));
fmt::println("option to disable this error.");
- ServerInstance->Exit(EXIT_STATUS_ROOT);
+ ServerInstance->Exit(EXIT_FAILURE);
}
#endif
}
@@ -151,20 +150,20 @@ namespace
if (setgroups(0, nullptr) == -1)
{
ServerInstance->Logs.Error("STARTUP", "setgroups() failed (wtf?): {}", strerror(errno));
- InspIRCd::QuickExit(EXIT_STATUS_CONFIG);
+ InspIRCd::QuickExit(EXIT_FAILURE);
}
struct group* g = getgrnam(SetGroup.c_str());
if (!g)
{
ServerInstance->Logs.Error("STARTUP", "getgrnam({}) failed (wrong group?): {}", SetGroup, strerror(errno));
- InspIRCd::QuickExit(EXIT_STATUS_CONFIG);
+ InspIRCd::QuickExit(EXIT_FAILURE);
}
if (setgid(g->gr_gid) == -1)
{
ServerInstance->Logs.Error("STARTUP", "setgid({}) failed (wrong group?): {}", g->gr_gid, strerror(errno));
- InspIRCd::QuickExit(EXIT_STATUS_CONFIG);
+ InspIRCd::QuickExit(EXIT_FAILURE);
}
}
@@ -176,13 +175,13 @@ namespace
if (!u)
{
ServerInstance->Logs.Error("STARTUP", "getpwnam({}) failed (wrong user?): {}", SetUser, strerror(errno));
- InspIRCd::QuickExit(EXIT_STATUS_CONFIG);
+ InspIRCd::QuickExit(EXIT_FAILURE);
}
if (setuid(u->pw_uid) == -1)
{
ServerInstance->Logs.Error("STARTUP", "setuid({}) failed (wrong user?): {}", u->pw_uid, strerror(errno));
- InspIRCd::QuickExit(EXIT_STATUS_CONFIG);
+ InspIRCd::QuickExit(EXIT_FAILURE);
}
}
#endif
@@ -228,7 +227,7 @@ namespace
{
#ifndef _WIN32
// We use VoidSignalHandler whilst forking to avoid breaking daemon scripts
- // if the parent process exits with SIGTERM (15) instead of EXIT_STATUS_NOERROR (0).
+ // if the parent process exits with SIGTERM (15) instead of EXIT_SUCCESS (0).
signal(SIGTERM, VoidSignalHandler);
errno = 0;
@@ -237,7 +236,7 @@ namespace
{
ServerInstance->Logs.Error("STARTUP", "fork() failed: {}", strerror(errno));
fmt::println("{} unable to fork into background: {}", fmt::styled("Error:", fmt::emphasis::bold | fmt::fg(fmt::terminal_color::red)), strerror(errno));
- ServerInstance->Exit(EXIT_STATUS_FORK);
+ ServerInstance->Exit(EXIT_FAILURE);
}
else if (childpid > 0)
{
@@ -247,7 +246,7 @@ namespace
// happened and the parent should exit.
while (kill(childpid, 0) != -1)
sleep(1);
- InspIRCd::QuickExit(EXIT_STATUS_NOERROR);
+ InspIRCd::QuickExit(EXIT_SUCCESS);
}
else
{
@@ -318,19 +317,19 @@ namespace
if (!result)
{
fmt::println(stderr, "{} {}", fmt::styled("Error:", fmt::emphasis::bold | fmt::fg(fmt::terminal_color::red)), result.message());
- ServerInstance->Exit(EXIT_STATUS_ARGV);
+ ServerInstance->Exit(EXIT_FAILURE);
}
if (do_help)
{
std::cout << cli << std::endl;
- ServerInstance->Exit(EXIT_STATUS_NOERROR);
+ ServerInstance->Exit(EXIT_SUCCESS);
}
if (do_version)
{
fmt::println(INSPIRCD_VERSION);
- ServerInstance->Exit(EXIT_STATUS_NOERROR);
+ ServerInstance->Exit(EXIT_SUCCESS);
}
// Store the relevant parsed arguments
@@ -398,7 +397,7 @@ namespace
// Required for returning the proper value of EXIT_SUCCESS for the parent process.
void VoidSignalHandler(int)
{
- InspIRCd::QuickExit(EXIT_STATUS_NOERROR);
+ InspIRCd::QuickExit(EXIT_SUCCESS);
}
}
@@ -457,7 +456,7 @@ void InspIRCd::WritePID()
{
fmt::println("Failed to write PID-file '{}', exiting.", pidfile);
this->Logs.Error("STARTUP", "Failed to write PID-file '{}', exiting.", pidfile);
- Exit(EXIT_STATUS_PID);
+ Exit(EXIT_FAILURE);
}
}
@@ -503,7 +502,7 @@ InspIRCd::InspIRCd(int argc, char** argv)
this->Logs.Error("STARTUP", "Unable to open config file {}", ConfigFileName);
fmt::println("ERROR: Cannot open config file: {}", ConfigFileName);
fmt::println("Exiting...");
- Exit(EXIT_STATUS_CONFIG);
+ Exit(EXIT_FAILURE);
}
SetSignals();
@@ -529,7 +528,7 @@ InspIRCd::InspIRCd(int argc, char** argv)
{
fmt::println("ERROR: Cannot open log files: {}", ex.GetReason());
fmt::println("Exiting...");
- Exit(EXIT_STATUS_LOG);
+ Exit(EXIT_FAILURE);
}
// If we don't have a SID, generate one based on the server name and the server description
@@ -560,7 +559,7 @@ InspIRCd::InspIRCd(int argc, char** argv)
{
fmt::println("ERROR: Cannot open log files: {}", ex.GetReason());
fmt::println("Exiting...");
- Exit(EXIT_STATUS_LOG);
+ Exit(EXIT_FAILURE);
}
fmt::println("InspIRCd is now running as '{}'[{}] with {} max open sockets",
diff --git a/src/modulemanager.cpp b/src/modulemanager.cpp
index b0ac5f711..9a7ebfe3c 100644
--- a/src/modulemanager.cpp
+++ b/src/modulemanager.cpp
@@ -28,7 +28,6 @@
#include "inspircd.h"
#include "dynamic.h"
-#include "exitcodes.h"
bool ModuleManager::Load(const std::string& modname, bool defer)
{
@@ -150,14 +149,14 @@ void ModuleManager::LoadCoreModules(std::map<std::string, ServiceList>& servicem
fmt::println("");
fmt::println("[{}] {}", fmt::styled("*", fmt::emphasis::bold | fmt::fg(fmt::terminal_color::red)), LastError());
fmt::println("");
- ServerInstance->Exit(EXIT_STATUS_MODULE);
+ ServerInstance->Exit(EXIT_FAILURE);
}
}
}
catch (const std::filesystem::filesystem_error& err)
{
fmt::println("failed: {}", err.what());
- ServerInstance->Exit(EXIT_STATUS_MODULE);
+ ServerInstance->Exit(EXIT_FAILURE);
}
fmt::println("");
diff --git a/src/modules.cpp b/src/modules.cpp
index 13c73cb28..c400b1100 100644
--- a/src/modules.cpp
+++ b/src/modules.cpp
@@ -33,7 +33,6 @@
#include <fmt/color.h>
#include "inspircd.h"
-#include "exitcodes.h"
#include "dynamic.h"
#include "utility/map.h"
@@ -540,7 +539,7 @@ void ModuleManager::LoadAll()
fmt::println("");
fmt::println("[{}] {}", fmt::styled("*", fmt::emphasis::bold | fmt::fg(fmt::terminal_color::red)), LastError());
fmt::println("");
- ServerInstance->Exit(EXIT_STATUS_MODULE);
+ ServerInstance->Exit(EXIT_FAILURE);
}
}
@@ -561,7 +560,7 @@ void ModuleManager::LoadAll()
fmt::println("");
fmt::println("[{}] {}", fmt::styled("*", fmt::emphasis::bold | fmt::fg(fmt::terminal_color::red)), LastModuleError);
fmt::println("");
- ServerInstance->Exit(EXIT_STATUS_MODULE);
+ ServerInstance->Exit(EXIT_FAILURE);
}
}
@@ -585,12 +584,12 @@ void ModuleManager::LoadAll()
fmt::println("");
fmt::println("[{}] {}", fmt::styled("*", fmt::emphasis::bold | fmt::fg(fmt::terminal_color::red)), LastModuleError);
fmt::println("");
- ServerInstance->Exit(EXIT_STATUS_CONFIG);
+ ServerInstance->Exit(EXIT_FAILURE);
}
}
if (!PrioritizeHooks())
- ServerInstance->Exit(EXIT_STATUS_MODULE);
+ ServerInstance->Exit(EXIT_FAILURE);
}
std::string& ModuleManager::LastError()
diff --git a/src/server.cpp b/src/server.cpp
index 653ab16f9..1eba75e92 100644
--- a/src/server.cpp
+++ b/src/server.cpp
@@ -27,14 +27,13 @@
#include "inspircd.h"
-#include "exitcodes.h"
void InspIRCd::SignalHandler(int signal)
{
switch (signal)
{
case SIGTERM:
- Exit(EXIT_STATUS_SIGTERM);
+ Exit(EXIT_FAILURE);
#ifndef _WIN32
case SIGHUP:
@@ -63,12 +62,7 @@ void InspIRCd::Exit(int 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 c760b1a12..42b54062d 100644
--- a/src/socketengine.cpp
+++ b/src/socketengine.cpp
@@ -35,7 +35,6 @@
#include <fmt/color.h>
#include "inspircd.h"
-#include "exitcodes.h"
/** Reference table, contains all current handlers
**/
@@ -71,7 +70,7 @@ void EventHandler::OnEventHandlerError(int errornum)
void SocketEngine::InitError()
{
fmt::println(stderr, "{} Socket engine initialization failed. {}.", fmt::styled("FATAL ERROR!", fmt::emphasis::bold | fmt::fg(fmt::terminal_color::red)), strerror(errno));
- InspIRCd::QuickExit(EXIT_STATUS_SOCKETENGINE);
+ InspIRCd::QuickExit(EXIT_FAILURE);
}
void SocketEngine::LookupMaxFds()