git: c5cdc1304565 - main - timeout(1): Handle sig_alrm and sig_term together to dedup code
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Wed, 16 Apr 2025 19:46:29 UTC
The branch main has been updated by bapt:
URL: https://cgit.FreeBSD.org/src/commit/?id=c5cdc13045650a9daf33dd6316ef57496e4a5dbc
commit c5cdc13045650a9daf33dd6316ef57496e4a5dbc
Author: Aaron LI <aly@aaronly.me>
AuthorDate: 2025-04-02 14:34:45 +0000
Commit: Baptiste Daroussin <bapt@FreeBSD.org>
CommitDate: 2025-04-16 19:45:38 +0000
timeout(1): Handle sig_alrm and sig_term together to dedup code
Merge the 'sig_alrm' and 'sig_term' conditionals, and thus reduce some
duplicate code.
Obtained-from: DragonFly BSD
---
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) {