]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lsfd: fill MNTID coulmn for exe, cwd, and rtd assocations
authorMasatake YAMATO <yamato@redhat.com>
Fri, 9 Jan 2026 05:46:15 +0000 (14:46 +0900)
committerMasatake YAMATO <yamato@redhat.com>
Mon, 12 Jan 2026 18:39:33 +0000 (03:39 +0900)
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
lsfd-cmd/lsfd.c
lsfd-cmd/lsfd.h
tests/expected/lsfd/column-mntid-nonroot [new file with mode: 0644]
tests/ts/lsfd/column-mntid-nonroot [new file with mode: 0755]

index 429cd7b52ccd699dc950175d7ea2ca9eb96d3aea..4ccc4638da8e48b24ec4416001240494c20b20a8 100644 (file)
@@ -1091,9 +1091,19 @@ static void collect_outofbox_files(struct path_cxt *pc,
 {
        size_t i;
 
-       for (i = 0; i < count; i++)
-               collect_file_symlink(pc, proc, names[assocs[i]], assocs[i] * -1,
-                                    sockets_only);
+       for (i = 0; i < count; i++) {
+               struct file *f __attribute__((unused))
+                       = collect_file_symlink(pc, proc, names[assocs[i]], assocs[i] * -1,
+                                              sockets_only);
+#if defined(HAVE_STATX) && defined(HAVE_STRUCT_STATX_STX_MNT_ID)
+               if (f && has_mnt_id(f)) {
+                       struct statx stx;
+                       if (ul_path_statx(pc, &stx, AT_NO_AUTOMOUNT|AT_STATX_DONT_SYNC,
+                                         STATX_MNT_ID, names[assocs[i]]) == 0)
+                               f->mnt_id = stx.stx_mnt_id;
+               }
+#endif /* #if defined(HAVE_STATX) && defined(HAVE_STRUCT_STATX_STX_MNT_ID) */
+       }
 }
 
 static void collect_execve_file(struct path_cxt *pc, struct proc *proc,
index a33cebdcac5cf7cd5e2fc2258d996651da84f9ef..daebb9d5626fa99eb426167283f0696b54c37d31 100644 (file)
@@ -226,7 +226,8 @@ struct file {
 #define is_opened_file(_f) ((_f)->association >= 0)
 #define is_mapped_file(_f) (is_association((_f), SHM) || is_association((_f), MEM))
 #define is_association(_f, a)  ((_f)->association < 0 && (_f)->association == -ASSOC_ ## a)
-#define has_mnt_id(_f) (is_opened_file(_f) || is_mapped_file(_f))
+#define has_mnt_id(_f) (is_opened_file(_f) || is_mapped_file(_f) \
+                       || is_association(_f, EXE) || is_association(_f, CWD) || is_association(_f, ROOT))
 
 struct file_class {
        const struct file_class *super;
diff --git a/tests/expected/lsfd/column-mntid-nonroot b/tests/expected/lsfd/column-mntid-nonroot
new file mode 100644 (file)
index 0000000..65a5662
--- /dev/null
@@ -0,0 +1,3 @@
+exe:OK
+cwd:OK
+rtd:OK
diff --git a/tests/ts/lsfd/column-mntid-nonroot b/tests/ts/lsfd/column-mntid-nonroot
new file mode 100755 (executable)
index 0000000..3e8ecdb
--- /dev/null
@@ -0,0 +1,65 @@
+#!/bin/bash
+#
+# Copyright (C) 2025 Masatake YAMATO <yamato@redhat.com>
+#
+# This file is part of util-linux.
+#
+# This file is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This file is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+TS_TOPDIR="${0%/*}/../.."
+TS_DESC="MNTID column"
+
+. "$TS_TOPDIR"/functions.sh
+ts_init "$*"
+ts_skip_docker
+ts_skip_config HAVE_STRUCT_STATX_STX_MNT_ID "cannot get mnt_id via statx(2)"
+
+. "$TS_SELF/lsfd-functions.bash"
+ts_check_test_command "$TS_CMD_LSFD"
+ts_check_test_command "$TS_HELPER_MKFDS"
+ts_check_test_command "$TS_CMD_FINDMNT"
+
+ts_cd "$TS_OUTDIR"
+
+ID_EXE=$("$TS_CMD_FINDMNT" -n -o ID --target "$TS_HELPER_MKFDS" 2>> "$TS_OUTPUT" )
+ID_CWD=$("$TS_CMD_FINDMNT" -n -o ID --target . 2>> "$TS_OUTPUT" )
+ID_RTD=$("$TS_CMD_FINDMNT" -n -o ID --target / 2>> "$TS_OUTPUT" )
+
+{
+    coproc MKFDS { "$TS_HELPER_MKFDS" ro-regular-file 5; }
+
+    if read -u ${MKFDS[0]} PID; then
+       MNTID_EXE=$("$TS_CMD_LSFD" -n -o MNTID -Q 'ASSOC == "exe"' -p "$PID")
+       if [[ "$MNTID_EXE" == "$ID_EXE" ]]; then
+           echo exe:OK
+       else
+           echo exe:ERROR: "MNTID:$MNTID_EXE" != "ID:$ID_EXE"
+       fi
+       MNTID_CWD=$("$TS_CMD_LSFD" -n -o MNTID -Q 'ASSOC == "cwd"' -p "$PID")
+       if [[ "$MNTID_CWD" == "$ID_CWD" ]]; then
+           echo cwd:OK
+       else
+           echo cwd:ERROR: "MNTID:$MNTID_CWD" != "ID:$ID_CWD"
+       fi
+       MNTID_RTD=$("$TS_CMD_LSFD" -n -o MNTID -Q 'ASSOC == "rtd"' -p "$PID")
+       if [[ "$MNTID_RTD" == "$ID_RTD" ]]; then
+           echo rtd:OK
+       else
+           echo rtd:ERROR: "MNTID:$MNTID_RTD" != "ID:$ID_RTD"
+       fi
+    fi
+
+} >> "$TS_OUTPUT" 2>&1
+
+echo DONE >&"${MKFDS[1]}"
+wait "${MKFDS_PID}"
+
+ts_finalize