Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 2 Jan 2011 12:16:57 +0000 (UTC)
From:      Edward Tomasz Napierala <trasz@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r216888 - head/sys/kern
Message-ID:  <201101021216.p02CGvMC045213@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
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;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201101021216.p02CGvMC045213>