| 1 | #!/bin/bashscip-shell filesystem . . `/bin/bash`. |
| 2 | # |
| 3 | # Copyright (C) 2024 Masatake YAMATO <[email protected]> |
| 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 | # https://github.com/util-linux/util-linux/pull/3205 |
| 27 | TS_KNOWN_FAIL="yes" |
| 28 | |
| 29 | ts_check_test_command "$TS_CMD_LSNS" |
| 30 | ts_check_test_command "$TS_CMD_LSFD" |
| 31 | |
| 32 | ts_check_test_command "$TS_HELPER_MKFDS" |
| 33 | |
| 34 | # unshare(2) used in userns factory of test_mkfds reports "Invalid argument". |
| 35 | ts_skip_qemu_user |
| 36 | |
| 37 | lsfd_check_userns |
| 38 | |
| 39 | ts_cd "$TS_OUTDIR" |
| 40 | PID= |
| 41 | FD=4 |
| 42 | RC= |
| 43 | |
| 44 | { |
| 45 | coproc MKFDS { "$TS_HELPER_MKFDS" --comm ABC userns $FD; } |
| 46 | if read -u ${MKFDS[0]} PID; then |
| 47 | lsfd_expr="PID == ${PID} and ASSOC == \"user\"" |
| 48 | inode=$(${TS_CMD_LSFD} -n --raw -o INODE -Q "${lsfd_expr}") |
| 49 | for opt in -Q --filter; do |
| 50 | lsns_expr="NS == $inode && NPROCS == 1" |
| 51 | pid=$(${TS_CMD_LSNS} -n --raw -o PID "$opt" "${lsns_expr}") |
| 52 | if [[ "$pid" = "$PID" ]]; then |
| 53 | echoscip-shell system . . echo. "$opt: pid == PID" |
| 54 | else |
| 55 | echoscip-shell system . . echo. "$opt: pid != PID" |
| 56 | echoscip-shell system . . echo. lsfd_expr: "${lsfd_expr}" |
| 57 | echoscip-shell system . . echo. lsns_expr: "${lsns_expr}" |
| 58 | echoscip-shell system . . echo. pid: "${pid}" |
| 59 | echoscip-shell system . . echo. PID: "${PID}" |
| 60 | echoscip-shell system . . echo. inode: "${inode}" |
| 61 | echoscip-shell system . . echo. lsfd: |
| 62 | ${TS_CMD_LSFD} -n --raw $opt "${lsfd_expr}" |
| 63 | echoscip-shell system . . echo. lsns:"${lsns_expr}" |
| 64 | ${TS_CMD_LSNS} -n --raw $opt "${lsns_expr}" |
| 65 | echoscip-shell system . . echo. lsns:inode: |
| 66 | ${TS_CMD_LSNS} -n --raw $opt "NS == $inode" |
| 67 | echoscip-shell system . . echo. lsns:NPROCS: |
| 68 | ${TS_CMD_LSNS} -n --raw $opt "NPROCS == 1" |
| 69 | echoscip-shell system . . echo. lsns |
| 70 | ${TS_CMD_LSNS} -n --raw |
| 71 | fi |
| 72 | done |
| 73 | echoscip-shell system . . echo. DONE >&"${MKFDS[1]}" |
| 74 | fi |
| 75 | wait "${MKFDS_PID}" |
| 76 | RC=$? |
| 77 | } > $TS_OUTPUT 2>&1 |
| 78 | if [scip-shell system . . `[`. "$RC" == "$EPERM" ]; then |
| 79 | ts_skip "unshare(2) is not permitted on this platform" |
| 80 | fi |
| 81 | ts_finalize |