From: Pádraig Brady Date: Wed, 22 Jul 2026 19:10:57 +0000 (+0100) Subject: maint: refactor stat syscall determination X-Git-Url: http://git.ipfire.org/gitweb/?a=commitdiff_plain;h=8f7ed6cf504ca492ba1a85f10dae86bf19030707;p=thirdparty%2Fcoreutils.git maint: refactor stat syscall determination * init.cfg (+get_stat_syscalls_): Refactor from ... * tests/ls/stat-free-color.sh: ... here. * tests/ls/stat-free-symlinks.sh: ... here. * tests/misc/traversal-missing.sh: ... here. * tests/shred/fifo.sh: .. here. --- diff --git a/init.cfg b/init.cfg index 0896d8ddac..8630940aca 100644 --- a/init.cfg +++ b/init.cfg @@ -265,6 +265,20 @@ require_strace_() fi } +# Output a comma-separated list of file-name stat syscalls recognized +# by strace. Callers that require strace should invoke require_strace_ +# separately. +get_stat_syscalls_() +{ + local stats=stat + local stat + for stat in statx lstat stat64 lstat64 newfstatat fstatat64; do + strace -qe "$stat" true > /dev/null 2>&1 && + stats="$stats,$stat" + done + printf '%s\n' "$stats" +} + # Skip the current test if valgrind doesn't work, # which could happen if not installed, # or hasn't support for the built architecture, diff --git a/tests/ls/stat-free-color.sh b/tests/ls/stat-free-color.sh index 7e95671f52..27fe0d7b6d 100755 --- a/tests/ls/stat-free-color.sh +++ b/tests/ls/stat-free-color.sh @@ -21,13 +21,7 @@ print_ver_ ls require_strace_ stat require_dirent_d_type_ -stats='stat' -# List of other _file name_ stat functions to increase coverage. -other_stats='statx lstat stat64 lstat64 newfstatat fstatat64' -for stat in $other_stats; do - strace -qe "$stat" true > /dev/null 2>&1 && - stats="$stats,$stat" -done +stats=$(get_stat_syscalls_) # Disable enough features via LS_COLORS so that ls --color # can do its job without calling stat (other than the obligatory diff --git a/tests/ls/stat-free-symlinks.sh b/tests/ls/stat-free-symlinks.sh index 5597c04ccb..2d884adecd 100755 --- a/tests/ls/stat-free-symlinks.sh +++ b/tests/ls/stat-free-symlinks.sh @@ -20,13 +20,7 @@ print_ver_ ls require_strace_ stat -stats='stat' -# List of other _file name_ stat functions to increase coverage. -other_stats='statx lstat stat64 lstat64 newfstatat fstatat64' -for stat in $other_stats; do - strace -qe "$stat" true > /dev/null 2>&1 && - stats="$stats,$stat" -done +stats=$(get_stat_syscalls_) # The system may perform additional stat-like calls before main. # Furthermore, underlying library functions may also implicitly diff --git a/tests/misc/traversal-missing.sh b/tests/misc/traversal-missing.sh index 7352331002..764d9ca10a 100755 --- a/tests/misc/traversal-missing.sh +++ b/tests/misc/traversal-missing.sh @@ -25,14 +25,7 @@ touch d/foo || framework_failure_ uid=$(id -u) || framework_failure_ gid=$(id -g) || framework_failure_ -stats='stat' -# List other _file name_ stat functions to increase coverage. -other_stats='statx lstat stat64 lstat64 newfstatat fstatat64' -for stat in $other_stats; do - strace -qe "$stat" true > /dev/null 2>&1 && - stats="$stats,$stat" -done - +stats=$(get_stat_syscalls_) chmods=chmod,fchmodat,fchmodat2 chowns=chown,lchown,fchownat diff --git a/tests/shred/fifo.sh b/tests/shred/fifo.sh index d89cd2ff7c..377fc65680 100755 --- a/tests/shred/fifo.sh +++ b/tests/shred/fifo.sh @@ -21,13 +21,7 @@ print_ver_ shred getlimits_ uses_strace_ -stats='stat' -# List of other _file name_ stat functions to increase coverage. -other_stats='statx lstat stat64 lstat64 newfstatat fstatat64' -for stat in $other_stats; do - strace -qe "$stat" true > /dev/null 2>&1 && - stats="$stats,$stat" -done +stats=$(get_stat_syscalls_) open_stat_fail () {