From 6972e25a95ec904306734b71c843bf788e807096 Mon Sep 17 00:00:00 2001 From: Valery Yatsko Date: Sun, 20 Apr 2008 07:38:56 +0400 Subject: [PATCH] Moving some m_die code into ircd_shutdown(reason) function and use it on SIGTERM too --- include/ircd.h | 2 ++ modules/core/m_die.c | 28 +--------------------------- src/ircd.c | 28 ++++++++++++++++++++++++++++ src/ircd_signal.c | 7 +------ 4 files changed, 32 insertions(+), 33 deletions(-) diff --git a/include/ircd.h b/include/ircd.h index dd7bd83..c600f5c 100644 --- a/include/ircd.h +++ b/include/ircd.h @@ -107,4 +107,6 @@ extern int ssl_ok; extern int zlib_ok; extern int maxconnections; +void ircd_shutdown(const char *reason); + #endif diff --git a/modules/core/m_die.c b/modules/core/m_die.c index 624fbc6..10e914d 100644 --- a/modules/core/m_die.c +++ b/modules/core/m_die.c @@ -74,33 +74,7 @@ mo_die(struct Client *client_p __unused, struct Client *source_p, int parc, cons return 0; } - RB_DLINK_FOREACH(ptr, lclient_list.head) - { - target_p = ptr->data; - - sendto_one_notice(target_p, ":Server Terminating. %s", get_client_name(source_p, HIDE_IP)); - } - - RB_DLINK_FOREACH(ptr, serv_list.head) - { - target_p = ptr->data; - - sendto_one(target_p, "SQUIT %s :Terminated by %s", - use_id(target_p), - get_client_name(source_p, HIDE_IP)); - } - - /* - * XXX we called flush_connections() here. Read server_reboot() - * for an explanation as to what we should do. - * -- adrian - */ - ilog(L_MAIN, "Server terminated by %s", get_oper_name(source_p)); - - /* this is a normal exit, tell the os it's ok */ - unlink(pidFileName); - exit(0); - /* NOT REACHED */ + ircd_shutdown(get_client_name(source_p, HIDE_IP)); return 0; } diff --git a/src/ircd.c b/src/ircd.c index 6a80edd..af922db 100644 --- a/src/ircd.c +++ b/src/ircd.c @@ -141,6 +141,34 @@ rb_bh *linebuf_heap; rb_bh *dnode_heap; +void +ircd_shutdown(const char *reason) +{ + struct Client *target_p; + rb_dlink_node *ptr; + + RB_DLINK_FOREACH(ptr, lclient_list.head) + { + target_p = ptr->data; + + sendto_one(target_p, ":%s NOTICE %s :Server Terminating. %s", + me.name, target_p->name, reason); + } + + RB_DLINK_FOREACH(ptr, serv_list.head) + { + target_p = ptr->data; + + sendto_one(target_p, ":%s ERROR :Terminated by %s", + me.name, reason); + } + + ilog(L_MAIN, "Server Terminating. %s", reason); + + unlink(pidFileName); + exit(0); +} + /* * print_startup - print startup information */ diff --git a/src/ircd_signal.c b/src/ircd_signal.c index 0a02c09..4ea20aa 100644 --- a/src/ircd_signal.c +++ b/src/ircd_signal.c @@ -57,12 +57,7 @@ sigchld_handler(int sig) static void sigterm_handler(int sig) { - /* XXX we had a flush_connections() here - we should close all the - * connections and flush data. read server_reboot() for my explanation. - * -- adrian - */ - ilog(L_MAIN, "Server killed By SIGTERM"); - exit(-1); + ircd_shutdown("Received SIGTERM"); } /*