From: Arkadiusz Miskiewicz Date: Sat, 19 May 2012 08:39:02 +0000 (+1000) Subject: Fake pstree root with kernels with hidepid X-Git-Tag: v22.17~6 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=26f9b6c1553d021c0bf9dd85f0647dc6e210948d;p=psmisc Fake pstree root with kernels with hidepid Kernels that hide pids hide pid=1 which pstree needs to show any output. If pstree detects this it now makes a "fake" root. Bug-Sourceforge: https://sourceforge.net/tracker/?func=detail&aid=3509672&group_id=15273&atid=115273 Signed-off-by: Craig Small --- diff --git a/ChangeLog b/ChangeLog index 4db5ffd..36b68fb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -11,6 +11,7 @@ Changes in 22.17 (unreleased) * fuser uses correct timeout_stat define Debian #661723 * fuser is not compiled on hurd-i386 Debian #673485 * No TEXTRELS in src/lists built as PIE on x86 + * Fake pstree root for kernels with hidepid turned on Changes in 22.16 ================ diff --git a/src/pstree.c b/src/pstree.c index a6c8f6e..6d821a4 100644 --- a/src/pstree.c +++ b/src/pstree.c @@ -363,12 +363,27 @@ add_proc(const char *comm, pid_t pid, pid_t ppid, uid_t uid, ppid = 0; if (isthread) this->flags |= PFLAG_THREAD; - if (!(parent = find_proc(ppid))) + if (!(parent = find_proc(ppid))) { #ifdef WITH_SELINUX parent = new_proc("?", ppid, 0, scontext); #else /*WITH_SELINUX */ parent = new_proc("?", ppid, 0); #endif /*WITH_SELINUX */ + /* When using kernel 3.3 with hidepid feature enabled on /proc + * then we need fake root pid */ + if (!isthread && pid != 1) { + PROC *root; + if (!(root = find_proc(1))) { +#ifdef WITH_SELINUX + root = new_proc("?", 1, 0, scontext); +#else /*WITH_SELINUX */ + root = new_proc("?", 1, 0); +#endif + } + add_child(root, parent); + parent->parent = root; + } + } add_child(parent, this); this->parent = parent; }