blob: 16f552b589c3df236cf54611fb043ab5cd2e2a91 [file] [log] [blame]
Elliott Hughes5dec78d2014-02-26 15:56:23 -08001#!/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
44if [ -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'
53 }
54fi
55
56cleanup
57exit 0