Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 6 Dec 2010 16:39:19 +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: r216233 - head/sys/kern
Message-ID:  <201012061639.oB6GdJN2038646@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: trasz
Date: Mon Dec  6 16:39:18 2010
New Revision: 216233
URL: http://svn.freebsd.org/changeset/base/216233

Log:
  Improve readability by factoring out the !RFPROC case.  While here,
  turn K&R function definitions into ANSI.  No functional changes.
  
  Reviewed by:	kib@

Modified:
  head/sys/kern/kern_fork.c

Modified: head/sys/kern/kern_fork.c
==============================================================================
--- head/sys/kern/kern_fork.c	Mon Dec  6 15:19:03 2010	(r216232)
+++ head/sys/kern/kern_fork.c	Mon Dec  6 16:39:18 2010	(r216233)
@@ -97,9 +97,7 @@ struct fork_args {
 
 /* ARGSUSED */
 int
-fork(td, uap)
-	struct thread *td;
-	struct fork_args *uap;
+fork(struct thread *td, struct fork_args *uap)
 {
 	int error;
 	struct proc *p2;
@@ -135,9 +133,7 @@ vfork(td, uap)
 }
 
 int
-rfork(td, uap)
-	struct thread *td;
-	struct rfork_args *uap;
+rfork(struct thread *td, struct rfork_args *uap)
 {
 	struct proc *p2;
 	int error;
@@ -197,12 +193,57 @@ sysctl_kern_randompid(SYSCTL_HANDLER_ARG
 SYSCTL_PROC(_kern, OID_AUTO, randompid, CTLTYPE_INT|CTLFLAG_RW,
     0, 0, sysctl_kern_randompid, "I", "Random PID modulus");
 
+static int
+fork_norfproc(struct thread *td, int flags, struct proc **procp)
+{
+	int error;
+	struct proc *p1;
+
+	p1 = td->td_proc;
+
+	if (((p1->p_flag & (P_HADTHREADS|P_SYSTEM)) == P_HADTHREADS) &&
+	    (flags & (RFCFDG | RFFDG))) {
+		PROC_LOCK(p1);
+		if (thread_single(SINGLE_BOUNDARY)) {
+			PROC_UNLOCK(p1);
+			return (ERESTART);
+		}
+		PROC_UNLOCK(p1);
+	}
+
+	error = vm_forkproc(td, NULL, NULL, NULL, flags);
+	if (error)
+		goto fail;
+
+	/*
+	 * Close all file descriptors.
+	 */
+	if (flags & RFCFDG) {
+		struct filedesc *fdtmp;
+		fdtmp = fdinit(td->td_proc->p_fd);
+		fdfree(td);
+		p1->p_fd = fdtmp;
+	}
+
+	/*
+	 * Unshare file descriptors (from parent).
+	 */
+	if (flags & RFFDG) 
+		fdunshare(p1, td);
+
+fail:
+	if (((p1->p_flag & (P_HADTHREADS|P_SYSTEM)) == P_HADTHREADS) &&
+			(flags & (RFCFDG | RFFDG))) {
+		PROC_LOCK(p1);
+		thread_single_end();
+		PROC_UNLOCK(p1);
+	}
+	*procp = NULL;
+	return (error);
+}
+
 int
-fork1(td, flags, pages, procp)
-	struct thread *td;
-	int flags;
-	int pages;
-	struct proc **procp;
+fork1(struct thread *td, int flags, int pages, struct proc **procp)
 {
 	struct proc *p1, *p2, *pptr;
 	struct proc *newproc;
@@ -227,47 +268,8 @@ fork1(td, flags, pages, procp)
 	 * Here we don't create a new process, but we divorce
 	 * certain parts of a process from itself.
 	 */
-	if ((flags & RFPROC) == 0) {
-		if (((p1->p_flag & (P_HADTHREADS|P_SYSTEM)) == P_HADTHREADS) &&
-		    (flags & (RFCFDG | RFFDG))) {
-			PROC_LOCK(p1);
-			if (thread_single(SINGLE_BOUNDARY)) {
-				PROC_UNLOCK(p1);
-				return (ERESTART);
-			}
-			PROC_UNLOCK(p1);
-		}
-
-		error = vm_forkproc(td, NULL, NULL, NULL, flags);
-		if (error)
-			goto norfproc_fail;
-
-		/*
-		 * Close all file descriptors.
-		 */
-		if (flags & RFCFDG) {
-			struct filedesc *fdtmp;
-			fdtmp = fdinit(td->td_proc->p_fd);
-			fdfree(td);
-			p1->p_fd = fdtmp;
-		}
-
-		/*
-		 * Unshare file descriptors (from parent).
-		 */
-		if (flags & RFFDG) 
-			fdunshare(p1, td);
-
-norfproc_fail:
-		if (((p1->p_flag & (P_HADTHREADS|P_SYSTEM)) == P_HADTHREADS) &&
-		    (flags & (RFCFDG | RFFDG))) {
-			PROC_LOCK(p1);
-			thread_single_end();
-			PROC_UNLOCK(p1);
-		}
-		*procp = NULL;
-		return (error);
-	}
+	if ((flags & RFPROC) == 0)
+		return (fork_norfproc(td, flags, procp));
 
 	/*
 	 * XXX
@@ -798,10 +800,8 @@ fail1:
  * is called from the MD fork_trampoline() entry point.
  */
 void
-fork_exit(callout, arg, frame)
-	void (*callout)(void *, struct trapframe *);
-	void *arg;
-	struct trapframe *frame;
+fork_exit(void (*callout)(void *, struct trapframe *), void *arg,
+    struct trapframe *frame)
 {
 	struct proc *p;
 	struct thread *td;
@@ -855,9 +855,7 @@ fork_exit(callout, arg, frame)
  * first parameter and is called when returning to a new userland process.
  */
 void
-fork_return(td, frame)
-	struct thread *td;
-	struct trapframe *frame;
+fork_return(struct thread *td, struct trapframe *frame)
 {
 
 	userret(td, frame);



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