3 # Ensure that strace can detach from running 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 \
19 sleep $TIMEOUT_DURATION &
26 ../set_ptracer_any sh -c "echo > $LOG; while :; do :; done" > /dev/null &
28 while ! [ -s "$LOG" ]; do
29 kill -0 $! 2> /dev/null ||
30 fail_ 'set_ptracer_any sh failed'
40 wait $tracee_pid 2> /dev/null
44 $STRACE -p $tracee_pid 2> "$LOG" &
46 while ! grep -F "Process $tracee_pid attached" "$LOG" > /dev/null; do
47 kill -0 $! 2> /dev/null || {
49 dump_log_and_fail_with "$STRACE -p failed to attach"
55 wait $! && rc=0 || rc=$?
57 grep -F "Process $tracee_pid detached" "$LOG" > /dev/null || {
59 dump_log_and_fail_with "$STRACE -p failed to detach"
62 [ "$rc" = "$expected_rc" ] || {
64 dump_log_and_fail_with "$STRACE -p failed to terminate itself"
67 if [ -f /proc/self/status ]; then
69 test -d /proc/$tracee_pid || {
71 dump_log_and_fail_with 'tracee died after detach'
73 grep_pid_status "$tracee_pid" '^State:.*R (running)' > /dev/null || {
74 grep_pid_status "$tracee_pid" '^State:'
76 dump_log_and_fail_with 'tracee is not running after detach'