• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/sh
2
3# Ensure that strace can detach from stopped processes.
4
5. "${srcdir=.}/init.sh"
6
7check_prog sleep
8check_prog grep
9
10set -e
11
12rm -f $LOG
13./set_ptracer_any sleep $((2*$TIMEOUT_DURATION)) > $LOG &
14
15while ! [ -s $LOG ]; do
16	kill -0 $! 2> /dev/null ||
17		fail_ 'set_ptracer_any sleep failed'
18	$SLEEP_A_BIT
19done
20
21tracee_pid=$!
22kill -STOP $tracee_pid
23
24cleanup()
25{
26	set +e
27	kill $tracee_pid
28	kill -CONT $tracee_pid
29	wait $tracee_pid 2> /dev/null
30}
31
32rm -f $LOG
33$STRACE -p $tracee_pid 2> $LOG &
34
35while ! grep -F "Process $tracee_pid attached" $LOG > /dev/null; do
36	kill -0 $! 2> /dev/null ||
37		{ cat $LOG; cleanup; fail_ 'strace -p does not work'; }
38	$SLEEP_A_BIT
39done
40
41while ! grep -F -e '--- stopped by ' $LOG > /dev/null; do
42	kill -0 $! 2> /dev/null ||
43		{ cat $LOG; cleanup; fail_ 'strace -p does not work'; }
44	$SLEEP_A_BIT
45done
46
47kill -INT $!
48wait $!
49
50grep -F "Process $tracee_pid detached" $LOG > /dev/null ||
51	{ cat $LOG; cleanup; fail_ 'strace -p failed to detach'; }
52
53if [ -f /proc/self/status ]; then
54	$SLEEP_A_BIT
55	test -d /proc/$tracee_pid ||
56		{ cat $LOG; cleanup; fail_ 'tracee died after detach'; }
57	grep '^State:.*T (stopped)' < /proc/$tracee_pid/status > /dev/null || {
58		cat $LOG
59		grep '^State:' < /proc/$tracee_pid/status
60		cleanup
61		fail_ 'tracee is not group-stopped after detach'
62	}
63fi
64
65cleanup
66exit 0
67