* Close any files on exec? */
| 2772 | * Close any files on exec? |
| 2773 | */ |
| 2774 | void |
| 2775 | fdcloseexec(struct thread *td) |
| 2776 | { |
| 2777 | struct filedesc *fdp; |
| 2778 | struct filedescent *fde; |
| 2779 | struct file *fp; |
| 2780 | int i, lastfile; |
| 2781 | |
| 2782 | fdp = td->td_proc->p_fd; |
| 2783 | KASSERT(refcount_load(&fdp->fd_refcnt) == 1, |
| 2784 | ("the fdtable should not be shared")); |
| 2785 | lastfile = fdlastfile_single(fdp); |
| 2786 | for (i = 0; i <= lastfile; i++) { |
| 2787 | fde = &fdp->fd_ofiles[i]; |
| 2788 | fp = fde->fde_file; |
| 2789 | if (fp != NULL && (fp->f_type == DTYPE_MQUEUE || |
| 2790 | (fde->fde_flags & UF_EXCLOSE))) { |
| 2791 | FILEDESC_XLOCK(fdp); |
| 2792 | fdfree(fdp, i); |
| 2793 | (void) closefp(fdp, i, fp, td, false, false); |
| 2794 | FILEDESC_UNLOCK_ASSERT(fdp); |
| 2795 | } |
| 2796 | } |
| 2797 | } |
| 2798 | |
| 2799 | /* |
| 2800 | * It is unsafe for set[ug]id processes to be started with file |
no test coverage detected