]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
dd,ls,sort: prefer sigaction over signal
authorPádraig Brady <P@draigBrady.com>
Sat, 22 Nov 2025 13:56:15 +0000 (13:56 +0000)
committerPádraig Brady <P@draigBrady.com>
Sat, 22 Nov 2025 14:08:20 +0000 (14:08 +0000)
sigaction() is generally available and if not
provided by the sigaction gnulib module.

* src/dd.c [SA_NOCLDSTOP]: Delete workarounds.
* src/ls.c: Likewise.
* src/sort.c: Likewise.
Suggested by Collin Funk.

src/dd.c
src/ls.c
src/sort.c

index a12ef983928f610383de15f35f834da562e19c63..117d6190818794e027777dd17a7a94b1891ab570 100644 (file)
--- a/src/dd.c
+++ b/src/dd.c
   proper_name ("David MacKenzie"), \
   proper_name ("Stuart Kemp")
 
-/* 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
-
 /* NonStop circa 2011 lacks SA_RESETHAND; see Bug#9076.  */
 #ifndef SA_RESETHAND
 # define SA_RESETHAND 0
@@ -850,10 +839,8 @@ interrupt_handler (int sig)
 /* An info signal was received; arrange for the program to print status.  */
 
 static void
-siginfo_handler (int sig)
+siginfo_handler (MAYBE_UNUSED int sig)
 {
-  if (! SA_NOCLDSTOP)
-    signal (sig, siginfo_handler);
   info_signal_count++;
 }
 
@@ -864,8 +851,6 @@ install_signal_handlers (void)
 {
   bool catch_siginfo = ! (SIGINFO == SIGUSR1 && getenv ("POSIXLY_CORRECT"));
 
-#if SA_NOCLDSTOP
-
   struct sigaction act;
   sigemptyset (&caught_signals);
   if (catch_siginfo)
@@ -891,20 +876,6 @@ install_signal_handlers (void)
       act.sa_flags = SA_NODEFER | SA_RESETHAND;
       sigaction (SIGINT, &act, nullptr);
     }
-
-#else
-
-  if (catch_siginfo)
-    {
-      signal (SIGINFO, siginfo_handler);
-      siginterrupt (SIGINFO, 1);
-    }
-  if (signal (SIGINT, SIG_IGN) != SIG_IGN)
-    {
-      signal (SIGINT, interrupt_handler);
-      siginterrupt (SIGINT, 1);
-    }
-#endif
 }
 
 /* Close FD.  Return 0 if successful, -1 (setting errno) otherwise.
index 5f3f597554093b2f2e62df4706f89cded6aa9235..a81bab9c64ff74f9506710f7656f8bbfc4fa6677 100644 (file)
--- a/src/ls.c
+++ b/src/ls.c
 # include <langinfo.h>
 #endif
 
-/* 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
-
 /* NonStop circa 2011 lacks both SA_RESTART and siginterrupt, so don't
    restart syscalls after a signal handler fires.  This may cause
    colors to get messed up on the screen if 'ls' is interrupted, but
@@ -1529,8 +1518,6 @@ set_normal_color (void)
 static void
 sighandler (int sig)
 {
-  if (! SA_NOCLDSTOP)
-    signal (sig, SIG_IGN);
   if (! interrupt_signal)
     interrupt_signal = sig;
 }
@@ -1538,10 +1525,8 @@ sighandler (int sig)
 /* A SIGTSTP was received; arrange for the program to suspend itself.  */
 
 static void
-stophandler (int sig)
+stophandler (MAYBE_UNUSED int sig)
 {
-  if (! SA_NOCLDSTOP)
-    signal (sig, stophandler);
   if (! interrupt_signal)
     stop_signal_count++;
 }
@@ -1607,13 +1592,8 @@ signal_setup (bool init)
 
   enum { nsigs = countof (term_sig), nstop = countof (stop_sig) };
 
-#if ! SA_NOCLDSTOP
-  static bool caught_sig[nsigs + nstop];
-#endif
-
   if (init)
     {
-#if SA_NOCLDSTOP
       struct sigaction act;
 
       sigemptyset (&caught_signals);
@@ -1637,29 +1617,13 @@ signal_setup (bool init)
               sigaction (sig, &act, nullptr);
             }
         }
-#else
-      for (int j = 0; j < nsigs + nstop; j++)
-        {
-          int sig = j < nsigs ? term_sig[j]: stop_sig[j - nsigs];
-          caught_sig[j] = (signal (sig, SIG_IGN) != SIG_IGN);
-          if (caught_sig[j])
-            {
-              signal (sig, j < nsigs ? sighandler : stophandler);
-              siginterrupt (sig[j], 0);
-            }
-        }
-#endif
     }
   else /* restore.  */
     {
       for (int j = 0; j < nsigs + nstop; j++)
         {
           int sig = j < nsigs ? term_sig[j]: stop_sig[j - nsigs];
-#if SA_NOCLDSTOP
           if (sigismember (&caught_signals, sig))
-#else
-          if (caught_sig[j])
-#endif
             signal (sig, SIG_DFL);
         }
     }
index dee50d98c0fd5688c542368d91f1b29d288c0afe..671a953d2c018d55e1b72b4b3d74929140c2f738 100644 (file)
@@ -73,18 +73,6 @@ struct rlimit { size_t rlim_cur; };
 # include <langinfo.h>
 #endif
 
-/* Use SA_NOCLDSTOP as a proxy for whether the sigaction machinery is
-   present.  */
-#ifndef SA_NOCLDSTOP
-# define SA_NOCLDSTOP 0
-/* No sigprocmask.  Always 'return' zero. */
-# define sigprocmask(How, Set, Oset) (0)
-# define sigset_t int
-# if ! HAVE_SIGINTERRUPT
-#  define siginterrupt(sig, flag) /* empty */
-# endif
-#endif
-
 #if !defined OPEN_MAX && defined NR_OPEN
 # define OPEN_MAX NR_OPEN
 #endif
@@ -402,9 +390,6 @@ cleanup (void)
 static void
 sighandler (int sig)
 {
-  if (! SA_NOCLDSTOP)
-    signal (sig, SIG_IGN);
-
   cleanup ();
 
   signal (sig, SIG_DFL);
@@ -4450,7 +4435,6 @@ main (int argc, char **argv)
   {
     enum { nsigs = countof (term_sig) };
 
-#if SA_NOCLDSTOP
     struct sigaction act;
 
     sigemptyset (&caught_signals);
@@ -4468,14 +4452,6 @@ main (int argc, char **argv)
     for (size_t i = 0; i < nsigs; i++)
       if (sigismember (&caught_signals, term_sig[i]))
         sigaction (term_sig[i], &act, nullptr);
-#else
-    for (size_t i = 0; i < nsigs; i++)
-      if (signal (term_sig[i], SIG_IGN) != SIG_IGN)
-        {
-          signal (term_sig[i], sighandler);
-          siginterrupt (term_sig[i], 1);
-        }
-#endif
   }
   signal (SIGCHLD, SIG_DFL); /* Don't inherit CHLD handling from parent.  */