NetBSD Problem Report #58920

From www@netbsd.org  Thu Dec 19 16:09:26 2024
Return-Path: <www@netbsd.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256
	 client-signature RSA-PSS (2048 bits) client-digest SHA256)
	(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id 7F2D31A9238
	for <gnats-bugs@gnats.NetBSD.org>; Thu, 19 Dec 2024 16:09:26 +0000 (UTC)
Message-Id: <20241219160925.17CCC1A923A@mollari.NetBSD.org>
Date: Thu, 19 Dec 2024 16:09:25 +0000 (UTC)
From: campbell+netbsd@mumble.net
Reply-To: campbell+netbsd@mumble.net
To: gnats-bugs@NetBSD.org
Subject: timer_settime fails ETIMEDOUT on negative interval, not EINVAL
X-Send-Pr-Version: www-1.0

>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
>Last-Modified:  Thu Dec 19 23:40:01 +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!

>Audit-Trail:
From: "Taylor R Campbell" <riastradh@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/58920 CVS commit: src/tests/lib/libc/sys
Date: Thu, 19 Dec 2024 20:07:29 +0000

 Module Name:	src
 Committed By:	riastradh
 Date:		Thu Dec 19 20:07:29 UTC 2024

 Modified Files:
 	src/tests/lib/libc/sys: t_timer_create.c

 Log Message:
 t_timer_create: Fix up tests for edge cases.

 While here, save and restore errno in signal handler.

 PR kern/58919: timer_settime fails to trigger for past times

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


 To generate a diff of this commit:
 cvs rdiff -u -r1.6 -r1.7 src/tests/lib/libc/sys/t_timer_create.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: "Taylor R Campbell" <riastradh@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/58920 CVS commit: src
Date: Thu, 19 Dec 2024 23:36:49 +0000

 Module Name:	src
 Committed By:	riastradh
 Date:		Thu Dec 19 23:36:49 UTC 2024

 Modified Files:
 	src/sys/kern: kern_time.c
 	src/tests/lib/libc/sys: t_timer_create.c

 Log Message:
 timer_settime(2): Fix error code for negative it_interval.

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


 To generate a diff of this commit:
 cvs rdiff -u -r1.221 -r1.222 src/sys/kern/kern_time.c
 cvs rdiff -u -r1.7 -r1.8 src/tests/lib/libc/sys/t_timer_create.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.47 2022/09/11 19:34:41 kim Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2024 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.