moving NeonServ into background by default; added a few startup parameters
[NeonServV5.git] / src / signal.c
index d5431da482bbed62855f2beeec2f6217988269d3..848828c4a27779c95f6fa42c1eeff527aa800abc 100644 (file)
@@ -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:
@@ -44,12 +45,6 @@ void sighandler(int signum) {
 
 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 +60,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,6 +84,8 @@ static void sigcrash(int signum) {
             bot->flags &= SOCKET_FLAG_CONNECTED;
         }
     }
+    putlog(LOGLEVEL_INFO, "hard shutdown...");
+    exit_daemon();
     sleep(1);
     //hard restart
     restart_process();
@@ -88,4 +93,6 @@ static void sigcrash(int signum) {
 
 static void sigexit(int signum) {
     cleanup();
+    exit_daemon();
+    exit(0);
 }