Debian Codegraph @

tests/ts/lsns/netns-from-sock

raw
1 #!/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
18 TS_TOPDIR="${0%/*}/../.."
19 TS_DESC="find an isolated net namespace via socket"
20
21 . "$TS_TOPDIR"/functions.sh
22 # for $EPERM
23 . "$TS_TOPDIR"/ts/lsfd/lsfd-functions.bash
24
25 ts_init "$*"
26
27 ts_check_test_command "$TS_CMD_LSNS"
28 ts_check_test_command "$TS_HELPER_MKFDS"
29 ts_check_test_command "$TS_HELPER_SYSINFO"
30
31 ts_skip_nonroot
32
33 if [ "$($TS_HELPER_SYSINFO ns-gettype-ok)" == "0" ]; then
34 ts_skip "NS_GET_NSTYPE ioctl cmd not available"
35 fi
36 if [ "$($TS_HELPER_SYSINFO ns-getuserns-ok)" == "0" ]; then
37 ts_skip "NS_GET_USERNS ioctl cmd not available"
38 fi
39
40 ts_cd "$TS_OUTDIR"
41
42 declare -A tcase
43 tcase[NS]=
44 tcase[TYPE]=net
45 tcase[NPROCS]=0
46 tcase[PID]=
47 tcase[USER]=root
48 tcase[COMMAND]=
49
50 PID_UNUSED=
51 NETNS=
52 RC=
53
54 {
55 coproc MKFDS { "$TS_HELPER_MKFDS" foreign-sockets 3 4; }
56 if read -r -u "${MKFDS[0]}" PID_UNUSED NETNS; then
57 tcase[NS]=${NETNS}
58
59 for t in $(for t0 in "${!tcase[@]}"; do echo "$t0"; done | sort); do
60 column=$t
61 expected=${tcase[$t]}
62 output=$(${TS_CMD_LSNS} --noheadings --raw --output $column --filter "NS == $NETNS")
63 echo "$column \$? $?"
64
65 if [[ "${output}" == "$expected" ]]; then
66 echo "$column == 0"
67 else
68 echo "$column == 1"
69 echo expected: "$expected"
70 echo actual: "$output"
71 fi
72 done
73 echo DONE >&"${MKFDS[1]}"
74 fi
75
76 wait "${MKFDS_PID}"
77 RC=$?
78 } > $TS_OUTPUT 2>&1
79 if [[ "$RC" == "$EPERM" ]]; then
80 ts_skip "unshare(2) is not permitted on this platform"
81 fi
82 ts_finalize