git: aae3eb24dfdb - main - timeout(1): Fix the handling of repeated terminating signals
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Wed, 16 Apr 2025 19:46:33 UTC
The branch main has been updated by bapt: URL: https://cgit.FreeBSD.org/src/commit/?id=aae3eb24dfdbbe0a9e62fe7239d6038060cd07f6 commit aae3eb24dfdbbe0a9e62fe7239d6038060cd07f6 Author: Aaron LI <aly@aaronly.me> AuthorDate: 2025-04-02 16:14:40 +0000 Commit: Baptiste Daroussin <bapt@FreeBSD.org> CommitDate: 2025-04-16 19:45:38 +0000 timeout(1): Fix the handling of repeated terminating signals This actually fixes the following two issues: * If a terminating signal (e.g., HUP/INT/TERM) was received, timeout would propagate it to the command and then ignore it. So it was unable to resend the same terminating signal to the command. This was different from the GNU's timeout(1), and also contradicted the POSIX.1-2024 standard. * Sending two different terminating signals would break timeout(1)'s --kill-after mechanism. That was because the second signal would break the for() loop, so the second SIGALRM set by '--kill-after' would never be caught. For example, in one shell run: $ time timeout -f -v -s INT -k 1 2 sh -T -c \ 'trap date INT HUP; sleep 5; echo ok; date' and in another shell run: $ pkill -INT timeout; pkill -HUP timeout in the end, the time(1) would report it cost 5 seconds instead of the expected 3 seconds. Obtained-from: DragonFly BSD --- bin/timeout/timeout.c | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/bin/timeout/timeout.c b/bin/timeout/timeout.c index e702803a25c2..c3c7532a9d08 100644 --- a/bin/timeout/timeout.c +++ b/bin/timeout/timeout.c @@ -49,7 +49,6 @@ static volatile sig_atomic_t sig_chld = 0; static volatile sig_atomic_t sig_term = 0; static volatile sig_atomic_t sig_alrm = 0; -static volatile sig_atomic_t sig_ign = 0; static const char *command = NULL; static bool verbose = false; @@ -138,11 +137,6 @@ parse_signal(const char *str) static void sig_handler(int signo) { - if (sig_ign != 0 && signo == sig_ign) { - sig_ign = 0; - return; - } - switch (signo) { case SIGINT: case SIGHUP: @@ -377,19 +371,11 @@ main(int argc, char **argv) if (do_second_kill) { set_interval(second_kill); do_second_kill = false; - sig_ign = killsig; killsig = SIGKILL; - } else { - break; } } } - while (!child_done && wait(&pstat) == -1) { - if (errno != EINTR) - err(EXIT_FAILURE, "wait()"); - } - if (!foreground) procctl(P_PID, getpid(), PROC_REAP_RELEASE, NULL);