NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

kern/58919: timer_settime fails to trigger for past times



>Number:         58919
>Category:       kern
>Synopsis:       timer_settime fails to trigger for past times
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    kern-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Dec 18 22:15:00 +0000 2024
>Originator:     Taylor R Campbell
>Release:        current, 10, 9, ...
>Organization:
The NetBSD Tachyondation
>Environment:
>Description:
POSIX says:

> If the specified time has already passed, the function shall succeed and the expiration notification shall be made.

https://pubs.opengroup.org/onlinepubs/9799919799.2024edition/functions/timer_settime.html

But for relative timers, timer_settime fails with ETIMEDOUT, and for absolute timers, nothing happens at all.
>How-To-Repeat:
$ cat timerpastabs.c
#include <err.h>
#include <signal.h>
#include <time.h>

sig_atomic_t woken;

static void
wakeup(int signo)
{

	woken = 1;
}

int
main(void)
{
	timer_t t;
	struct itimerspec it = { .it_value = { .tv_sec = -1, .tv_nsec = 0 } };
	struct timespec t0;

	if (signal(SIGALRM, wakeup) == SIG_ERR)
		err(1, "signal(SIGALRM)");
	if (timer_create(CLOCK_MONOTONIC, NULL, &t) == -1)
		err(1, "timer_create");
	if (clock_gettime(CLOCK_MONOTONIC, &t0) == -1)
		err(1, "clock_gettime");
	timespecadd(&t0, &it.it_value, &it.it_value);
	if (timer_settime(t, TIMER_ABSTIME, &it, NULL) == -1)
		err(1, "timer_settime");
	return woken ? 0 : 1;
}
$ cat timerpastrel
cat: timerpastrel: No such file or directory
$ cat timerpastrel.c
#include <err.h>
#include <signal.h>
#include <time.h>

sig_atomic_t woken;

static void
wakeup(int signo)
{

	woken = 1;
}

int
main(void)
{
	timer_t t;
	struct itimerspec it = { .it_value = { .tv_sec = -1, .tv_nsec = 0 } };

	if (signal(SIGALRM, wakeup) == SIG_ERR)
		err(1, "signal(SIGALRM)");
	if (timer_create(CLOCK_MONOTONIC, NULL, &t) == -1)
		err(1, "timer_create");
	if (timer_settime(t, 0, &it, NULL) == -1)
		err(1, "timer_settime");
	return woken ? 0 : 1;
}
$ make timerpastabs timerpastrel
cc -O2   -o timerpastabs timerpastabs.c 
cc -O2   -o timerpastrel timerpastrel.c 
$ ./timerpastabs
$ echo $?
1
$ ./timerpastrel
timerpastrel: timer_settime: Connection timed out

>Fix:
Yes, please!



Home | Main Index | Thread Index | Old Index