]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/cmd_restart.cpp
Jesus, look who's the commit whore today. More header updates, and removal of namespa...
[user/henk/code/inspircd.git] / src / cmd_restart.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2007 InspIRCd Development Team
6  * See: http://www.inspircd.org/wiki/index.php/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #include "configreader.h"
15 #include "users.h"
16 #include "commands/cmd_restart.h"
17
18
19
20 extern "C" command_t* init_command(InspIRCd* Instance)
21 {
22         return new cmd_restart(Instance);
23 }
24
25 CmdResult cmd_restart::Handle (const char** parameters, int pcnt, userrec *user)
26 {
27         char *argv[32];
28         ServerInstance->Log(DEFAULT,"Restart: %s",user->nick);
29         if (!strcmp(parameters[0],ServerInstance->Config->restartpass))
30         {
31                 ServerInstance->WriteOpers("*** RESTART command from %s!%s@%s, restarting server.",user->nick,user->ident,user->host);
32
33                 argv[0] = ServerInstance->Config->MyExecutable;
34                 argv[1] = "-wait";
35                 if (ServerInstance->Config->nofork)
36                 {
37                         argv[2] = "-nofork";
38                 }
39                 else
40                 {
41                         argv[2] = NULL;
42                 }
43                 argv[3] = NULL;
44                 
45                 // close ALL file descriptors
46                 ServerInstance->SendError("Server restarting.");
47                 sleep(1);
48                 for (int i = 0; i < MAX_DESCRIPTORS; i++)
49                 {
50                         shutdown(i,2);
51                         close(i);
52                 }
53                 sleep(2);
54                 
55                 execv(ServerInstance->Config->MyExecutable,argv);
56
57                 exit(0);
58         }
59         else
60         {
61                 ServerInstance->WriteOpers("*** Failed RESTART Command from %s!%s@%s.",user->nick,user->ident,user->host);
62                 return CMD_FAILURE;
63         }
64
65         return CMD_SUCCESS;
66 }
67