Changeset View
Changeset View
Standalone View
Standalone View
sys/kern/kern_fork.c
Show First 20 Lines • Show All 326 Lines • ▼ Show 20 Lines | fork_norfproc(struct thread *td, int flags) | ||||
if (error) | if (error) | ||||
goto fail; | goto fail; | ||||
/* | /* | ||||
* Close all file descriptors. | * Close all file descriptors. | ||||
*/ | */ | ||||
if (flags & RFCFDG) { | if (flags & RFCFDG) { | ||||
struct filedesc *fdtmp; | struct filedesc *fdtmp; | ||||
struct pwddesc *pdtmp; | |||||
pdtmp = pdinit(td->td_proc->p_pd, false); | |||||
fdtmp = fdinit(td->td_proc->p_fd, false, NULL); | fdtmp = fdinit(td->td_proc->p_fd, false, NULL); | ||||
pdescfree(td); | |||||
fdescfree(td); | fdescfree(td); | ||||
p1->p_fd = fdtmp; | p1->p_fd = fdtmp; | ||||
p1->p_pd = pdtmp; | |||||
} | } | ||||
/* | /* | ||||
* Unshare file descriptors (from parent). | * Unshare file descriptors (from parent). | ||||
*/ | */ | ||||
if (flags & RFFDG) | if (flags & RFFDG) { | ||||
fdunshare(td); | fdunshare(td); | ||||
pdunshare(td); | |||||
} | |||||
fail: | fail: | ||||
if (((p1->p_flag & (P_HADTHREADS|P_SYSTEM)) == P_HADTHREADS) && | if (((p1->p_flag & (P_HADTHREADS|P_SYSTEM)) == P_HADTHREADS) && | ||||
(flags & (RFCFDG | RFFDG))) { | (flags & (RFCFDG | RFFDG))) { | ||||
PROC_LOCK(p1); | PROC_LOCK(p1); | ||||
thread_single_end(p1, SINGLE_BOUNDARY); | thread_single_end(p1, SINGLE_BOUNDARY); | ||||
PROC_UNLOCK(p1); | PROC_UNLOCK(p1); | ||||
} | } | ||||
return (error); | return (error); | ||||
} | } | ||||
static void | static void | ||||
do_fork(struct thread *td, struct fork_req *fr, struct proc *p2, struct thread *td2, | do_fork(struct thread *td, struct fork_req *fr, struct proc *p2, struct thread *td2, | ||||
struct vmspace *vm2, struct file *fp_procdesc) | struct vmspace *vm2, struct file *fp_procdesc) | ||||
{ | { | ||||
struct proc *p1, *pptr; | struct proc *p1, *pptr; | ||||
struct filedesc *fd; | struct filedesc *fd; | ||||
struct filedesc_to_leader *fdtol; | struct filedesc_to_leader *fdtol; | ||||
struct pwddesc *pd; | |||||
struct sigacts *newsigacts; | struct sigacts *newsigacts; | ||||
p1 = td->td_proc; | p1 = td->td_proc; | ||||
PROC_LOCK(p1); | PROC_LOCK(p1); | ||||
bcopy(&p1->p_startcopy, &p2->p_startcopy, | bcopy(&p1->p_startcopy, &p2->p_startcopy, | ||||
__rangeof(struct proc, p_startcopy, p_endcopy)); | __rangeof(struct proc, p_startcopy, p_endcopy)); | ||||
pargs_hold(p2->p_args); | pargs_hold(p2->p_args); | ||||
Show All 27 Lines | if (fr->fr_flags & RFSIGSHARE) | ||||
newsigacts = NULL; | newsigacts = NULL; | ||||
else | else | ||||
newsigacts = sigacts_alloc(); | newsigacts = sigacts_alloc(); | ||||
/* | /* | ||||
* Copy filedesc. | * Copy filedesc. | ||||
*/ | */ | ||||
if (fr->fr_flags & RFCFDG) { | if (fr->fr_flags & RFCFDG) { | ||||
pd = pdinit(p1->p_pd, false); | |||||
fd = fdinit(p1->p_fd, false, NULL); | fd = fdinit(p1->p_fd, false, NULL); | ||||
fdtol = NULL; | fdtol = NULL; | ||||
} else if (fr->fr_flags & RFFDG) { | } else if (fr->fr_flags & RFFDG) { | ||||
pd = pdcopy(p1->p_pd); | |||||
fd = fdcopy(p1->p_fd); | fd = fdcopy(p1->p_fd); | ||||
fdtol = NULL; | fdtol = NULL; | ||||
} else { | } else { | ||||
pd = pdshare(p1->p_pd); | |||||
fd = fdshare(p1->p_fd); | fd = fdshare(p1->p_fd); | ||||
if (p1->p_fdtol == NULL) | if (p1->p_fdtol == NULL) | ||||
p1->p_fdtol = filedesc_to_leader_alloc(NULL, NULL, | p1->p_fdtol = filedesc_to_leader_alloc(NULL, NULL, | ||||
p1->p_leader); | p1->p_leader); | ||||
if ((fr->fr_flags & RFTHREAD) != 0) { | if ((fr->fr_flags & RFTHREAD) != 0) { | ||||
/* | /* | ||||
* Shared file descriptor table, and shared | * Shared file descriptor table, and shared | ||||
* process leaders. | * process leaders. | ||||
▲ Show 20 Lines • Show All 73 Lines • ▼ Show 20 Lines | #endif | ||||
else if (fr->fr_flags & RFLINUXTHPN) | else if (fr->fr_flags & RFLINUXTHPN) | ||||
p2->p_sigparent = SIGUSR1; | p2->p_sigparent = SIGUSR1; | ||||
else | else | ||||
p2->p_sigparent = SIGCHLD; | p2->p_sigparent = SIGCHLD; | ||||
p2->p_textvp = p1->p_textvp; | p2->p_textvp = p1->p_textvp; | ||||
p2->p_fd = fd; | p2->p_fd = fd; | ||||
p2->p_fdtol = fdtol; | p2->p_fdtol = fdtol; | ||||
p2->p_pd = pd; | |||||
if (p1->p_flag2 & P2_INHERIT_PROTECTED) { | if (p1->p_flag2 & P2_INHERIT_PROTECTED) { | ||||
p2->p_flag |= P_PROTECTED; | p2->p_flag |= P_PROTECTED; | ||||
p2->p_flag2 |= P2_INHERIT_PROTECTED; | p2->p_flag2 |= P2_INHERIT_PROTECTED; | ||||
} | } | ||||
/* | /* | ||||
* p_limit is copy-on-write. Bump its refcount. | * p_limit is copy-on-write. Bump its refcount. | ||||
▲ Show 20 Lines • Show All 610 Lines • Show Last 20 Lines |