]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
tests: (lsfd::*) revise the way to use "$?"
authorMasatake YAMATO <yamato@redhat.com>
Tue, 24 Feb 2026 17:58:02 +0000 (02:58 +0900)
committerMasatake YAMATO <yamato@redhat.com>
Tue, 24 Feb 2026 18:23:29 +0000 (03:23 +0900)
* Don't use $? for printing the result of if-conditions; use
  literals instead (0 or 1).

* Don' use $? for referring to the result of wait built-in; store the
  result to $RC just after the wait built-in invocation.

* Use ${PIPESTATUS[]} instead of $?.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
17 files changed:
tests/ts/lsfd/column-ainodeclass
tests/ts/lsfd/column-name
tests/ts/lsfd/column-type
tests/ts/lsfd/column-xmode
tests/ts/lsfd/filter-floating-point-nums
tests/ts/lsfd/mkfds-bpf-map
tests/ts/lsfd/mkfds-bpf-prog
tests/ts/lsfd/mkfds-cdev-tun
tests/ts/lsfd/mkfds-directory
tests/ts/lsfd/mkfds-eventfd
tests/ts/lsfd/mkfds-foreign-sockets
tests/ts/lsfd/mkfds-netlink-groups
tests/ts/lsfd/mkfds-netlink-protocol
tests/ts/lsfd/mkfds-netns
tests/ts/lsfd/mkfds-pidfd
tests/ts/lsfd/mkfds-pipe-no-fork
tests/ts/lsfd/mkfds-unix-in-netns

index ab2abebd6ade225765a264dce383e8e7487cb0ac..01b5d6891c4e8d2772d2af8847952448c6aa9912 100755 (executable)
@@ -29,8 +29,10 @@ ts_cd "$TS_OUTDIR"
 PID=
 FD=3
 EXPR="(FD == 3)"
+RC=
 
 for C in pidfd inotify; do
+    RC=
     ts_init_subtest $C
     {
        coproc MKFDS { "$TS_HELPER_MKFDS" $C $FD ; }
@@ -41,9 +43,10 @@ for C in pidfd inotify; do
            echo DONE >&"${MKFDS[1]}"
        fi
        wait "${MKFDS_PID}"
+       RC=$?
     } > "$TS_OUTPUT" 2>&1
 
-    if [ "$C-$?" == "pidfd-$TS_EXIT_NOTSUPP" ]; then
+    if [ "$C-$RC" == "pidfd-$TS_EXIT_NOTSUPP" ]; then
        ts_skip_subtest "pidfd_open(2) is not available"
        continue
     fi
index 9c67de889351003da127bfc14c09c0a5f66129a6..00b47c6bb3948835c6f9805ad50f68d36c9f6f21 100755 (executable)
@@ -30,6 +30,7 @@ ts_cd "$TS_OUTDIR"
 PID=
 FD=3
 EXPR="(FD == 3)"
+RC=
 
 make_state_connected()
 {
@@ -41,6 +42,7 @@ make_state_connected()
 }
 
 for C in ro-regular-file pidfd socketpair; do
+    RC=
     ts_init_subtest $C
     {
        coproc MKFDS {
@@ -64,8 +66,9 @@ for C in ro-regular-file pidfd socketpair; do
        fi
     } > "$TS_OUTPUT" 2>&1
     wait "${MKFDS_PID}"
+    RC=$?
 
-    if [ "$C-$?" == "pidfd-$TS_EXIT_NOTSUPP" ]; then
+    if [ "$C-$RC" == "pidfd-$TS_EXIT_NOTSUPP" ]; then
        ts_skip_subtest "pidfd_open(2) is not available"
        continue
     fi
index 1b8aa8c6fc511a650aac1119f897e6084f17a967..73dab873af764535e5d0be251093b321cb2e61fa 100755 (executable)
@@ -29,8 +29,10 @@ ts_cd "$TS_OUTDIR"
 PID=
 FD=3
 EXPR="(FD == 3)"
+RC=
 
 for C in ro-regular-file pidfd inotify socketpair; do
+    RC=
     ts_init_subtest $C
     {
        coproc MKFDS {
@@ -49,9 +51,10 @@ for C in ro-regular-file pidfd inotify socketpair; do
            echo DONE >&"${MKFDS[1]}"
        fi
        wait "${MKFDS_PID}"
+       RC=$?
     } > "$TS_OUTPUT" 2>&1
 
-    if [ "$C-$?" == "pidfd-$TS_EXIT_NOTSUPP" ]; then
+    if [ "$C-$RC" == "pidfd-$TS_EXIT_NOTSUPP" ]; then
        ts_skip_subtest "pidfd_open(2) is not available"
        continue
     fi
index 1e719a4a51060297c83a7e1ccfc2f6a46bd63659..048be3b5db64c42c269d7207e7f2e6399016df6b 100755 (executable)
@@ -131,6 +131,7 @@ ts_init_subtest "XMODE-D-bit"
 wait "${MKFDS_PID}"
 ts_finalize_subtest
 
+RC=
 for m in flock-sh posix-r- ofd-r-; do
     ts_init_subtest "XMODE-l-bit-$m"
     {
@@ -143,7 +144,8 @@ for m in flock-sh posix-r- ofd-r-; do
        fi
     } > "$TS_OUTPUT" 2>&1
     wait "${MKFDS_PID}"
-    if [ "$?" == "$TS_EXIT_NOTSUPP" ]; then
+    RC=$?
+    if [ "$RC" == "$TS_EXIT_NOTSUPP" ]; then
        ts_skip_subtest "$m lock is not available"
        continue
     fi
@@ -165,6 +167,7 @@ wait "${MKFDS_PID}"
 rm -f "$f"
 ts_finalize_subtest
 
+RC=
 for m in flock-ex posix--w posix-rw  ofd--w ofd-rw lease-w; do
     ts_init_subtest "XMODE-L-bit-$m"
     {
@@ -177,7 +180,8 @@ for m in flock-ex posix--w posix-rw  ofd--w ofd-rw lease-w; do
        fi
     } > "$TS_OUTPUT" 2>&1
     wait "${MKFDS_PID}"
-    if [ "$?" == "$TS_EXIT_NOTSUPP" ]; then
+    RC=$?
+    if [ "$RC" == "$TS_EXIT_NOTSUPP" ]; then
        ts_skip_subtest "$m lock is not available"
        continue
     fi
index 7f66dd51d3fe1cb6902a1abc8a8b852fb465f321..f7d13759278864a00cd63b6ef698a206f780c316 100755 (executable)
@@ -39,9 +39,9 @@ EXPR=
        echo "pid in a range:" $?
 
        if [[ "${PID_0}" == "${PID}" ]]; then
-           echo "coparing pids": $?
+           echo "coparing pids": 0
        else
-           echo "coparing pids": $? "PID_0:${PID_0} == PID:${PID}"
+           echo "coparing pids": 1 "PID_0:${PID_0} == PID:${PID}"
        fi
 
        EXPR='(TIMERFD.INTERVAL < 10.000051) and (TIMERFD.INTERVAL > 10)'
index 7821fe50625ba8e9eb69fc9688e9298008eee1f4..d4fb8e7afdd045dd35c28a07e0239434ef12f98d 100755 (executable)
@@ -31,6 +31,8 @@ ts_cd "$TS_OUTDIR"
 PID=
 FD=3
 NAME=mkfds_map
+RC=
+
 {
     coproc MKFDS { "$TS_HELPER_MKFDS" bpf-map "$FD" map-type-id=2 name="$NAME"; }
     if read -r -u "${MKFDS[0]}" PID; then
@@ -40,9 +42,10 @@ NAME=mkfds_map
        echo DONE >&"${MKFDS[1]}"
     fi
     wait "${MKFDS_PID}"
+    RC=$?
 } > "$TS_OUTPUT" 2>&1
 
-if [ "$?" == "$TS_EXIT_NOTSUPP" ]; then
+if [ "$RC" == "$TS_EXIT_NOTSUPP" ]; then
     ts_skip "bpf(2) is not available"
 fi
 
index 1ec4cbf8ffefa04dc004685c0735c4fd7bc3eac1..c7ef895e4d294669bb7c422cb7c5bca63950f3c4 100755 (executable)
@@ -33,6 +33,8 @@ ID=
 TAG=
 FD=3
 NAME=mkdfs_prog
+RC=
+
 {
     coproc MKFDS { "$TS_HELPER_MKFDS" bpf-prog "$FD" prog-type-id=2 name="$NAME"; }
     if read -r -u "${MKFDS[0]}" PID ID TAG; then
@@ -56,9 +58,10 @@ NAME=mkdfs_prog
        echo DONE >&"${MKFDS[1]}"
     fi
     wait "${MKFDS_PID}"
+    RC=$?
 } > "$TS_OUTPUT" 2>&1
 
-if [ "$?" == "$TS_EXIT_NOTSUPP" ]; then
+if [ "$RC" == "$TS_EXIT_NOTSUPP" ]; then
     ts_skip "bpf(2) is not available"
 fi
 
index 5848f18bd49a1dc7cdbf69f1af1fac332b62e0da..f6987401066266ba809255c48b3d1da605d734be 100755 (executable)
@@ -68,12 +68,12 @@ cdev_tun_test()
 
            output=$(${TS_CMD_LSFD} -p "${PID}" -n --raw -o NAME -Q "${EXPR}")
            if [[ "$output" =~ "iface=$IFNAME"(\\x20devnetns=$netns)? ]]; then
-               echo 'NAME': $?
+               echo 'NAME': 0
                if [[ -n "${BASH_REMATCH[1]}" ]]; then
                    devnetns_available=yes
                fi
            else
-               echo 'NAME': $?
+               echo 'NAME': 1
                echo "expected NAME: iface=$IFNAME"
                echo "output NAME: $output"
                echo "netns: $netns"
@@ -81,9 +81,9 @@ cdev_tun_test()
 
            output=$(${TS_CMD_LSFD} -p "${PID}" -n --raw -o TUN.IFACE -Q "${EXPR}")
            if [[ "$output" == "$IFNAME" ]]; then
-               echo 'TUN.IFACE': $?
+               echo 'TUN.IFACE': 0
            else
-               echo 'TUN.IFACE': $?
+               echo 'TUN.IFACE': 1
                echo "expected TUN.IFACE: $IFNAME"
                echo "output TUN.IFACE: $output"
            fi
@@ -98,9 +98,9 @@ cdev_tun_test()
        {
            output=$(${TS_CMD_LSFD} -p "${PID}" -n --raw -o TUN.DEVNETNS -Q "${EXPR}")
            if [[ "$output" == "$netns" ]]; then
-               echo 'TUN.DEVNETNS': $?
+               echo 'TUN.DEVNETNS': 0
            else
-               echo 'TUN.DEVNETNS': $?
+               echo 'TUN.DEVNETNS': 1
                echo "expected TUN.DEVNETNS: $netns"
                echo "output TUN.DEVNETNS: $output"
            fi
index 272bdb3878978d604c6fa4f1943b39c1936520f4..2e0ac24c0b5693609e87a932a6c7b6f47da9e746 100755 (executable)
@@ -71,7 +71,7 @@ esac
                cat
            fi
        }
-       echo 'ASSOC,MODE,TYPE,FLAGS,NAME': $?
+       echo 'ASSOC,MODE,TYPE,FLAGS,NAME': ${PIPESTATUS[0]}
 
        LSFD_PID=$(${TS_CMD_LSFD} --raw -n -o PID -Q "${EXPR}")
        echo 'PID[RUN]:' $?
index 02c86a604a829cb31ef4e1de278ce6650488e7c5..d21b11252cff8fe6567b2c2acdf3e42c9bdfde35 100755 (executable)
@@ -60,25 +60,25 @@ ENDPOINTS=
        echo 'child: ID': $?
 
        if [ "${NAME0}" == "${NAME1}" ]; then
-           echo 'NAME[STR]:' $?
+           echo 'NAME[STR]:' 0
        else
-           echo 'NAME[STR]:' $?
+           echo 'NAME[STR]:' 1
            echo NAME0: "${NAME0}"
            echo NAME1: "${NAME1}"
        fi
 
        if [ "${ID0}" == "${ID1}" ]; then
-           echo 'ID[STR]:' $?
+           echo 'ID[STR]:' 0
        else
-           echo 'ID[STR]:' $?
+           echo 'ID[STR]:' 1
            echo ID0: "${ID0}"
            echo ID0: "${ID1}"
        fi
 
        if [ "${NAME0}" == "id=${ID1}" ]; then
-           echo 'NAMExID[STR]:' $?
+           echo 'NAMExID[STR]:' 0
        else
-           echo 'NAMExID[STR]:' $?
+           echo 'NAMExID[STR]:' 1
            echo NAME0: "${NAME0}"
            echo ID0: "${ID0}"
        fi
@@ -89,9 +89,9 @@ ENDPOINTS=
                     "$PID0" "$FD0" "$PID1" "$FD1" \
                     "$PID1" "$FD1" "$PID0" "$FD0")
        if [ "$ENDPOINTS" == "$tmp" ]; then
-           echo 'ENDPOINTS[STR]:' $?
+           echo 'ENDPOINTS[STR]:' 0
        else
-           echo 'ENDPOINTS[STR]:' $?
+           echo 'ENDPOINTS[STR]:' 1
            echo 'ENDPOINTS:' "$ENDPOINTS"
            echo 'lsfd:' "$tmp"
        fi
index 76138a7a6fe2ae2a876cc7304af7498f2f9354be..2fabdb4e5b8418b1a3b17c5b4bcf06d3169a5742 100755 (executable)
@@ -41,6 +41,7 @@ PID=
 NETNS=
 FD0=3
 FD1=4
+RC=
 
 {
     coproc MKFDS { "$TS_HELPER_MKFDS" foreign-sockets $FD0 $FD1 ; }
@@ -74,8 +75,9 @@ FD1=4
        echo DONE >&"${MKFDS[1]}"
     fi
     wait "${MKFDS_PID}"
+    RC=$?
 } > "$TS_OUTPUT" 2>&1
-if [[ "$?" == "$EPERM" ]]; then
+if [[ "$RC" == "$EPERM" ]]; then
     ts_skip "unshare(2) is not permitted on this platform"
 fi
 
index b7646c228451d6254cfbd6ca08cd7d58475a3917..f16e6d1becf784831306251f504327720c986212 100755 (executable)
@@ -33,6 +33,7 @@ EXPR='(TYPE == "NETLINK") and (FD == 3)'
 NETLINK_PROTOCOL=4
 NETLINK_LPORT=
 NETLINK_GROUPS=5
+RC=
 
 {
     coproc MKFDS { "$TS_HELPER_MKFDS" netlink $FD protocol=$NETLINK_PROTOCOL groups=$NETLINK_GROUPS; }
@@ -50,9 +51,10 @@ NETLINK_GROUPS=5
        echo DONE >&"${MKFDS[1]}"
     fi
     wait "${MKFDS_PID}"
+    RC=$?
 } > "$TS_OUTPUT" 2>&1
 
-if [[ $? == "$EPROTONOSUPPORT" ]]; then
+if [[ $RC == "$EPROTONOSUPPORT" ]]; then
     ts_skip "It seems that this platform doesn't support making a netlink socket"
 fi
 
index abf2eb2ca2389a605dccd3bd5f6dcdef4e1d444f..9c1496601baec79ba57f36a9ddadd64575aff4fb 100755 (executable)
@@ -32,6 +32,7 @@ EXPR='(TYPE == "NETLINK") and (FD == 3)'
 NETLINK_PROTOCOL=4
 NETLINK_LPORT=
 NETLINK_GROUPS=5
+RC=
 
 {
     coproc MKFDS { "$TS_HELPER_MKFDS" netlink $FD protocol=$NETLINK_PROTOCOL; }
@@ -49,9 +50,10 @@ NETLINK_GROUPS=5
        echo DONE >&"${MKFDS[1]}"
     fi
     wait "${MKFDS_PID}"
+    RC=$?
 } > "$TS_OUTPUT" 2>&1
 
-if [[ $? == "$EPROTONOSUPPORT" ]]; then
+if [[ $RC == "$EPROTONOSUPPORT" ]]; then
     ts_skip "It seems that this platform doesn't support making a netlink socket"
 fi
 
index 0fbaec88f3bcaa318b508f432556cfca7c54b9bf..ddd68deb0c3da84f105bea3914cd1c32dc638765 100755 (executable)
@@ -35,6 +35,7 @@ NAME_FD=
 NAME_NS=
 INO_FD=
 INO_NS=
+RC=
 {
     coproc MKFDS { "$TS_HELPER_MKFDS" netns "$FD"; }
     if read -r -u "${MKFDS[0]}" PID; then
@@ -45,28 +46,29 @@ INO_NS=
        INO_NS=$( "${TS_CMD_LSFD}" -n -oINODE   -p "${PID}" -Q '(ASSOC == "net")')
 
        if [[ "$NAME_FD" = "$NAME_NS" ]]; then
-           echo "NAME_FD" == "NAME_NS": $?
+           echo "NAME_FD" == "NAME_NS": 0
        else
-           echo "NAME_FD: $NAME_FD" == "NAME_NS: $NAME_NS": $?
+           echo "NAME_FD: $NAME_FD" == "NAME_NS: $NAME_NS": 1
        fi
 
        if [[ "$NAME_FD" = "net:[$INO_FD]" ]]; then
-           echo "NAME_FD" == "net:[INO_FD]": $?
+           echo "NAME_FD" == "net:[INO_FD]": 0
        else
-           echo "NAME_FD: $NAME_FD" == "net:[INO_FD: $INO_FD]": $?
+           echo "NAME_FD: $NAME_FD" == "net:[INO_FD: $INO_FD]": 1
        fi
 
        if [[ "$NAME_FD" = "net:[$INO_NS]" ]]; then
-           echo "NAME_FD" == "net:[INO_NS]": $?
+           echo "NAME_FD" == "net:[INO_NS]": 0
        else
-           echo "NAME_FD: $NAME_FD" == "net:[INO_NS: $INO_NS]": $?
+           echo "NAME_FD: $NAME_FD" == "net:[INO_NS: $INO_NS]": 1
        fi
 
        echo DONE >&"${MKFDS[1]}"
     fi
     wait "${MKFDS_PID}"
+    RC=$?
 } > "$TS_OUTPUT" 2>&1
-if [ "$?" == "$TS_EXIT_NOTSUPP" ]; then
+if [ "$RC" == "$TS_EXIT_NOTSUPP" ]; then
     ts_skip "ioctl(fd, SIOCGSKNS) is not available"
 fi
 
index 9b0ff33c60a709d3f989c1bf1539e6f1edd432f8..9370d337c2f1bbb785ab64689f5f3f09de0985e1 100755 (executable)
@@ -33,6 +33,7 @@ PID=
 FD=3
 TARGET=1
 EXPR="(PID != ${TARGET}) and (FD == 3) and (PIDFD.PID == ${TARGET})"
+RC=
 
 {
     coproc MKFDS { "$TS_HELPER_MKFDS" pidfd $FD target-pid=${TARGET} ; }
@@ -43,9 +44,10 @@ EXPR="(PID != ${TARGET}) and (FD == 3) and (PIDFD.PID == ${TARGET})"
        echo DONE >&"${MKFDS[1]}"
     fi
     wait ${MKFDS_PID}
+    RC=$?
 } > $TS_OUTPUT 2>&1
 
-if [ "$?" == "$TS_EXIT_NOTSUPP" ]; then
+if [ "$RC" == "$TS_EXIT_NOTSUPP" ]; then
     ts_skip "pidfd_open(2) is not available"
 fi
 
index f2f950a878de4f1c8958066d7c28c981d59f560e..d3ca46c3bab79c8a4171c2d3fd95e651c80a2bda 100755 (executable)
@@ -85,7 +85,7 @@ EXPR=
 
        expected=$(printf '%s\n%s' "${line0}" "${line1}")
        if [ "${LSFD_ENDPOINTS}" == "${expected}" ]; then
-           echo 'ENDPOINTS[STR]:' $?
+           echo 'ENDPOINTS[STR]:' 0
        else
            echo "lsfd output:"
            echo "${LSFD_ENDPOINTS}"
index 2df604029b1341817fb8d47397f8fe1935a276e6..3078adf31d1f1eefe1c29818eae998676bb25b7b 100755 (executable)
@@ -35,6 +35,7 @@ FDALTNS=4
 FDSOCK=5
 
 EXPR='((TYPE == "UNIX") or (TYPE == "UNIX-STREAM")) and (FD == 5)'
+RC=
 
 compare_net_namespaces()
 {
@@ -65,6 +66,7 @@ strip_type_stream()
 }
 
 for t in stream dgram seqpacket; do
+    RC=
     ts_init_subtest "$t"
     {
        coproc MKFDS { "$TS_HELPER_MKFDS" unix-in-netns $FDSELFNS $FDALTNS $FDSOCK \
@@ -97,8 +99,9 @@ for t in stream dgram seqpacket; do
            echo DONE >&"${MKFDS[1]}"
        fi
        wait "${MKFDS_PID}"
+       RC=$?
     } > "$TS_OUTPUT" 2>&1
-    if [ "$?" == "$EPERM" ]; then
+    if [ "$RC" == "$EPERM" ]; then
        ts_skip_subtest "unshare(2) is not permitted on this platform"
        continue
     fi