gpsd-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gpsd-dev] [PATCH] gpsd: use sigaction() to register signals


From: Mike Frysinger
Subject: [gpsd-dev] [PATCH] gpsd: use sigaction() to register signals
Date: Sat, 14 Jan 2012 06:19:53 -0500

We want to avoid the unportable signal() semantics wrt handlers being
reset upon signal delivery.

Signed-off-by: Mike Frysinger <address@hidden>
---
note: only lightly tested with `./gpsd -N` and running `kill`

 gpsd.c |   18 ++++++++++++------
 1 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/gpsd.c b/gpsd.c
index d342f5a..2a0855c 100644
--- a/gpsd.c
+++ b/gpsd.c
@@ -24,6 +24,7 @@
 #include <syslog.h>
 #include <errno.h>
 #include <fcntl.h>
+#include <signal.h>
 #include <pthread.h>
 #ifndef S_SPLINT_S
 #include <netdb.h>
@@ -1768,6 +1769,7 @@ int main(int argc, char *argv[])
     struct timeval tv;
     const struct gps_type_t **dp;
     bool in_restart;
+    struct sigaction sa;
 
 #ifdef PPS_ENABLE
     /address@hidden@*/
@@ -2038,6 +2040,16 @@ int main(int argc, char *argv[])
        subscribers[i].fd = UNALLOCATED_FD;
 #endif /* SOCKET_EXPORT_ENABLE*/
 
+    /* Handle some signals */
+    sa.sa_flags = 0;
+    sa.sa_handler = onsig;
+    sigfillset(&sa.sa_mask);
+    (void)sigaction(SIGHUP, &sa, NULL);
+    (void)sigaction(SIGINT, &sa, NULL);
+    (void)sigaction(SIGTERM, &sa, NULL);
+    (void)sigaction(SIGQUIT, &sa, NULL);
+    (void)signal(SIGPIPE, SIG_IGN);
+
     /* daemon got termination or interrupt signal */
     if (setjmp(restartbuf) > 0) {
        /* try to undo all device configurations */
@@ -2049,13 +2061,7 @@ int main(int argc, char *argv[])
        gpsd_report(LOG_WARN, "gpsd restarted by SIGHUP\n");
     }
 
-    /* Handle some signals */
     signalled = 0;
-    (void)signal(SIGHUP, onsig);
-    (void)signal(SIGINT, onsig);
-    (void)signal(SIGTERM, onsig);
-    (void)signal(SIGQUIT, onsig);
-    (void)signal(SIGPIPE, SIG_IGN);
 
     for (i = 0; i < AFCOUNT; i++)
        if (msocks[i] >= 0) {
-- 
1.7.8.3




reply via email to

[Prev in Thread] Current Thread [Next in Thread]