MCPcopy Create free account
hub / github.com/F-Stack/f-stack / fdcloseexec

Function fdcloseexec

freebsd/kern/kern_descrip.c:2774–2797  ·  view source on GitHub ↗

* Close any files on exec? */

Source from the content-addressed store, hash-verified

2772 * Close any files on exec?
2773 */
2774void
2775fdcloseexec(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

Callers 1

do_execveFunction · 0.85

Calls 4

refcount_loadFunction · 0.85
fdlastfile_singleFunction · 0.85
fdfreeFunction · 0.85
closefpFunction · 0.85

Tested by

no test coverage detected