1 /* signal.c - NeonServ v5.4
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 "ConfigParser.h"
23 static void sigcrash();
24 static void sigexit();
26 void sighandler(int signum) {
27 putlog(LOGLEVEL_INFO, "Received Signal %d\n", signum);
28 signal(signum, SIG_DFL);
46 kill(getpid(), signum);
50 static void sigcrash(int signum) {
64 signame = "SIGUNKNOWN";
67 putlog(LOGLEVEL_ERROR, "NeonServ process crashed (%s)\n", signame);
70 sprintf(gcore, "gcore %u", getpid());
71 system(gcore); //generate core file
72 coregen = "core file generated.";
73 putlog(LOGLEVEL_ERROR | LOGLEVEL_INFO, "generated core file.\n");
75 char *alertchan = get_string_field("General.alertchan");
77 struct ChanNode *channel = getChanByName(alertchan);
78 struct ClientSocket *client;
79 if(channel && (client = getChannelBot(channel, 0))) {
80 putsock(client, "PRIVMSG %s :\00304NeonServ received signal %d (%s). %s", alertchan, signum, signame, coregen);
84 struct ClientSocket *bot;
85 for(bot = getBots(SOCKET_FLAG_READY, NULL); bot; bot = getBots(SOCKET_FLAG_READY, bot)) {
86 if((bot->flags & SOCKET_FLAG_CONNECTED)) {
88 bot->flags &= SOCKET_FLAG_CONNECTED;
91 putlog(LOGLEVEL_INFO, "hard shutdown...\n");
98 static void sigexit(int signum) {