proc: introduce the proc_add_orphan function

This API allows adding the process to its parent orphan list.

Reviewed by:	kib, markj
MFC after:	1 month
This commit is contained in:
Mariusz Zaborski 2019-08-05 20:11:57 +00:00
parent 41fadb3fca
commit 799d92ab78
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=350611
2 changed files with 21 additions and 10 deletions

View File

@ -1355,6 +1355,24 @@ kern_wait6(struct thread *td, idtype_t idtype, id_t id, int *status,
goto loop;
}
void
proc_add_orphan(struct proc *child, struct proc *parent)
{
sx_assert(&proctree_lock, SX_XLOCKED);
KASSERT((child->p_flag & P_TRACED) != 0,
("proc_add_orphan: not traced"));
if (LIST_EMPTY(&parent->p_orphans)) {
child->p_treeflag |= P_TREE_FIRST_ORPHAN;
LIST_INSERT_HEAD(&parent->p_orphans, child, p_orphan);
} else {
LIST_INSERT_AFTER(LIST_FIRST(&parent->p_orphans),
child, p_orphan);
}
child->p_treeflag |= P_TREE_ORPHANED;
}
/*
* Make process 'parent' the new parent of process 'child'.
* Must be called with an exclusive hold of proctree lock.
@ -1375,16 +1393,8 @@ proc_reparent(struct proc *child, struct proc *parent, bool set_oppid)
LIST_INSERT_HEAD(&parent->p_children, child, p_sibling);
proc_clear_orphan(child);
if (child->p_flag & P_TRACED) {
if (LIST_EMPTY(&child->p_pptr->p_orphans)) {
child->p_treeflag |= P_TREE_FIRST_ORPHAN;
LIST_INSERT_HEAD(&child->p_pptr->p_orphans, child,
p_orphan);
} else {
LIST_INSERT_AFTER(LIST_FIRST(&child->p_pptr->p_orphans),
child, p_orphan);
}
child->p_treeflag |= P_TREE_ORPHANED;
if ((child->p_flag & P_TRACED) != 0) {
proc_add_orphan(child, child->p_pptr);
}
child->p_pptr = parent;

View File

@ -1069,6 +1069,7 @@ void proc_linkup(struct proc *p, struct thread *td);
struct proc *proc_realparent(struct proc *child);
void proc_reap(struct thread *td, struct proc *p, int *status, int options);
void proc_reparent(struct proc *child, struct proc *newparent, bool set_oppid);
void proc_add_orphan(struct proc *child, struct proc *parent);
void proc_set_traced(struct proc *p, bool stop);
void proc_wkilled(struct proc *p);
struct pstats *pstats_alloc(void);