]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
csplit: prefer sigaction over signal
authorEric Blake <ebb9@byu.net>
Tue, 14 Oct 2008 04:04:51 +0000 (22:04 -0600)
committerEric Blake <ebb9@byu.net>
Thu, 16 Oct 2008 12:20:50 +0000 (06:20 -0600)
* 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.

bootstrap.conf
src/csplit.c

index b3eec48d52faa015dbc97c2aecca8511214d5f67..6405955c6ff5d2b552fd71f41696a44cba3db989 100644 (file)
@@ -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
index 55489c3abd59efa9d21e117bd73afd3a54eeb34a..b50a650769f3e3793c7b3268d06cc405747bbc5d 100644 (file)
 #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 ();