Better handling of forking and exiting and signals.
authorPierre Habouzit <madcoder@debian.org>
Thu, 30 Aug 2007 22:19:27 +0000 (00:19 +0200)
committerPierre Habouzit <madcoder@debian.org>
Thu, 30 Aug 2007 22:19:27 +0000 (00:19 +0200)
Signed-off-by: Pierre Habouzit <madcoder@debian.org>
common.c
srsd.c

index 13adb2d..7ede07b 100644 (file)
--- a/common.c
+++ b/common.c
@@ -55,19 +55,14 @@ void common_sighandler(int sig)
         }
         return;
 
-      case SIGTERM:
-        break;
-
       case SIGHUP:
         sighup = true;
         return;
 
       default:
-        return;
+        syslog(LOG_ERR, "Killed (got signal %d)...", sig);
+        exit(-1);
     }
-
-    syslog(LOG_ERR, "Killed...");
-    exit(-1);
 }
 
 void common_initialize(void)
diff --git a/srsd.c b/srsd.c
index 0958bfd..bdd98a8 100644 (file)
--- a/srsd.c
+++ b/srsd.c
@@ -201,13 +201,13 @@ static int main_initialize(void)
     signal(SIGINT,  &common_sighandler);
     signal(SIGTERM, &common_sighandler);
     signal(SIGHUP,  &common_sighandler);
+    signal(SIGSEGV, &common_sighandler);
     syslog(LOG_INFO, "Starting...");
     return 0;
 }
 
 static void main_shutdown(void)
 {
-    syslog(LOG_INFO, cleanexit ? "Stopping..." : "Unclean exit...");
     closelog();
 }
 
@@ -332,7 +332,6 @@ int main_loop(srs_t *srs, const char *domain, int port_enc, int port_dec)
     close(epollfd);
 
   error:
-    cleanexit = true;
     return exitcode;
 }
 
@@ -456,5 +455,6 @@ int main(int argc, char *argv[])
         fclose(f);
         f = NULL;
     }
+    syslog(LOG_INFO, "Stopping...");
     return res;
 }