From cf973e7f8006dde84722585d3dfc1af9592bd15d Mon Sep 17 00:00:00 2001
From: =?utf8?q?P=C3=A1draig=20Brady?=
Date: Sat, 22 Nov 2025 13:56:15 +0000
Subject: [PATCH] dd,ls,sort: prefer sigaction over signal
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 | 31 +------------------------------
src/ls.c | 38 +-------------------------------------
src/sort.c | 24 ------------------------
3 files changed, 2 insertions(+), 91 deletions(-)
diff --git a/src/dd.c b/src/dd.c
index a12ef98392..117d619081 100644
--- a/src/dd.c
+++ b/src/dd.c
@@ -42,17 +42,6 @@
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.
diff --git a/src/ls.c b/src/ls.c
index 5f3f597554..a81bab9c64 100644
--- a/src/ls.c
+++ b/src/ls.c
@@ -60,17 +60,6 @@
# include
#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);
}
}
diff --git a/src/sort.c b/src/sort.c
index dee50d98c0..671a953d2c 100644
--- a/src/sort.c
+++ b/src/sort.c
@@ -73,18 +73,6 @@ struct rlimit { size_t rlim_cur; };
# include
#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. */
--
2.47.3