diff options
author | Claudio Jeker <claudio@cvs.openbsd.org> | 2024-10-08 12:02:25 +0000 |
---|---|---|
committer | Claudio Jeker <claudio@cvs.openbsd.org> | 2024-10-08 12:02:25 +0000 |
commit | 747760e190a0a310514f3dd47e4e1e9174658c13 (patch) | |
tree | 7a7eb2db167d845b99f9da4e0ea94ece27e03238 | |
parent | 95fc67dc16e9e434bea9ac58b6b562fc8b9b637a (diff) |
Replace ps_oppid (old parent pid) with ps_opptr (a pointer to the old parent process struct).
This simplifies some code and removes the no need to call prfind in
process_untrace().
OK mpi@
-rw-r--r-- | sys/kern/kern_exit.c | 24 | ||||
-rw-r--r-- | sys/kern/kern_fork.c | 4 | ||||
-rw-r--r-- | sys/kern/sys_process.c | 6 | ||||
-rw-r--r-- | sys/sys/proc.h | 4 |
4 files changed, 19 insertions, 19 deletions
diff --git a/sys/kern/kern_exit.c b/sys/kern/kern_exit.c index 874e197389b..dd9a124f78d 100644 --- a/sys/kern/kern_exit.c +++ b/sys/kern/kern_exit.c @@ -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); diff --git a/sys/kern/kern_fork.c b/sys/kern/kern_fork.c index 5be080bf618..ca0d00172e2 100644 --- a/sys/kern/kern_fork.c +++ b/sys/kern/kern_fork.c @@ -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); /* diff --git a/sys/kern/sys_process.c b/sys/kern/sys_process.c index 36c402135ae..6ab263c7eca 100644 --- a/sys/kern/sys_process.c +++ b/sys/kern/sys_process.c @@ -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) diff --git a/sys/sys/proc.h b/sys/sys/proc.h index 86cd44d1946..0a6fee0f87a 100644 --- a/sys/sys/proc.h +++ b/sys/sys/proc.h @@ -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. */ |