# define SA_RESTART 0
#endif
+#ifndef SIGRTMIN
+# define SIGRTMIN 0
+# undef SIGRTMAX
+#endif
+#ifndef SIGRTMAX
+# define SIGRTMAX (SIGRTMIN - 1)
+#endif
+
#define PROGRAM_NAME "timeout"
#define AUTHORS proper_name_lite ("Padraig Brady", "P\303\241draig Brady")
{
}
+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)
sa.sa_flags = SA_RESTART; /* Restart syscalls if possible, as that's
more likely to work cleanly. */
- sigaction (SIGALRM, &sa, nullptr); /* our timeout. */
- sigaction (SIGINT, &sa, nullptr); /* Ctrl-C at terminal for example. */
- sigaction (SIGQUIT, &sa, nullptr); /* Ctrl-\ at terminal for example. */
- sigaction (SIGHUP, &sa, nullptr); /* terminal closed for example. */
- sigaction (SIGTERM, &sa, nullptr); /* if killed, stop monitored proc. */
+ for (int i = 0; i < countof (term_sig); i++)
+ sigaction (term_sig[i], &sa, nullptr);
+
+ /* Real Time signals also terminate by default. */
+ for (int s = SIGRTMIN; s <= SIGRTMAX; s++)
+ sigaction (s, &sa, nullptr);
+
sigaction (sigterm, &sa, nullptr); /* user specified termination signal. */
}
sigset_t block_set;
sigemptyset (&block_set);
- sigaddset (&block_set, SIGALRM);
- sigaddset (&block_set, SIGINT);
- sigaddset (&block_set, SIGQUIT);
- sigaddset (&block_set, SIGHUP);
- sigaddset (&block_set, SIGTERM);
+ for (int i = 0; i < countof (term_sig); i++)
+ sigaddset (&block_set, term_sig[i]);
+
+ for (int s = SIGRTMIN; s <= SIGRTMAX; s++)
+ sigaddset (&block_set, s);
+
sigaddset (&block_set, sigterm);
sigaddset (&block_set, SIGCHLD);
# along with this program. If not, see <https://www.gnu.org/licenses/>.
. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
-print_ver_ timeout
+print_ver_ timeout kill
require_trap_signame_
# no timeout
compare exp err || fail=1
done
+# Ensure we propagate all terminating signals.
+# Specifically here we're testing that SIGPIPE is handled.
+# I.e., that we're not killed by the SIGPIPE (and leave the sleep running).
+# timeout would exit with 141 usually if SIGPIPE wasn't being handled.
+echo 125 > timeout.exp || framework_failure_
+{ timeout -v .1 sleep 10 2>&1; echo $? >timeout.status; } | :
+compare timeout.exp timeout.status || fail=1
+
Exit $fail