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