Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 22 May 1996 11:24:20 EST
From:      "Kaleb S. KEITHLEY" <kaleb@x.org>
To:        Kees Jan Koster <dutchman@spase.nl>
Cc:        hackers@freefall.FreeBSD.org
Subject:   Re: Forgiving select() call. 
Message-ID:  <199605221524.LAA06575@exalt.x.org>
In-Reply-To: Your message of Wed, 22 May 1996 15:02:14 EST. <199605221302.PAA00484@phobos.spase.nl> 

next in thread | previous in thread | raw e-mail | index | archive | help

> 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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199605221524.LAA06575>