--- /dev/null
+#!/bin/bash
+#
+# Copyright (C) 2024 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="-Q, --filter option"
+
+. "$TS_TOPDIR"/functions.sh
+# for $EPERM
+. "$TS_TOPDIR"/ts/lsfd/lsfd-functions.bash
+
+ts_init "$*"
+
+ts_check_test_command "$TS_CMD_LSNS"
+ts_check_test_command "$TS_CMD_LSFD"
+
+ts_check_test_command "$TS_HELPER_MKFDS"
+
+# unshare(2) used in userns factory of test_mkfds reports "Invalid argument".
+ts_skip_qemu_user
+
+ts_cd "$TS_OUTDIR"
+PID=
+FD=4
+EXPR=
+
+{
+ coproc MKFDS { "$TS_HELPER_MKFDS" --comm ABC userns $FD; }
+ if read -u ${MKFDS[0]} PID; then
+ expr="PID == \"${PID}\" and ASSOC == \"user\""
+ inode=$(${TS_CMD_LSFD} -n --raw -o INODE -Q "${expr}")
+ for opt in -Q --filter; do
+ pid=$(${TS_CMD_LSNS} -n --raw -o PID "$opt" "NS == $inode && NPROCS == 1")
+ if [[ "$pid" = "$PID" ]]; then
+ echo "$opt: pid == PID"
+ else
+ echo "$opt: pid != PID"
+ echo expr: "${expr}"
+ ${TS_CMD_LSFD} -n --raw -o INODE -Q "${expr}"
+ echo inode: "${inode}"
+ ${TS_CMD_LSNS} -n --raw -o PID -Q "NS == $inode && NPROCS == 1"
+ echo pid: "${pid}"
+ echo PID: "${PID}"
+ fi
+ done
+ echo DONE >&"${MKFDS[1]}"
+ fi
+ wait "${MKFDS_PID}"
+} > $TS_OUTPUT 2>&1
+if [ "$?" == "$EPERM" ]; then
+ ts_skip "unshare(2) is not permitted on this platform"
+fi
+ts_finalize