1 /* signal.c - NeonServ v5.6
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"
25 static void sigcrash();
26 static void sigexit();
28 void sighandler(int signum) {
29 printf_log("main", LOG_INFO, "Received Signal %d\n", signum);
30 signal(signum, SIG_DFL);
48 kill(getpid(), signum);
52 static void sigcrash(int signum) {
67 signame = "SIGUNKNOWN";
70 printf_log("main", LOG_ERROR, "NeonServ process crashed (%s)\n", signame);
73 sprintf(gcore, "gcore %u", getpid());
74 int sysretn = system(gcore); //generate core file
75 sprintf(coregen, "core file generated. (%d)", sysretn);
76 printf_log("main", LOG_ERROR | LOG_INFO, "generated core file.\n");
79 struct ClientSocket *bot;
80 for(bot = getBots(SOCKET_FLAG_READY, NULL); bot; bot = getBots(SOCKET_FLAG_READY, bot)) {
81 if((bot->flags & SOCKET_FLAG_CONNECTED)) {
82 iohandler_close(bot->iofd);
83 bot->flags &= ~(SOCKET_FLAG_CONNECTED | SOCKET_FLAG_READY);
87 printf_log("main", LOG_INFO, "hard shutdown...\n");
94 static void sigexit(int signum) {