Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/kern exit1(): make sure that, if orphaned child is being...



details:   https://anonhg.NetBSD.org/src/rev/cb6b518f40c7
branches:  trunk
changeset: 539890:cb6b518f40c7
user:      jdolecek <jdolecek%NetBSD.org@localhost>
date:      Thu Nov 28 21:41:29 2002 +0000

description:
exit1(): make sure that, if orphaned child is being traced, it's
reparented back to original parent before it's killed.
This makes the original parent aware that the child has exited if
the debugger failed to wait() on the debugged zombie before exiting.
Since we clear tracing flags before killing the child, the reparenting
logic in wait4() wouldn't be triggered, so it's necessary to do it here.

Problem reported and fix provided in kern/14443 by David Sainty.

diffstat:

 sys/kern/kern_exit.c |  20 +++++++++++++++-----
 1 files changed, 15 insertions(+), 5 deletions(-)

diffs (46 lines):

diff -r dcbf5f770f53 -r cb6b518f40c7 sys/kern/kern_exit.c
--- a/sys/kern/kern_exit.c      Thu Nov 28 21:23:54 2002 +0000
+++ b/sys/kern/kern_exit.c      Thu Nov 28 21:41:29 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_exit.c,v 1.103 2002/10/23 09:14:16 jdolecek Exp $ */
+/*     $NetBSD: kern_exit.c,v 1.104 2002/11/28 21:41:29 jdolecek Exp $ */
 
 /*-
  * Copyright (c) 1998, 1999 The NetBSD Foundation, Inc.
@@ -78,7 +78,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_exit.c,v 1.103 2002/10/23 09:14:16 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_exit.c,v 1.104 2002/11/28 21:41:29 jdolecek Exp $");
 
 #include "opt_ktrace.h"
 #include "opt_perfctrs.h"
@@ -260,14 +260,24 @@
                wakeup((caddr_t)initproc);
        for (; q != 0; q = nq) {
                nq = LIST_NEXT(q, p_sibling);
-               proc_reparent(q, initproc);
+
                /*
-                * Traced processes are killed
-                * since their existence means someone is screwing up.
+                * Traced processes are killed since their existence
+                * means someone is screwing up. Since we reset the
+                * trace flags, the logic in sys_wait4() would not be
+                * triggered to reparent the process to its
+                * original parent, so we must to this here.
                 */
                if (q->p_flag & P_TRACED) {
+                       if (q->p_opptr != q->p_pptr) {
+                               struct proc *t = q->p_opptr;
+                               proc_reparent(q, t ? t : initproc);
+                               q->p_opptr = NULL;
+                       }
                        q->p_flag &= ~(P_TRACED|P_WAITED|P_FSTRACE);
                        psignal(q, SIGKILL);
+               } else {
+                       proc_reparent(q, initproc);
                }
        }
 



Home | Main Index | Thread Index | Old Index