]> granicus.if.org Git - strace/blob - tests/redirect.test
Update copyright headers
[strace] / tests / redirect.test
1 #!/bin/sh
2 #
3 # Ensure that strace does not retain stdin and stdout descriptors.
4 #
5 # Copyright (c) 2016 Dmitry V. Levin <ldv@altlinux.org>
6 # Copyright (c) 2016-2018 The strace developers.
7 # All rights reserved.
8 #
9 # SPDX-License-Identifier: GPL-2.0-or-later
10
11 . "${srcdir=.}/init.sh"
12
13 run_prog_skip_if_failed \
14         kill -0 $$
15
16 check_prog sleep
17 check_prog yes
18
19 > "$OUT"
20 > "$LOG"
21 (
22         while [ -f "$LOG" ]; do
23                 :
24         done
25         $SLEEP_A_BIT &
26         yes
27         if kill -0 $! 2> /dev/null; then
28                 wait
29         else
30                 echo TIMEOUT >> "$OUT"
31         fi
32 ) | $STRACE -qq -enone -esignal=none \
33         sh -c "exec <&- >&-; rm -f -- $LOG; $SLEEP_A_BIT; $SLEEP_A_BIT"
34
35 if [ -s "$OUT" ]; then
36         fail_ "$STRACE failed to redirect standard input"
37 fi
38
39 > "$LOG"
40 $STRACE -qq -enone -esignal=none \
41         sh -c "exec <&- >&-; rm -f -- $LOG; $SLEEP_A_BIT; $SLEEP_A_BIT" |
42 (
43         while [ -f "$LOG" ]; do
44                 :
45         done
46         $SLEEP_A_BIT &
47         cat > /dev/null
48         if kill -0 $! 2> /dev/null; then
49                 wait
50         else
51                 echo TIMEOUT >> "$OUT"
52         fi
53 )
54
55 if [ -s "$OUT" ]; then
56         fail_ "$STRACE failed to redirect standard output"
57 fi