Emulate what vfork does instead of using it in linux_vfork. This way

we can do the stuff we need to do with linux processes at fork and
don't panic the kernel at exit of the child.

Submitted by:	rdivacky
Tested with:	tst-vfork* (glibc regression tests)
Tested by:	netchild
This commit is contained in:
Alexander Leidinger 2006-08-25 11:59:56 +00:00
parent 3e8df637c0
commit 40f734dd0d
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=161611
2 changed files with 25 additions and 2 deletions

View File

@ -472,20 +472,31 @@ int
linux_vfork(struct thread *td, struct linux_vfork_args *args)
{
int error;
struct proc *p2;
#ifdef DEBUG
if (ldebug(vfork))
printf(ARGS(vfork, ""));
#endif
if ((error = vfork(td, (struct vfork_args *)args)) != 0)
/* exclude RFPPWAIT */
if ((error = fork1(td, RFFDG | RFPROC | RFMEM, 0, &p2)) != 0)
return (error);
if (error == 0) {
td->td_retval[0] = p2->p_pid;
td->td_retval[1] = 0;
}
/* Are we the child? */
if (td->td_retval[1] == 1)
td->td_retval[0] = 0;
error = linux_proc_init(td, td->td_retval[0], 0);
if (error)
return (error);
/* wait for the children to exit, ie. emulate vfork */
PROC_LOCK(p2);
while (p2->p_flag & P_PPWAIT)
msleep(td->td_proc, &p2->p_mtx, PWAIT, "ppwait", 0);
PROC_UNLOCK(p2);
return (0);
}

View File

@ -316,20 +316,32 @@ int
linux_vfork(struct thread *td, struct linux_vfork_args *args)
{
int error;
struct proc *p2;
#ifdef DEBUG
if (ldebug(vfork))
printf(ARGS(vfork, ""));
#endif
if ((error = vfork(td, (struct vfork_args *)args)) != 0)
/* exclude RFPPWAIT */
if ((error = fork1(td, RFFDG | RFPROC | RFMEM, 0, &p2)) != 0)
return (error);
if (error == 0) {
td->td_retval[0] = p2->p_pid;
td->td_retval[1] = 0;
}
/* Are we the child? */
if (td->td_retval[1] == 1)
td->td_retval[0] = 0;
error = linux_proc_init(td, td->td_retval[0], 0);
if (error)
return (error);
/* wait for the children to exit, ie. emulate vfork */
PROC_LOCK(p2);
while (p2->p_flag & P_PPWAIT)
msleep(td->td_proc, &p2->p_mtx, PWAIT, "ppwait", 0);
PROC_UNLOCK(p2);
return (0);
}