*** VERSION 5.4.0 ***
[NeonServV5.git] / src / signal.c
index d5431da482bbed62855f2beeec2f6217988269d3..9ec12f05237433376267fe2556958c4a859d8250 100644 (file)
@@ -1,4 +1,4 @@
-/* signal.c - NeonServ v5.3
+/* signal.c - NeonServ v5.4
  * Copyright (C) 2011-2012  Philipp Kreil (pk910)
  * 
  * This program is free software: you can redistribute it and/or modify
@@ -24,6 +24,7 @@ static void sigcrash();
 static void sigexit();
 
 void sighandler(int signum) {
+    putlog(LOGLEVEL_INFO, "Received Signal %d", signum);
     signal(signum, SIG_DFL);
     switch(signum) {
         case SIGABRT:
@@ -39,17 +40,15 @@ 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 *signame;
     switch(signum) {
         case SIGSEGV:
@@ -65,6 +64,14 @@ static void sigcrash(int signum) {
             signame = "SIGUNKNOWN";
             break;
     }
+    putlog(LOGLEVEL_ERROR, "NeonServ process crashed (%s)", signame);
+    #ifndef WIN32
+    char gcore[50];
+    sprintf(gcore, "gcore %u", getpid());
+    system(gcore); //generate core file
+    coregen = "core file generated.";
+    putlog(LOGLEVEL_ERROR | LOGLEVEL_INFO, "generated core file.");
+    #endif
     char *alertchan = get_string_field("General.alertchan");
     if(alertchan) {
         struct ChanNode *channel = getChanByName(alertchan);
@@ -81,11 +88,15 @@ static void sigcrash(int signum) {
             bot->flags &= SOCKET_FLAG_CONNECTED;
         }
     }
-    sleep(1);
+    putlog(LOGLEVEL_INFO, "hard shutdown...");
+    exit_daemon();
+    usleep(1000000);
     //hard restart
     restart_process();
 }
 
 static void sigexit(int signum) {
     cleanup();
+    exit_daemon();
+    exit(0);
 }