Dmitry V. Levin | 97c8508 | 2013-06-18 16:50:18 +0000 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | # Ensure that strace can detach from sleeping processes. |
| 4 | |
| 5 | . "${srcdir=.}/init.sh" |
| 6 | |
Dmitry V. Levin | 8f54664 | 2015-03-17 17:07:57 +0000 | [diff] [blame] | 7 | run_prog_skip_if_failed \ |
| 8 | kill -0 $$ |
Dmitry V. Levin | 74697bd | 2015-01-14 08:08:56 +0000 | [diff] [blame] | 9 | |
Dmitry V. Levin | 3ec5c04 | 2014-09-23 01:51:05 +0000 | [diff] [blame] | 10 | check_prog sleep |
Dmitry V. Levin | 97c8508 | 2013-06-18 16:50:18 +0000 | [diff] [blame] | 11 | |
| 12 | set -e |
| 13 | |
Dmitry V. Levin | 8f54664 | 2015-03-17 17:07:57 +0000 | [diff] [blame] | 14 | rm -f "$LOG" |
| 15 | ./set_ptracer_any sleep $((2*$TIMEOUT_DURATION)) > "$LOG" & |
Dmitry V. Levin | 97c8508 | 2013-06-18 16:50:18 +0000 | [diff] [blame] | 16 | |
Dmitry V. Levin | 8f54664 | 2015-03-17 17:07:57 +0000 | [diff] [blame] | 17 | while ! [ -s "$LOG" ]; do |
Dmitry V. Levin | 97c8508 | 2013-06-18 16:50:18 +0000 | [diff] [blame] | 18 | kill -0 $! 2> /dev/null || |
| 19 | fail_ 'set_ptracer_any sleep failed' |
Dmitry V. Levin | 1e0a280 | 2013-06-18 20:51:49 +0000 | [diff] [blame] | 20 | $SLEEP_A_BIT |
Dmitry V. Levin | 97c8508 | 2013-06-18 16:50:18 +0000 | [diff] [blame] | 21 | done |
Dmitry V. Levin | 97c8508 | 2013-06-18 16:50:18 +0000 | [diff] [blame] | 22 | |
| 23 | tracee_pid=$! |
| 24 | |
| 25 | cleanup() |
| 26 | { |
| 27 | set +e |
| 28 | kill $tracee_pid |
Dmitry V. Levin | 97c8508 | 2013-06-18 16:50:18 +0000 | [diff] [blame] | 29 | wait $tracee_pid 2> /dev/null |
Mike Frysinger | 2b5bfeb | 2014-08-11 01:31:23 -0400 | [diff] [blame] | 30 | return 0 |
Dmitry V. Levin | 97c8508 | 2013-06-18 16:50:18 +0000 | [diff] [blame] | 31 | } |
| 32 | |
Dmitry V. Levin | 8f54664 | 2015-03-17 17:07:57 +0000 | [diff] [blame] | 33 | rm -f "$LOG" |
| 34 | $STRACE -p $tracee_pid 2> "$LOG" & |
Dmitry V. Levin | 97c8508 | 2013-06-18 16:50:18 +0000 | [diff] [blame] | 35 | |
Dmitry V. Levin | 8f54664 | 2015-03-17 17:07:57 +0000 | [diff] [blame] | 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 | } |
Dmitry V. Levin | 1e0a280 | 2013-06-18 20:51:49 +0000 | [diff] [blame] | 41 | $SLEEP_A_BIT |
Dmitry V. Levin | 97c8508 | 2013-06-18 16:50:18 +0000 | [diff] [blame] | 42 | done |
| 43 | |
| 44 | kill -INT $! |
| 45 | wait $! |
| 46 | |
Dmitry V. Levin | 8f54664 | 2015-03-17 17:07:57 +0000 | [diff] [blame] | 47 | grep -F "Process $tracee_pid detached" "$LOG" > /dev/null || { |
| 48 | cleanup |
| 49 | dump_log_and_fail_with "$STRACE -p failed to detach" |
| 50 | } |
Dmitry V. Levin | 97c8508 | 2013-06-18 16:50:18 +0000 | [diff] [blame] | 51 | |
Dmitry V. Levin | 0d7c365 | 2013-06-19 14:57:05 +0000 | [diff] [blame] | 52 | if [ -f /proc/self/status ]; then |
| 53 | $SLEEP_A_BIT |
Dmitry V. Levin | 8f54664 | 2015-03-17 17:07:57 +0000 | [diff] [blame] | 54 | test -d /proc/$tracee_pid || { |
| 55 | cleanup |
| 56 | dump_log_and_fail_with 'tracee died after detach' |
| 57 | } |
Dmitry V. Levin | 0d7c365 | 2013-06-19 14:57:05 +0000 | [diff] [blame] | 58 | grep '^State:.*S (sleeping)' < /proc/$tracee_pid/status > /dev/null || { |
Dmitry V. Levin | 0d7c365 | 2013-06-19 14:57:05 +0000 | [diff] [blame] | 59 | grep '^State:' < /proc/$tracee_pid/status |
| 60 | cleanup |
Dmitry V. Levin | 8f54664 | 2015-03-17 17:07:57 +0000 | [diff] [blame] | 61 | dump_log_and_fail_with 'tracee is not sleeping after detach' |
Denys Vlasenko | a815185 | 2013-06-19 16:37:24 +0200 | [diff] [blame] | 62 | } |
Dmitry V. Levin | 0d7c365 | 2013-06-19 14:57:05 +0000 | [diff] [blame] | 63 | fi |
Denys Vlasenko | a815185 | 2013-06-19 16:37:24 +0200 | [diff] [blame] | 64 | |
Dmitry V. Levin | 97c8508 | 2013-06-18 16:50:18 +0000 | [diff] [blame] | 65 | cleanup |
| 66 | exit 0 |