Debian Codegraph @

tests/ts/lsns/nsfs

raw symbols SCIP
1 #!/bin/bashscip-shell filesystem . . `/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 grepscip-shell system . . grep. -q '#define HAVE_LINUX_NET_NAMESPACE_H' ${top_builddir}/config.h || ts_skip "no netns support"
38
39 if [scip-shell system . . `[`. "$($TS_HELPER_SYSINFO ns-gettype-ok)" == "0" ]; then
40 ts_skip "NS_GET_NSTYPE ioctl cmd not available"
41 fi
42 if [scip-shell system . . `[`. "$($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/nullscip-shell filesystem . . `/dev/null`.
54
55 function cleanupscip-shell shell util-linux 2.42.2-1 cleanup(). {
56 rmscip-shell system . . rm. -f $FIFO
57 $TS_CMD_UMOUNT $PATH2 2> /dev/nullscip-shell filesystem . . `/dev/null`. || :
58 rmscip-shell system . . rm. -f $PATH2
59 ip netns delete $NAME1 2> /dev/nullscip-shell filesystem . . `/dev/null`. || :
60 }
61
62 cleanupscip-shell shell util-linux 2.42.2-1 cleanup().
63 mkfifoscip-shell system . . mkfifo. $FIFO
64
65 if ip netns add $NAME1 &&
66 touchscip-shell system . . 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 cleanupscip-shell shell util-linux 2.42.2-1 cleanup().
72 ts_skip "failed to initialize"
73 fi
74 {
75 ddscip-shell system . . dd. if=/dev/zeroscip-shell filesystem . . `/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 echoscip-shell system . . echo. $VAL; done; } )
78 NSFS_NAMES_1LINE=$($TS_CMD_LSNS -n -o NSFS --nowrap --type net --task $PID | { while read VAL; do echoscip-shell system . . echo. $VAL; done; } )
79 ddscip-shell system . . dd. if=/dev/zeroscip-shell filesystem . . `/dev/zero`. bs=1 count=1 2> $NULL
80 } > $FIFO
81
82
83 does_combination_includescip-shell shell util-linux 2.42.2-1 does_combination_include().()
84 {
85 local p1 p2
86 for p1 in "$@"; do
87 for p2 in "$@"; do
88 if [scip-shell system . . `[`. "$p1" = "$PATH1" ] && [scip-shell system . . `[`. "$p2" = "$PATH2" ]; then
89 return 0
90 fi
91 done
92 done
93 return 1
94 }
95
96 does_combination_includescip-shell shell util-linux 2.42.2-1 does_combination_include(). $NSFS_NAMES_MLINES &&
97 does_combination_includescip-shell shell util-linux 2.42.2-1 does_combination_include(). ${NSFS_NAMES_1LINE//,/ }
98
99 RESULT=$?
100 echoscip-shell system . . echo. $RESULT >> $TS_OUTPUT
101
102 if [scip-shell system . . `[`. $RESULT -ne 0 ]; then
103 echoscip-shell system . . echo.
104 echoscip-shell system . . echo. "**Full-report**"
105 echoscip-shell system . . echo. "$LSNS_FULL"
106 echoscip-shell system . . echo. "**Paths**"
107 echoscip-shell system . . echo. "PATH1: $PATH1"
108 echoscip-shell system . . echo. "PATH2: $PATH2"
109 echoscip-shell system . . echo. "**Multi-line:**"
110 echoscip-shell system . . echo. "$NSFS_NAMES_MLINES"
111 echoscip-shell system . . echo. "**One-line:**"
112 echoscip-shell system . . echo. "$NSFS_NAMES_1LINE"
113 echoscip-shell system . . echo. "****"
114 fi
115
116 cleanupscip-shell shell util-linux 2.42.2-1 cleanup().
117 ts_finalize