1#!/bin/sh 2 3# Ensure that strace can detach from stopped processes. 4 5. "${srcdir=.}/init.sh" 6 7run_prog_skip_if_failed \ 8 kill -0 $$ 9 10check_prog sleep 11 12$STRACE -d -enone / > /dev/null 2> "$LOG" 13if grep -F -x "PTRACE_SEIZE doesn't work" "$LOG" > /dev/null; then 14 skip_ "PTRACE_SEIZE doesn't work" 15fi 16 17set -e 18 19rm -f "$LOG" 20./set_ptracer_any sleep $((2*$TIMEOUT_DURATION)) > "$LOG" & 21 22while ! [ -s "$LOG" ]; do 23 kill -0 $! 2> /dev/null || 24 fail_ 'set_ptracer_any sleep failed' 25 $SLEEP_A_BIT 26done 27 28tracee_pid=$! 29kill -STOP $tracee_pid 30 31cleanup() 32{ 33 set +e 34 kill $tracee_pid 35 kill -CONT $tracee_pid 36 wait $tracee_pid 2> /dev/null 37 return 0 38} 39 40rm -f "$LOG" 41$STRACE -p $tracee_pid 2> "$LOG" & 42 43while ! grep -F "Process $tracee_pid attached" "$LOG" > /dev/null; do 44 kill -0 $! 2> /dev/null || { 45 cleanup 46 dump_log_and_fail_with "$STRACE -p failed to attach" 47 } 48 $SLEEP_A_BIT 49done 50 51while ! grep -F -e '--- stopped by ' "$LOG" > /dev/null; do 52 kill -0 $! 2> /dev/null || { 53 cleanup 54 dump_log_and_fail_with "$STRACE -p missed stop notifications" 55 } 56 $SLEEP_A_BIT 57done 58 59kill -INT $! 60wait $! 61 62grep -F "Process $tracee_pid detached" "$LOG" > /dev/null || { 63 cleanup 64 dump_log_and_fail_with "$STRACE -p failed to detach" 65} 66 67if [ -f /proc/self/status ]; then 68 $SLEEP_A_BIT 69 test -d /proc/$tracee_pid || { 70 cleanup 71 dump_log_and_fail_with 'tracee died after detach' 72 } 73 grep '^State:.*T (stopped)' < /proc/$tracee_pid/status > /dev/null || { 74 grep '^State:' < /proc/$tracee_pid/status 75 cleanup 76 dump_log_and_fail_with 'tracee is not group-stopped after detach' 77 } 78fi 79 80cleanup 81exit 0 82