3 # Ensure that strace can detach from stopped processes.
5 # Copyright (c) 2013-2015 Dmitry V. Levin <ldv@altlinux.org>
6 # Copyright (c) 2014-2018 The strace developers.
9 # SPDX-License-Identifier: GPL-2.0-or-later
11 . "${srcdir=.}/init.sh"
13 run_prog_skip_if_failed \
16 $STRACE -d -enone / > /dev/null 2> "$LOG"
17 if grep -x "[^:]*strace: PTRACE_SEIZE doesn't work" "$LOG" > /dev/null; then
18 skip_ "PTRACE_SEIZE doesn't work"
24 sleep $TIMEOUT_DURATION &
32 ../set_ptracer_any sleep $((2*$TIMEOUT_DURATION)) > "$LOG" &
34 while ! [ -s "$LOG" ]; do
35 kill -0 $! 2> /dev/null ||
36 fail_ 'set_ptracer_any sleep failed'
41 kill -STOP $tracee_pid
47 kill -CONT $tracee_pid
48 wait $tracee_pid 2> /dev/null
53 $STRACE -p $tracee_pid 2> "$LOG" &
55 while ! grep -F "Process $tracee_pid attached" "$LOG" > /dev/null; do
56 kill -0 $! 2> /dev/null || {
58 dump_log_and_fail_with "$STRACE -p failed to attach"
63 while ! grep -F -e '--- stopped by ' "$LOG" > /dev/null; do
64 kill -0 $! 2> /dev/null || {
66 dump_log_and_fail_with "$STRACE -p missed stop notifications"
72 wait $! && rc=0 || rc=$?
74 grep -F "Process $tracee_pid detached" "$LOG" > /dev/null || {
76 dump_log_and_fail_with "$STRACE -p failed to detach"
79 [ "$rc" = "$expected_rc" ] || {
81 dump_log_and_fail_with "$STRACE -p failed to terminate itself"
84 if [ -f /proc/self/status ]; then
86 test -d /proc/$tracee_pid || {
88 dump_log_and_fail_with 'tracee died after detach'
90 grep_pid_status "$tracee_pid" '^State:.*T (stopped)' > /dev/null || {
91 grep_pid_status "$tracee_pid" '^State:'
93 dump_log_and_fail_with 'tracee is not group-stopped after detach'