[Patch] sys/kern/kern_descrip.c: remove double limit check in fcntl()

John Baldwin jhb at freebsd.org
Tue Nov 14 19:46:11 UTC 2006


On Thursday 09 November 2006 14:33, Ed Schouten wrote:
> * Ed Schouten <ed at fxq.nl> wrote:
> > The patch below prevents this by performing this check by do_dup(). It
> > will prevent fcntl() from PROC_LOCK()'ing twice. It also fixes the
> > return value of fcntl(). The manual page states that it should return
> > EMFILE when it exceeds its limit, though the actual code sets EINVAL.
> 
> Woops - It looks like I wasn't awake when I was reading the fcntl()
> manual page. fcntl() should return EINVAL when the minimum value is
> higher than the limit and EMFILE when it can't find a free descriptor in
> the range from the minimum value to the maximum. dup() generalizes this
> to EMFILE. It cannot return EINVAL.
> 
> I decided to change the patch that do_dup() can return EINVAL for the
> fcntl() scenario and that the dup()/dup2() system calls readjust the
> errno right before returning. Please use the patch below.

I actually the resulting changes obfuscate the code more than the current 
code, so I'd prefer to just leave it as it is.

-- 
John Baldwin


More information about the freebsd-hackers mailing list