Dmitry V. Levin | 97c8508 | 2013-06-18 16:50:18 +0000 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | # Ensure that strace can detach from stopped 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 | |
Dmitry V. Levin | 8f54664 | 2015-03-17 17:07:57 +0000 | [diff] [blame] | 12 | $STRACE -d -enone / > /dev/null 2> "$LOG" |
| 13 | if grep -F -x "PTRACE_SEIZE doesn't work" "$LOG" > /dev/null; then |
Dmitry V. Levin | e55264e | 2014-08-11 23:18:56 +0000 | [diff] [blame] | 14 | skip_ "PTRACE_SEIZE doesn't work" |
| 15 | fi |
| 16 | |
Dmitry V. Levin | 97c8508 | 2013-06-18 16:50:18 +0000 | [diff] [blame] | 17 | set -e |
| 18 | |
Dmitry V. Levin | 8f54664 | 2015-03-17 17:07:57 +0000 | [diff] [blame] | 19 | rm -f "$LOG" |
| 20 | ./set_ptracer_any sleep $((2*$TIMEOUT_DURATION)) > "$LOG" & |
Dmitry V. Levin | 97c8508 | 2013-06-18 16:50:18 +0000 | [diff] [blame] | 21 | |
Dmitry V. Levin | 8f54664 | 2015-03-17 17:07:57 +0000 | [diff] [blame] | 22 | while ! [ -s "$LOG" ]; do |
Dmitry V. Levin | 97c8508 | 2013-06-18 16:50:18 +0000 | [diff] [blame] | 23 | kill -0 $! 2> /dev/null || |
| 24 | fail_ 'set_ptracer_any sleep failed' |
Dmitry V. Levin | 1e0a280 | 2013-06-18 20:51:49 +0000 | [diff] [blame] | 25 | $SLEEP_A_BIT |
Dmitry V. Levin | 97c8508 | 2013-06-18 16:50:18 +0000 | [diff] [blame] | 26 | done |
Dmitry V. Levin | 97c8508 | 2013-06-18 16:50:18 +0000 | [diff] [blame] | 27 | |
| 28 | tracee_pid=$! |
| 29 | kill -STOP $tracee_pid |
| 30 | |
| 31 | cleanup() |
| 32 | { |
| 33 | set +e |
| 34 | kill $tracee_pid |
| 35 | kill -CONT $tracee_pid |
| 36 | wait $tracee_pid 2> /dev/null |
Mike Frysinger | 2b5bfeb | 2014-08-11 01:31:23 -0400 | [diff] [blame] | 37 | return 0 |
Dmitry V. Levin | 97c8508 | 2013-06-18 16:50:18 +0000 | [diff] [blame] | 38 | } |
| 39 | |
Dmitry V. Levin | 8f54664 | 2015-03-17 17:07:57 +0000 | [diff] [blame] | 40 | rm -f "$LOG" |
| 41 | $STRACE -p $tracee_pid 2> "$LOG" & |
Dmitry V. Levin | 97c8508 | 2013-06-18 16:50:18 +0000 | [diff] [blame] | 42 | |
Dmitry V. Levin | 8f54664 | 2015-03-17 17:07:57 +0000 | [diff] [blame] | 43 | while ! grep -F "Process $tracee_pid attached" "$LOG" > /dev/null; do |
| 44 | kill -0 $! 2> /dev/null || { |
| 45 | cleanup |
| 46 | dump_log_and_fail_with "$STRACE -p failed to attach" |
| 47 | } |
Dmitry V. Levin | 1e0a280 | 2013-06-18 20:51:49 +0000 | [diff] [blame] | 48 | $SLEEP_A_BIT |
Dmitry V. Levin | 97c8508 | 2013-06-18 16:50:18 +0000 | [diff] [blame] | 49 | done |
| 50 | |
Dmitry V. Levin | 8f54664 | 2015-03-17 17:07:57 +0000 | [diff] [blame] | 51 | while ! grep -F -e '--- stopped by ' "$LOG" > /dev/null; do |
| 52 | kill -0 $! 2> /dev/null || { |
| 53 | cleanup |
| 54 | dump_log_and_fail_with "$STRACE -p missed stop notifications" |
| 55 | } |
Dmitry V. Levin | 1e0a280 | 2013-06-18 20:51:49 +0000 | [diff] [blame] | 56 | $SLEEP_A_BIT |
Dmitry V. Levin | 97c8508 | 2013-06-18 16:50:18 +0000 | [diff] [blame] | 57 | done |
| 58 | |
| 59 | kill -INT $! |
| 60 | wait $! |
| 61 | |
Dmitry V. Levin | 8f54664 | 2015-03-17 17:07:57 +0000 | [diff] [blame] | 62 | grep -F "Process $tracee_pid detached" "$LOG" > /dev/null || { |
| 63 | cleanup |
| 64 | dump_log_and_fail_with "$STRACE -p failed to detach" |
| 65 | } |
Dmitry V. Levin | 97c8508 | 2013-06-18 16:50:18 +0000 | [diff] [blame] | 66 | |
Dmitry V. Levin | 0d7c365 | 2013-06-19 14:57:05 +0000 | [diff] [blame] | 67 | if [ -f /proc/self/status ]; then |
| 68 | $SLEEP_A_BIT |
Dmitry V. Levin | 8f54664 | 2015-03-17 17:07:57 +0000 | [diff] [blame] | 69 | test -d /proc/$tracee_pid || { |
| 70 | cleanup |
| 71 | dump_log_and_fail_with 'tracee died after detach' |
| 72 | } |
Dmitry V. Levin | 0d7c365 | 2013-06-19 14:57:05 +0000 | [diff] [blame] | 73 | grep '^State:.*T (stopped)' < /proc/$tracee_pid/status > /dev/null || { |
Dmitry V. Levin | 0d7c365 | 2013-06-19 14:57:05 +0000 | [diff] [blame] | 74 | grep '^State:' < /proc/$tracee_pid/status |
| 75 | cleanup |
Dmitry V. Levin | 8f54664 | 2015-03-17 17:07:57 +0000 | [diff] [blame] | 76 | dump_log_and_fail_with 'tracee is not group-stopped after detach' |
Denys Vlasenko | a815185 | 2013-06-19 16:37:24 +0200 | [diff] [blame] | 77 | } |
Dmitry V. Levin | 0d7c365 | 2013-06-19 14:57:05 +0000 | [diff] [blame] | 78 | fi |
Denys Vlasenko | a815185 | 2013-06-19 16:37:24 +0200 | [diff] [blame] | 79 | |
Dmitry V. Levin | 97c8508 | 2013-06-18 16:50:18 +0000 | [diff] [blame] | 80 | cleanup |
| 81 | exit 0 |