]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
tests: (lsfd) make the message for skipping the case more descriptive
authorMasatake YAMATO <yamato@redhat.com>
Wed, 19 Apr 2023 22:01:06 +0000 (07:01 +0900)
committerMasatake YAMATO <yamato@redhat.com>
Wed, 19 Apr 2023 22:25:39 +0000 (07:25 +0900)
Using errno is suggested by Thomas Weißschuh <thomas@t-8ch.de>

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
tests/helpers/test_mkfds.c
tests/ts/lsfd/lsfd-functions.bash
tests/ts/lsfd/mkfds-ping

index 813444fc58d4b4aef8a6cf121cd9c523085bcb8c..194c1755044d34683a864c74a3ed89ffd19d145e 100644 (file)
@@ -55,6 +55,7 @@
 #define EXIT_EPERM  18
 #define EXIT_ENOPROTOOPT 19
 #define EXIT_EPROTONOSUPPORT 20
+#define EXIT_EACCESS 21
 
 #define _U_ __attribute__((__unused__))
 
@@ -1669,7 +1670,7 @@ static void *make_ping_common(const struct factory *factory, struct fdesc fdescs
 
        sd = socket(family, SOCK_DGRAM, protocol);
        if (sd < 0)
-               err(EXIT_FAILURE,
+               err((errno == EACCES? EXIT_EACCESS: EXIT_FAILURE),
                    "failed to make an icmp socket");
 
        if (sd != fdescs[0].fd) {
@@ -1689,7 +1690,8 @@ static void *make_ping_common(const struct factory *factory, struct fdesc fdescs
                        int e = errno;
                        close(sd);
                        errno = e;
-                       err(EXIT_FAILURE, "failed in bind(2)");
+                       err((errno == EACCES? EXIT_EACCESS: EXIT_FAILURE),
+                           "failed in bind(2)");
                }
        }
 
index 0306615b2eed98c493684bd298f368e0c3e69dda..d9a35956d89da8cfe9e63d51de67c14579662aec 100644 (file)
@@ -20,6 +20,7 @@ readonly ENOSYS=17
 readonly EPERM=18
 readonly ENOPROTOOPT=19
 readonly EPROTONOSUPPORT=20
+readonly EACCESS=21
 
 function lsfd_wait_for_pausing {
        ts_check_prog "sleep"
index 610901cee846fa51507419dc7a3f2eb7e6ec536e..c2ca049ab00b0574d0b6f5f7276fea09c292d3a5 100755 (executable)
@@ -22,8 +22,12 @@ ts_init "$*"
 
 ts_skip_nonroot
 
+. "$TS_SELF"/lsfd-functions.bash
+
 ts_check_test_command "$TS_CMD_LSFD"
 ts_check_test_command "$TS_HELPER_MKFDS"
+ts_check_prog "id"
+
 ts_check_native_byteorder
 
 ts_cd "$TS_OUTDIR"
@@ -48,9 +52,64 @@ COLNS=(
 )
 ID=9999
 
+range_check()
+{
+    local v=$1
+    local min=$2
+    local max=$3
+
+    [[ $min -le $v && $v -le $max ]]
+    return $?
+}
+
+ping_group_range_check()
+{
+    local g
+    local group_min group_max
+
+    if ! read group_min group_max < /proc/sys/net/ipv4/ping_group_range; then
+       # We can say nothing. Just allow to go ahead.
+       return 0
+    fi
+
+    if [[ -z "$group_min" || -z "$group_max" ]]; then
+       # We can say nothing. Just allow to go ahead.
+       return 0
+    fi
+
+    for g in $(id -G); do
+       if range_check "$g" "$group_min" "$group_max"; then
+          return 0
+       fi
+    done
+
+    return 1
+}
+
+ERRMSG=
 for i in 0 1; do
-    if ! "$TS_HELPER_MKFDS"  -c -q "${FACTORY[$i]}" 3 id=$ID; then
-       ts_skip "making ${TYPE[$i]} socket with specifying id is failed (blocked by SELinux?)"
+    ERRMSG=$("$TS_HELPER_MKFDS"  -c -q "${FACTORY[$i]}" 3 id=$ID 2>&1)
+    ERR="$?"
+    if [[ "$ERR" == "$EACCESS" ]]; then
+       case "$ERRMSG" in
+           *bind*)
+               MSG="making ${TYPE[$i]} socket with specifying id is not allowed (blocked by SELinux?)"
+               ;;
+           *socket*)
+               if ! ping_group_range_check; then
+                   MSG="the group(s) ($(id -G)) of the process is not in the expected range"
+                   MSG+=" [$(cat /proc/sys/net/ipv4/ping_group_range)])"
+               else
+                   MSG="$ERRMSG"
+               fi
+               ;;
+           *)
+               MSG="$ERRMSG"
+               ;;
+       esac
+       ts_skip "${MSG}"
+    elif [[ "$ERR" != 0 ]]; then
+       ts_skip "making ${TYPE[$i]} socket is failed ($ERR: $ERRMSG)"
     fi
 done