summaryrefslogtreecommitdiffstats
path: root/sys-utils/lsns.c
Commit message (Collapse)AuthorAgeFilesLines
* misc: consolidate version printing and close_stdout()Karel Zak2019-04-161-6/+6
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lsns: remove unnecessary includeKarel Zak2018-05-171-1/+0Star
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lsns: add --output-all optionSami Kerola2018-05-031-0/+9
| | | | Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* lsns: use scols_column_set_json_type()Karel Zak2018-04-181-5/+9
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lsns: remove if-after-xcallocKarel Zak2018-02-201-4/+0Star
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lsns: fix clang compiler warningRuediger Meier2018-02-161-2/+3
| | | | | | | | | | | ../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>
* include/debug: introduce __UL_INIT_DEBUG_FROM_STRING()Karel Zak2018-01-171-1/+1
| | | | | | | 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>
* include/debug: don't print pointer address for SUID programsKarel Zak2018-01-121-0/+3
| | | | | | | | | | | | | | | | * 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>
* misc: fix printf i386 compiler warningsRuediger Meier2018-01-091-1/+1
| | | | | | 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>
* lsns: initialize stuff when really necessaryKarel Zak2017-11-271-22/+25
| | | | | | | It's more robust to depend on list of the wanted columns than on another variables. Signed-off-by: Karel Zak <kzak@redhat.com>
* lsns: rename notruns to no_truncKarel Zak2017-11-271-3/+3
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lsns: nsfs stuff cleanupKarel Zak2017-11-271-37/+37
| | | | | | | | | | * 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>
* lsns: add --nowrap(-W) optionMasatake YAMATO2017-11-271-2/+10
| | | | | | | | | | | 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>
* lsns: add nsfs columnMasatake YAMATO2017-11-271-4/+104
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* lsns: disable netnsid column by defaultMasatake YAMATO2017-11-271-5/+20
| | | | | | | | | | | Enable only when * --type=net is given, or * -o NETNSID is given. Suggested by Karel Zak. Signed-off-by: Masatake YAMATO <yamato@redhat.com>
* lsns: add netnsid columnMasatake YAMATO2017-11-271-2/+184
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* misc: consolidate macro style USAGE_HELP_OPTIONSRuediger Meier2017-06-291-2/+2
| | | | | | | | | 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>
* misc: introduce print_usage_help_options()Ruediger Meier2017-06-271-2/+1Star
| | | | | | | | | | | | 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>
* misc: cosmetics, remove argument from usage(FILE*)Ruediger Meier2017-06-261-3/+4
| | | | | | | | | | | | | | 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>
* misc: consolidate usage() "Available columns"Karel Zak2017-06-261-2/+1Star
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* misc: add static keyword to where needed [smatch scan]Sami Kerola2017-02-201-2/+2
| | | | | | | text-utils/rev.c:68:9: warning: symbol 'buf' was not declared. Should it be static? Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* Use --help suggestion on invalid optionKarel Zak2016-12-191-2/+1Star
| | | | | | | | The current default is to print all usage() output. This is overkill in many case. Addresses: https://github.com/karelzak/util-linux/issues/338 Signed-off-by: Karel Zak <kzak@redhat.com>
* lsns: Fix parser for /proc/<pid>/stat which is including space in commOGAWA Hirofumi2016-12-021-4/+26
| | | | | | | | | | | | | | | | | | | | 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>
* lsns: fix mem leak [coverity scan]Karel Zak2016-10-051-1/+1
|
* lsns: support cgroup namespacesMichał Bartoszkiewicz2016-08-161-3/+5
| | | | Signed-off-by: Michał Bartoszkiewicz <mbartoszkiewicz@gmail.com>
* lsns: missing ns/<name> is not errorKarel Zak2016-08-151-2/+2
| | | | | | | | 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>
* lsns: check for OOMKarel Zak2016-07-011-2/+2
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* misc: fix printf i386 compiler warningsRuediger Meier2016-03-121-3/+4
| | | | | | | | | | | | | | | 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>
* lsns.c: fix error returnYuriy M. Kaminskiy2016-03-071-1/+1
| | | | | | | If non-negative value returned, errno could be unset (especially 0). Signed-off-by: Karel Zak <kzak@redhat.com>
* lsns: use xcalloc()Ruediger Meier2016-02-181-2/+2
| | | | | | ... found by tools/checkxalloc.sh Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* lsns: fix failure after zombie processYuriy M. Kaminskiy2016-01-181-1/+1
| | | | | (At least on kernel 3.16), stat("/proc/${pid_of_zombie}/ns/mnt") returns -ENOENT, as a result lsns stops scanning processes prematurely.
* lsns: Fix "lowers" -> "lowest" typo in --help for COL_PIDW. Trevor King2016-01-051-1/+1
| | | | | | | | | | | 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>
* lsns: fix usage()Karel Zak2015-12-011-2/+2
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lsns: sort namespaces, avoid duplicate entries in tree outputKarel Zak2015-12-011-1/+14
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lsns: remove unwanted commentKarel Zak2015-12-011-3/+2Star
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lsns: filter by NS typeKarel Zak2015-11-301-12/+47
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lsln: allows to list namespace processesKarel Zak2015-11-301-47/+145
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lsns: read all processes when --task specifiedKarel Zak2015-11-271-9/+21
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lsns: add USER and UIDKarel Zak2015-11-271-9/+37
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lsns: new commandKarel Zak2015-11-261-0/+572
Signed-off-by: Karel Zak <kzak@redhat.com>