Commit Graph

36 Commits

Author SHA1 Message Date
Karel Zak 887810a8a5 lsns: remove if-after-xcalloc
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-02-20 14:59:40 +01:00
Ruediger Meier 58b29eedb0 lsns: fix clang compiler warning
../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>
2018-02-16 11:12:44 +01:00
Karel Zak a15dca2f6d include/debug: introduce __UL_INIT_DEBUG_FROM_STRING()
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>
2018-01-17 13:58:29 +01:00
Karel Zak 6d00cfb233 include/debug: don't print pointer address for SUID programs
* 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>
2018-01-12 11:01:26 +01:00
Ruediger Meier 845dac5f8e misc: fix printf i386 compiler warnings
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>
2018-01-09 23:12:19 +01:00
Karel Zak f593e2797e lsns: initialize stuff when really necessary
It's more robust to depend on list of the wanted columns than on
another variables.

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-11-27 17:40:56 +01:00
Karel Zak deb3f5180c lsns: rename notruns to no_trunc
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-11-27 17:13:50 +01:00
Karel Zak 7eda2400db lsns: nsfs stuff cleanup
* 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>
2017-11-27 17:13:50 +01:00
Masatake YAMATO 0a32d39a0b lsns: add --nowrap(-W) option
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>
2017-11-27 15:54:56 +01:00
Masatake YAMATO 74d2056ae8 lsns: add nsfs column
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>
2017-11-27 15:54:55 +01:00
Masatake YAMATO 7a360346d3 lsns: disable netnsid column by default
Enable only when

* --type=net is given, or
* -o NETNSID is given.

Suggested by Karel Zak.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
2017-11-27 15:54:52 +01:00
Masatake YAMATO 4195756e03 lsns: add netnsid column
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>
2017-11-27 15:54:49 +01:00
Ruediger Meier f45f3ec34a misc: consolidate macro style USAGE_HELP_OPTIONS
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>
2017-06-29 16:54:33 +02:00
Ruediger Meier b1a294c448 misc: introduce print_usage_help_options()
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>
2017-06-27 12:26:19 +02:00
Ruediger Meier 86be6a32d3 misc: cosmetics, remove argument from usage(FILE*)
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>
2017-06-26 14:38:24 +02:00
Karel Zak c3a4cfc579 misc: consolidate usage() "Available columns"
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-06-26 14:09:53 +02:00
Sami Kerola 2ba641e5f3 misc: add static keyword to where needed [smatch scan]
text-utils/rev.c:68:9: warning: symbol 'buf' was not declared. Should it be
static?

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-02-20 12:58:49 +01:00
Karel Zak 677ec86cef Use --help suggestion on invalid option
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>
2016-12-19 13:13:34 +01:00
OGAWA Hirofumi 3fcbd79789 lsns: Fix parser for /proc/<pid>/stat which is including space in comm
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>
2016-12-02 13:20:41 +01:00
Karel Zak 3e11eaa831 lsns: fix mem leak [coverity scan] 2016-10-05 10:53:02 +02:00
Michał Bartoszkiewicz 2b8889c44b lsns: support cgroup namespaces
Signed-off-by: Michał Bartoszkiewicz <mbartoszkiewicz@gmail.com>
2016-08-16 13:36:12 +02:00
Karel Zak 3082f8518f lsns: missing ns/<name> is not error
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>
2016-08-15 11:02:18 +02:00
Karel Zak 99ae5a4956 lsns: check for OOM
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-07-01 15:42:50 +02:00
Ruediger Meier e1a15f8f68 misc: fix printf i386 compiler warnings
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>
2016-03-12 11:28:03 +01:00
Yuriy M. Kaminskiy ff27b20f3c lsns.c: fix error return
If non-negative value returned, errno could be unset (especially 0).


Signed-off-by: Karel Zak <kzak@redhat.com>
2016-03-07 15:11:06 +01:00
Ruediger Meier 9d3d66dfaa lsns: use xcalloc()
... found by tools/checkxalloc.sh

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-02-18 16:54:26 +01:00
Yuriy M. Kaminskiy 5dc625b669 lsns: fix failure after zombie process
(At least on kernel 3.16), stat("/proc/${pid_of_zombie}/ns/mnt") returns
-ENOENT, as a result lsns stops scanning processes prematurely.
2016-01-18 10:08:02 +01:00
W. Trevor King dd62675a87 lsns: Fix "lowers" -> "lowest" typo in --help for COL_PID
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>
2016-01-05 12:03:18 +01:00
Karel Zak 8ff3d5d077 lsns: fix usage()
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-12-01 13:50:51 +01:00
Karel Zak 1880a5781f lsns: sort namespaces, avoid duplicate entries in tree output
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-12-01 12:31:40 +01:00
Karel Zak 82a437c79d lsns: remove unwanted comment
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-12-01 11:45:11 +01:00
Karel Zak 304fbe8b3c lsns: filter by NS type
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-11-30 15:55:31 +01:00
Karel Zak 969d3d15aa lsln: allows to list namespace processes
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-11-30 14:06:05 +01:00
Karel Zak 9dfd601976 lsns: read all processes when --task specified
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-11-27 14:24:09 +01:00
Karel Zak a52852d37a lsns: add USER and UID
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-11-27 13:56:31 +01:00
Karel Zak 8a2045620e lsns: new command
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-11-26 14:09:45 +01:00