aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMasatake YAMATO <yamato@redhat.com>2024-04-13 03:16:32 +0900
committerMasatake YAMATO <yamato@redhat.com>2024-04-13 03:51:27 +0900
commit8317645892082cc6a4fc21df9b1b13ce6e799644 (patch)
treedb4032ea9d1ed1656e7769fb5c2706d7537189b6
parentd444d4b828657be67d87876ef5a07df4e29fba4f (diff)
downloadutil-linux-8317645892082cc6a4fc21df9b1b13ce6e799644.tar.gz
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 <yamato@redhat.com>
-rw-r--r--sys-utils/lsns.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/sys-utils/lsns.c b/sys-utils/lsns.c
index bc966dadb5..0c66d648af 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;
}