2016-02-08 19:47:40 +03:00
#!/bin/sh
#
# Ensure that strace does not retain stdin and stdout descriptors.
#
# Copyright (c) 2016 Dmitry V. Levin <ldv@altlinux.org>
2018-12-25 02:46:43 +03:00
# Copyright (c) 2016-2018 The strace developers.
2016-02-08 19:47:40 +03:00
# All rights reserved.
#
2018-12-10 03:00:00 +03:00
# SPDX-License-Identifier: GPL-2.0-or-later
2016-02-08 19:47:40 +03:00
. "${srcdir=.}/init.sh"
run_prog_skip_if_failed \
kill -0 $$
check_prog sleep
check_prog yes
2016-12-06 05:55:49 +03:00
> "$OUT"
2016-02-08 19:47:40 +03:00
> "$LOG"
(
2016-12-06 05:55:49 +03:00
while [ -f "$LOG" ]; do
:
done
2016-02-08 19:47:40 +03:00
$SLEEP_A_BIT &
yes
if kill -0 $! 2> /dev/null; then
wait
else
2016-12-06 05:55:49 +03:00
echo TIMEOUT >> "$OUT"
2016-02-08 19:47:40 +03:00
fi
2016-02-14 03:54:32 +03:00
) | $STRACE -qq -enone -esignal=none \
2016-12-06 05:55:49 +03:00
sh -c "exec <&- >&-; rm -f -- $LOG; $SLEEP_A_BIT; $SLEEP_A_BIT"
2016-02-08 19:47:40 +03:00
2016-12-06 05:55:49 +03:00
if [ -s "$OUT" ]; then
2016-02-08 19:47:40 +03:00
fail_ "$STRACE failed to redirect standard input"
fi
2016-12-06 05:55:49 +03:00
> "$LOG"
2016-02-14 03:54:32 +03:00
$STRACE -qq -enone -esignal=none \
2016-12-06 05:55:49 +03:00
sh -c "exec <&- >&-; rm -f -- $LOG; $SLEEP_A_BIT; $SLEEP_A_BIT" |
2016-02-08 19:47:40 +03:00
(
2016-12-06 05:55:49 +03:00
while [ -f "$LOG" ]; do
:
done
2016-02-08 19:47:40 +03:00
$SLEEP_A_BIT &
cat > /dev/null
if kill -0 $! 2> /dev/null; then
wait
else
2016-12-06 05:55:49 +03:00
echo TIMEOUT >> "$OUT"
2016-02-08 19:47:40 +03:00
fi
)
2016-12-06 05:55:49 +03:00
if [ -s "$OUT" ]; then
2016-02-08 19:47:40 +03:00
fail_ "$STRACE failed to redirect standard output"
fi