The tree of *parent* and *owner* could be forests because *lsns*
cannot track a namespace having no process.
This change tries interpolating the missing namespaces by calling
ioctl(NS_GET_PARENT) and ioctl(NS_GET_USERNS) recursively.
The original output for -Tparent:
# ./lsns -Tparent
NS TYPE NPROCS PID USER COMMAND
4026531837 user 404 1 root /usr/lib/systemd/sy
├─4026532508 user 1 29376 yamato /usr/lib64/firefox/
...
└─4026533513 user 1 24245 yamato /usr/lib64/firefox/
...
4026533733 user 1 30839 yamato /opt/google/chrome-
4026533734 user 15 10076 yamato /opt/google/chrome-
user namespaces 4026533733 and 4026533734 are orphans.
lsns could not find their parents.
With this change:
# ./lsns-with-changes -Tparent
NS TYPE NPROCS PID USER COMMAND
4026531837 user 404 1 root /usr/lib/systemd/
├─4026532508 user 1 29376 yamato /usr/lib64/firefo
...
├─4026532639 user 0
│ ├─4026532637 user 0
│ │ └─4026533733 user 1 30839 yamato /opt/google/chrom
│ └─4026533734 user 14 10076 yamato /opt/google/chrom
Now user namespaces 4026533733 and 4026533734 are integrated to the
tree. lsns interpolates the missing namespace 4026532639 and
4026532637 for the integration.
The original output for -Towner:
# ./lsns -Towner
NS TYPE NPROCS PID USER COMMAND
4026531837 user 405 1 root /usr/lib/systemd/s
├─4026531835 cgroup 431 1 root /usr/lib/systemd/s
...
4026532638 pid 1 30839 yamato /opt/google/chrome
4026532640 pid 2 30837 yamato /opt/google/chrome
...
pid namespaces 4026532638 and 4026532640 are orphans.
lsns could not find their owners.
With this change:
# ./lsns-with-changes -Towner
NS TYPE NPROCS PID USER COMMAND
4026531837 user 403 1 root /usr/lib/systemd
├─4026531835 cgroup 429 1 root /usr/lib/systemd
...
├─4026532639 user 0
...
│ ├─4026532637 user 0
│ │ ├─4026532638 pid 1 30839 yamato /opt/google/chro
│ │ ├─4026533638 net 1 30839 yamato /opt/google/chro
│ │ └─4026533733 user 1 30839 yamato /opt/google/chro
│ ├─4026532640 pid 2 30837 yamato /opt/google/chro
Now pid namespaces 4026532638 and 4026532640 are integrated to the
tree. lsns interpolates the missing namespace 4026532639 and
4026532637 for the integration.
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
This is a preparation change for planed "tree interpolation" patch.
parentid, ownerid, parentns, and ownerns were members of
lsns_namespace struct. When interpolating missing namespaces
for building a unified name space tree, duplicated functions
are needed; one is for parentid and parentns members, and
another is for ownerid and ownerns members. To avoid the
duplication, this change unifies the members as following:
parentid and ownerid => related_id [2]
parentns and ownerns => related_ns [2]
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
* make --tree=process default for 'lsns' and 'lsns <ns>'
* remove 'list' from struct lsns
* update man page
Addresses: https://github.com/karelzak/util-linux/pull/1281
Signed-off-by: Karel Zak <kzak@redhat.com>
Suggested by Karel Zak.
`--tree` option is introduced as replacement for `--nstree`.
In addition to `parent` and `owner`, `--tree` take `process` as the
option argument.
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
Introduce new option -T[parent|owner]|--nstree[=parent|=owner].
With this change, lsns prints parent/child relationship tree if
"-T parent" is given and owner/owned relationship tree if "-T owner is given.
Passing only "-T" is same as passing "-Towner."
Example sessions:
# ./lsns -Tparent -ons,type,pns| head -20
NS TYPE PNS
4026531837 user 0
├─4026532508 user 4026531837
├─4026532609 user 4026531837
├─4026532610 user 4026531837
├─4026532629 user 4026531837
├─4026532705 user 4026531837
├─4026532901 user 4026531837
├─4026533090 user 4026531837
├─4026533185 user 4026531837
├─4026533280 user 4026531837
└─4026533468 user 4026531837
4026531835 cgroup 0
4026531836 pid 0
└─4026533038 pid 4026531836
├─4026532934 pid 4026533038
├─4026533715 pid 4026533038
├─4026533716 pid 4026533038
...
# ./lsns -Towner -ons,type,ons| head -20
NS TYPE ONS
4026531837 user 0
├─4026531835 cgroup 4026531837
├─4026531836 pid 4026531837
├─4026531838 uts 4026531837
├─4026531839 ipc 4026531837
├─4026531840 mnt 4026531837
├─4026531861 mnt 4026531837
├─4026532001 net 4026531837
├─4026532219 mnt 4026531837
├─4026532357 mnt 4026531837
├─4026532383 net 4026531837
├─4026532475 mnt 4026531837
├─4026532476 mnt 4026531837
├─4026532504 mnt 4026531837
├─4026532508 user 4026531837
│ ├─4026532509 ipc 4026532508
│ └─4026532511 net 4026532508
├─4026532573 mnt 4026531837
├─4026532574 mnt 4026531837
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
../sys-utils/lsns.c:360:8: warning: comparison of integers of different signs: '__u32' (aka 'unsigned int') and 'int' [-Wsign-compare]
if (!(NLMSG_OK(nlh, reslen)
^~~~~~~~~~~~~~~~~~~~~
/usr/include/linux/netlink.h:90:24: note: expanded from macro 'NLMSG_OK'
(nlh)->nlmsg_len <= (len))
~~~~~~~~~~~~~~~~ ^ ~~~
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
Let's make it possible to use debug.h without environment variables.
Suggested-by: J William Piggott <elseifthen@gmx.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
* introduce new flag __UL_DEBUG_FL_NOADDR to suppress pointer address printing
* use __UL_DEBUG_FL_NOADDR when SUID
* move ul_debugobj() to debugobj.h, and require UL_DEBUG_CURRENT_MASK
to provide access to the current mask from ul_debugobj(). It's better
than modify all ul_debugobj() calls and use the global mask as
argument.
* remove never used UL_DEBUG_DEFINE_FLAG
Reported-by: halfdog <me@halfdog.net>
Signed-off-by: Karel Zak <kzak@redhat.com>
sys-utils/lsns.c:683:2: error: format ‘%lu’ expects argument of type ‘long unsigned int’, but argument 4 has type ‘ino_t’ [-Werror=format=]
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* don't use booleans
* use is_ prefix for boolean-like functions
* make nsfs_xasputs() more readable
* enable 'nowrap' together with 'raw' and don't test for "nowrap || raw"
* add missing 'W' to getopt_long()
Signed-off-by: Karel Zak <kzak@redhat.com>
This option forces lsns command not use
multi-line presentation when printing a cell.
Currently, it affects only NSFS column.
Implementing this option is suggested by Karl Zak.
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
nsfs provides kernel level interface for assigning
logical name to a namespace. Following message is quoted
from git log of linux kernel:
commit 0226f4923f6c9b40cfa1c1c1b19a6ac6b3924ead
Author: Al Viro <viro@zeniv.linux.org.uk>
Date: Tue Dec 6 12:21:54 2011 -0500
vfs: take /proc/*/mounts and friends to fs/proc_namespace.c
rationale: that stuff is far tighter bound to fs/namespace.c than to
the guts of procfs proper.
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
/proc/self/mountinfo lists the logical names for namespaces:
...
652 81 0:3 net:[4026532579] /tmp/XYZ rw shared:192 - nsfs nsfs rw,seclabel
...
In the lines /tmp/XYZ is a logical name for 4026532579 of net
namespace.
This patch adds nsfs column. It seems that the logical name is
used only in "ip netns" now. So the column is disabled by default.
Use '--type=net' or '-o NSFS' options to enable it.
This feature and the way to implementation using multi lines in a column
is Suggested by Karel Zak.
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
Linux network subsystem assigns an unique integer to a network
namespace.
term0# ip netns add UTIL-LINUX-LSNS-TEST-NS
term0# ip netns list
UTIL-LINUX-LSNS-TEST-NS
term0# ip link add name lsns-vetha type veth peer name lsns-vethb
term0 # ip link set lsns-vethb netns UTIL-LINUX-LSNS-TEST-NS
term0# ip netns list
UTIL-LINUX-LSNS-TEST-NS (id: 0)
term0# ip link show dev lsns-vetha
230: lsns-vetha@if229: <BROADCAST,MULTICAST> mtu 1500 qdisc noop ...
link/ether 3e:27:68:ba:b3:95 brd ff:ff:ff:ff:ff:ff link-netnsid 0
In this example 0 is assigned to UTIL-LINUX-LSNS-TEST-NS net namespace.
The name, UTIL-LINUX-LSNS-TEST-NS, and it semantics is given and defined
by iproute2 in userland; and nothing to do with util-linux.
However, the id, 0, is managed in linux kernel. If lsns can show
the ids, it helps users understand the state of network namespaces.
This commit adds NETNSID column to the output.
Here is an example of session:
term0# ip netns exec UTIL-LINUX-LSNS-TEST-NS cat
(Open another terminal)
term1# ./lsns --type net
NS TYPE NPROCS PID USER NETNSID COMMAND
4026531993 net 383 1 root unassigned /usr/lib/systemd/...
4026532433 net 1 1219 rtkit unassigned /usr/libexec/rtkit-daemon
4026532562 net 1 18201 root 0 cat
0 is shown as NETNSID for the cat process.
For the initial name space, "unassigned" is printed.
For the namespaces other type than net, "n/a" is printed.
If an error occurred during getting the id, "n/a" is printed.
Changes in V2:
* Remove wrongly used & operators.
* Make netnsid field empty if value for the column is not available.
Suggested by Karel Zak.
* Remove redundant condtion for checking the avaiablebility of netlink
socket. Suggested by Karel Zak.
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
changed in include/c.h and applied via sed:
sed -i 's/fprintf.*\(USAGE_MAN_TAIL.*\)/printf(\1/' $(git ls-files -- "*.c")
sed -i 's/print_usage_help_options\(.*\);/printf(USAGE_HELP_OPTIONS\1);/' $(git ls-files -- "*.c")
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
Consolidate --help and --version descriptions. We are
now able to align them to the other options.
We changed include/c.h. The rest of this patch was
generated by sed, plus manually setting the right
alignment numbers. We do not change anything but
white spaces in the --help output.
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
This patch is trivial and changes nothing, because
we were always using usage(stdout)
Now all our usage() functions look very similar. If wanted we
could auto-generate another big cosmetical patch to remove all
the useless "FILE *out" constants and use printf and puts
rather than their f* friends. Such patch could be automatically
synchronized with the translation project (newlines!) to not
make the translators sick.
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
For example, child process of spamd has
32031 (spamd child) S 32026 32026 32026 0 -1 4210752 338 0 0 0 ...
fscanf("%d %*s %c %d*[^\n]") in read_process() can't parse above as we
expected, because %s only skips non-whitespace. I.e. it parses like
following,
32031 (spamd child) S 32026 32026 32026 0 -1 4210752 338 0 0 0 ...
+---+ +----+ +
%d %*s %c
and returns 2 (pid=32031, state=c).
This fixes it by skipping task->comm part manually.
Signed-off-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
For example user namespace is optional it does not make sense to
ignore process completely if the ns/user file is missing.
Reported-by: Michał Bartoszkiewicz <mbartoszkiewicz@gmail.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
Still a few printf warnings found on i386 Linux:
libfdisk/src/alignment.c: In function 'fdisk_align_lba':
libfdisk/src/alignment.c:115:3: warning: format '%ju' expects argument of type 'uintmax_t', but argument 6 has type 'long unsigned int' [-Wformat]
sys-utils/lsns.c: In function ‘add_namespace’:
sys-utils/lsns.c:346:2: warning: format ‘%lu’ expects argument of type ‘long unsigned int’, but argument 4 has type ‘ino_t’ [-Wformat]
sys-utils/lsns.c: In function ‘add_process_to_namespace’:
sys-utils/lsns.c:362:2: warning: format ‘%lu’ expects argument of type ‘long unsigned int’, but argument 6 has type ‘ino_t’ [-Wformat]
sys-utils/lsns.c: In function ‘add_scols_line’:
sys-utils/lsns.c:440:4: warning: format ‘%lu’ expects argument of type ‘long unsigned int’, but argument 3 has type ‘ino_t’ [-Wformat]
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
The process-selection logic is in add_process_to_namespace:
if (!ns->proc || ns->proc->pid > proc->pid)
ns->proc = proc;
so it's just selecting the lowest PID.
Signed-off-by: W. Trevor King <wking@tremily.us>