]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lsfd: add "nsfs" to the nodev_table to fill SOURCE column for nsfs files
authorMasatake YAMATO <yamato@redhat.com>
Tue, 21 Mar 2023 16:22:18 +0000 (01:22 +0900)
committerMasatake YAMATO <yamato@redhat.com>
Tue, 23 May 2023 16:02:02 +0000 (01:02 +0900)
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
misc-utils/lsfd-sock-xinfo.c
tests/expected/lsfd/column-source-namespace-ASSOC [new file with mode: 0644]
tests/ts/lsfd/column-source [new file with mode: 0755]

index 3a11b75f00e8fadde07adc0800a8dd34ff5b96ea..5869828324a4e9a6f79c3ec9cbdbeb00ad4e47bd 100644 (file)
@@ -212,8 +212,12 @@ void initialize_sock_xinfos(void)
                load_sock_xinfo_no_nsswitch(NULL);
        else {
                if (fstat(self_netns_fd, &self_netns_sb) == 0) {
+                       unsigned long m;
                        struct netns *nsobj = mark_sock_xinfo_loaded(self_netns_sb.st_ino);
                        load_sock_xinfo_no_nsswitch(nsobj);
+
+                       m = minor(self_netns_sb.st_dev);
+                       add_nodev(m, "nsfs");
                }
        }
 
diff --git a/tests/expected/lsfd/column-source-namespace-ASSOC b/tests/expected/lsfd/column-source-namespace-ASSOC
new file mode 100644 (file)
index 0000000..8b26e32
--- /dev/null
@@ -0,0 +1,7 @@
+  ipc   nsfs
+  mnt   nsfs
+  net   nsfs
+  pid   nsfs
+pid4c   nsfs
+ user   nsfs
+  uts   nsfs
diff --git a/tests/ts/lsfd/column-source b/tests/ts/lsfd/column-source
new file mode 100755 (executable)
index 0000000..a74f9de
--- /dev/null
@@ -0,0 +1,51 @@
+#!/bin/bash
+#
+# Copyright (C) 2023 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="SOURCE column"
+
+. "$TS_TOPDIR"/functions.sh
+ts_init "$*"
+
+. "$TS_SELF/lsfd-functions.bash"
+ts_check_test_command "$TS_CMD_LSFD"
+
+ts_cd "$TS_OUTDIR"
+
+declare -a NAMESPACES=(
+    cgorup
+    ipc
+    mnt
+    net
+    pid
+    pid4c
+    # older kernel doesn't support time namespace.
+    # time
+    # time4c
+    user
+    uts
+)
+ts_init_subtest namespace-ASSOC
+{
+    EXPR="false"
+    for ns in "${NAMESPACES[@]}"; do
+       EXPR=${EXPR}' || (ASSOC == "'"$ns"'")'
+    done
+    ${TS_CMD_LSFD} -p $$ -n -o ASSOC,SOURCE -Q "$EXPR"
+} > "$TS_OUTPUT" 2>&1
+ts_finalize_subtest
+
+ts_finalize