[PATCH] please review. file descriptor passing for libc_r.

Daniel Eischen eischen at vigrid.com
Sat Nov 29 14:57:50 PST 2003


On Sat, 29 Nov 2003, Alfred Perlstein wrote:

> * Daniel Eischen <eischen at vigrid.com> [031122 20:46] wrote:
> > On Sat, 22 Nov 2003, Alfred Perlstein wrote:
> > 
> > > This should make things work properly for apps that are linked
> > > against libc_r and use filedescriptor passing.
> > > 
> > > Can someone review and approve it please?
> > 
> > This isn't needed.  Any time a file descriptor is used, a call
> > should first be made to _FD_LOCK() which ends up calling
> > _thread_fd_lock() which then calls _thread_fd_table_init()
> > for the file descriptor.
> > 
> > If there's a reason that this is necessary, then I think it
> > is just covering up another problem.  I think I made this
> > same comment a couple of years ago ;-)
> 
> Sorry for the long delay here, I was in Vegas for my sister's
> birthday.
> 
> Actually there is a problem here. :(
> 
> Descriptor's passed can't be closed because the uthread kernel does this:
> 
> int
> _close(int fd)
> {
>         int             flags;
>         int             ret;
>         struct stat     sb;
>         struct fd_table_entry   *entry;
> 
>         if ((fd < 0) || (fd >= _thread_dtablesize) ||
>             (fd == _thread_kern_pipe[0]) || (fd == _thread_kern_pipe[1]) ||
>             (_thread_fd_table[fd] == NULL)) {
>                 /*
>                  * Don't allow silly programs to close the kernel pipe
>                  * and non-active descriptors.
>                  */
>                 errno = EBADF;
>                 ret = -1;
>         }
> ...
> 
> So basically, if the entry is not initialized we can't close descriptors.
> 
> What do you suggest we do?

Just close the file:

	if ((fd < 0) || (fd >= _thread_dtablesize) ||
	    (fd == _thread_kern_pipe[0]) || (fd == _thread_kern_pipe[1])) {
		/*
		 * Don't allow silly programs to close the kernel pipe
		 * and non-active descriptors.
		 */
		errno = EBADF;
		ret = -1;
	}
	else if (_thread_fd_table[fd] == NULL)
		ret = __sys_close(fd);
	else {
		...
	}

-- 
Dan Eischen




More information about the freebsd-current mailing list