1 |
/* |
2 |
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
3 |
* |
4 |
* Copyright (c) 1997-2014 ircd-hybrid development team |
5 |
* |
6 |
* This program is free software; you can redistribute it and/or modify |
7 |
* it under the terms of the GNU General Public License as published by |
8 |
* the Free Software Foundation; either version 2 of the License, or |
9 |
* (at your option) any later version. |
10 |
* |
11 |
* This program is distributed in the hope that it will be useful, |
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
* GNU General Public License for more details. |
15 |
* |
16 |
* You should have received a copy of the GNU General Public License |
17 |
* along with this program; if not, write to the Free Software |
18 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
19 |
* USA |
20 |
*/ |
21 |
|
22 |
/*! \file restart.c |
23 |
* \brief Functions to allow the ircd to restart. |
24 |
* \version $Id$ |
25 |
*/ |
26 |
|
27 |
#include "stdinc.h" |
28 |
#include "list.h" |
29 |
#include "restart.h" |
30 |
#include "fdlist.h" |
31 |
#include "ircd.h" |
32 |
#include "irc_string.h" |
33 |
#include "send.h" |
34 |
#include "log.h" |
35 |
#include "client.h" |
36 |
#include "memory.h" |
37 |
#include "conf_db.h" |
38 |
|
39 |
void |
40 |
restart(const char *mesg) |
41 |
{ |
42 |
static int was_here = 0; /* redundant due to restarting flag below */ |
43 |
|
44 |
if (was_here++) |
45 |
abort(); |
46 |
|
47 |
server_die(mesg, 1); |
48 |
} |
49 |
|
50 |
void |
51 |
server_die(const char *mesg, int rboot) |
52 |
{ |
53 |
char buffer[IRCD_BUFSIZE]; |
54 |
dlink_node *ptr = NULL; |
55 |
struct Client *target_p = NULL; |
56 |
static int was_here = 0; |
57 |
|
58 |
if (rboot && was_here++) |
59 |
abort(); |
60 |
|
61 |
if (EmptyString(mesg)) |
62 |
snprintf(buffer, sizeof(buffer), "Server %s", |
63 |
rboot ? "Restarting" : "Terminating"); |
64 |
else |
65 |
snprintf(buffer, sizeof(buffer), "Server %s: %s", |
66 |
rboot ? "Restarting" : "Terminating", mesg); |
67 |
|
68 |
DLINK_FOREACH(ptr, local_client_list.head) |
69 |
{ |
70 |
target_p = ptr->data; |
71 |
|
72 |
sendto_one(target_p, ":%s NOTICE %s :%s", |
73 |
me.name, target_p->name, buffer); |
74 |
} |
75 |
|
76 |
sendto_server(NULL, NOCAPS, NOCAPS, ":%s ERROR :%s", ID(&me), buffer); |
77 |
|
78 |
ilog(LOG_TYPE_IRCD, "%s", buffer); |
79 |
|
80 |
save_all_databases(NULL); |
81 |
|
82 |
send_queued_all(); |
83 |
close_fds(NULL); |
84 |
|
85 |
unlink(pidFileName); |
86 |
|
87 |
if (rboot) |
88 |
{ |
89 |
execv(SPATH, myargv); |
90 |
exit(1); |
91 |
} |
92 |
else |
93 |
exit(0); |
94 |
} |