]> git.ipfire.org Git - thirdparty/util-linux.git/commit
lsns: don't abort if /proc/self/ns/user is absent; probe other ns entries
authorMasatake YAMATO <yamato@redhat.com>
Thu, 2 Oct 2025 16:21:21 +0000 (01:21 +0900)
committerMasatake YAMATO <yamato@redhat.com>
Thu, 2 Oct 2025 17:10:33 +0000 (02:10 +0900)
commit4e4d54e9847035ca82816330d46be9088d727ff4
tree56ba546271ba42bce5c7523b6ae920893eaa87e1
parenteb0e08a76e3ebd4571b957e727847060304c32bb
lsns: don't abort if /proc/self/ns/user is absent; probe other ns entries

In 7d5036fdafe0 ("lsns: show namespaces only kept alive by open file
descriptors"), I added code that calls stat(2) on /proc/self/ns/user
and made lsns exit after reporting an error if the call failed. I
assumed /proc/self/ns/user would be available on all platforms.

As Axel Karjalainen reported (link below), that assumption was
wrong: on some platforms, the file is absent. Exiting for this reason
is undesirable.

The stat(2) call is used to obtain the dev_t of the backing device of
nsfs. However, /proc/self/ns/user is not the only source; calling
stat(2) on other namespace files under /proc/self/ns yields the same
dev_t. This change iterates over entries under /proc/self/ns and uses
the first one whose stat(2) succeeds.

Reported-by: Axel Karjalainen <axel@axka.fi>
Link: https://github.com/util-linux/util-linux/pull/2902#issuecomment-3348630885
Fixes: 7d5036fdafe0 ("lsns: show namespaces only kept alive by open file descriptors")
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
sys-utils/lsns.c