aboutsummaryrefslogtreecommitdiff
path: root/sys/sys/proc.h
diff options
context:
space:
mode:
authorKonstantin Belousov <kib@FreeBSD.org>2020-08-22 21:32:11 +0000
committerKonstantin Belousov <kib@FreeBSD.org>2020-08-22 21:32:11 +0000
commitc5bc28b27333e892b44e767c6188c214f09d5e7c (patch)
tree2a238de1377b66db55e6591f3c5a18960ffbb3e9 /sys/sys/proc.h
parentda232c04ab9eba3d3a7fc73881daff847071e9fd (diff)
downloadsrc-c5bc28b27333e892b44e767c6188c214f09d5e7c.tar.gz
src-c5bc28b27333e892b44e767c6188c214f09d5e7c.zip
Fix several issues with process group orphanage.
Attempt of adding assertions that pgrp->pg_jobc counters do not underflow in r361967, reverted in r362910, points out bugs in the handling of job control. Peter Holm was able to narrow down the problem to very easy reproduction with timeout(1) which uses reaping. The following list of problems with calculation of pg_jobs which directs SIGHUP/SIGCONT delivery for orphaned process group was identified: - Re-calculation of the orphaned status for children of exiting parent was wrong, but mostly unnoticed when all children were reparented to init(8). When child can be reparented to a different process which could affect the child' job control state, it was not properly accounted for in pg_jobc. - Lockless check for exiting process' parent process group is racy because nothing prevents the parent from changing its group membership. - Exited process is left in the process group, until waited. This affects other calculations of pg_jobc. Split handling of job control status on process changing its process group, and process exiting. Calculate increments and decrements for pg_jobs by exact checking the orphanage instead of assuming process group membership for children and parent. Move the call to killjobc() later under the proctree_lock. Mark exiting process in killjobc() with a new flag P_TREE_GRPEXITED and skip it for all pg_jobc calculations after the flag is set. Add checker that independently recalculates pg_jobc value and compares it with the memoized process group state. This is enabled under INVARIANTS. Reviewed by: jilles Discussed with: kevans Tested by: pho Sponsored by: The FreeBSD Foundation MFC after: 2 weeks Differential revision: https://reviews.freebsd.org/D26116
Notes
Notes: svn path=/head/; revision=364495
Diffstat (limited to 'sys/sys/proc.h')
-rw-r--r--sys/sys/proc.h2
1 files changed, 1 insertions, 1 deletions
diff --git a/sys/sys/proc.h b/sys/sys/proc.h
index 83d0ca1e3a4f..68d60bb41a78 100644
--- a/sys/sys/proc.h
+++ b/sys/sys/proc.h
@@ -790,6 +790,7 @@ struct proc {
#define P_TREE_FIRST_ORPHAN 0x00000002 /* First element of orphan
list */
#define P_TREE_REAPER 0x00000004 /* Reaper of subtree */
+#define P_TREE_GRPEXITED 0x00000008 /* exit1() done with job ctl */
/*
* These were process status values (p_stat), now they are only used in
@@ -1045,7 +1046,6 @@ int enterpgrp(struct proc *p, pid_t pgid, struct pgrp *pgrp,
struct session *sess);
int enterthispgrp(struct proc *p, struct pgrp *pgrp);
void faultin(struct proc *p);
-void fixjobc(struct proc *p, struct pgrp *pgrp, int entering);
int fork1(struct thread *, struct fork_req *);
void fork_rfppwait(struct thread *);
void fork_exit(void (*)(void *, struct trapframe *), void *,