2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2018 linuxdaemon <linuxdaemon.irc@gmail.com>
5 * Copyright (C) 2018 Sadie Powell <sadie@witchery.services>
6 * Copyright (C) 2017 Jordyn/The Linux Geek <onlinecloud1@gmail.com>
7 * Copyright (C) 2012, 2019 Robby <robby@chatbelgie.be>
8 * Copyright (C) 2012, 2014-2016 Attila Molnar <attilamolnar@hush.com>
9 * Copyright (C) 2009-2010 Daniel De Graaf <danieldg@inspircd.org>
10 * Copyright (C) 2009 Uli Schlachter <psychon@inspircd.org>
11 * Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
12 * Copyright (C) 2006 Craig Edwards <brain@inspircd.org>
14 * This file is part of InspIRCd. InspIRCd is free software: you can
15 * redistribute it and/or modify it under the terms of the GNU General Public
16 * License as published by the Free Software Foundation, version 2.
18 * This program is distributed in the hope that it will be useful, but WITHOUT
19 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
20 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
23 * You should have received a copy of the GNU General Public License
24 * along with this program. If not, see <http://www.gnu.org/licenses/>.
29 #include "core_oper.h"
31 CommandRestart::CommandRestart(Module* parent, std::string& hashref)
32 : Command(parent, "RESTART", 1, 1)
36 syntax = "<servername>";
39 CmdResult CommandRestart::Handle(User* user, const Params& parameters)
41 ServerInstance->Logs->Log(MODNAME, LOG_DEFAULT, "Restart: %s", user->nick.c_str());
42 if (ServerInstance->PassCompare(user, password, parameters[0], hash))
44 ServerInstance->SNO->WriteGlobalSno('a', "RESTART command from %s, restarting server.", user->GetFullRealHost().c_str());
46 DieRestart::SendError("Server restarting.");
49 /* XXX: This hack sets FD_CLOEXEC on all possible file descriptors, so they're closed if the execvp() below succeeds.
50 * Certainly, this is not a nice way to do things and it's slow when the fd limit is high.
52 * A better solution would be to set the close-on-exec flag for each fd we create (or create them with O_CLOEXEC),
53 * however there is no guarantee that third party libs will do the same.
55 for (int i = getdtablesize(); --i > 2;)
57 int flags = fcntl(i, F_GETFD);
59 fcntl(i, F_SETFD, flags | FD_CLOEXEC);
63 execvp(ServerInstance->Config->cmdline.argv[0], ServerInstance->Config->cmdline.argv);
64 ServerInstance->SNO->WriteGlobalSno('a', "Failed RESTART - could not execute '%s' (%s)",
65 ServerInstance->Config->cmdline.argv[0], strerror(errno));
69 ServerInstance->SNO->WriteGlobalSno('a', "Failed RESTART command from %s.", user->GetFullRealHost().c_str());