Might as well inject openat2 in case any libc implementation decides
to use it more often. E.g., how glibc began using fchmodat2 for
fchmod.
-- 8< --
* init.cfg (get_open_syscalls_): New function based on
get_stat_syscalls_.
* tests/chcon/traversal-missing.sh: Use it.
* tests/shred/chmod-race.sh: Use it.
* tests/shred/fifo.sh: Use it.
---
init.cfg | 14 ++++++++++++++
tests/chcon/traversal-missing.sh | 2 +-
tests/shred/chmod-race.sh | 4 +++-
tests/shred/fifo.sh | 3 ++-
4 files changed, 20 insertions(+), 3 deletions(-)
diff --git a/init.cfg b/init.cfg
index b741520a5..7ed892ed8 100644
--- a/init.cfg
+++ b/init.cfg
@@ -283,6 +283,20 @@ get_stat_syscalls_()
printf '%s\n' "$stats"
}
+# Output a comma-separated list of file-name open syscalls recognized
+# by strace. Callers that require strace should invoke require_strace_
+# separately.
+get_open_syscalls_()
+{
+ local opens=open
+ local open
+ for open in openat openat2; do
+ strace -qe trace="$open" true > /dev/null 2>&1 &&
+ opens="$opens,$open"
+ done
+ printf '%s\n' "$opens"
+}
+
# 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/chcon/traversal-missing.sh b/tests/chcon/traversal-missing.sh
index 711de906f..13b281681 100755
--- a/tests/chcon/traversal-missing.sh
+++ b/tests/chcon/traversal-missing.sh
@@ -22,7 +22,7 @@ require_strace_ getxattr
mkdir -p d/foo || framework_failure_
touch d/foo/bar || framework_failure_
-opens=open,openat
+opens=$(get_open_syscalls_)
xattrs=getxattr,lgetxattr,setxattr,lsetxattr
(cd d && chcon -R -t user_tmp_t . > /dev/null 2>&1) \
diff --git a/tests/shred/chmod-race.sh b/tests/shred/chmod-race.sh
index 17c68a0d2..51a202a41 100755
--- a/tests/shred/chmod-race.sh
+++ b/tests/shred/chmod-race.sh
@@ -20,6 +20,8 @@
print_ver_ shred timeout
require_strace_ openat
+opens=$(get_open_syscalls_)
+
mkdir d1 d2 &&
echo shred >d1/f &&
echo saved >d2/f &&
@@ -31,7 +33,7 @@ chmod 400 d1/f d2/f || framework_failure_
# Note we wrap with timeout as strace ignores SIGTERM with -o.
# Also even with --interruptible=wait strace might not handle
# stopped tracee's appropriately.
-inject=open,openat:error=EACCES:signal=SIGSTOP:when=1
+inject=$opens:error=EACCES:signal=SIGSTOP:when=1
timeout -k 1 60 strace --quiet=all -o /dev/null -P d1/f -P f \
-e inject=$inject true 2>/dev/null \
|| skip_ 'strace does not support the required injection options'
diff --git a/tests/shred/fifo.sh b/tests/shred/fifo.sh
index 377fc6568..ae1f2ce11 100755
--- a/tests/shred/fifo.sh
+++ b/tests/shred/fifo.sh
@@ -22,10 +22,11 @@ getlimits_
uses_strace_
stats=$(get_stat_syscalls_)
+opens=$(get_open_syscalls_)
open_stat_fail ()
{
- strace --quiet=all -o /dev/null -P file -e inject=open,openat:error=ENXIO \
+ strace --quiet=all -o /dev/null -P file -e inject=$opens:error=ENXIO \
-e inject=$stats:error=ENOSYS "$@"
}
--
2.56.1