git: a56833c9f727 - stable/14 - timeout(1): Handle sig_alrm and sig_term together to dedup code
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Mon, 16 Jun 2025 08:53:59 UTC
The branch stable/14 has been updated by kib:
URL: https://cgit.FreeBSD.org/src/commit/?id=a56833c9f72703ad6438c7236e60c2c44030c6ea
commit a56833c9f72703ad6438c7236e60c2c44030c6ea
Author: Aaron LI <aly@aaronly.me>
AuthorDate: 2025-04-02 14:34:45 +0000
Commit: Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2025-06-16 08:51:52 +0000
timeout(1): Handle sig_alrm and sig_term together to dedup code
(cherry picked from commit c5cdc13045650a9daf33dd6316ef57496e4a5dbc)
---
bin/timeout/timeout.c | 37 ++++++++++++-------------------------
1 file changed, 12 insertions(+), 25 deletions(-)
diff --git a/bin/timeout/timeout.c b/bin/timeout/timeout.c
index aaecd7fec2e5..4c81b64cd2b6 100644
--- a/bin/timeout/timeout.c
+++ b/bin/timeout/timeout.c
@@ -174,7 +174,7 @@ set_interval(double iv)
int
main(int argc, char **argv)
{
- int ch, status;
+ int ch, status, sig;
int foreground, preserve;
int pstat = 0;
int killsig = SIGTERM;
@@ -314,36 +314,23 @@ main(int argc, char **argv)
break;
}
}
- } else if (sig_alrm) {
- sig_alrm = 0;
-
- timedout = true;
- if (!foreground) {
- killemall.rk_sig = killsig;
- killemall.rk_flags = 0;
- procctl(P_PID, getpid(), PROC_REAP_KILL,
- &killemall);
+ } else if (sig_alrm || sig_term) {
+ if (sig_alrm) {
+ sig = killsig;
+ sig_alrm = 0;
+ timedout = true;
} else {
- send_sig(pid, killsig);
+ sig = sig_term;
+ sig_term = 0;
}
- if (do_second_kill) {
- set_interval(second_kill);
- do_second_kill = false;
- sig_ign = killsig;
- killsig = SIGKILL;
+ if (foreground) {
+ send_sig(pid, sig);
} else {
- break;
- }
-
- } else if (sig_term) {
- if (!foreground) {
- killemall.rk_sig = sig_term;
+ killemall.rk_sig = sig;
killemall.rk_flags = 0;
procctl(P_PID, getpid(), PROC_REAP_KILL,
- &killemall);
- } else {
- send_sig(pid, sig_term);
+ &killemall);
}
if (do_second_kill) {