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