PERFORCE change 156860 for review

Robert Watson rwatson at FreeBSD.org
Thu Jan 29 06:25:34 PST 2009


http://perforce.freebsd.org/chv.cgi?CH=156860

Change 156860 by rwatson at rwatson_freebsd_capabilities on 2009/01/29 14:25:22

	When close() is called on a process descriptor and the process
	isn't yet dead, we will kill it with SIGKILL--detach the process
	from its descriptor before reparenting to init since otherwise
	init won't be able to see it in wait4() and we end up with a
	zombie.

Affected files ...

.. //depot/projects/trustedbsd/capabilities/src/sys/kern/sys_procdesc.c#10 edit

Differences ...

==== //depot/projects/trustedbsd/capabilities/src/sys/kern/sys_procdesc.c#10 (text+ko) ====

@@ -244,6 +244,12 @@
 procdesc_free(struct procdesc *pd)
 {
 
+	/*
+	 * When the last reference is released, we assert that the descriptor
+	 * has been closed, but not that the process has exited, as we will
+	 * detach the descriptor before the process dies if the descript is
+	 * closed, as we can't wait synchronously.
+	 */
 	if (refcount_release(&pd->pd_refcount)) {
 		KASSERT(pd->pd_proc == NULL,
 		    ("procdesc_free: pd_proc != NULL"));
@@ -351,9 +357,17 @@
 		/*
 		 * If the process is not yet dead, we need to kill it, but we
 		 * can't wait around synchronously for it to go away, as that
-		 * path leads to madness (and deadlocks).  Reparent the
-		 * target to init(8) so that there's someone to pick up the
-		 * pieces, then terminate with prejudice.
+		 * path leads to madness (and deadlocks).  First, detach the
+		 * process from its descriptor so that its exit status will
+		 * be reported normally.
+		 */
+		pd->pd_proc = NULL;
+		p->p_procdesc = NULL;
+		procdesc_free(pd);
+
+		/*
+		 * Next, reparent it to init(8) so that there's someone to
+		 * pick up the pieces; finally, terminate with prejudice.
 		 */
 		p->p_sigparent = SIGCHLD;
 		proc_reparent(p, initproc);


More information about the p4-projects mailing list