Home | History | Annotate | Download | only in tests
      1 #!/bin/sh
      2 
      3 # Ensure that strace can detach from sleeping 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 rm -f "$LOG"
     15 ./set_ptracer_any sleep $((2*$TIMEOUT_DURATION)) > "$LOG" &
     16 
     17 while ! [ -s "$LOG" ]; do
     18 	kill -0 $! 2> /dev/null ||
     19 		fail_ 'set_ptracer_any sleep failed'
     20 	$SLEEP_A_BIT
     21 done
     22 
     23 tracee_pid=$!
     24 
     25 cleanup()
     26 {
     27 	set +e
     28 	kill $tracee_pid
     29 	wait $tracee_pid 2> /dev/null
     30 	return 0
     31 }
     32 
     33 rm -f "$LOG"
     34 $STRACE -p $tracee_pid 2> "$LOG" &
     35 
     36 while ! 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
     42 done
     43 
     44 kill -INT $!
     45 wait $!
     46 
     47 grep -F "Process $tracee_pid detached" "$LOG" > /dev/null || {
     48 	cleanup
     49 	dump_log_and_fail_with "$STRACE -p failed to detach"
     50 }
     51 
     52 if [ -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 	}
     63 fi
     64 
     65 cleanup
     66 exit 0
     67