1 /* signal.c - NeonServ v5.5
2 * Copyright (C) 2011-2012 Philipp Kreil (pk910)
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include "ClientSocket.h"
21 #include "IOHandler.h"
22 #include "ConfigParser.h"
24 static void sigcrash();
25 static void sigexit();
27 void sighandler(int signum) {
28 putlog(LOGLEVEL_INFO, "Received Signal %d\n", signum);
29 signal(signum, SIG_DFL);
47 kill(getpid(), signum);
51 static void sigcrash(int signum) {
66 signame = "SIGUNKNOWN";
69 putlog(LOGLEVEL_ERROR, "NeonServ process crashed (%s)\n", signame);
72 sprintf(gcore, "gcore %u", getpid());
73 int sysretn = system(gcore); //generate core file
74 sprintf(coregen, "core file generated. (%d)", sysretn);
75 putlog(LOGLEVEL_ERROR | LOGLEVEL_INFO, "generated core file.\n");
77 char *alertchan = get_string_field("General.alertchan");
79 struct ChanNode *channel = getChanByName(alertchan);
80 struct ClientSocket *client;
81 if(channel && (client = getChannelBot(channel, 0))) {
82 putsock(client, "PRIVMSG %s :\00304NeonServ received signal %d (%s). %s", alertchan, signum, signame, coregen);
86 struct ClientSocket *bot;
87 for(bot = getBots(SOCKET_FLAG_READY, NULL); bot; bot = getBots(SOCKET_FLAG_READY, bot)) {
88 if((bot->flags & SOCKET_FLAG_CONNECTED)) {
89 iohandler_close(bot->iofd);
90 bot->flags &= ~(SOCKET_FLAG_CONNECTED | SOCKET_FLAG_READY);
94 putlog(LOGLEVEL_INFO, "hard shutdown...\n");
102 static void sigexit(int signum) {