File: filedesc

package info (click to toggle)
util-linux 2.41.3-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 93,056 kB
  • sloc: ansic: 179,151; sh: 22,716; yacc: 1,284; makefile: 527; xml: 422; python: 316; lex: 89; ruby: 75; csh: 37; exp: 19; sed: 16; perl: 15; sql: 9
file content (81 lines) | stat: -rwxr-xr-x 2,174 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/bin/bash
#
# Copyright (C) 2024 Masatake YAMATO <yamato@redhat.com>
#
# This file is part of util-linux.
#
# This file is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This file is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#

# This test case is based on the issue (#1884) submitted by @hesch
TS_TOPDIR="${0%/*}/../.."
TS_DESC="list the namespace pointed by a file descriptor"

. "$TS_TOPDIR"/functions.sh
ts_init "$*"

ts_check_test_command "$TS_CMD_LSNS"
ts_check_test_command "$TS_CMD_LSFD"
ts_check_test_command "$TS_HELPER_MKFDS"
ts_check_test_command "$TS_HELPER_SYSINFO"

ts_check_prog "ip"

ts_skip_nonroot

if [ "$($TS_HELPER_SYSINFO ns-gettype-ok)" == "0" ]; then
    ts_skip "NS_GET_NSTYPE ioctl cmd not available"
fi

if [ "$($TS_HELPER_SYSINFO ns-getuserns-ok)" == "0" ]; then
    ts_skip "NS_GET_USERNS ioctl cmd not available"
fi

FD=4
NS=LSNS-TEST-FILEDESC-NS
FILE=/run/netns/$NS
PID=

cleanup()
{
    ip netns delete $NS 2> /dev/null || :
}

cleanup

if ! ip netns add $NS; then
   ts_skip "failed to make a namespace"
fi
trap "cleanup" EXIT

{
    coproc MKFDS { "$TS_HELPER_MKFDS" ro-regular-file $FD file=$FILE; }
    if read -u ${MKFDS[0]} PID; then
	# Make the namespace invisible from the file system tree.
	cleanup
	lsfd_expr="PID == ${PID} and FD == $FD"
	lsfd_inode=$(${TS_CMD_LSFD} -n --raw -o INODE -Q "${lsfd_expr}")
	lsns_expr="NS == $lsfd_inode"
	lsns_output=$(${TS_CMD_LSNS}    -n --raw -o TYPE,NPROCS,USER -Q "${lsns_expr}")
	if ! [ "${lsns_output}" == "net 0 root" ]; then
	    echo lsfd_inode: $lsfd_inode
	    echo lsns_output: $lsns_output
	    echo LSFD:
	    ${TS_CMD_LSFD} -Q "PID == $PID"
	    echo LSNS:
	    LSNS_DEBUG=all ${TS_CMD_LSNS}
	    echo lsns_status: $?
	fi
	echo DONE >&"${MKFDS[1]}"
    fi
    wait "${MKFDS_PID}"
} > $TS_OUTPUT 2>&1
ts_finalize