From 8d6f49b7317a0f199de175e20f65022d269553dd Mon Sep 17 00:00:00 2001 From: jhb Date: Thu, 26 Apr 2007 18:01:19 +0000 Subject: Avoid a lot of code duplication by using kern_open() to open /dev/null in fdcheckstd() instead of a stripped down version of kern_open()'s code. MFC after: 1 week Reviewed by: cperciva --- sys/kern/kern_descrip.c | 54 +++++++++---------------------------------------- 1 file changed, 9 insertions(+), 45 deletions(-) (limited to 'sys/kern') diff --git a/sys/kern/kern_descrip.c b/sys/kern/kern_descrip.c index 2b91db7..963b286 100644 --- a/sys/kern/kern_descrip.c +++ b/sys/kern/kern_descrip.c @@ -1813,11 +1813,9 @@ fdcloseexec(struct thread *td) int fdcheckstd(struct thread *td) { - struct nameidata nd; struct filedesc *fdp; - struct file *fp; - register_t retval; - int fd, i, error, flags, devnull; + register_t retval, save; + int i, error, devnull; fdp = td->td_proc->p_fd; if (fdp == NULL) @@ -1829,48 +1827,14 @@ fdcheckstd(struct thread *td) if (fdp->fd_ofiles[i] != NULL) continue; if (devnull < 0) { - int vfslocked; - error = falloc(td, &fp, &fd); - if (error != 0) - break; - /* Note extra ref on `fp' held for us by falloc(). */ - KASSERT(fd == i, ("oof, we didn't get our fd")); - NDINIT(&nd, LOOKUP, FOLLOW | MPSAFE, UIO_SYSSPACE, - "/dev/null", td); - flags = FREAD | FWRITE; - error = vn_open(&nd, &flags, 0, fd); - if (error != 0) { - /* - * Someone may have closed the entry in the - * file descriptor table, so check it hasn't - * changed before dropping the reference - * count. - */ - FILEDESC_XLOCK(fdp); - KASSERT(fdp->fd_ofiles[fd] == fp, - ("table not shared, how did it change?")); - fdp->fd_ofiles[fd] = NULL; - fdunused(fdp, fd); - FILEDESC_XUNLOCK(fdp); - fdrop(fp, td); - fdrop(fp, td); + save = td->td_retval[0]; + error = kern_open(td, "/dev/null", UIO_SYSSPACE, + O_RDWR, 0); + devnull = td->td_retval[0]; + KASSERT(devnull == i, ("oof, we didn't get our fd")); + td->td_retval[0] = save; + if (error) break; - } - vfslocked = NDHASGIANT(&nd); - NDFREE(&nd, NDF_ONLY_PNBUF); - FILE_LOCK(fp); - fp->f_flag = flags; - fp->f_vnode = nd.ni_vp; - if (fp->f_data == NULL) - fp->f_data = nd.ni_vp; - fp->f_type = DTYPE_VNODE; - if (fp->f_ops == &badfileops) - fp->f_ops = &vnops; - FILE_UNLOCK(fp); - VOP_UNLOCK(nd.ni_vp, 0, td); - VFS_UNLOCK_GIANT(vfslocked); - devnull = fd; - fdrop(fp, td); } else { error = do_dup(td, DUP_FIXED, devnull, i, &retval); if (error != 0) -- cgit v1.1