From: Masatake YAMATO Date: Fri, 12 Apr 2024 18:16:32 +0000 (+0900) Subject: lsns: continue the executing even if opening a /proc/$pid fails X-Git-Tag: v2.42-start~429 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=8317645892082cc6a4fc21df9b1b13ce6e799644;p=thirdparty%2Futil-linux.git 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 --- 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; }