summaryrefslogtreecommitdiffstats
path: root/sys/kern/kern_descrip.c
diff options
context:
space:
mode:
authorpjd <pjd@FreeBSD.org>2012-06-13 19:00:29 +0000
committerpjd <pjd@FreeBSD.org>2012-06-13 19:00:29 +0000
commitb836448bf31196deb9b7c15c6666ffb60713ab38 (patch)
tree0647e44306015a226cddd62eb3bb5bb0e708097c /sys/kern/kern_descrip.c
parent142d5d1bbd74110e93521e872e859c2a4780a669 (diff)
downloadFreeBSD-src-b836448bf31196deb9b7c15c6666ffb60713ab38.zip
FreeBSD-src-b836448bf31196deb9b7c15c6666ffb60713ab38.tar.gz
There is only one caller of the dupfdopen() function, so we can simplify
it a bit: - We can assert that only ENODEV and ENXIO errors are passed instead of handling other errors. - The caller always call finstall() for indx descriptor, so we can assume it is set. Actually the filedesc lock is dropped between finstall() and dupfdopen(), so there is a window there for another thread to close the indx descriptor, but it will be closed in next commit. Reviewed by: mjg MFC after: 1 month
Diffstat (limited to 'sys/kern/kern_descrip.c')
-rw-r--r--sys/kern/kern_descrip.c46
1 files changed, 14 insertions, 32 deletions
diff --git a/sys/kern/kern_descrip.c b/sys/kern/kern_descrip.c
index 9592d8e..ef4da6e 100644
--- a/sys/kern/kern_descrip.c
+++ b/sys/kern/kern_descrip.c
@@ -2593,6 +2593,9 @@ dupfdopen(struct thread *td, struct filedesc *fdp, int indx, int dfd, int mode,
struct file *wfp;
struct file *fp;
+ KASSERT(error == ENODEV || error == ENXIO,
+ ("unexpected error %d in %s", error, __func__));
+
/*
* 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
@@ -2612,9 +2615,8 @@ dupfdopen(struct thread *td, struct filedesc *fdp, int indx, int dfd, int mode,
*
* For ENXIO steal away the file structure from (dfd) and store it in
* (indx). (dfd) is effectively closed by this operation.
- *
- * Any other error code is just returned.
*/
+ fp = fdp->fd_ofiles[indx];
switch (error) {
case ENODEV:
/*
@@ -2625,48 +2627,28 @@ dupfdopen(struct thread *td, struct filedesc *fdp, int indx, int dfd, int mode,
FILEDESC_XUNLOCK(fdp);
return (EACCES);
}
- fp = fdp->fd_ofiles[indx];
fdp->fd_ofiles[indx] = wfp;
fdp->fd_ofileflags[indx] = fdp->fd_ofileflags[dfd];
- if (fp == NULL)
- fdused(fdp, indx);
fhold(wfp);
- FILEDESC_XUNLOCK(fdp);
- if (fp != NULL)
- /*
- * We now own the reference to fp that the ofiles[]
- * array used to own. Release it.
- */
- fdrop(fp, td);
- return (0);
-
+ break;
case ENXIO:
/*
* Steal away the file pointer from dfd and stuff it into indx.
*/
- fp = fdp->fd_ofiles[indx];
- fdp->fd_ofiles[indx] = fdp->fd_ofiles[dfd];
+ fdp->fd_ofiles[indx] = wfp;
fdp->fd_ofiles[dfd] = NULL;
fdp->fd_ofileflags[indx] = fdp->fd_ofileflags[dfd];
fdp->fd_ofileflags[dfd] = 0;
fdunused(fdp, dfd);
- if (fp == NULL)
- fdused(fdp, indx);
- FILEDESC_XUNLOCK(fdp);
-
- /*
- * We now own the reference to fp that the ofiles[] array
- * used to own. Release it.
- */
- if (fp != NULL)
- fdrop(fp, td);
- return (0);
-
- default:
- FILEDESC_XUNLOCK(fdp);
- return (error);
+ break;
}
- /* NOTREACHED */
+ FILEDESC_XUNLOCK(fdp);
+ /*
+ * We now own the reference to fp that the ofiles[] array used to own.
+ * Release it.
+ */
+ fdrop(fp, td);
+ return (0);
}
/*
OpenPOWER on IntegriCloud