diff options
author | Artur Grabowski <art@cvs.openbsd.org> | 2002-02-04 11:48:23 +0000 |
---|---|---|
committer | Artur Grabowski <art@cvs.openbsd.org> | 2002-02-04 11:48:23 +0000 |
commit | 1a306037dcc43d3a113c7157c23636afbb1721e1 (patch) | |
tree | 7a9f7f55e13aafa1fda9503e25da6fc36350e8f6 | |
parent | 51aa95a1c51e94cdc54eb7a2d196b9f94dc5f797 (diff) |
Add some comments documenting why we use fd_ofiles instead
of fd_getfile in some places.
Also, get rid of the check for old == new in dupfdopen and document why
the semantics of fd_getfile make it unnecessary.
-rw-r--r-- | sys/kern/kern_descrip.c | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/sys/kern/kern_descrip.c b/sys/kern/kern_descrip.c index d025aa2b46a..ee2b3201076 100644 --- a/sys/kern/kern_descrip.c +++ b/sys/kern/kern_descrip.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_descrip.c,v 1.45 2002/02/02 17:52:27 art Exp $ */ +/* $OpenBSD: kern_descrip.c,v 1.46 2002/02/04 11:48:22 art Exp $ */ /* $NetBSD: kern_descrip.c,v 1.42 1996/03/30 22:24:38 christos Exp $ */ /* @@ -491,6 +491,10 @@ finishdup(p, old, new, retval) struct file *fp, *oldfp; struct filedesc *fdp = p->p_fd; + /* + * Don't fd_getfile here. We want to closef LARVAL files and + * closef can deal with that. + */ oldfp = fdp->fd_ofiles[new]; fp = fdp->fd_ofiles[old]; @@ -529,6 +533,10 @@ fdrelease(p, fd) struct filedesc *fdp = p->p_fd; struct file **fpp, *fp; + /* + * Don't fd_getfile here. We want to closef LARVAL files and closef + * can deal with that. + */ fpp = &fdp->fd_ofiles[fd]; fp = *fpp; if (fp == NULL) @@ -1138,28 +1146,23 @@ filedescopen(dev, mode, type, p) */ int dupfdopen(fdp, indx, dfd, mode, error) - register struct filedesc *fdp; - register int indx, dfd; + struct filedesc *fdp; + int indx, dfd; int mode; int error; { - register struct file *wfp; - struct file *fp; + struct file *wfp; /* * If the to-be-dup'd fd number is greater than the allowed number * of file descriptors, or the fd to be dup'd has already been - * closed, reject. Note, check for new == old is necessary as - * falloc could allocate an already closed to-be-dup'd descriptor - * as the new descriptor. + * closed, reject. Note, there is no need to check for new == old + * because fd_getfile will return NULL if the file at indx is + * newly created by falloc (FIF_LARVAL). */ - fp = fdp->fd_ofiles[indx]; if ((wfp = fd_getfile(fdp, dfd)) == NULL) return (EBADF); - if (fp == wfp) - return (EBADF); - /* * There are two cases of interest here. * |