Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 16 Apr 2007 17:49:04 GMT
From:      John Baldwin <jhb@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 118253 for review
Message-ID:  <200704161749.l3GHn4XI038442@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=118253

Change 118253 by jhb@jhb_mutex on 2007/04/16 17:48:17

	Use kern_open() to open "/dev/null" in fdcheckstd().

Affected files ...

.. //depot/projects/smpng/sys/kern/kern_descrip.c#105 edit

Differences ...

==== //depot/projects/smpng/sys/kern/kern_descrip.c#105 (text+ko) ====

@@ -1813,11 +1813,9 @@
 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 @@
 		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)



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200704161749.l3GHn4XI038442>