Page MenuHomeFreeBSD

D26416.id76961.diff
No OneTemporary

D26416.id76961.diff

Index: sys/kern/kern_proc.c
===================================================================
--- sys/kern/kern_proc.c
+++ sys/kern/kern_proc.c
@@ -661,7 +661,7 @@
if ((q->p_treeflag & P_TREE_GRPEXITED) != 0 ||
q->p_pptr == NULL)
continue;
- if (isjobproc(q->p_pptr, pgrp))
+ if (isjobproc(proc_realparent(q), pgrp))
cnt++;
}
KASSERT(pgrp->pg_jobc == cnt, ("pgrp %d %p pg_jobc %d cnt %d",
@@ -784,6 +784,25 @@
PGRP_UNLOCK(pgrp);
}
+static void
+fixjobc_enterpgrp_q(struct pgrp *pgrp, struct proc *p, struct proc *q, bool adj)
+{
+ struct pgrp *childpgrp;
+ bool future_jobc;
+
+ sx_assert(&proctree_lock, SX_LOCKED);
+
+ if ((q->p_treeflag & P_TREE_GRPEXITED) != 0)
+ return;
+ childpgrp = q->p_pgrp;
+ future_jobc = childpgrp != pgrp &&
+ childpgrp->pg_session == pgrp->pg_session;
+
+ if ((adj && !isjobproc(p, childpgrp) && future_jobc) ||
+ (!adj && isjobproc(p, childpgrp) && !future_jobc))
+ pgadjustjobc(childpgrp, adj);
+}
+
/*
* Adjust pgrp jobc counters when specified process changes process group.
* We count the number of processes in each process group that "qualify"
@@ -798,8 +817,6 @@
fixjobc_enterpgrp(struct proc *p, struct pgrp *pgrp)
{
struct proc *q;
- struct pgrp *childpgrp;
- bool future_jobc;
sx_assert(&proctree_lock, SX_LOCKED);
PROC_LOCK_ASSERT(p, MA_NOTOWNED);
@@ -812,33 +829,44 @@
if (isjobproc(p->p_pptr, pgrp))
pgadjustjobc(pgrp, true);
LIST_FOREACH(q, &p->p_children, p_sibling) {
- if ((q->p_treeflag & P_TREE_GRPEXITED) != 0)
+ if (q->p_pptr->p_pid != p->p_oppid)
continue;
- childpgrp = q->p_pgrp;
- future_jobc = childpgrp != pgrp &&
- childpgrp->pg_session == pgrp->pg_session;
- if (!isjobproc(p, childpgrp) && future_jobc)
- pgadjustjobc(childpgrp, true);
+ fixjobc_enterpgrp_q(pgrp, p, q, true);
}
+ LIST_FOREACH(q, &p->p_orphans, p_orphan)
+ fixjobc_enterpgrp_q(pgrp, p, q, true);
- if (isjobproc(p->p_pptr, p->p_pgrp))
- pgadjustjobc(p->p_pgrp, false);
LIST_FOREACH(q, &p->p_children, p_sibling) {
- if ((q->p_treeflag & P_TREE_GRPEXITED) != 0)
+ if (q->p_pptr->p_pid != p->p_oppid)
continue;
- childpgrp = q->p_pgrp;
- future_jobc = childpgrp != pgrp &&
- childpgrp->pg_session == pgrp->pg_session;
- if (isjobproc(p, childpgrp) && !future_jobc)
- pgadjustjobc(childpgrp, false);
+ fixjobc_enterpgrp_q(pgrp, p, q, false);
}
+ LIST_FOREACH(q, &p->p_orphans, p_orphan)
+ fixjobc_enterpgrp_q(pgrp, p, q, false);
+}
+
+static void
+fixjobc_kill_q(struct proc *q, struct proc *p, bool adj)
+{
+ struct pgrp *childpgrp;
+
+ sx_assert(&proctree_lock, SX_LOCKED);
+
+ if ((q->p_treeflag & P_TREE_GRPEXITED) != 0)
+ return;
+ childpgrp = q->p_pgrp;
+
+ if ((adj && isjobproc(q->p_reaper, childpgrp) &&
+ !isjobproc(p, childpgrp)) || (!adj && !isjobproc(q->p_reaper,
+ childpgrp) && isjobproc(p, childpgrp)))
+ pgadjustjobc(childpgrp, adj);
}
static void
fixjobc_kill(struct proc *p)
{
struct proc *q;
- struct pgrp *childpgrp, *pgrp;
+ struct pgrp *pgrp;
sx_assert(&proctree_lock, SX_LOCKED);
PROC_LOCK_ASSERT(p, MA_NOTOWNED);
@@ -857,7 +885,7 @@
* Check p's parent to see whether p qualifies its own process
* group; if so, adjust count for p's process group.
*/
- if (isjobproc(p->p_pptr, pgrp))
+ if (isjobproc(proc_realparent(p), pgrp))
pgadjustjobc(pgrp, false);
/*
@@ -866,21 +894,19 @@
* adjust counts for children's process groups.
*/
LIST_FOREACH(q, &p->p_children, p_sibling) {
- if ((q->p_treeflag & P_TREE_GRPEXITED) != 0)
+ if (q->p_pptr->p_pid != p->p_oppid)
continue;
- childpgrp = q->p_pgrp;
- if (isjobproc(q->p_reaper, childpgrp) &&
- !isjobproc(p, childpgrp))
- pgadjustjobc(childpgrp, true);
+ fixjobc_kill_q(p, q, true);
}
+ LIST_FOREACH(q, &p->p_orphans, p_orphan)
+ fixjobc_kill_q(p, q, true);
LIST_FOREACH(q, &p->p_children, p_sibling) {
- if ((q->p_treeflag & P_TREE_GRPEXITED) != 0)
+ if (q->p_pptr->p_pid != p->p_oppid)
continue;
- childpgrp = q->p_pgrp;
- if (!isjobproc(q->p_reaper, childpgrp) &&
- isjobproc(p, childpgrp))
- pgadjustjobc(childpgrp, false);
+ fixjobc_kill_q(p, q, false);
}
+ LIST_FOREACH(q, &p->p_orphans, p_orphan)
+ fixjobc_kill_q(p, q, false);
}
void

File Metadata

Mime Type
text/plain
Expires
Tue, Jan 21, 11:29 AM (9 h, 49 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
16009154
Default Alt Text
D26416.id76961.diff (4 KB)

Event Timeline