Finishing touches to fork1() - ANSIfy missed function definition, style(9)
fixes, removal of few comments that didn't really make sense and addition of fork_findpid() locking requirements.
This commit is contained in:
parent
e53f353cdc
commit
f3e31127df
@ -112,9 +112,7 @@ fork(struct thread *td, struct fork_args *uap)
|
||||
|
||||
/* ARGSUSED */
|
||||
int
|
||||
vfork(td, uap)
|
||||
struct thread *td;
|
||||
struct vfork_args *uap;
|
||||
vfork(struct thread *td, struct vfork_args *uap)
|
||||
{
|
||||
int error, flags;
|
||||
struct proc *p2;
|
||||
@ -200,7 +198,12 @@ fork_findpid(int flags)
|
||||
int trypid;
|
||||
static int pidchecked = 0;
|
||||
|
||||
sx_assert(&allproc_lock, SX_XLOCKED);
|
||||
/*
|
||||
* Requires allproc_lock in order to iterate over the list
|
||||
* of processes, and proctree_lock to access p_pgrp.
|
||||
*/
|
||||
sx_assert(&allproc_lock, SX_LOCKED);
|
||||
sx_assert(&proctree_lock, SX_LOCKED);
|
||||
|
||||
/*
|
||||
* Find an unused process ID. We remember a range of unused IDs
|
||||
@ -281,7 +284,7 @@ again:
|
||||
}
|
||||
|
||||
static int
|
||||
fork_norfproc(struct thread *td, int flags, struct proc **procp)
|
||||
fork_norfproc(struct thread *td, int flags)
|
||||
{
|
||||
int error;
|
||||
struct proc *p1;
|
||||
@ -289,7 +292,6 @@ fork_norfproc(struct thread *td, int flags, struct proc **procp)
|
||||
KASSERT((flags & RFPROC) == 0,
|
||||
("fork_norfproc called with RFPROC set"));
|
||||
p1 = td->td_proc;
|
||||
*procp = NULL;
|
||||
|
||||
if (((p1->p_flag & (P_HADTHREADS|P_SYSTEM)) == P_HADTHREADS) &&
|
||||
(flags & (RFCFDG | RFFDG))) {
|
||||
@ -408,14 +410,12 @@ do_fork(struct thread *td, int flags, struct proc *p2, struct thread *td2,
|
||||
} else {
|
||||
fd = fdshare(p1->p_fd);
|
||||
if (p1->p_fdtol == NULL)
|
||||
p1->p_fdtol =
|
||||
filedesc_to_leader_alloc(NULL,
|
||||
NULL,
|
||||
p1->p_leader);
|
||||
p1->p_fdtol = filedesc_to_leader_alloc(NULL, NULL,
|
||||
p1->p_leader);
|
||||
if ((flags & RFTHREAD) != 0) {
|
||||
/*
|
||||
* Shared file descriptor table and
|
||||
* shared process leaders.
|
||||
* Shared file descriptor table, and shared
|
||||
* process leaders.
|
||||
*/
|
||||
fdtol = p1->p_fdtol;
|
||||
FILEDESC_XLOCK(p1->p_fd);
|
||||
@ -423,12 +423,11 @@ do_fork(struct thread *td, int flags, struct proc *p2, struct thread *td2,
|
||||
FILEDESC_XUNLOCK(p1->p_fd);
|
||||
} else {
|
||||
/*
|
||||
* Shared file descriptor table, and
|
||||
* different process leaders
|
||||
* Shared file descriptor table, and different
|
||||
* process leaders.
|
||||
*/
|
||||
fdtol = filedesc_to_leader_alloc(p1->p_fdtol,
|
||||
p1->p_fd,
|
||||
p2);
|
||||
p1->p_fd, p2);
|
||||
}
|
||||
}
|
||||
/*
|
||||
@ -492,7 +491,7 @@ do_fork(struct thread *td, int flags, struct proc *p2, struct thread *td2,
|
||||
PROC_UNLOCK(p1);
|
||||
PROC_UNLOCK(p2);
|
||||
|
||||
/* Bump references to the text vnode (for procfs) */
|
||||
/* Bump references to the text vnode (for procfs). */
|
||||
if (p2->p_textvp)
|
||||
vref(p2->p_textvp);
|
||||
|
||||
@ -622,7 +621,6 @@ do_fork(struct thread *td, int flags, struct proc *p2, struct thread *td2,
|
||||
/*
|
||||
* Both processes are set up, now check if any loadable modules want
|
||||
* to adjust anything.
|
||||
* What if they have an error? XXX
|
||||
*/
|
||||
EVENTHANDLER_INVOKE(process_fork, p1, p2, flags);
|
||||
|
||||
@ -682,7 +680,6 @@ do_fork(struct thread *td, int flags, struct proc *p2, struct thread *td2,
|
||||
while (p2->p_flag & P_PPWAIT)
|
||||
cv_wait(&p2->p_pwait, &p2->p_mtx);
|
||||
PROC_UNLOCK(p2);
|
||||
|
||||
}
|
||||
|
||||
int
|
||||
@ -708,14 +705,10 @@ fork1(struct thread *td, int flags, int pages, struct proc **procp)
|
||||
* Here we don't create a new process, but we divorce
|
||||
* certain parts of a process from itself.
|
||||
*/
|
||||
if ((flags & RFPROC) == 0)
|
||||
return (fork_norfproc(td, flags, procp));
|
||||
|
||||
/*
|
||||
* XXX
|
||||
* We did have single-threading code here
|
||||
* however it proved un-needed and caused problems
|
||||
*/
|
||||
if ((flags & RFPROC) == 0) {
|
||||
*procp = NULL;
|
||||
return (fork_norfproc(td, flags));
|
||||
}
|
||||
|
||||
mem_charged = 0;
|
||||
vm2 = NULL;
|
||||
|
Loading…
x
Reference in New Issue
Block a user