From owner-svn-src-head@FreeBSD.ORG Sun Jan 2 12:16:58 2011 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 2942E106564A; Sun, 2 Jan 2011 12:16:58 +0000 (UTC) (envelope-from trasz@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 188148FC13; Sun, 2 Jan 2011 12:16:58 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id p02CGv5H045215; Sun, 2 Jan 2011 12:16:57 GMT (envelope-from trasz@svn.freebsd.org) Received: (from trasz@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id p02CGvMC045213; Sun, 2 Jan 2011 12:16:57 GMT (envelope-from trasz@svn.freebsd.org) Message-Id: <201101021216.p02CGvMC045213@svn.freebsd.org> From: Edward Tomasz Napierala Date: Sun, 2 Jan 2011 12:16:57 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r216888 - head/sys/kern X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 02 Jan 2011 12:16:58 -0000 Author: trasz Date: Sun Jan 2 12:16:57 2011 New Revision: 216888 URL: http://svn.freebsd.org/changeset/base/216888 Log: 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. Modified: head/sys/kern/kern_fork.c Modified: head/sys/kern/kern_fork.c ============================================================================== --- head/sys/kern/kern_fork.c Sun Jan 2 10:27:27 2011 (r216887) +++ head/sys/kern/kern_fork.c Sun Jan 2 12:16:57 2011 (r216888) @@ -112,9 +112,7 @@ fork(struct thread *td, struct fork_args /* 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 fla 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, st } 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, st 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, st 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, st /* * 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, st 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 * 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;