From: Eric Blake Date: Tue, 14 Oct 2008 04:04:51 +0000 (-0600) Subject: csplit: prefer sigaction over signal X-Git-Tag: v7.1~178 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ddc409b59e57ac0dce72eda1e532c5224b4205ab;p=thirdparty%2Fcoreutils.git csplit: prefer sigaction over signal * bootstrap.conf (gnulib_modules): Import sigaction. * src/csplit.c (sigprocmask, siginterrupt) [SA_NOCLDSTOP]: Delete workarounds. (interrupt_handler, main): Drop use of signal. Rely on sigaction to block fatal signal during cleanup, and to restore it to default in case of nested signals. --- diff --git a/bootstrap.conf b/bootstrap.conf index b3eec48d52..6405955c6f 100644 --- a/bootstrap.conf +++ b/bootstrap.conf @@ -84,7 +84,7 @@ gnulib_modules=" safe-read same save-cwd savedir savewd selinux-at - settime sig2str ssize_t stat-macros + settime sig2str sigaction ssize_t stat-macros stat-time stdbool stdlib-safer stpcpy stpncpy strftime diff --git a/src/csplit.c b/src/csplit.c index 55489c3abd..b50a650769 100644 --- a/src/csplit.c +++ b/src/csplit.c @@ -34,17 +34,6 @@ #include "stdio--.h" #include "xstrtol.h" -/* Use SA_NOCLDSTOP as a proxy for whether the sigaction machinery is - present. */ -#ifndef SA_NOCLDSTOP -# define SA_NOCLDSTOP 0 -# define sigprocmask(How, Set, Oset) /* empty */ -# define sigset_t int -# if ! HAVE_SIGINTERRUPT -# define siginterrupt(sig, flag) /* empty */ -# endif -#endif - /* The official name of this program (e.g., no `g' prefix). */ #define PROGRAM_NAME "csplit" @@ -238,12 +227,10 @@ xalloc_die (void) static void interrupt_handler (int sig) { - if (! SA_NOCLDSTOP) - signal (sig, SIG_IGN); - delete_all_files (true); - - signal (sig, SIG_DFL); + /* The signal has been reset to SIG_DFL, but blocked during this + handler. Force the default action of this signal once the + handler returns and the block is removed. */ raise (sig); } @@ -1421,7 +1408,6 @@ main (int argc, char **argv) }; enum { nsigs = sizeof sig / sizeof sig[0] }; -#if SA_NOCLDSTOP struct sigaction act; sigemptyset (&caught_signals); @@ -1434,19 +1420,11 @@ main (int argc, char **argv) act.sa_handler = interrupt_handler; act.sa_mask = caught_signals; - act.sa_flags = 0; + act.sa_flags = SA_NODEFER | SA_RESETHAND; for (i = 0; i < nsigs; i++) if (sigismember (&caught_signals, sig[i])) sigaction (sig[i], &act, NULL); -#else - for (i = 0; i < nsigs; i++) - if (signal (sig[i], SIG_IGN) != SIG_IGN) - { - signal (sig[i], interrupt_handler); - siginterrupt (sig[i], 1); - } -#endif } split_file ();