Blame SOURCES/pstree-introduce-namespace-transition-information.patch

f10d51
From 29ac10530c97631d76aa34b2d2ed018ded60d6bf Mon Sep 17 00:00:00 2001
f10d51
From: Aristeu Rozanski <arozansk@redhat.com>
f10d51
Date: Thu, 25 Apr 2013 11:35:15 -0400
f10d51
Subject: [PATCH 2/3] pstree: introduce namespace transition information
f10d51
f10d51
This patch adds a new option (-S, --ns-change) that will show
f10d51
when a namespace was changed compared to parent's.
f10d51
f10d51
Signed-off-by: Aristeu Rozanski <arozansk@redhat.com>
f10d51
Signed-off-by: Craig Small <csmall@enc.com.au>
f10d51
---
f10d51
 doc/pstree.1 |    4 ++++
f10d51
 src/pstree.c |   27 ++++++++++++++++++++++++---
f10d51
 2 files changed, 28 insertions(+), 3 deletions(-)
f10d51
f10d51
--- psmisc-22.20.orig/doc/pstree.1	2013-09-17 16:26:00.000000000 -0400
f10d51
+++ psmisc-22.20/doc/pstree.1	2013-09-17 16:27:22.510167111 -0400
f10d51
@@ -21,6 +21,7 @@ pstree \- display a tree of processes
f10d51
 .RB [ \-N  , \ \-\-ns\-sort \fIns\fB
f10d51
 .RB [ \-p  , \ \-\-show\-pids ]
f10d51
 .RB [ \-s  , \ \-\-show\-parents ]
f10d51
+.RB [ \-S  , \ \-\-ns-changes ]
f10d51
 .RB [ \-u  , \ \-\-uid\-changes ]
f10d51
 .RB [ \-Z  , \ \-\-security\-context ]
f10d51
 .RB [ \-A  , \ \-\-ascii  , \ \-G  , \ \-\-vt100  , \ \-U  , \ \-\-unicode ]
f10d51
@@ -134,6 +135,9 @@ process name.
f10d51
 implicitly disables compaction.
f10d51
 .IP \fB\-s\fP
f10d51
 Show parent processes of the specified process.
f10d51
+.IP \fB\-S\fP
f10d51
+Show namespaces transitions.  Like \-N, the output is limited when running
f10d51
+as a regular user.
f10d51
 .IP \fB\-u\fP
f10d51
 Show uid transitions.  Whenever the uid of a process differs from the
f10d51
 uid of its parent, the new uid is shown in parentheses after the
f10d51
--- psmisc-22.20.orig/src/pstree.c	2013-09-17 16:27:12.000000000 -0400
f10d51
+++ psmisc-22.20/src/pstree.c	2013-09-17 16:28:04.156698164 -0400
f10d51
@@ -133,7 +133,7 @@ static int *width = NULL;
f10d51
 static int *more = NULL;
f10d51
 
f10d51
 static int print_args = 0, compact = 1, user_change = 0, pids = 0, pgids = 0,
f10d51
-    show_parents = 0, by_pid = 0, trunc = 1, wait_end = 0;
f10d51
+    show_parents = 0, by_pid = 0, trunc = 1, wait_end = 0, ns_change = 0;
f10d51
 #ifdef WITH_SELINUX
f10d51
 static int show_scontext = 0;
f10d51
 #endif                                /*WITH_SELINUX */
f10d51
@@ -545,11 +545,17 @@     if (pid != 0) {
f10d51
 static int tree_equal(const PROC * a, const PROC * b)
f10d51
 {
f10d51
     const CHILD *walk_a, *walk_b;
f10d51
+    int i;
f10d51
 
f10d51
     if (strcmp(a->comm, b->comm))
f10d51
         return 0;
f10d51
     if (user_change && a->uid != b->uid)
f10d51
         return 0;
f10d51
+    if (ns_change) {
f10d51
+        for (i = 0; i < NUM_NS; i++)
f10d51
+            if (a->ns[i] != b->ns[i])
f10d51
+                return 0;
f10d51
+    }
f10d51
     for (walk_a = a->children, walk_b = b->children; walk_a && walk_b;
f10d51
          walk_a = walk_a->next, walk_b = walk_b->next)
f10d51
         if (!tree_equal(walk_a->child, walk_b->child))
f10d51
@@ -630,6 +636,16 @@     if (swapped && current->argc < 0)
f10d51
         else
f10d51
             (void) out_int(current->uid);
f10d51
     }
f10d51
+    if (ns_change && current->parent) {
f10d51
+        for (i = 0; i < NUM_NS; i++) {
f10d51
+            if (current->ns[i] == 0 || current->parent->ns[i] == 0)
f10d51
+                continue;
f10d51
+            if (current->ns[i] != current->parent->ns[i]) {
f10d51
+                out_char(info++ ? ',' : '(');
f10d51
+                out_string(get_ns_name(i));
f10d51
+            }
f10d51
+        }
f10d51
+    }
f10d51
 #ifdef WITH_SELINUX
f10d51
     if (show_scontext) {
f10d51
         out_char(info++ ? ',' : '(');
f10d51
@@ -1002,6 +1018,7 @@              "  -G, --vt100         use 
f10d51
              "  --ns-sort=type      sort by namespace type (ipc, mnt, net, pid, user, uts)\n"
f10d51
              "  -p, --show-pids     show PIDs; implies -c\n"
f10d51
              "  -s, --show-parents  show parents of the selected process\n"
f10d51
+             "  -S, --ns-changes    show namespace transitions\n"
f10d51
              "  -u, --uid-changes   show uid transitions\n"
f10d51
              "  -U, --unicode       use UTF-8 (Unicode) line drawing characters\n"
f10d51
              "  -V, --version       display version information\n"));
f10d51
@@ -1054,6 +1071,7 @@         {"numeric-sort", 0, NULL, 'n'},
f10d51
         {"show-pids", 0, NULL, 'p'},
f10d51
         {"show-pgids", 0, NULL, 'g'},
f10d51
         {"show-parents", 0, NULL, 's'},
f10d51
+        {"ns-changes", 0, NULL, 'S' },
f10d51
         {"uid-changes", 0, NULL, 'u'},
f10d51
         {"unicode", 0, NULL, 'U'},
f10d51
         {"version", 0, NULL, 'V'},
f10d51
@@ -1106,11 +1124,11 @@         /* problems with VT100 on some t
f10d51
 
f10d51
 #ifdef WITH_SELINUX
f10d51
     while ((c =
f10d51
-            getopt_long(argc, argv, "aAcGhH:nN:pglsuUVZ", options,
f10d51
+            getopt_long(argc, argv, "aAcGhH:nN:pglsSuUVZ", options,
f10d51
                         NULL)) != -1)
f10d51
 #else                                /*WITH_SELINUX */
f10d51
     while ((c =
f10d51
-            getopt_long(argc, argv, "aAcGhH:nN:pglsuUV", options, NULL)) != -1)
f10d51
+            getopt_long(argc, argv, "aAcGhH:nN:pglsSuUV", options, NULL)) != -1)
f10d51
 #endif                                /*WITH_SELINUX */
f10d51
         switch (c) {
f10d51
         case 'a':
f10d51
@@ -1174,6 +1192,9 @@             compact = 0;
f10d51
         case 's':
f10d51
             show_parents = 1;
f10d51
             break;
f10d51
+        case 'S':
f10d51
+            ns_change = 1;
f10d51
+            break;
f10d51
         case 'u':
f10d51
             user_change = 1;
f10d51
             break;