NetBSD Problem Report #41094
From www@NetBSD.org Sun Mar 29 16:12:18 2009
Return-Path: <www@NetBSD.org>
Received: from mail.netbsd.org (mail.netbsd.org [204.152.190.11])
by www.NetBSD.org (Postfix) with ESMTP id E19E863BA2C
for <gnats-bugs@gnats.netbsd.org>; Sun, 29 Mar 2009 16:12:17 +0000 (UTC)
Message-Id: <20090329161217.6CBD163B946@www.NetBSD.org>
Date: Sun, 29 Mar 2009 16:12:17 +0000 (UTC)
From: matteo@beccati.com
Reply-To: matteo@beccati.com
To: gnats-bugs@NetBSD.org
Subject: sigtimedwait returns EAGAIN instead of EINVAL if timeout is invalid
X-Send-Pr-Version: www-1.0
>Number: 41094
>Category: kern
>Synopsis: sigtimedwait returns EAGAIN instead of EINVAL if timeout is invalid
>Confidential: no
>Severity: non-critical
>Priority: medium
>Responsible: kern-bug-people
>State: closed
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Sun Mar 29 16:15:00 +0000 2009
>Closed-Date: Mon May 18 06:35:02 +0000 2009
>Last-Modified: Mon May 18 06:35:02 +0000 2009
>Originator: Matteo Beccati
>Release: NetBSD 5.0_RC3
>Organization:
>Environment:
NetBSD epia.hq.beccati.com 5.0_RC3 NetBSD 5.0_RC3 (EPIA) #5: Sun Mar 29 17:17:36 CEST 2009 root@aperol.beccati.com:/array1/compile/netbsd-5/src/sys/arch/i386/compile/obj/EPIA i386
>Description:
sigtimedwait returns EAGAIN instead of EINVAL if the specified timeout overflows when converted in Hz.
From the man page:
sigtimedwait() may also fail if:
[EINVAL] The specified timeout was invalid.
>How-To-Repeat:
#include <stdio.h>
#include <string.h>
#include <signal.h>
#include <limits.h>
#include <time.h>
#include <errno.h>
int main(int argc, char **argv)
{
sigset_t mask;
siginfo_t info;
struct timespec ts;
sigemptyset(&mask);
sigaddset(&mask, SIGTERM);
sigprocmask(SIG_BLOCK, &mask, NULL);
ts.tv_sec = LONG_MAX;
ts.tv_nsec = 999;
int ret = sigtimedwait(&mask, &info, &ts);
printf("Ret: %d, Error: %d %s\n", ret, errno, strerror(errno));
return 0;
}
>Fix:
Index: sys/kern/sys_sig.c
===================================================================
RCS file: /cvsroot/src/sys/kern/sys_sig.c,v
retrieving revision 1.17
diff -u -r1.17 sys_sig.c
--- sys/kern/sys_sig.c 15 Oct 2008 06:51:20 -0000 1.17
+++ sys/kern/sys_sig.c 29 Mar 2009 16:10:53 -0000
@@ -640,7 +640,7 @@
if (timo == 0 && ts.tv_sec == 0 && ts.tv_nsec > 0)
timo = 1;
if (timo <= 0)
- return (EAGAIN);
+ return (EINVAL);
/*
* Remember current uptime, it would be used in
>Release-Note:
>Audit-Trail:
From: Matteo Beccati <matteo@beccati.com>
To: gnats-bugs@NetBSD.org
Cc:
Subject: Re: kern/41094: sigtimedwait returns EAGAIN instead of EINVAL if
timeout is invalid
Date: Sun, 29 Mar 2009 18:29:08 +0200
However, the fix doesn't work if both tv_sec and tv_usec == LONG_MAX.
Reusing the mstohz definition from sys/sys/param.h, with hz set to 100,
I got: 2147483649147ms -> 100hz
From: christos@zoulas.com (Christos Zoulas)
To: gnats-bugs@NetBSD.org, kern-bug-people@netbsd.org,
gnats-admin@netbsd.org, netbsd-bugs@netbsd.org, matteo@beccati.com
Cc:
Subject: Re: kern/41094: sigtimedwait returns EAGAIN instead of EINVAL if timeout is invalid
Date: Sun, 29 Mar 2009 12:36:45 -0400
On Mar 29, 4:30pm, matteo@beccati.com (Matteo Beccati) wrote:
-- Subject: Re: kern/41094: sigtimedwait returns EAGAIN instead of EINVAL if
| The following reply was made to PR kern/41094; it has been noted by GNATS.
|
| From: Matteo Beccati <matteo@beccati.com>
| To: gnats-bugs@NetBSD.org
| Cc:
| Subject: Re: kern/41094: sigtimedwait returns EAGAIN instead of EINVAL if
| timeout is invalid
| Date: Sun, 29 Mar 2009 18:29:08 +0200
|
| However, the fix doesn't work if both tv_sec and tv_usec == LONG_MAX.
|
| Reusing the mstohz definition from sys/sys/param.h, with hz set to 100,
| I got: 2147483649147ms -> 100hz
Does changing the mstohz(ms) to tstohz(&ts) work?
christos
From: Matteo Beccati <matteo@beccati.com>
To: gnats-bugs@NetBSD.org
Cc: kern-bug-people@netbsd.org, gnats-admin@netbsd.org,
netbsd-bugs@netbsd.org
Subject: Re: kern/41094: sigtimedwait returns EAGAIN instead of EINVAL if
timeout is invalid
Date: Sun, 29 Mar 2009 19:07:05 +0200
Christos Zoulas wrote:
> | However, the fix doesn't work if both tv_sec and tv_usec == LONG_MAX.
> |
> | Reusing the mstohz definition from sys/sys/param.h, with hz set to 100,
> | I got: 2147483649147ms -> 100hz
>
> Does changing the mstohz(ms) to tstohz(&ts) work?
Updated the kernel, the function now waits indefinitely. Probably the
timeout was rounded down to INT_MAX, but I can't tell as it's in the kernel.
For reference, looks like Linux performs some additional validation on
the usec field:
sec = LONG_MAX, usec = 0: ok
sec = LONG_MAX, usec = 999999999: ok
sec = 0, usec = 1000000000: EINVAL
sec = LONG_MAX, usec = LONG_MAX: EINVAL
From: Matteo Beccati <matteo@beccati.com>
To: gnats-bugs@NetBSD.org
Cc:
Subject: Re: kern/41094: sigtimedwait returns EAGAIN instead of EINVAL if
timeout is invalid
Date: Wed, 01 Apr 2009 11:30:33 +0200
Thanks for the fix in -current. I've applied it to netbsd-5 and works good.
Can I request a pullup of the related changes to the netbsd-5 branch:
cvs rdiff -r 1.21 -r 1.23 src/sys/kern/sys_sig.c
Thanks
State-Changed-From-To: open->feedback
State-Changed-By: rmind@NetBSD.org
State-Changed-When: Wed, 01 Apr 2009 10:46:53 +0000
State-Changed-Why:
Christos fixed the return value. Request for pull-up sent.
Thanks for good bug-report.
Are other checks required by POSIX?
From: Matteo Beccati <matteo@beccati.com>
To: gnats-bugs@NetBSD.org
Cc:
Subject: Re: kern/41094 (sigtimedwait returns EAGAIN instead of EINVAL if
timeout is invalid)
Date: Tue, 05 May 2009 11:08:42 +0200
rmind@NetBSD.org wrote:
> Are other checks required by POSIX?
I'm not a POSIX expert, but I haven't noticed anything else during my tests.
Sorry for the late feedback: I thought I responsed while in fact I did not.
Cheers
State-Changed-From-To: feedback->closed
State-Changed-By: dholland@NetBSD.org
State-Changed-When: Mon, 18 May 2009 06:35:02 +0000
State-Changed-Why:
Fixed & pullups done. Thanks.
>Unformatted:
(Contact us)
$NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2007
The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.