]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
tests: (lsfd) adjust the output for unix datagram sockets created by socketpair
authorMasatake YAMATO <yamato@redhat.com>
Sat, 15 Apr 2023 11:50:29 +0000 (20:50 +0900)
committerMasatake YAMATO <yamato@redhat.com>
Sun, 16 Apr 2023 12:08:45 +0000 (21:08 +0900)
Though older kernels report such sockets as "unconnected" via /proc/net/unix,
the newer kernels report them as "connected". The change is introduced in
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=83301b5367a98c17ec0d76c7bc0ccdc3c7e7ad6d

This caused a failure in a test case. To avoid the failure,
this change rewrites "state=unconnected" in the lsfd's output
to "state=connected".

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
tests/ts/lsfd/column-name
tests/ts/lsfd/lsfd-functions.bash

index 7dff8f7b23e0a86bcc8d97735789b956c905a740..dba86b9b694f0d303dfb94fafc5df8d8165ce064 100755 (executable)
@@ -31,6 +31,15 @@ PID=
 FD=3
 EXPR="(FD == 3)"
 
+make_state_connected()
+{
+    if [ "$1" = "socketpair" ]; then
+       lsfd_make_state_connected
+    else
+       cat
+    fi
+}
+
 for C in ro-regular-file pidfd socketpair; do
     ts_init_subtest $C
     {
@@ -47,7 +56,7 @@ for C in ro-regular-file pidfd socketpair; do
            ${TS_CMD_LSFD} -n -o ASSOC,KNAME,NAME -p "${PID}" -Q "${EXPR}" | {
                # Replace the unpredictable an inode number for the socket
                # with "INODENUM".
-               sed -e 's/\[[0-9]\+\]/[INODENUM]/g'
+               sed -e 's/\[[0-9]\+\]/[INODENUM]/g' | make_state_connected $C
            }
            echo "$C"':ASSOC,KNAME,NAME': ${PIPESTATUS[0]}
 
index 1ebc327592ad7045983c511a76dcf88589f5d941..8f68db930f4969697dc5b7602b5d6577183352e7 100644 (file)
@@ -66,3 +66,16 @@ lsfd_strip_type_stream()
     # NAME column. Let's delete the appended string before comparing.
     sed -e 's/ type=stream//'
 }
+
+lsfd_make_state_connected()
+{
+    # Newer kernels report the states of unix dgram sockets created by
+    # sockerpair(2) are "connected" via /proc/net/unix though Older
+    # kernels report "unconnected".
+    #
+    # https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=83301b5367a98c17ec0d76c7bc0ccdc3c7e7ad6d
+    #
+    # This rewriting adjusts the output of lsfd running on older kernels
+    # to that on newer kernels.
+    sed -e 's/state=unconnected/state=connected/'
+}