From: Masatake YAMATO Date: Wed, 19 Apr 2023 22:01:06 +0000 (+0900) Subject: tests: (lsfd) make the message for skipping the case more descriptive X-Git-Tag: v2.39~66^2~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ca1265456220e602e7d87994c5896e5c99f60f02;p=thirdparty%2Futil-linux.git tests: (lsfd) make the message for skipping the case more descriptive Using errno is suggested by Thomas Weißschuh Signed-off-by: Masatake YAMATO --- diff --git a/tests/helpers/test_mkfds.c b/tests/helpers/test_mkfds.c index 813444fc58..194c175504 100644 --- a/tests/helpers/test_mkfds.c +++ b/tests/helpers/test_mkfds.c @@ -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)"); } } diff --git a/tests/ts/lsfd/lsfd-functions.bash b/tests/ts/lsfd/lsfd-functions.bash index 0306615b2e..d9a35956d8 100644 --- a/tests/ts/lsfd/lsfd-functions.bash +++ b/tests/ts/lsfd/lsfd-functions.bash @@ -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" diff --git a/tests/ts/lsfd/mkfds-ping b/tests/ts/lsfd/mkfds-ping index 610901cee8..c2ca049ab0 100755 --- a/tests/ts/lsfd/mkfds-ping +++ b/tests/ts/lsfd/mkfds-ping @@ -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