From owner-freebsd-hackers Wed May 22 08:25:13 1996 Return-Path: owner-hackers Received: (from root@localhost) by freefall.freebsd.org (8.7.3/8.7.3) id IAA03482 for hackers-outgoing; Wed, 22 May 1996 08:25:13 -0700 (PDT) Received: from expo.x.org (expo.x.org [198.112.45.11]) by freefall.freebsd.org (8.7.3/8.7.3) with ESMTP id IAA03463 for ; Wed, 22 May 1996 08:25:03 -0700 (PDT) Received: from exalt.x.org by expo.x.org id AA16933; Wed, 22 May 96 11:24:24 -0400 Received: from localhost by exalt.x.org id LAA06575; Wed, 22 May 1996 11:24:21 -0400 Message-Id: <199605221524.LAA06575@exalt.x.org> To: Kees Jan Koster Cc: hackers@freefall.FreeBSD.org Subject: Re: Forgiving select() call. In-Reply-To: Your message of Wed, 22 May 1996 15:02:14 EST. <199605221302.PAA00484@phobos.spase.nl> Organization: X Consortium Date: Wed, 22 May 1996 11:24:20 EST From: "Kaleb S. KEITHLEY" Sender: owner-hackers@FreeBSD.ORG X-Loop: FreeBSD.org Precedence: bulk > Hoi Hackers, > > Consider the following excerpt from /sys/kern/sys_generic.c, from > 2.1.0-release. Somewhere near line 550. This piece of code forgives > programs that specify a too large `nd' value by setting it to a more > acceptable value. > > ... > if (uap->nd > p->p_fd->fd_nfiles) > uap->nd = p->p_fd->fd_nfiles; /* forgiving; slightly wrong */ > ... This looks to me like an optimization. Why check for I/O on file descriptors that are known not to be in use? > Out of curiosity I printed the process ID's of processes that were > forgiven in this way. One of the biggest offenders was the X server %-). > > My questions: > - shouldn't programs that are forgiven be patched to specify correct > values? The parameters the X server passes are legal and, strictly speaking, not incorrect. What makes you think they are not correct? > - If I were to hack my kernel to return EINVAL instead, would that be > a correct (if pedantic) thing to do? No, it would not. The value passed, e.g., by the X server is not invalid. And breaking legacy software is rarely, if ever, the correct thing to do. > - I noticed that EINVAL is also returned if (uap->nd > FD_SETSIZE), why > is that not forgiven. Why should it be forgiven when it clearly is an error. > > I want to modify select(2) to return the `timeout left' as described in the > BUGS section of the manual page. Any reason why I should not? To what point? If you write a program that depends on this behavior it won't be portable to any other system because no other system (that I know of) has a select that fixes this "bug". -- Kaleb KEITHLEY X Consortium