1#!/bin/sh 2 3# Ensure that strace can detach from sleeping processes. 4 5. "${srcdir=.}/init.sh" 6 7check_prog sleep 8check_prog grep 9 10set -e 11 12rm -f $LOG 13./set_ptracer_any sleep $((2*$TIMEOUT_DURATION)) > $LOG & 14 15while ! [ -s $LOG ]; do 16 kill -0 $! 2> /dev/null || 17 fail_ 'set_ptracer_any sleep failed' 18 $SLEEP_A_BIT 19done 20 21tracee_pid=$! 22 23cleanup() 24{ 25 set +e 26 kill $tracee_pid 27 wait $tracee_pid 2> /dev/null 28} 29 30rm -f $LOG 31$STRACE -p $tracee_pid 2> $LOG & 32 33while ! 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 37done 38 39kill -INT $! 40wait $! 41 42grep -F "Process $tracee_pid detached" $LOG > /dev/null || 43 { cat $LOG; cleanup; fail_ 'strace -p failed to detach'; } 44 45if [ -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 } 55fi 56 57cleanup 58exit 0 59