From a6d4491c71877016dd4d4dd04846121224fcd47c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dag-Erling=20Sm=C3=B8rgrav?= Date: Sat, 17 Jan 2004 00:59:04 +0000 Subject: [PATCH] Restore correct semantics for F_DUPFD fcntl. This should fix the errors people have been getting with configure scripts. --- sys/kern/kern_descrip.c | 8 ++++---- sys/kern/uipc_usrreq.c | 2 +- sys/sys/filedesc.h | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/sys/kern/kern_descrip.c b/sys/kern/kern_descrip.c index a391fed95135..b6eaee271a6c 100644 --- a/sys/kern/kern_descrip.c +++ b/sys/kern/kern_descrip.c @@ -602,7 +602,7 @@ do_dup(td, type, old, new, retval) if (fdp->fd_ofiles[new] == NULL) fdused(fdp, new); } else { - if ((error = fdalloc(td, &new)) != 0) { + if ((error = fdalloc(td, new, &new)) != 0) { FILEDESC_UNLOCK(fdp); fdrop(fp, td); return (error); @@ -1205,7 +1205,7 @@ fdgrowtable(struct filedesc *fdp, int nfd) * Allocate a file descriptor for the process. */ int -fdalloc(struct thread *td, int *result) +fdalloc(struct thread *td, int minfd, int *result) { struct proc *p = td->td_proc; struct filedesc *fdp = p->p_fd; @@ -1222,7 +1222,7 @@ fdalloc(struct thread *td, int *result) * may drop the filedesc lock, so we're in a race. */ for (;;) { - fd = fd_first_free(fdp, fdp->fd_freefile, fdp->fd_nfiles); + fd = fd_first_free(fdp, minfd, fdp->fd_nfiles); if (fd >= maxfd) return (EMFILE); if (fd < fdp->fd_nfiles) @@ -1326,7 +1326,7 @@ falloc(td, resultfp, resultfd) LIST_INSERT_HEAD(&filehead, fp, f_list); } sx_xunlock(&filelist_lock); - if ((error = fdalloc(td, &i))) { + if ((error = fdalloc(td, 0, &i))) { FILEDESC_UNLOCK(p->p_fd); fdrop(fp, td); if (resultfp) diff --git a/sys/kern/uipc_usrreq.c b/sys/kern/uipc_usrreq.c index 8dd9b7e4595d..1f9ca3d2007b 100644 --- a/sys/kern/uipc_usrreq.c +++ b/sys/kern/uipc_usrreq.c @@ -1047,7 +1047,7 @@ unp_externalize(control, controlp) fdp = (int *) CMSG_DATA(mtod(*controlp, struct cmsghdr *)); for (i = 0; i < newfds; i++) { - if (fdalloc(td, &f)) + if (fdalloc(td, 0, &f)) panic("unp_externalize fdalloc failed"); fp = *rp++; td->td_proc->p_fd->fd_ofiles[f] = fp; diff --git a/sys/sys/filedesc.h b/sys/sys/filedesc.h index ff8cefea2fff..8904435f32e5 100644 --- a/sys/sys/filedesc.h +++ b/sys/sys/filedesc.h @@ -147,7 +147,7 @@ int dupfdopen(struct thread *td, struct filedesc *fdp, int indx, int dfd, int falloc(struct thread *p, struct file **resultfp, int *resultfd); void fdused(struct filedesc *fdp, int fd); void fdunused(struct filedesc *fdp, int fd); -int fdalloc(struct thread *p, int *result); +int fdalloc(struct thread *p, int minfd, int *result); int fdavail(struct thread *td, int n); void fdcloseexec(struct thread *td); int fdcheckstd(struct thread *td);