blob: 345d7d0aa4c085437ecb35bf4d8d2c2e21c14775 [file] [log] [blame]
Dmitry V. Levin97c85082013-06-18 16:50:18 +00001#!/bin/sh
2
3# Ensure that strace can detach from sleeping 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
12set -e
13
Dmitry V. Levin8f546642015-03-17 17:07:57 +000014rm -f "$LOG"
15./set_ptracer_any sleep $((2*$TIMEOUT_DURATION)) > "$LOG" &
Dmitry V. Levin97c85082013-06-18 16:50:18 +000016
Dmitry V. Levin8f546642015-03-17 17:07:57 +000017while ! [ -s "$LOG" ]; do
Dmitry V. Levin97c85082013-06-18 16:50:18 +000018 kill -0 $! 2> /dev/null ||
19 fail_ 'set_ptracer_any sleep failed'
Dmitry V. Levin1e0a2802013-06-18 20:51:49 +000020 $SLEEP_A_BIT
Dmitry V. Levin97c85082013-06-18 16:50:18 +000021done
Dmitry V. Levin97c85082013-06-18 16:50:18 +000022
23tracee_pid=$!
24
25cleanup()
26{
27 set +e
28 kill $tracee_pid
Dmitry V. Levin97c85082013-06-18 16:50:18 +000029 wait $tracee_pid 2> /dev/null
Mike Frysinger2b5bfeb2014-08-11 01:31:23 -040030 return 0
Dmitry V. Levin97c85082013-06-18 16:50:18 +000031}
32
Dmitry V. Levin8f546642015-03-17 17:07:57 +000033rm -f "$LOG"
34$STRACE -p $tracee_pid 2> "$LOG" &
Dmitry V. Levin97c85082013-06-18 16:50:18 +000035
Dmitry V. Levin8f546642015-03-17 17:07:57 +000036while ! 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. Levin1e0a2802013-06-18 20:51:49 +000041 $SLEEP_A_BIT
Dmitry V. Levin97c85082013-06-18 16:50:18 +000042done
43
44kill -INT $!
45wait $!
46
Dmitry V. Levin8f546642015-03-17 17:07:57 +000047grep -F "Process $tracee_pid detached" "$LOG" > /dev/null || {
48 cleanup
49 dump_log_and_fail_with "$STRACE -p failed to detach"
50}
Dmitry V. Levin97c85082013-06-18 16:50:18 +000051
Dmitry V. Levin0d7c3652013-06-19 14:57:05 +000052if [ -f /proc/self/status ]; then
53 $SLEEP_A_BIT
Dmitry V. Levin8f546642015-03-17 17:07:57 +000054 test -d /proc/$tracee_pid || {
55 cleanup
56 dump_log_and_fail_with 'tracee died after detach'
57 }
Dmitry V. Levin0d7c3652013-06-19 14:57:05 +000058 grep '^State:.*S (sleeping)' < /proc/$tracee_pid/status > /dev/null || {
Dmitry V. Levin0d7c3652013-06-19 14:57:05 +000059 grep '^State:' < /proc/$tracee_pid/status
60 cleanup
Dmitry V. Levin8f546642015-03-17 17:07:57 +000061 dump_log_and_fail_with 'tracee is not sleeping after detach'
Denys Vlasenkoa8151852013-06-19 16:37:24 +020062 }
Dmitry V. Levin0d7c3652013-06-19 14:57:05 +000063fi
Denys Vlasenkoa8151852013-06-19 16:37:24 +020064
Dmitry V. Levin97c85082013-06-18 16:50:18 +000065cleanup
66exit 0