Author: oshogbo
Date: Mon Aug  5 20:11:57 2019
New Revision: 350611
URL: https://svnweb.freebsd.org/changeset/base/350611

Log:
  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

Modified:
  head/sys/kern/kern_exit.c
  head/sys/sys/proc.h

Modified: head/sys/kern/kern_exit.c
==============================================================================
--- head/sys/kern/kern_exit.c   Mon Aug  5 19:59:23 2019        (r350610)
+++ head/sys/kern/kern_exit.c   Mon Aug  5 20:11:57 2019        (r350611)
@@ -1355,6 +1355,24 @@ loop_locked:
        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,
        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;

Modified: head/sys/sys/proc.h
==============================================================================
--- head/sys/sys/proc.h Mon Aug  5 19:59:23 2019        (r350610)
+++ head/sys/sys/proc.h Mon Aug  5 20:11:57 2019        (r350611)
@@ -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);
_______________________________________________
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to