]>
Commit | Line | Data |
---|---|---|
c5eb81b3 MY |
1 | #!/bin/bash |
2 | # | |
3 | # Copyright (C) 2022 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="netns associated with a fd" | |
19 | ||
20 | . "$TS_TOPDIR"/functions.sh | |
21 | ts_init "$*" | |
22 | ts_skip_nonroot | |
d53284bb | 23 | ts_skip_docker |
c5eb81b3 | 24 | |
7b061401 | 25 | . "$TS_SELF/lsfd-functions.bash" |
c5eb81b3 MY |
26 | ts_check_test_command "$TS_CMD_LSFD" |
27 | ts_check_test_command "$TS_HELPER_MKFDS" | |
28 | ||
29 | ts_cd "$TS_OUTDIR" | |
30 | ||
31 | PID= | |
32 | FD=3 | |
33 | NAME_FD= | |
34 | NAME_NS= | |
35 | INO_FD= | |
36 | INO_NS= | |
37 | { | |
38 | coproc MKFDS { "$TS_HELPER_MKFDS" netns "$FD"; } | |
39 | if read -r -u "${MKFDS[0]}" PID; then | |
40 | "${TS_CMD_LSFD}" -n -oNS.TYPE -p "${PID}" -Q "(FD == $FD)" | |
41 | NAME_FD=$("${TS_CMD_LSFD}" -n -oNS.NAME -p "${PID}" -Q "(FD == $FD)") | |
42 | NAME_NS=$("${TS_CMD_LSFD}" -n -oNS.NAME -p "${PID}" -Q '(ASSOC == "net")') | |
43 | INO_FD=$( "${TS_CMD_LSFD}" -n -oINODE -p "${PID}" -Q "(FD == $FD)") | |
44 | INO_NS=$( "${TS_CMD_LSFD}" -n -oINODE -p "${PID}" -Q '(ASSOC == "net")') | |
45 | ||
55a9ad3e MY |
46 | if [[ "$NAME_FD" = "$NAME_NS" ]]; then |
47 | echo "NAME_FD" == "NAME_NS": $? | |
48 | else | |
49 | echo "NAME_FD: $NAME_FD" == "NAME_NS: $NAME_NS": $? | |
50 | fi | |
c5eb81b3 | 51 | |
55a9ad3e MY |
52 | if [[ "$NAME_FD" = "net:[$INO_FD]" ]]; then |
53 | echo "NAME_FD" == "net:[INO_FD]": $? | |
54 | else | |
55 | echo "NAME_FD: $NAME_FD" == "net:[INO_FD: $INO_FD]": $? | |
56 | fi | |
c5eb81b3 | 57 | |
55a9ad3e MY |
58 | if [[ "$NAME_FD" = "net:[$INO_NS]" ]]; then |
59 | echo "NAME_FD" == "net:[INO_NS]": $? | |
60 | else | |
61 | echo "NAME_FD: $NAME_FD" == "net:[INO_NS: $INO_NS]": $? | |
62 | fi | |
c5eb81b3 | 63 | |
0fec4965 | 64 | echo DONE >&"${MKFDS[1]}" |
c5eb81b3 MY |
65 | fi |
66 | wait "${MKFDS_PID}" | |
67 | } > "$TS_OUTPUT" 2>&1 | |
73a0eecf | 68 | if [ "$?" == "$TS_EXIT_NOTSUPP" ]; then |
7b061401 MY |
69 | ts_skip "ioctl(fd, SIOCGSKNS) is not available" |
70 | fi | |
c5eb81b3 MY |
71 | |
72 | ts_finalize |