diff options
| author | 2026-06-19 16:25:36 +0100 | |
|---|---|---|
| committer | 2026-06-19 16:43:54 +0100 | |
| commit | ebcce68b6095ca9766641ce5dc00aae01d61de06 (patch) | |
| tree | 1031bb5de5cbfd3be5ce37470d593bbe30154c95 /modules/core | |
| parent | Rework error reporting and shutting down. (diff) | |
Move server restart logic to the core.
- Properly clean up the process with Cleanup() instead of using
- DieRestart.
- Use close_range on modern Linux instead of the CLOEXEC hack.
Diffstat (limited to 'modules/core')
| -rw-r--r-- | modules/core/core_oper/cmd_die.cpp | 23 | ||||
| -rw-r--r-- | modules/core/core_oper/cmd_restart.cpp | 31 | ||||
| -rw-r--r-- | modules/core/core_oper/core_oper.h | 8 |
3 files changed, 3 insertions, 59 deletions
diff --git a/modules/core/core_oper/cmd_die.cpp b/modules/core/core_oper/cmd_die.cpp index 61d7658bb..f7aa67613 100644 --- a/modules/core/core_oper/cmd_die.cpp +++ b/modules/core/core_oper/cmd_die.cpp @@ -37,32 +37,11 @@ CommandDie::CommandDie(const WeakModulePtr& parent) syntax = { "<servername>" }; } -void DieRestart::SendError(const std::string& message) -{ - ClientProtocol::Messages::Error errormsg(message); - ClientProtocol::Event errorevent(ServerInstance->GetRFCEvents().error, errormsg); - - for (auto* user : ServerInstance->Users.GetLocalUsers()) - { - if (user->IsFullyConnected()) - { - user->WriteNotice(message); - } - else - { - // Partially connected users receive ERROR, not a NOTICE - user->Send(errorevent); - } - } -} - CmdResult CommandDie::Handle(User* user, const Params& parameters) { if (insp::casemapped_equals(parameters[0], ServerInstance->Config->ServerName)) { - const std::string diebuf = "*** DIE command from " + user->GetMask() + ". Terminating."; - ServerInstance->Logs.Critical(MODNAME, diebuf); - DieRestart::SendError(diebuf); + ServerInstance->SNO.WriteGlobalSno('a', "DIE command from {}, shutting down server.", user->GetRealMask()); ServerInstance->Exit(EXIT_SUCCESS); } return CmdResult::FAILURE; diff --git a/modules/core/core_oper/cmd_restart.cpp b/modules/core/core_oper/cmd_restart.cpp index 0274bfac3..030f98362 100644 --- a/modules/core/core_oper/cmd_restart.cpp +++ b/modules/core/core_oper/cmd_restart.cpp @@ -23,13 +23,6 @@ */ -#ifdef _WIN32 -# include <process.h> -#else -# include <fcntl.h> -# include <unistd.h> -#endif - #include "inspircd.h" #include "core_oper.h" @@ -42,31 +35,11 @@ CommandRestart::CommandRestart(const WeakModulePtr& parent) CmdResult CommandRestart::Handle(User* user, const Params& parameters) { - ServerInstance->Logs.Normal(MODNAME, "Restart: {}", user->nick); if (insp::casemapped_equals(parameters[0], ServerInstance->Config->ServerName)) { ServerInstance->SNO.WriteGlobalSno('a', "RESTART command from {}, restarting server.", user->GetRealMask()); - - DieRestart::SendError("Server restarting."); - -#ifdef FD_CLOEXEC - /* XXX: This hack sets FD_CLOEXEC on all possible file descriptors, so they're closed if the execvp() below succeeds. - * Certainly, this is not a nice way to do things and it's slow when the fd limit is high. - * - * A better solution would be to set the close-on-exec flag for each fd we create (or create them with O_CLOEXEC), - * however there is no guarantee that third party libs will do the same. - */ - for (int i = (int)SocketEngine::GetMaxFds(); --i > 2; ) - { - int flags = fcntl(i, F_GETFD); - if (flags != -1) - fcntl(i, F_SETFD, flags | FD_CLOEXEC); - } -#endif - - execvp(ServerInstance->CommandLine.argv[0], ServerInstance->CommandLine.argv); - ServerInstance->SNO.WriteGlobalSno('a', "Failed RESTART - could not execute '{}' ({})", - ServerInstance->CommandLine.argv[0], strerror(errno)); + const auto error = ServerInstance->Restart(); + ServerInstance->SNO.WriteGlobalSno('a', "Failed RESTART: {}", error); } return CmdResult::FAILURE; } diff --git a/modules/core/core_oper/core_oper.h b/modules/core/core_oper/core_oper.h index 48375946e..d6729ad26 100644 --- a/modules/core/core_oper/core_oper.h +++ b/modules/core/core_oper/core_oper.h @@ -29,14 +29,6 @@ enum ERR_NOOPERHOST = 491, }; -namespace DieRestart -{ - /** Send an ERROR to partially connected users and a NOTICE to fully connected users - * @param message Message to send - */ - void SendError(const std::string& message); -} - class CommandDie final : public Command { |
