blob: 16f552b589c3df236cf54611fb043ab5cd2e2a91 [file] [log] [blame]
Dmitry V. Levin78460f82013-06-19 10:22:18 +00001#!/bin/sh
2
3# Ensure that strace can detach from running processes.
4
5. "${srcdir=.}/init.sh"
6
7check_prog sleep
8check_prog grep
9
10set -e
11
12./set_ptracer_any sh -c "echo > $LOG; while :; do :; done" > /dev/null &
13
14while ! [ -s $LOG ]; do
15 kill -0 $! 2> /dev/null ||
16 fail_ 'set_ptracer_any sh failed'
17 $SLEEP_A_BIT
18done
19
20tracee_pid=$!
21
22cleanup()
23{
24 set +e
25 kill $tracee_pid
26 wait $tracee_pid 2> /dev/null
27}
28
29rm -f $LOG
30$STRACE -p $tracee_pid 2> $LOG &
31
32while ! 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
36done
37
38kill -INT $!
39wait $!
40
41grep -F "Process $tracee_pid detached" $LOG > /dev/null ||
42 { cat $LOG; cleanup; fail_ 'strace -p failed to detach'; }
43
Dmitry V. Levin0d7c3652013-06-19 14:57:05 +000044if [ -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 Vlasenkoa8151852013-06-19 16:37:24 +020053 }
Dmitry V. Levin0d7c3652013-06-19 14:57:05 +000054fi
Denys Vlasenkoa8151852013-06-19 16:37:24 +020055
Dmitry V. Levin78460f82013-06-19 10:22:18 +000056cleanup
57exit 0