]> granicus.if.org Git - psmisc/commitdiff
Fake pstree root with kernels with hidepid
authorArkadiusz Miskiewicz <arekm@users.sourceforge.net>
Sat, 19 May 2012 08:39:02 +0000 (18:39 +1000)
committerCraig Small <csmall@users.sourceforge.net>
Sat, 19 May 2012 08:39:02 +0000 (18:39 +1000)
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 <csmall@enc.com.au>
ChangeLog
src/pstree.c

index 4db5ffd41efea7a6eb520ff65e9f78dbe4519743..36b68fb5f339b9f9d449aa7a5165f538024483e7 100644 (file)
--- 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
 ================
index a6c8f6e72478bcc05d54b0b9326d2d0fe6124efd..6d821a4eaefda8b03dcd486ede452731e7e11b94 100644 (file)
@@ -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;
 }