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

From: Daniel Eischen <eischen_at_vigrid.com>
Date: Sun, 30 Nov 2003 00:41:06 -0500 (EST)
On Sat, 29 Nov 2003, Alfred Perlstein wrote:

> * Daniel Eischen <eischen_at_vigrid.com> [031129 14:57] wrote:
> > > 
> > > 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 {
> > 		...
> > 	}
> 
> So remove the check?  do you approve? does re_at_ approve?

You should just call close() if the fd has not been initialized.

Index: uthread_close.c
===================================================================
RCS file: /opt/FreeBSD/cvs/src/lib/libc_r/uthread/uthread_close.c,v
retrieving revision 1.16
diff -u -r1.16 uthread_close.c
--- uthread_close.c	9 Jun 2003 16:45:37 -0000	1.16
+++ uthread_close.c	30 Nov 2003 09:05:52 -0000
_at__at_ -50,8 +50,7 _at__at_
 	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)) {
+	    (fd == _thread_kern_pipe[0]) || (fd == _thread_kern_pipe[1])) {
 		/*
 		 * Don't allow silly programs to close the kernel pipe
 		 * and non-active descriptors.
_at__at_ -59,6 +58,8 _at__at_
 		errno = EBADF;
 		ret = -1;
 	}
+	else if (_thread_fd_table[fd] == NULL)
+		ret = __sys_close(fd);
 	/*
 	 * Lock the file descriptor while the file is closed and get
 	 * the file descriptor status:

-- 
Dan Eischen
Received on Sat Nov 29 2003 - 20:41:08 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:37:31 UTC