From 34a94ce86b1bada9c0768f631540735d44f41100 Mon Sep 17 00:00:00 2001 From: Justus Winter Date: Thu, 9 Mar 2017 23:55:12 +0100 Subject: proc: Hierarchical proc servers. Previously, a Subhurd's tasks were shown as weird processes in the Motherhurd. This change connects the proc server in the Motherhurd with the proc server in the Subhurd, embedding the Subhurd's process hierarchy. Subhurd's processes can now be inspected and debugged like any other process. * NEWS: Update. * boot/boot.c (mach_msg_forward): New function. (boot_demuxer): Forward messages arriving on the new task notification port from the proc server, and forward them to the proc server inside the Subhurd via the notification port. * proc/info.c (S_proc_task2proc): Relay request for processes in a task namespace to the Subhurd's proc server. (S_proc_pid2proc): Likewise. (S_proc_getprocargs): Likewise. (S_proc_getprocenv): Likewise. (S_proc_getprocinfo): Likewise. Translate PIDs. (S_proc_getloginid): Likewise. (S_proc_getloginpids): Likewise. * proc/mgt.c (namespace_is_subprocess): New function. (namespace_translate_pids): Likewise. * proc/msg.c (S_proc_getmsgport): Relay request for processes in a task namespace to the Subhurd's proc server. * proc/pgrp.c (S_proc_getsid): Likewise. Translate PIDs. (S_proc_getsessionpids): Likewise. (S_proc_getsessionpgids): Likewise. (S_proc_getpgrppids): Likewise. * proc/proc.h (namespace_is_subprocess): New prototype. (namespace_translate_pids): Likewise. --- proc/pgrp.c | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) (limited to 'proc/pgrp.c') diff --git a/proc/pgrp.c b/proc/pgrp.c index d7c562fa..9db1dba6 100644 --- a/proc/pgrp.c +++ b/proc/pgrp.c @@ -147,6 +147,30 @@ S_proc_getsid (struct proc *callerp, /* No need to check CALLERP; we don't use it. */ + if (namespace_is_subprocess (p)) + { + /* Relay it to the Subhurd's proc server (if any). */ + error_t err; + pid_t pid_sub; + + /* Release global lock while talking to the other proc server. */ + pthread_mutex_unlock (&global_lock); + + err = proc_task2pid (p->p_task_namespace, p->p_task, &pid_sub); + if (! err) + err = proc_getsid (p->p_task_namespace, pid_sub, sid); + if (! err) + /* Acquires global_lock. */ + err = namespace_translate_pids (p->p_task_namespace, sid, 1); + else + pthread_mutex_lock (&global_lock); + + if (! err) + return 0; + + /* Fallback. */ + } + *sid = p->p_pgrp->pg_session->s_sid; return 0; } @@ -167,6 +191,31 @@ S_proc_getsessionpids (struct proc *callerp, /* No need to check CALLERP; we don't use it. */ + p = pid_find (sid); + if (namespace_is_subprocess (p)) + { + /* Relay it to the Subhurd's proc server (if any). */ + error_t err; + pid_t pid_sub; + + /* Release global lock while talking to the other proc server. */ + pthread_mutex_unlock (&global_lock); + + err = proc_task2pid (p->p_task_namespace, p->p_task, &pid_sub); + if (! err) + err = proc_getsessionpids (p->p_task_namespace, pid_sub, pids, npidsp); + if (! err) + /* Acquires global_lock. */ + err = namespace_translate_pids (p->p_task_namespace, *pids, *npidsp); + else + pthread_mutex_lock (&global_lock); + + if (! err) + return 0; + + /* Fallback. */ + } + s = session_find (sid); if (!s) return ESRCH; @@ -206,6 +255,7 @@ S_proc_getsessionpgids (struct proc *callerp, size_t *npgidsp) { int count; + struct proc *p; struct pgrp *pg; struct session *s; pid_t *pp = *pgids; @@ -213,6 +263,31 @@ S_proc_getsessionpgids (struct proc *callerp, /* No need to check CALLERP; we don't use it. */ + p = pid_find (sid); + if (namespace_is_subprocess (p)) + { + /* Relay it to the Subhurd's proc server (if any). */ + error_t err; + pid_t pid_sub; + + /* Release global lock while talking to the other proc server. */ + pthread_mutex_unlock (&global_lock); + + err = proc_task2pid (p->p_task_namespace, p->p_task, &pid_sub); + if (! err) + err = proc_getsessionpgids (p->p_task_namespace, pid_sub, pgids, npgidsp); + if (! err) + /* Acquires global_lock. */ + err = namespace_translate_pids (p->p_task_namespace, *pgids, *npgidsp); + else + pthread_mutex_lock (&global_lock); + + if (! err) + return 0; + + /* Fallback. */ + } + s = session_find (sid); if (!s) return ESRCH; @@ -254,6 +329,31 @@ S_proc_getpgrppids (struct proc *callerp, /* No need to check CALLERP; we don't use it. */ + p = pid_find (pgid); + if (namespace_is_subprocess (p)) + { + /* Relay it to the Subhurd's proc server (if any). */ + error_t err; + pid_t pid_sub; + + /* Release global lock while talking to the other proc server. */ + pthread_mutex_unlock (&global_lock); + + err = proc_task2pid (p->p_task_namespace, p->p_task, &pid_sub); + if (! err) + err = proc_getpgrppids (p->p_task_namespace, pid_sub, pids, npidsp); + if (! err) + /* Acquires global_lock. */ + err = namespace_translate_pids (p->p_task_namespace, *pids, *npidsp); + else + pthread_mutex_lock (&global_lock); + + if (! err) + return 0; + + /* Fallback. */ + } + if (pgid == 0) pg = callerp->p_pgrp; else -- cgit v1.2.3