]> granicus.if.org Git - recode/commitdiff
Fix FIXME: use sigaction instead of signal
authorReuben Thomas <rrt@sc3d.org>
Fri, 26 Jan 2018 21:12:12 +0000 (21:12 +0000)
committerReuben Thomas <rrt@sc3d.org>
Sun, 28 Jan 2018 22:41:22 +0000 (22:41 +0000)
Using signal to set a handler is non-portable (according to POSIX! sigh…).

bootstrap.conf
lib/.gitignore
m4/.gitignore
src/main.c

index 84a7f2fcb504ff24e73ab3c407d6cbebe0b322e9..6ea216507d302ff3d478e3e049882047c7cac04c 100644 (file)
@@ -1,4 +1,4 @@
-# bootstrap.conf (Recode) version 2018-01-24
+# bootstrap.conf (Recode) version 2018-01-26
 
 # This file is part of Recode.
 #
@@ -63,6 +63,7 @@ gnulib_modules='
         pathmax
         pipe-posix
         quotearg
+        sigaction
         snippet/unused-parameter
         strndup
         sys_wait
index c849c28e0a2b62df5c4d5d327ab42c550def001c..0ed9dffea2d829ce0297dd02aa238d602f4c9a12 100644 (file)
 /xstrndup.h
 /asprintf.c
 /vasprintf.c
+/raise.c
+/sig-handler.c
+/sig-handler.h
+/sigaction.c
+/signal.in.h
+/sigprocmask.c
+/signal.h
index ea3690d52be6cda27f5fcc72f79c481b680b63d6..2466b0f2499e5902494076df81d08fced6667d56 100644 (file)
@@ -139,3 +139,7 @@ gnulib-comp.m4
 /xstrndup.m4
 /vasprintf.m4
 /valgrind-tests.m4
+/raise.m4
+/sigaction.m4
+/signal_h.m4
+/signalblocking.m4
index fa3c5f0e602de3c749f133b6405dbf1c30639b3c..aa426aa35d0d41dd79372db0ce5802e3f273353d 100644 (file)
@@ -134,24 +134,32 @@ task_perror (RECODE_CONST_TASK task)
 | Signal handler.  |
 `-----------------*/
 
+static void
+sig_catch(int sig, void (*handler) (int))
+{
+  struct sigaction sa;
+  sa.sa_handler = handler;
+  sa.sa_flags = 0;
+  sigemptyset (&sa.sa_mask);
+  sigaction (sig, &sa, NULL);  /* ignore error: none possible */
+}
+
 static void
 signal_handler (int number)
 {
   recode_interrupted = 1;
-  signal (number, signal_handler);
+  sig_catch (number, signal_handler);
 }
 
 /*------------------------------------------------------------------------.
 | Prepare to handle signals, intercept willingful requests for stopping.  |
 `------------------------------------------------------------------------*/
 
-/* FIXME: Use sigaction */
-
 static void
 setup_signals (void)
 {
 #ifdef SIGPIPE
-  signal (SIGPIPE, signal_handler);
+  sig_catch (SIGPIPE, signal_handler);
 #endif
 }
 \f