From 2b7b68ae4ccb0c2443141f0ad02fd632d00602b7 Mon Sep 17 00:00:00 2001 From: Reuben Thomas Date: Fri, 26 Jan 2018 21:12:12 +0000 Subject: [PATCH] Fix FIXME: use sigaction instead of signal MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Using signal to set a handler is non-portable (according to POSIX! sigh…). --- bootstrap.conf | 3 ++- lib/.gitignore | 7 +++++++ m4/.gitignore | 4 ++++ src/main.c | 16 ++++++++++++---- 4 files changed, 25 insertions(+), 5 deletions(-) diff --git a/bootstrap.conf b/bootstrap.conf index 84a7f2f..6ea2165 100644 --- a/bootstrap.conf +++ b/bootstrap.conf @@ -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 diff --git a/lib/.gitignore b/lib/.gitignore index c849c28..0ed9dff 100644 --- a/lib/.gitignore +++ b/lib/.gitignore @@ -180,3 +180,10 @@ /xstrndup.h /asprintf.c /vasprintf.c +/raise.c +/sig-handler.c +/sig-handler.h +/sigaction.c +/signal.in.h +/sigprocmask.c +/signal.h diff --git a/m4/.gitignore b/m4/.gitignore index ea3690d..2466b0f 100644 --- a/m4/.gitignore +++ b/m4/.gitignore @@ -139,3 +139,7 @@ gnulib-comp.m4 /xstrndup.m4 /vasprintf.m4 /valgrind-tests.m4 +/raise.m4 +/sigaction.m4 +/signal_h.m4 +/signalblocking.m4 diff --git a/src/main.c b/src/main.c index fa3c5f0..aa426aa 100644 --- a/src/main.c +++ b/src/main.c @@ -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 } -- 2.50.1