From 150ff2ad69344d8555c14b42b2658313f16e9d1e Mon Sep 17 00:00:00 2001 From: Justus Winter Date: Thu, 9 Mar 2017 23:51:54 +0100 Subject: proc: Refactor. * proc/mgt.c (namespace_find_root): New function. (process_has_exited): Use new function. * proc/proc.h (namespace_find_root): New declaration. --- proc/mgt.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'proc/mgt.c') diff --git a/proc/mgt.c b/proc/mgt.c index 831a3510..87a7c96b 100644 --- a/proc/mgt.c +++ b/proc/mgt.c @@ -733,6 +733,22 @@ new_proc (task_t task) return p; } +/* Find the creator of the task namespace that P is in. */ +struct proc * +namespace_find_root (struct proc *p) +{ + for (; + MACH_PORT_VALID (p->p_parent->p_task_namespace); + p = p->p_parent) + { + /* Walk up the process hierarchy until we find the creator of + the task namespace. The last process we encounter that has a + valid task_namespace must be the creator. */ + } + + return p; +} + /* Used with prociterate to terminate all tasks in a task namespace. */ static void @@ -785,14 +801,7 @@ process_has_exited (struct proc *p) if (MACH_PORT_VALID (p->p_task_namespace)) { - for (tp = p; - MACH_PORT_VALID (tp->p_parent->p_task_namespace); - tp = tp->p_parent) - { - /* Walk up the process hierarchy until we find the - creator of the task namespace. */ - } - + tp = namespace_find_root (p); if (p == tp) { /* The creator of the task namespace died. Terminate -- cgit v1.2.3