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