* src/term-sig.h: A new file defining a TERM_SIG array signals.
* src/local.mk: Reference the new file.
* src/csplit.c: Likewise.
* src/sort.c: Likewise.
* src/timeout.c: Likewise.
* src/ls.c: Likewise. Also handle SIGTSTP separately.
* NEWS: Mention the improvement.
timeout(1) in a shell backgrounded job, will not terminate upon receiving
SIGINT or SIGQUIT, as these are ignored by default in shell background jobs.
+** Improvements
+
+ csplit, ls, and sort, now handle a more complete set of terminating signals.
+
* Noteworthy changes in release 9.9 (2025-11-10) [stable]
#include "quote.h"
#include "safe-read.h"
#include "stdio--.h"
+#include "term-sig.h"
#include "xdectoint.h"
#include "xstrtol.h"
parse_patterns (argc, optind, argv);
{
- static int const sig[] =
- {
- /* The usual suspects. */
- SIGALRM, SIGHUP, SIGINT, SIGPIPE, SIGQUIT, SIGTERM,
-#ifdef SIGPOLL
- SIGPOLL,
-#endif
-#ifdef SIGPROF
- SIGPROF,
-#endif
-#ifdef SIGVTALRM
- SIGVTALRM,
-#endif
-#ifdef SIGXCPU
- SIGXCPU,
-#endif
-#ifdef SIGXFSZ
- SIGXFSZ,
-#endif
- };
- enum { nsigs = countof (sig) };
+ enum { nsigs = countof (term_sig) };
struct sigaction act;
sigemptyset (&caught_signals);
for (int i = 0; i < nsigs; i++)
{
- sigaction (sig[i], nullptr, &act);
+ sigaction (term_sig[i], nullptr, &act);
if (act.sa_handler != SIG_IGN)
- sigaddset (&caught_signals, sig[i]);
+ sigaddset (&caught_signals, term_sig[i]);
}
act.sa_handler = interrupt_handler;
act.sa_flags = 0;
for (int i = 0; i < nsigs; i++)
- if (sigismember (&caught_signals, sig[i]))
- sigaction (sig[i], &act, nullptr);
+ if (sigismember (&caught_signals, term_sig[i]))
+ sigaction (term_sig[i], &act, nullptr);
}
split_file ();
src/statx.h \
src/system.h \
src/temp-stream.h \
+ src/term-sig.h \
src/uname.h \
src/wc.h
#include "stat-size.h"
#include "stat-time.h"
#include "strftime.h"
+#include "term-sig.h"
#include "xdectoint.h"
#include "xstrtol.h"
#include "xstrtol-error.h"
signal_setup (bool init)
{
/* The signals that are trapped, and the number of such signals. */
- static int const sig[] =
+ static int const stop_sig[] =
{
/* This one is handled specially. */
SIGTSTP,
-
- /* The usual suspects. */
- SIGALRM, SIGHUP, SIGINT, SIGPIPE, SIGQUIT, SIGTERM,
-#ifdef SIGPOLL
- SIGPOLL,
-#endif
-#ifdef SIGPROF
- SIGPROF,
-#endif
-#ifdef SIGVTALRM
- SIGVTALRM,
-#endif
-#ifdef SIGXCPU
- SIGXCPU,
-#endif
-#ifdef SIGXFSZ
- SIGXFSZ,
-#endif
};
- enum { nsigs = countof (sig) };
+
+ enum { nsigs = countof (term_sig), nstop = countof (stop_sig) };
#if ! SA_NOCLDSTOP
- static bool caught_sig[nsigs];
+ static bool caught_sig[nsigs + nstop];
#endif
if (init)
struct sigaction act;
sigemptyset (&caught_signals);
- for (int j = 0; j < nsigs; j++)
+ for (int j = 0; j < nsigs + nstop; j++)
{
- sigaction (sig[j], nullptr, &act);
+ int sig = j < nsigs ? term_sig[j]: stop_sig[j - nsigs];
+ sigaction (sig, nullptr, &act);
if (act.sa_handler != SIG_IGN)
- sigaddset (&caught_signals, sig[j]);
+ sigaddset (&caught_signals, sig);
}
act.sa_mask = caught_signals;
act.sa_flags = SA_RESTART;
- for (int j = 0; j < nsigs; j++)
- if (sigismember (&caught_signals, sig[j]))
- {
- act.sa_handler = sig[j] == SIGTSTP ? stophandler : sighandler;
- sigaction (sig[j], &act, nullptr);
- }
+ for (int j = 0; j < nsigs + nstop; j++)
+ {
+ int sig = j < nsigs ? term_sig[j]: stop_sig[j - nsigs];
+ if (sigismember (&caught_signals, sig))
+ {
+ act.sa_handler = j < nsigs ? sighandler : stophandler;
+ sigaction (sig, &act, nullptr);
+ }
+ }
#else
- for (int j = 0; j < nsigs; j++)
+ for (int j = 0; j < nsigs + nstop; j++)
{
- caught_sig[j] = (signal (sig[j], SIG_IGN) != SIG_IGN);
+ 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], sig[j] == SIGTSTP ? stophandler : sighandler);
+ signal (sig, j < nsigs ? sighandler : stophandler);
siginterrupt (sig[j], 0);
}
}
}
else /* restore. */
{
+ for (int j = 0; j < nsigs + nstop; j++)
+ {
+ int sig = j < nsigs ? term_sig[j]: stop_sig[j - nsigs];
#if SA_NOCLDSTOP
- for (int j = 0; j < nsigs; j++)
- if (sigismember (&caught_signals, sig[j]))
- signal (sig[j], SIG_DFL);
+ if (sigismember (&caught_signals, sig))
#else
- for (int j = 0; j < nsigs; j++)
- if (caught_sig[j])
- signal (sig[j], SIG_DFL);
+ if (caught_sig[j])
#endif
+ signal (sig, SIG_DFL);
+ }
}
}
#include "readtokens0.h"
#include "stdlib--.h"
#include "strnumcmp.h"
+#include "term-sig.h"
#include "xmemcoll.h"
#include "xnanosleep.h"
#include "xstrtol.h"
inittables ();
{
- static int const sig[] =
- {
- /* The usual suspects. */
- SIGALRM, SIGHUP, SIGINT, SIGQUIT, SIGTERM,
-#ifdef SIGPOLL
- SIGPOLL,
-#endif
-#ifdef SIGPROF
- SIGPROF,
-#endif
-#ifdef SIGVTALRM
- SIGVTALRM,
-#endif
-#ifdef SIGXCPU
- SIGXCPU,
-#endif
-#ifdef SIGXFSZ
- SIGXFSZ,
-#endif
- };
- enum { nsigs = countof (sig) };
+ enum { nsigs = countof (term_sig) };
#if SA_NOCLDSTOP
struct sigaction act;
sigemptyset (&caught_signals);
for (size_t i = 0; i < nsigs; i++)
{
- sigaction (sig[i], nullptr, &act);
+ sigaction (term_sig[i], nullptr, &act);
if (act.sa_handler != SIG_IGN)
- sigaddset (&caught_signals, sig[i]);
+ sigaddset (&caught_signals, term_sig[i]);
}
act.sa_handler = sighandler;
act.sa_flags = 0;
for (size_t i = 0; i < nsigs; i++)
- if (sigismember (&caught_signals, sig[i]))
- sigaction (sig[i], &act, nullptr);
+ if (sigismember (&caught_signals, term_sig[i]))
+ sigaction (term_sig[i], &act, nullptr);
#else
for (size_t i = 0; i < nsigs; i++)
- if (signal (sig[i], SIG_IGN) != SIG_IGN)
+ if (signal (term_sig[i], SIG_IGN) != SIG_IGN)
{
- signal (sig[i], sighandler);
- siginterrupt (sig[i], 1);
+ signal (term_sig[i], sighandler);
+ siginterrupt (term_sig[i], 1);
}
#endif
}
--- /dev/null
+#ifndef TERM_SIG_H
+# define TERM_SIG_H
+
+# include <signal.h>
+
+static int const term_sig[] =
+ {
+ SIGALRM, /* our timeout. */
+ SIGINT, /* Ctrl-C at terminal for example. */
+ SIGQUIT, /* Ctrl-\ at terminal for example. */
+ SIGHUP, /* terminal closed for example. */
+ SIGTERM, /* if terminated, stop monitored proc. */
+
+ SIGPIPE, SIGUSR1, SIGUSR2,
+
+ SIGILL, SIGTRAP, SIGABRT, SIGBUS, SIGFPE, SIGSEGV,
+
+# ifdef SIGXCPU
+ SIGXCPU,
+# endif
+# ifdef SIGXFSZ
+ SIGXFSZ,
+# endif
+# ifdef SIGSYS
+ SIGSYS,
+# endif
+# ifdef SIGVTALRM
+ SIGVTALRM,
+# endif
+# ifdef SIGPROF
+ SIGPROF,
+# endif
+# ifdef SIGPOLL
+ SIGPOLL,
+# endif
+# ifdef SIGPWR
+ SIGPWR,
+# endif
+# ifdef SIGSTKFLT
+ SIGSTKFLT,
+# endif
+# ifdef SIGEMT
+ SIGEMT,
+# endif
+# ifdef SIGBREAK
+ SIGBREAK,
+# endif
+ };
+
+#endif
#include "dtimespec-bound.h"
#include "sig2str.h"
#include "operand2sig.h"
+#include "term-sig.h"
#include "quote.h"
#if HAVE_SETRLIMIT
{
}
-static int const term_sig[] =
- {
- SIGALRM, /* our timeout. */
- SIGINT, /* Ctrl-C at terminal for example. */
- SIGQUIT, /* Ctrl-\ at terminal for example. */
- SIGHUP, /* terminal closed for example. */
- SIGTERM, /* if terminated, stop monitored proc. */
-
- SIGPIPE, SIGUSR1, SIGUSR2,
- SIGILL, SIGTRAP, SIGABRT, SIGBUS, SIGFPE, SIGSEGV,
-#ifdef SIGXCPU
- SIGXCPU,
-#endif
-#ifdef SIGXFSZ
- SIGXFSZ,
-#endif
-#ifdef SIGSYS
- SIGSYS,
-#endif
-#ifdef SIGVTALRM
- SIGVTALRM,
-#endif
-#ifdef SIGPROF
- SIGPROF,
-#endif
-#ifdef SIGPOLL
- SIGPOLL,
-#endif
-#ifdef SIGPWR
- SIGPWR,
-#endif
-#ifdef SIGSTKFLT
- SIGSTKFLT,
-#endif
- };
-
static void
cleanup (int sig)
{