Debian Codegraph @

tests/ts/lsns/nsfs

raw symbols SCIP
1 #!/bin/bash
2 #
3 # Copyright (C) 2017 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="NSFS for ip-netns-add"
20
21 . "$TS_TOPDIR"/functions.sh
22 ts_init "$*"
23
24 ts_skip_nonroot
25
26 ts_check_enotty
27 ts_check_test_command "$TS_CMD_LSNS"
28 ts_check_test_command "$TS_CMD_MOUNT"
29 ts_check_test_command "$TS_CMD_UMOUNT"
30 ts_check_test_command "$TS_HELPER_SYSINFO"
31 ts_check_prog "ip"
32 ts_check_prog "dd"
33 ts_check_prog "touch"
34 ts_check_prog "mkfifo"
35 ts_check_prog "sed"
36
37 grep -q '#define HAVE_LINUX_NET_NAMESPACE_H' ${top_builddir}/config.h || ts_skip "no netns support"
38
39 if [ "$($TS_HELPER_SYSINFO ns-gettype-ok)" == "0" ]; then
40 ts_skip "NS_GET_NSTYPE ioctl cmd not available"
41 fi
42 if [ "$($TS_HELPER_SYSINFO ns-getuserns-ok)" == "0" ]; then
43 ts_skip "NS_GET_USERNS ioctl cmd not available"
44 fi
45
46 ts_cd "$TS_OUTDIR"
47
48 NAME1=ABC
49 NAME2=XYZ
50 PATH1=/run/netns/$NAME1
51 PATH2=$TS_OUTDIR/$NAME2
52 FIFO=$TS_OUTDIR/FIFO-NSFS
53 NULL=/dev/null
54
55 function cleanup {
56 rm -f $FIFO
57 $TS_CMD_UMOUNT $PATH2 2> /dev/null || :
58 rm -f $PATH2
59 ip netns delete $NAME1 2> /dev/null || :
60 }
61
62 cleanup
63 mkfifo $FIFO
64
65 if ip netns add $NAME1 &&
66 touch ${PATH2} &&
67 $TS_CMD_MOUNT -o bind ${PATH1} ${PATH2}; then
68 ip netns exec $NAME1 dd if=$FIFO bs=1 count=2 of=$NULL 2> $NULL &
69 PID=$!
70 else
71 cleanup
72 ts_skip "failed to initialize"
73 fi
74 {
75 dd if=/dev/zero bs=1 count=1 2> $NULL
76 LSNS_FULL=$($TS_CMD_LSNS --type net)
77 NSFS_NAMES_MLINES=$($TS_CMD_LSNS -n -o NSFS --type net --task $PID | { while read VAL; do echo $VAL; done; } )
78 NSFS_NAMES_1LINE=$($TS_CMD_LSNS -n -o NSFS --nowrap --type net --task $PID | { while read VAL; do echo $VAL; done; } )
79 dd if=/dev/zero bs=1 count=1 2> $NULL
80 } > $FIFO
81
82
83 does_combination_include()
84 {
85 local p1 p2
86 for p1 in "$@"; do
87 for p2 in "$@"; do
88 if [ "$p1" = "$PATH1" ] && [ "$p2" = "$PATH2" ]; then
89 return 0
90 fi
91 done
92 done
93 return 1
94 }
95
96 does_combination_include $NSFS_NAMES_MLINES &&
97 does_combination_include ${NSFS_NAMES_1LINE//,/ }
98
99 RESULT=$?
100 echo $RESULT >> $TS_OUTPUT
101
102 if [ $RESULT -ne 0 ]; then
103 echo
104 echo "**Full-report**"
105 echo "$LSNS_FULL"
106 echo "**Paths**"
107 echo "PATH1: $PATH1"
108 echo "PATH2: $PATH2"
109 echo "**Multi-line:**"
110 echo "$NSFS_NAMES_MLINES"
111 echo "**One-line:**"
112 echo "$NSFS_NAMES_1LINE"
113 echo "****"
114 fi
115
116 cleanup
117 ts_finalize