| 1 |
/* |
| 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 |
* $Id$ |
| 23 |
*/ |
| 24 |
|
| 25 |
#include "stdinc.h" |
| 26 |
#include "tools.h" |
| 27 |
#include "restart.h" |
| 28 |
#include "common.h" |
| 29 |
#include "fdlist.h" |
| 30 |
#include "ircd.h" |
| 31 |
#include "irc_string.h" |
| 32 |
#include "send.h" |
| 33 |
#include "s_log.h" |
| 34 |
#include "client.h" /* for UMODE_ALL */ |
| 35 |
#include "memory.h" |
| 36 |
|
| 37 |
void |
| 38 |
restart(const char *mesg) |
| 39 |
{ |
| 40 |
static int was_here = 0; /* redundant due to restarting flag below */ |
| 41 |
|
| 42 |
if (was_here) |
| 43 |
abort(); |
| 44 |
was_here = 1; |
| 45 |
|
| 46 |
server_die(mesg, YES); |
| 47 |
} |
| 48 |
|
| 49 |
void |
| 50 |
server_die(const char *mesg, int rboot) |
| 51 |
{ |
| 52 |
char buffer[IRCD_BUFSIZE]; |
| 53 |
dlink_node *ptr = NULL; |
| 54 |
struct Client *target_p = NULL; |
| 55 |
|
| 56 |
if (EmptyString(mesg)) |
| 57 |
snprintf(buffer, sizeof(buffer), "Server %s", |
| 58 |
rboot ? "Restarting" : "Terminating"); |
| 59 |
else |
| 60 |
snprintf(buffer, sizeof(buffer), "Server %s: %s", |
| 61 |
rboot ? "Restarting" : "Terminating", mesg); |
| 62 |
|
| 63 |
DLINK_FOREACH(ptr, local_client_list.head) |
| 64 |
{ |
| 65 |
target_p = ptr->data; |
| 66 |
|
| 67 |
sendto_one(target_p, ":%s NOTICE %s :%s", |
| 68 |
me.name, target_p->name, buffer); |
| 69 |
} |
| 70 |
|
| 71 |
DLINK_FOREACH(ptr, serv_list.head) |
| 72 |
{ |
| 73 |
target_p = ptr->data; |
| 74 |
|
| 75 |
sendto_one(target_p, ":%s ERROR :%s", me.name, buffer); |
| 76 |
} |
| 77 |
|
| 78 |
ilog(L_NOTICE, buffer); |
| 79 |
|
| 80 |
send_queued_all(); |
| 81 |
close_fds(NULL); |
| 82 |
|
| 83 |
unlink(pidFileName); |
| 84 |
|
| 85 |
if (rboot) |
| 86 |
{ |
| 87 |
execv(SPATH, myargv); |
| 88 |
exit(1); |
| 89 |
} |
| 90 |
else |
| 91 |
exit(0); |
| 92 |
} |