summaryrefslogtreecommitdiffstats
path: root/sys-utils/lsns.c
diff options
context:
space:
mode:
authorKarel Zak2015-11-27 14:24:09 +0100
committerKarel Zak2015-11-27 14:24:09 +0100
commit9dfd601976583aaba5264f31e8c626b31059f1e3 (patch)
treebf14bbac2bc70170460bc16dd6e1dc7add43ebe5 /sys-utils/lsns.c
parentbuild-sys: add lsns to gitignore (diff)
downloadkernel-qcow2-util-linux-9dfd601976583aaba5264f31e8c626b31059f1e3.tar.gz
kernel-qcow2-util-linux-9dfd601976583aaba5264f31e8c626b31059f1e3.tar.xz
kernel-qcow2-util-linux-9dfd601976583aaba5264f31e8c626b31059f1e3.zip
lsns: read all processes when --task specified
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'sys-utils/lsns.c')
-rw-r--r--sys-utils/lsns.c30
1 files changed, 21 insertions, 9 deletions
diff --git a/sys-utils/lsns.c b/sys-utils/lsns.c
index 48f0dddb7..2b02170a4 100644
--- a/sys-utils/lsns.c
+++ b/sys-utils/lsns.c
@@ -260,7 +260,7 @@ static int read_process(struct lsns *ls, pid_t pid)
INIT_LIST_HEAD(&p->branch);
INIT_LIST_HEAD(&p->children);
- DBG(PROC, ul_debug("add %d", p->pid));
+ DBG(PROC, ul_debugobj(p, "new pid=%d", p->pid));
list_add_tail(&p->processes, &ls->processes);
done:
if (f)
@@ -277,11 +277,6 @@ static int read_processes(struct lsns *ls)
pid_t pid;
int rc = 0;
- if (ls->pid) {
- rc = read_process(ls, ls->pid);
- goto done;
- }
-
DBG(PROC, ul_debug("opening /proc"));
if (!(proc = proc_open_processes())) {
@@ -314,6 +309,19 @@ static struct lsns_namespace *get_namespace(struct lsns *ls, int type, ino_t ino
return NULL;
}
+static int namespace_has_process(struct lsns_namespace *ns, pid_t pid)
+{
+ struct list_head *p;
+
+ list_for_each(p, &ns->processes) {
+ struct lsns_process *proc = list_entry(p, struct lsns_process, ns_siblings[ns->type]);
+
+ if (proc->pid == pid)
+ return 1;
+ }
+ return 0;
+}
+
static struct lsns_namespace *add_namespace(struct lsns *ls, int type, ino_t ino)
{
struct lsns_namespace *ns = calloc(1, sizeof(*ns));
@@ -321,7 +329,7 @@ static struct lsns_namespace *add_namespace(struct lsns *ls, int type, ino_t ino
if (!ns)
return NULL;
- DBG(NS, ul_debug("add %s[%lu]", ns_names[type], ino));
+ DBG(NS, ul_debugobj(ns, "new %s[%lu]", ns_names[type], ino));
INIT_LIST_HEAD(&ns->processes);
INIT_LIST_HEAD(&ns->namespaces);
@@ -335,7 +343,7 @@ static struct lsns_namespace *add_namespace(struct lsns *ls, int type, ino_t ino
static int add_process_to_namespace(struct lsns_namespace *ns, struct lsns_process *proc)
{
- DBG(NS, ul_debug("add process %d to %s[%lu]", proc->pid, ns_names[ns->type], ns->id));
+ DBG(NS, ul_debugobj(ns, "add process [%p] pid=%d to %s[%lu]", proc, proc->pid, ns_names[ns->type], ns->id));
list_add_tail(&proc->ns_siblings[ns->type], &ns->processes);
ns->nprocs++;
@@ -456,6 +464,10 @@ static int show_namespaces(struct lsns *ls)
list_for_each(p, &ls->namespaces) {
struct lsns_namespace *ns = list_entry(p, struct lsns_namespace, namespaces);
+
+ if (ls->pid != 0 && !namespace_has_process(ns, ls->pid))
+ continue;
+
add_scols_line(tab, ns);
}
@@ -479,7 +491,7 @@ static void __attribute__ ((__noreturn__)) usage(FILE * out)
fputs(USAGE_OPTIONS, out);
fputs(_(" -J, --json use JSON output format\n"), out);
- fputs(_(" -p, --task <pid> print process namespace\n"), out);
+ fputs(_(" -p, --task <pid> print process namespaces\n"), out);
fputs(_(" -n, --noheadings don't print headings\n"), out);
fputs(_(" -o, --output <list> define which output columns to use\n"), out);
fputs(_(" -r, --raw use the raw output format\n"), out);