* tests/set_ptracer_any.c: New file.
* tests/detach-sleeping: New test.
* tests/detach-stopped: Likewise.
* tests/Makefile.am (check_PROGRAMS): Add set_ptracer_any.
(TESTS): Add detach-sleeping and detach-stopped.
* tests/.gitignore: Add set_ptracer_any.
net-accept-connect
+set_ptracer_any
*.log
*.log.*
*.o
AM_CFLAGS = $(WARN_CFLAGS)
-check_PROGRAMS = net-accept-connect
+check_PROGRAMS = net-accept-connect set_ptracer_any
-TESTS = ptrace_setoptions strace-f qual_syscall stat net
+TESTS = ptrace_setoptions strace-f qual_syscall stat net \
+ detach-sleeping detach-stopped
LOG_COMPILER = $(srcdir)/run.sh
--- /dev/null
+#!/bin/sh
+
+# Ensure that strace can detach from sleeping processes.
+
+. "${srcdir=.}/init.sh"
+
+check_prog sleep
+check_prog grep
+
+set -e
+
+./set_ptracer_any sleep $((2*$TIMEOUT_DURATION)) > set_ptracer_any.out &
+
+while ! [ -s set_ptracer_any.out ]; do
+ kill -0 $! 2> /dev/null ||
+ fail_ 'set_ptracer_any sleep failed'
+ sleep 1
+done
+rm -f set_ptracer_any.out
+
+tracee_pid=$!
+
+cleanup()
+{
+ set +e
+ kill $tracee_pid
+ kill -CONT $tracee_pid
+ wait $tracee_pid 2> /dev/null
+}
+
+$STRACE -p $tracee_pid 2> $LOG &
+
+while ! grep -F "Process $tracee_pid attached" $LOG > /dev/null; do
+ kill -0 $! 2> /dev/null ||
+ { cat $LOG; cleanup; fail_ 'strace -p does not work'; }
+ sleep 1
+done
+
+kill -INT $!
+wait $!
+
+grep -F "Process $tracee_pid detached" $LOG > /dev/null ||
+ { cat $LOG; cleanup; fail_ 'strace -p failed to detach'; }
+
+cleanup
+exit 0
--- /dev/null
+#!/bin/sh
+
+# Ensure that strace can detach from stopped processes.
+
+. "${srcdir=.}/init.sh"
+
+check_prog sleep
+check_prog grep
+
+set -e
+
+./set_ptracer_any sleep $((2*$TIMEOUT_DURATION)) > set_ptracer_any.out &
+
+while ! [ -s set_ptracer_any.out ]; do
+ kill -0 $! 2> /dev/null ||
+ fail_ 'set_ptracer_any sleep failed'
+ sleep 1
+done
+rm -f set_ptracer_any.out
+
+tracee_pid=$!
+kill -STOP $tracee_pid
+
+cleanup()
+{
+ set +e
+ kill $tracee_pid
+ kill -CONT $tracee_pid
+ wait $tracee_pid 2> /dev/null
+}
+
+$STRACE -p $tracee_pid 2> $LOG &
+
+while ! grep -F "Process $tracee_pid attached" $LOG > /dev/null; do
+ kill -0 $! 2> /dev/null ||
+ { cat $LOG; cleanup; fail_ 'strace -p does not work'; }
+ sleep 1
+done
+
+while ! grep -F -e '--- stopped by ' $LOG > /dev/null; do
+ kill -0 $! 2> /dev/null ||
+ { cat $LOG; cleanup; fail_ 'strace -p does not work'; }
+ sleep 1
+done
+
+kill -INT $!
+wait $!
+
+grep -F "Process $tracee_pid detached" $LOG > /dev/null ||
+ { cat $LOG; cleanup; fail_ 'strace -p failed to detach'; }
+
+cleanup
+exit 0
--- /dev/null
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+#include <stdio.h>
+#include <unistd.h>
+#ifdef HAVE_PRCTL
+# include <sys/prctl.h>
+#endif
+
+int main(int argc, char **argv)
+{
+ if (argc < 2)
+ return 99;
+#if defined HAVE_PRCTL && defined PR_SET_PTRACER && defined PR_SET_PTRACER_ANY
+ (void) prctl(PR_SET_PTRACER, PR_SET_PTRACER_ANY);
+#endif
+ if (write(1, "\n", 1) != 1) {
+ perror("write");
+ return 99;
+ }
+ (void) execvp(argv[1], argv + 1);
+ perror(argv[1]);
+ return 99;
+}