>From 63e85c87b6d78489731ea86514dead2da108bff9 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Sun, 29 Nov 2026 13:54:04 -0500 Subject: [PATCH] ualarm: fix failure & indeterminate result with arguments > 1 second setitimer is required to fail if either timeval in the new setting is not in normalized form (tv_usec not in the range 0 to 999999). but ualarm may take value/interval arguments which exceed one second. in this case, the setitimer call failed, and ualarm silently returned indeterminate values. normalize the arguments properly before calling setitimer. --- src/unistd/ualarm.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/unistd/ualarm.c b/src/unistd/ualarm.c index 2985855c..5fd8c60e 100644 --- a/src/unistd/ualarm.c +++ b/src/unistd/ualarm.c @@ -5,8 +5,10 @@ unsigned ualarm(unsigned value, unsigned interval) { struct itimerval it = { - .it_interval.tv_usec = interval, - .it_value.tv_usec = value + .it_interval.tv_sec = interval / 1000000, + .it_interval.tv_usec = interval % 1000000, + .it_value.tv_sec = value / 1000000, + .it_value.tv_usec = value % 1000000, }, it_old; setitimer(ITIMER_REAL, &it, &it_old); return it_old.it_value.tv_sec*1000000 + it_old.it_value.tv_usec; -- 2.21.0