X-Git-Url: http://git.pk910.de/?p=NeonServV5.git;a=blobdiff_plain;f=src%2Fsignal.c;h=4e8f9a5d72f7a2a85ba77d186f549e5fd1e833a8;hp=d5431da482bbed62855f2beeec2f6217988269d3;hb=HEAD;hpb=db9df7a1356859ffb8dcca001317940c92a80045 diff --git a/src/signal.c b/src/signal.c index d5431da..4e8f9a5 100644 --- a/src/signal.c +++ b/src/signal.c @@ -1,4 +1,4 @@ -/* signal.c - NeonServ v5.3 +/* signal.c - NeonServ v5.6 * Copyright (C) 2011-2012 Philipp Kreil (pk910) * * This program is free software: you can redistribute it and/or modify @@ -18,12 +18,15 @@ #include "bots.h" #include "ChanNode.h" #include "ClientSocket.h" +#include "IOHandler.h" #include "ConfigParser.h" +#include "log.h" static void sigcrash(); static void sigexit(); void sighandler(int signum) { + printf_log("main", LOG_INFO, "Received Signal %d\n", signum); signal(signum, SIG_DFL); switch(signum) { case SIGABRT: @@ -39,17 +42,16 @@ void sighandler(int signum) { sigcrash(signum); break; } + #ifdef WIN32 + exit(signum); + #else kill(getpid(), signum); + #endif } static void sigcrash(int signum) { - char *coregen = ""; - #ifndef WIN32 - char gcore[50]; - sprintf(gcore, "gcore %u", getpid()); - system(gcore); //generate core file - coregen = "core file generated."; - #endif + char coregen[MAXLEN]; + coregen[0] = 0; char *signame; switch(signum) { case SIGSEGV: @@ -65,27 +67,30 @@ static void sigcrash(int signum) { signame = "SIGUNKNOWN"; break; } - char *alertchan = get_string_field("General.alertchan"); - if(alertchan) { - struct ChanNode *channel = getChanByName(alertchan); - struct ClientSocket *client; - if(channel && (client = getChannelBot(channel, 0))) { - putsock(client, "PRIVMSG %s :\00304NeonServ received signal %d (%s). %s", alertchan, signum, signame, coregen); - } - } + printf_log("main", LOG_ERROR, "NeonServ process crashed (%s)\n", signame); + #ifndef WIN32 + char gcore[50]; + sprintf(gcore, "gcore %u", getpid()); + int sysretn = system(gcore); //generate core file + sprintf(coregen, "core file generated. (%d)", sysretn); + printf_log("main", LOG_ERROR | LOG_INFO, "generated core file.\n"); + #endif //close all bots struct ClientSocket *bot; for(bot = getBots(SOCKET_FLAG_READY, NULL); bot; bot = getBots(SOCKET_FLAG_READY, bot)) { if((bot->flags & SOCKET_FLAG_CONNECTED)) { - close(bot->sock); - bot->flags &= SOCKET_FLAG_CONNECTED; + iohandler_close(bot->iofd); + bot->flags &= ~(SOCKET_FLAG_CONNECTED | SOCKET_FLAG_READY); + bot->iofd = NULL; } } - sleep(1); + printf_log("main", LOG_INFO, "hard shutdown...\n"); + usleep(2000000); //hard restart - restart_process(); + restart_bot(1); + exit(0); } static void sigexit(int signum) { - cleanup(); + stop_bot(); }