NetBSD-Bugs archive

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

kern/58920: timer_settime fails ETIMEDOUT on negative interval, not EINVAL



>Number:         58920
>Category:       kern
>Synopsis:       timer_settime fails ETIMEDOUT on negative interval, not EINVAL
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    kern-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Dec 19 16:10:00 +0000 2024
>Originator:     Taylor R Campbell
>Release:        current, 10, 9, ...
>Organization:
The timer_settime Timedoution
>Environment:
>Description:
The language in POSIX about timer_settime is unclear, but the language in ex-POSIX about setitimer is clear: EINVAL on negative it_interval.

The behaviour of timer_settime on negative it_value may be debatable (perhaps it should fail with EINVAL, perhaps it should return ETIMEDOUT, perhaps it should trigger the event immediately, perhaps it should trigger the event on the next tick) but returning ETIMEDOUT for negative it_interval is silly; the argument is invalid and cannot be interpreted.
>How-To-Repeat:
$ cat test.c
#include <err.h>
#include <time.h>

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

	if (timer_create(CLOCK_MONOTONIC, NULL, &t) == -1)
		err(1, "timer_create");
	if (timer_settime(t, 0, &it, NULL) == -1)
		err(1, "timer_settime");
	errx(1, "timer_settime failed to fail");
	return 0;
}
$ make test
cc -O2   -o test test.c 
$ ./test
test: timer_settime: Connection timed out

Expected `Invalid argument' instead of `Connection timed out'.
>Fix:
Yes, please!



Home | Main Index | Thread Index | Old Index