Index: kern_descrip.c =================================================================== --- kern_descrip.c (wersja 237014) +++ kern_descrip.c (kopia robocza) @@ -2594,6 +2594,12 @@ struct file *fp; /* + * We are not interested in any other errors. + */ + if (error != ENODEV && error != ENXIO) + return (error); + + /* * 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 * closed, then reject. @@ -2612,9 +2618,8 @@ * * 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 +2630,28 @@ 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); } /*