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