Replace ps_oppid (old parent pid) with ps_opptr (a pointer to the old parent process...
authorclaudio <claudio@openbsd.org>
Tue, 8 Oct 2024 12:02:24 +0000 (12:02 +0000)
committerclaudio <claudio@openbsd.org>
Tue, 8 Oct 2024 12:02:24 +0000 (12:02 +0000)
This simplifies some code and removes the no need to call prfind in
process_untrace().
OK mpi@

sys/kern/kern_exit.c
sys/kern/kern_fork.c
sys/kern/sys_process.c
sys/sys/proc.h

index 874e197..dd9a124 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: kern_exit.c,v 1.236 2024/10/08 11:57:59 claudio Exp $ */
+/*     $OpenBSD: kern_exit.c,v 1.237 2024/10/08 12:02:24 claudio Exp $ */
 /*     $NetBSD: kern_exit.c,v 1.39 1996/04/22 01:38:25 christos Exp $  */
 
 /*
@@ -325,8 +325,8 @@ exit1(struct proc *p, int xexit, int xsig, int flags)
                 */
                while ((qr = LIST_FIRST(&pr->ps_orphans)) != NULL) {
                        mtx_enter(&qr->ps_mtx);
-                       KASSERT(qr->ps_oppid == pr->ps_pid);
-                       qr->ps_oppid = 0;
+                       KASSERT(qr->ps_opptr == pr);
+                       qr->ps_opptr = NULL;
                        process_clear_orphan(qr);
                        mtx_leave(&qr->ps_mtx);
                }
@@ -744,9 +744,9 @@ proc_finish_wait(struct proc *waiter, struct process *pr)
         * we need to give it back to the old parent.
         */
        mtx_enter(&pr->ps_mtx);
-       if (pr->ps_oppid != 0 && (pr->ps_oppid != pr->ps_ppid) &&
-          (tr = prfind(pr->ps_oppid))) {
-               pr->ps_oppid = 0;
+       if (pr->ps_opptr != NULL && (pr->ps_opptr != pr->ps_pptr)) {
+               tr = pr->ps_opptr;
+               pr->ps_opptr = NULL;
                atomic_clearbits_int(&pr->ps_flags, PS_TRACED);
                process_reparent(pr, tr);
                mtx_leave(&pr->ps_mtx);
@@ -774,12 +774,12 @@ process_untrace(struct process *pr)
        KASSERT(pr->ps_flags & PS_TRACED);
        MUTEX_ASSERT_LOCKED(&pr->ps_mtx);
 
-       if (pr->ps_oppid != 0 &&
-           (pr->ps_oppid != pr->ps_ppid))
-               ppr = prfind(pr->ps_oppid);
+       if (pr->ps_opptr != NULL &&
+           (pr->ps_opptr != pr->ps_pptr))
+               ppr = pr->ps_opptr;
 
        /* not being traced any more */
-       pr->ps_oppid = 0;
+       pr->ps_opptr = NULL;
        atomic_clearbits_int(&pr->ps_flags, PS_TRACED);
        process_reparent(pr, ppr ? ppr : initprocess);
 }
@@ -803,8 +803,8 @@ process_reparent(struct process *child, struct process *parent)
        if (child->ps_pptr == parent)
                return;
 
-       KASSERT(child->ps_oppid == 0 ||
-               child->ps_oppid == child->ps_ppid);
+       KASSERT(child->ps_opptr == NULL ||
+               child->ps_opptr == child->ps_pptr);
 
        LIST_REMOVE(child, ps_sibling);
        LIST_INSERT_HEAD(&parent->ps_children, child, ps_sibling);
index 5be080b..ca0d001 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: kern_fork.c,v 1.266 2024/10/08 09:05:40 claudio Exp $ */
+/*     $OpenBSD: kern_fork.c,v 1.267 2024/10/08 12:02:24 claudio Exp $ */
 /*     $NetBSD: kern_fork.c,v 1.29 1996/02/09 18:59:34 christos Exp $  */
 
 /*
@@ -459,7 +459,7 @@ fork1(struct proc *curp, int flags, void (*func)(void *), void *arg,
 
        mtx_enter(&pr->ps_mtx);
        if (pr->ps_flags & PS_TRACED) {
-               pr->ps_oppid = curpr->ps_pid;
+               pr->ps_opptr = curpr;
                process_reparent(pr, curpr->ps_pptr);
 
                /*
index 36c4021..6ab263c 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: sys_process.c,v 1.101 2024/10/08 09:05:40 claudio Exp $       */
+/*     $OpenBSD: sys_process.c,v 1.102 2024/10/08 12:02:24 claudio Exp $       */
 /*     $NetBSD: sys_process.c,v 1.55 1996/05/15 06:17:47 tls Exp $     */
 
 /*-
@@ -294,7 +294,7 @@ ptrace_ctrl(struct proc *p, int req, pid_t pid, caddr_t addr, int data)
                        return EBUSY;
                }
                atomic_setbits_int(&tr->ps_flags, PS_TRACED);
-               tr->ps_oppid = tr->ps_ppid;
+               tr->ps_opptr = tr->ps_pptr;
                mtx_leave(&tr->ps_mtx);
                if (tr->ps_ptstat == NULL)
                        tr->ps_ptstat = malloc(sizeof(*tr->ps_ptstat),
@@ -534,7 +534,7 @@ ptrace_ctrl(struct proc *p, int req, pid_t pid, caddr_t addr, int data)
                 */
                mtx_enter(&tr->ps_mtx);
                atomic_setbits_int(&tr->ps_flags, PS_TRACED);
-               tr->ps_oppid = tr->ps_ppid;
+               tr->ps_opptr = tr->ps_pptr;
                process_reparent(tr, p->p_p);
                mtx_leave(&tr->ps_mtx);
                if (tr->ps_ptstat == NULL)
index 86cd44d..0a6fee0 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: proc.h,v 1.373 2024/10/08 09:05:40 claudio Exp $      */
+/*     $OpenBSD: proc.h,v 1.374 2024/10/08 12:02:24 claudio Exp $      */
 /*     $NetBSD: proc.h,v 1.44 1996/04/22 01:23:21 christos Exp $       */
 
 /*-
@@ -201,9 +201,9 @@ struct process {
        int     ps_xsig;                /* Stopping or killing signal */
 
        pid_t   ps_ppid;                /* [K|m] Cached parent pid */
-       pid_t   ps_oppid;               /* [K|m] Old parent pid during ptrace */
        int     ps_ptmask;              /* Ptrace event mask */
        struct  ptrace_state *ps_ptstat;/* Ptrace state */
+       struct  process *ps_opptr;      /* [K|m] Old parent during ptrace. */
 
        struct  rusage *ps_ru;          /* sum of stats for dead threads. */
        struct  tusage ps_tu;           /* [m] accumul times of dead threads. */