From: oech3 <[email protected]> * tests/dd/fail-ftruncate-fstat.sh: Replace LD_PRELOAD by strace to support static executables.
Link: https://github.com/coreutils/coreutils/pull/330 --- tests/dd/fail-ftruncate-fstat.sh | 49 +++++++------------------------- 1 file changed, 11 insertions(+), 38 deletions(-) diff --git a/tests/dd/fail-ftruncate-fstat.sh b/tests/dd/fail-ftruncate-fstat.sh index 219273bbc..4d3e9b809 100755 --- a/tests/dd/fail-ftruncate-fstat.sh +++ b/tests/dd/fail-ftruncate-fstat.sh @@ -18,52 +18,25 @@ . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src print_ver_ dd -require_gcc_shared_ +uses_strace_ getlimits_ -cat > k.c <<'EOF' || framework_failure_ -#include <sys/stat.h> -#include <stdio.h> -#include <unistd.h> -#include <errno.h> - -int -ftruncate (int fd, off_t length) -{ - /* Prove that LD_PRELOAD works: create the evidence file "x". */ - fclose (fopen ("x", "w")); - - /* Pretend failure. */ - errno = EPERM; - return -1; -} - -int -fstat (int fd, struct stat *statbuf) -{ - /* Prove that LD_PRELOAD works: create the evidence file "y". */ - fclose (fopen ("y", "w")); - - /* Pretend failure. */ - errno = EPERM; - return -1; -} -EOF - -# Then compile/link it: -gcc_shared_ k.c k.so \ - || framework_failure_ 'failed to build shared library' - # Setup the file "out" and preserve it's original contents in "exp-out". yes | head -n 2048 | tr -d '\n' > out || framework_failure_ cp out exp-out || framework_failure_ -LD_PRELOAD=$LD_PRELOAD:./k.so dd if=/dev/zero of=out count=1 \ - seek=1 status=none 2>err +strace -o strace.out \ + -e fault=ftruncate:error=EPERM \ + -e fault=fstat:error=EPERM \ + -P out \ + -e quiet=path-resolution \ + dd if=/dev/zero of=out count=1 seek=1 status=none 2>err + ret=$? -test -f x && test -f y \ - || skip_ "internal test failure: maybe LD_PRELOAD doesn't work?" +# This also implicitly checks for strace invocation issues +grep -oE '^(fstat|ftruncate)' strace.out || + skip_ 'ftruncate or fstat are not detected' # After ftruncate fails, we use fstat to get the file type. echo "dd: cannot fstat 'out': $EPERM" > exp -- 2.55.0
