]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/cmd_restart.cpp
Fix for parameters which contain a colon (which is not the first char in the string)
[user/henk/code/inspircd.git] / src / cmd_restart.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
6  *                       E-mail:
7  *                <brain@chatspike.net>
8  *                <Craig@chatspike.net>
9  *
10  * Written by Craig Edwards, Craig McLure, and others.
11  * This program is free but copyrighted software; see
12  *            the file COPYING for details.
13  *
14  * ---------------------------------------------------
15  */
16
17 #include "configreader.h"
18 #include "users.h"
19 #include "commands/cmd_restart.h"
20
21 void cmd_restart::Handle (const char** parameters, int pcnt, userrec *user)
22 {
23         char *argv[32];
24         ServerInstance->Log(DEFAULT,"Restart: %s",user->nick);
25         if (!strcmp(parameters[0],ServerInstance->Config->restartpass))
26         {
27                 ServerInstance->WriteOpers("*** RESTART command from %s!%s@%s, restarting server.",user->nick,user->ident,user->host);
28
29                 argv[0] = ServerInstance->Config->MyExecutable;
30                 argv[1] = "-wait";
31                 if (ServerInstance->Config->nofork)
32                 {
33                         argv[2] = "-nofork";
34                 }
35                 else
36                 {
37                         argv[2] = NULL;
38                 }
39                 argv[3] = NULL;
40                 
41                 // close ALL file descriptors
42                 ServerInstance->SendError("Server restarting.");
43                 sleep(1);
44                 for (int i = 0; i < MAX_DESCRIPTORS; i++)
45                 {
46                         shutdown(i,2);
47                         close(i);
48                 }
49                 sleep(2);
50                 
51                 execv(ServerInstance->Config->MyExecutable,argv);
52
53                 exit(0);
54         }
55         else
56         {
57                 ServerInstance->WriteOpers("*** Failed RESTART Command from %s!%s@%s.",user->nick,user->ident,user->host);
58         }
59 }