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