]> git.ipfire.org Git - thirdparty/util-linux.git/blob - tests/ts/lsns/filter
tests: (lsns::filter) delete an unused variable
[thirdparty/util-linux.git] / tests / ts / lsns / filter
1 #!/bin/bash
2 #
3 # Copyright (C) 2024 Masatake YAMATO <yamato@redhat.com>
4 #
5 # This file is part of util-linux.
6 #
7 # This file is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
11 #
12 # This file is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 TS_TOPDIR="${0%/*}/../.."
18 TS_DESC="-Q, --filter option"
19
20 . "$TS_TOPDIR"/functions.sh
21 # for $EPERM
22 . "$TS_TOPDIR"/ts/lsfd/lsfd-functions.bash
23
24 ts_init "$*"
25
26 ts_check_test_command "$TS_CMD_LSNS"
27 ts_check_test_command "$TS_CMD_LSFD"
28
29 ts_check_test_command "$TS_HELPER_MKFDS"
30
31 # unshare(2) used in userns factory of test_mkfds reports "Invalid argument".
32 ts_skip_qemu_user
33
34 ts_cd "$TS_OUTDIR"
35 PID=
36 FD=4
37
38 {
39 coproc MKFDS { "$TS_HELPER_MKFDS" --comm ABC userns $FD; }
40 if read -u ${MKFDS[0]} PID; then
41 expr="PID == \"${PID}\" and ASSOC == \"user\""
42 inode=$(${TS_CMD_LSFD} -n --raw -o INODE -Q "${expr}")
43 for opt in -Q --filter; do
44 pid=$(${TS_CMD_LSNS} -n --raw -o PID "$opt" "NS == $inode && NPROCS == 1")
45 if [[ "$pid" = "$PID" ]]; then
46 echo "$opt: pid == PID"
47 else
48 echo "$opt: pid != PID"
49 echo expr: "${expr}"
50 ${TS_CMD_LSFD} -n --raw -o INODE -Q "${expr}"
51 echo inode: "${inode}"
52 ${TS_CMD_LSNS} -n --raw -o PID -Q "NS == $inode && NPROCS == 1"
53 echo pid: "${pid}"
54 echo PID: "${PID}"
55 fi
56 done
57 echo DONE >&"${MKFDS[1]}"
58 fi
59 wait "${MKFDS_PID}"
60 } > $TS_OUTPUT 2>&1
61 if [ "$?" == "$EPERM" ]; then
62 ts_skip "unshare(2) is not permitted on this platform"
63 fi
64 ts_finalize