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