diff audioDB.cpp @ 104:97107ee61dba

Temporary signal handling. "Temporary" because it will not work on platforms which don't have real signals (Hello, Win32) but nevertheless useful, as otherwise gcov (the code coverage tool) will not count executions of processes that are killed by signals (in particular, the server processes started in the tests). A brief experiment suggests that we're up to about 80% statement coverage from our 20 tests.
author mas01cr
date Thu, 04 Oct 2007 15:02:29 +0000
parents 69424e77621f
children 10feb98abebf
line wrap: on
line diff
--- a/audioDB.cpp	Thu Oct 04 10:38:32 2007 +0000
+++ b/audioDB.cpp	Thu Oct 04 15:02:29 2007 +0000
@@ -1,5 +1,13 @@
 #include "audioDB.h"
 
+void sigterm_action(int signal, siginfo_t *info, void *context) {
+  exit(128+signal);
+}
+
+void sighup_action(int signal, siginfo_t *info, void *context) {
+  // FIXME: reread any configuration files
+}
+
 #define O2_DEBUG
 
 void audioDB::error(const char* a, const char* b, const char *sysFunc) {
@@ -196,6 +204,13 @@
     if(port<100 || port > 100000)
       error("port out of range");
     isServer=1;
+    struct sigaction sa;
+    sa.sa_sigaction = sigterm_action;
+    sa.sa_flags = SA_SIGINFO | SA_RESTART | SA_NODEFER;
+    sigaction(SIGTERM, &sa, NULL);
+    sa.sa_sigaction = sighup_action;
+    sa.sa_flags = SA_SIGINFO | SA_RESTART | SA_NODEFER;
+    sigaction(SIGHUP, &sa, NULL);
     return 0;
   }
 
@@ -2610,3 +2625,4 @@
 int main(const unsigned argc, char* const argv[]){
   audioDB(argc, argv);
 }
+