| 1 |
#!/bin/bash |
| 2 |
# |
| 3 |
# Copyright (C) 2022 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 |
TS_TOPDIR="${0%/*}/../.." |
| 18 |
TS_DESC="UNIX stream sockets" |
| 19 |
|
| 20 |
. "$TS_TOPDIR"/functions.sh |
| 21 |
ts_init "$*" |
| 22 |
|
| 23 |
. "$TS_SELF/lsfd-functions.bash" |
| 24 |
|
| 25 |
ts_check_test_command "$TS_CMD_LSFD" |
| 26 |
ts_check_test_command "$TS_HELPER_MKFDS" |
| 27 |
|
| 28 |
ts_cd "$TS_OUTDIR" |
| 29 |
|
| 30 |
PID= |
| 31 |
FDS=3 |
| 32 |
FDC=4 |
| 33 |
FDA=5 |
| 34 |
EXPR='(((TYPE == "UNIX-STREAM") or (TYPE == "UNIX")) and (FD >= 3) and (FD <= 5))' |
| 35 |
|
| 36 |
{ |
| 37 |
for t in stream seqpacket; do |
| 38 |
# TYPE is not tested here; AF_UNIX+SOCK_STREAM socket type was changed from "UNIX" |
| 39 |
# to "UNIX-STREAM" at a time in Linux kernel development history. |
| 40 |
coproc MKFDS { "$TS_HELPER_MKFDS" unix-stream $FDS $FDC $FDA \ |
| 41 |
path=test_mkfds-unix-${t} \ |
| 42 |
type=$t ; } |
| 43 |
if read -r -u "${MKFDS[0]}" PID; then |
| 44 |
${TS_CMD_LSFD} -n \ |
| 45 |
-o ASSOC,STTYPE,NAME,SOCK.STATE,SOCK.TYPE,SOCK.LISTENING,UNIX.PATH \ |
| 46 |
-p "${PID}" -Q "${EXPR}" | lsfd_strip_type_stream |
| 47 |
echo 'ASSOC,STTYPE,NAME,SOCK.STATE,SOCK.TYPE,SOCK.LISTENING,UNIX.PATH': ${PIPESTATUS[0]} |
| 48 |
|
| 49 |
echo DONE >&"${MKFDS[1]}" |
| 50 |
fi |
| 51 |
wait "${MKFDS_PID}" |
| 52 |
|
| 53 |
coproc MKFDS { "$TS_HELPER_MKFDS" unix-stream $FDS $FDC $FDA \ |
| 54 |
path=test_mkfds-unix-${t}-abs \ |
| 55 |
abstract=true ; } |
| 56 |
if read -r -u "${MKFDS[0]}" PID; then |
| 57 |
${TS_CMD_LSFD} -n \ |
| 58 |
-o ASSOC,STTYPE,NAME,SOCK.STATE,SOCK.TYPE,SOCK.LISTENING,UNIX.PATH \ |
| 59 |
-p "${PID}" -Q "${EXPR}" | lsfd_strip_type_stream |
| 60 |
echo '(abs) ASSOC,STTYPE,NAME,SOCK.STATE,SOCK.TYPE,SOCK.LISTENING,UNIX.PATH': ${PIPESTATUS[0]} |
| 61 |
|
| 62 |
echo DONE >&"${MKFDS[1]}" |
| 63 |
fi |
| 64 |
wait "${MKFDS_PID}" |
| 65 |
|
| 66 |
coproc MKFDS { "$TS_HELPER_MKFDS" unix-stream $FDS $FDC $FDA \ |
| 67 |
path=test_mkfds-unix-${t}-shutdown \ |
| 68 |
server-shutdown=3 \ |
| 69 |
client-shutdown=3 \ |
| 70 |
type=$t ; } |
| 71 |
if read -r -u "${MKFDS[0]}" PID; then |
| 72 |
${TS_CMD_LSFD} -n \ |
| 73 |
-o ASSOC,STTYPE,NAME,SOCK.STATE,SOCK.TYPE,SOCK.LISTENING,UNIX.PATH \ |
| 74 |
-p "${PID}" -Q "${EXPR}" | lsfd_strip_type_stream |
| 75 |
echo '(shutdown) ASSOC,STTYPE,NAME,SOCK.STATE,SOCK.TYPE,SOCK.LISTENING,UNIX.PATH': ${PIPESTATUS[0]} |
| 76 |
# Surprisingly, the socket status doesn't change at all. |
| 77 |
|
| 78 |
echo DONE >&"${MKFDS[1]}" |
| 79 |
fi |
| 80 |
wait "${MKFDS_PID}" |
| 81 |
|
| 82 |
coproc MKFDS { "$TS_HELPER_MKFDS" unix-stream $FDS $FDC $FDA \ |
| 83 |
path="test_mkfds-unix with spaces ${t}" \ |
| 84 |
type=$t ; } |
| 85 |
if read -r -u "${MKFDS[0]}" PID; then |
| 86 |
${TS_CMD_LSFD} -n \ |
| 87 |
-o ASSOC,STTYPE,NAME,SOCK.STATE,SOCK.TYPE,SOCK.LISTENING,UNIX.PATH \ |
| 88 |
-p "${PID}" -Q "${EXPR}" | lsfd_strip_type_stream |
| 89 |
echo 'ASSOC,STTYPE,NAME,SOCK.STATE,SOCK.TYPE,SOCK.LISTENING,UNIX.PATH': ${PIPESTATUS[0]} |
| 90 |
|
| 91 |
echo DONE >&"${MKFDS[1]}" |
| 92 |
fi |
| 93 |
wait "${MKFDS_PID}" |
| 94 |
|
| 95 |
done |
| 96 |
} > "$TS_OUTPUT" 2>&1 |
| 97 |
|
| 98 |
ts_finalize |