]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lsns: continue the executing even if opening a /proc/$pid fails
authorMasatake YAMATO <yamato@redhat.com>
Fri, 12 Apr 2024 18:16:32 +0000 (03:16 +0900)
committerMasatake YAMATO <yamato@redhat.com>
Fri, 12 Apr 2024 18:51:27 +0000 (03:51 +0900)
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>
sys-utils/lsns.c

index bc966dadb5724287f244daec298b708452e14ef1..0c66d648af5b7d87d6815a9376e1c5c607d4ff24 100644 (file)
@@ -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;
                }