]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/coremods/core_oper/cmd_restart.cpp
Advertise the available extbans for services.
[user/henk/code/inspircd.git] / src / coremods / core_oper / cmd_restart.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
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>
13  *
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.
17  *
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
21  * details.
22  *
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/>.
25  */
26
27
28 #include "inspircd.h"
29 #include "core_oper.h"
30
31 CommandRestart::CommandRestart(Module* parent, std::string& hashref)
32         : Command(parent, "RESTART", 1, 1)
33         , hash(hashref)
34 {
35         flags_needed = 'o';
36         syntax = "<servername>";
37 }
38
39 CmdResult CommandRestart::Handle(User* user, const Params& parameters)
40 {
41         ServerInstance->Logs->Log(MODNAME, LOG_DEFAULT, "Restart: %s", user->nick.c_str());
42         if (ServerInstance->PassCompare(user, password, parameters[0], hash))
43         {
44                 ServerInstance->SNO->WriteGlobalSno('a', "RESTART command from %s, restarting server.", user->GetFullRealHost().c_str());
45
46                 DieRestart::SendError("Server restarting.");
47
48 #ifndef _WIN32
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.
51                  *
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.
54                  */
55                 for (int i = getdtablesize(); --i > 2;)
56                 {
57                         int flags = fcntl(i, F_GETFD);
58                         if (flags != -1)
59                                 fcntl(i, F_SETFD, flags | FD_CLOEXEC);
60                 }
61 #endif
62
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));
66         }
67         else
68         {
69                 ServerInstance->SNO->WriteGlobalSno('a', "Failed RESTART command from %s.", user->GetFullRealHost().c_str());
70         }
71         return CMD_FAILURE;
72 }