From 8317645892082cc6a4fc21df9b1b13ce6e799644 Mon Sep 17 00:00:00 2001 From: Masatake YAMATO Date: Sat, 13 Apr 2024 03:16:32 +0900 Subject: [PATCH] lsns: continue the executing even if opening a /proc/$pid fails In the original code, lsns printed nothing if it failed in opening the last dntry in /proc/[0-9]* though lsns should work partially. The original behavior caused the combination of the following two test cases failed: $ tests/ts/lsns/filter & tests/ts/lsns/ioctl_ns & [1] 19178 [2] 19179 $ lsns: ownership and hierarchy ... \ lsns: -Q, --filter option ... FAILED FAILED [1]- Done tests/ts/lsns/filter [2]+ Done tests/ts/lsns/ioctl_ns Signed-off-by: Masatake YAMATO --- sys-utils/lsns.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/sys-utils/lsns.c b/sys-utils/lsns.c index bc966dadb..0c66d648a 100644 --- a/sys-utils/lsns.c +++ b/sys-utils/lsns.c @@ -602,7 +602,17 @@ static int read_processes(struct lsns *ls) DBG(PROC, ul_debug("reading %d", (int) pid)); rc = procfs_process_init_path(pc, pid); if (rc < 0) { - DBG(PROC, ul_debug("failed in reading /proc/%d", (int) pid)); + DBG(PROC, ul_debug("failed in reading /proc/%d (rc: %d)", (int) pid, rc)); + /* This failure is acceptable. If a process ($pid) owning + * a namespace is gone while running this lsns process, + * procfs_process_init_path(pc, $pid) may fail. + * + * We must reset this `rc' here. If this `d' is the last + * dentry in `dir', this read_processes() invocation + * returns this `rc'. In the caller context, the + * non-zero value returned from read_processes() makes + * lsns prints nothing. We should avoid the behavior. */ + rc = 0; continue; } -- 2.47.3