Restore correct semantics for F_DUPFD fcntl. This should fix the errors

people have been getting with configure scripts.
This commit is contained in:
Dag-Erling Smørgrav 2004-01-17 00:59:04 +00:00
parent f8edfc0dd6
commit a6d4491c71
3 changed files with 6 additions and 6 deletions

View File

@ -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)

View File

@ -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;

View File

@ -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);