blob: 3d1c67e0592fc3b8d1622efa12c148ed8076bc70 [file] [log] [blame]
Dmitry V. Levin97c85082013-06-18 16:50:18 +00001#!/bin/sh
2
3# Ensure that strace can detach from stopped processes.
4
5. "${srcdir=.}/init.sh"
6
Dmitry V. Levin8f546642015-03-17 17:07:57 +00007run_prog_skip_if_failed \
8 kill -0 $$
Dmitry V. Levin74697bd2015-01-14 08:08:56 +00009
Dmitry V. Levin3ec5c042014-09-23 01:51:05 +000010check_prog sleep
Dmitry V. Levin97c85082013-06-18 16:50:18 +000011
Dmitry V. Levin8f546642015-03-17 17:07:57 +000012$STRACE -d -enone / > /dev/null 2> "$LOG"
13if grep -F -x "PTRACE_SEIZE doesn't work" "$LOG" > /dev/null; then
Dmitry V. Levine55264e2014-08-11 23:18:56 +000014 skip_ "PTRACE_SEIZE doesn't work"
15fi
16
Dmitry V. Levin97c85082013-06-18 16:50:18 +000017set -e
18
Dmitry V. Levin8f546642015-03-17 17:07:57 +000019rm -f "$LOG"
20./set_ptracer_any sleep $((2*$TIMEOUT_DURATION)) > "$LOG" &
Dmitry V. Levin97c85082013-06-18 16:50:18 +000021
Dmitry V. Levin8f546642015-03-17 17:07:57 +000022while ! [ -s "$LOG" ]; do
Dmitry V. Levin97c85082013-06-18 16:50:18 +000023 kill -0 $! 2> /dev/null ||
24 fail_ 'set_ptracer_any sleep failed'
Dmitry V. Levin1e0a2802013-06-18 20:51:49 +000025 $SLEEP_A_BIT
Dmitry V. Levin97c85082013-06-18 16:50:18 +000026done
Dmitry V. Levin97c85082013-06-18 16:50:18 +000027
28tracee_pid=$!
29kill -STOP $tracee_pid
30
31cleanup()
32{
33 set +e
34 kill $tracee_pid
35 kill -CONT $tracee_pid
36 wait $tracee_pid 2> /dev/null
Mike Frysinger2b5bfeb2014-08-11 01:31:23 -040037 return 0
Dmitry V. Levin97c85082013-06-18 16:50:18 +000038}
39
Dmitry V. Levin8f546642015-03-17 17:07:57 +000040rm -f "$LOG"
41$STRACE -p $tracee_pid 2> "$LOG" &
Dmitry V. Levin97c85082013-06-18 16:50:18 +000042
Dmitry V. Levin8f546642015-03-17 17:07:57 +000043while ! 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. Levin1e0a2802013-06-18 20:51:49 +000048 $SLEEP_A_BIT
Dmitry V. Levin97c85082013-06-18 16:50:18 +000049done
50
Dmitry V. Levin8f546642015-03-17 17:07:57 +000051while ! 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. Levin1e0a2802013-06-18 20:51:49 +000056 $SLEEP_A_BIT
Dmitry V. Levin97c85082013-06-18 16:50:18 +000057done
58
59kill -INT $!
60wait $!
61
Dmitry V. Levin8f546642015-03-17 17:07:57 +000062grep -F "Process $tracee_pid detached" "$LOG" > /dev/null || {
63 cleanup
64 dump_log_and_fail_with "$STRACE -p failed to detach"
65}
Dmitry V. Levin97c85082013-06-18 16:50:18 +000066
Dmitry V. Levin0d7c3652013-06-19 14:57:05 +000067if [ -f /proc/self/status ]; then
68 $SLEEP_A_BIT
Dmitry V. Levin8f546642015-03-17 17:07:57 +000069 test -d /proc/$tracee_pid || {
70 cleanup
71 dump_log_and_fail_with 'tracee died after detach'
72 }
Dmitry V. Levin0d7c3652013-06-19 14:57:05 +000073 grep '^State:.*T (stopped)' < /proc/$tracee_pid/status > /dev/null || {
Dmitry V. Levin0d7c3652013-06-19 14:57:05 +000074 grep '^State:' < /proc/$tracee_pid/status
75 cleanup
Dmitry V. Levin8f546642015-03-17 17:07:57 +000076 dump_log_and_fail_with 'tracee is not group-stopped after detach'
Denys Vlasenkoa8151852013-06-19 16:37:24 +020077 }
Dmitry V. Levin0d7c3652013-06-19 14:57:05 +000078fi
Denys Vlasenkoa8151852013-06-19 16:37:24 +020079
Dmitry V. Levin97c85082013-06-18 16:50:18 +000080cleanup
81exit 0