1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
|
#!/bin/sh -efu
#
# Check -D option.
#
# Copyright (c) 2019 Dmitry V. Levin <ldv@strace.io>
# Copyright (c) 2019-2020 The strace developers.
# All rights reserved.
#
# SPDX-License-Identifier: GPL-2.0-or-later
. "${srcdir=.}/init.sh"
check_prog sed
run_prog_skip_if_failed \
kill -0 $$
get_parent_pid()
{
sed '/^PPid:[[:space:]]*/!d;s///'
}
get_tracer_pid()
{
sed '/^TracerPid:[[:space:]]*/!d;s///'
}
set -- ../print_ppid_tracerpid
"$@" > "$LOG" ||
framework_skip_ "$* does not work"
# not traced: PPid > 0, TracerPid == 0
[ "$(get_parent_pid < "$LOG")" -gt 0 ] &&
[ "$(get_tracer_pid < "$LOG")" -eq 0 ] ||
dump_log_and_fail_with "$*: unexpected output"
# !-D: PPid > 0, TracerPid > 0, PPid == TracerPid
run_strace -e q=attach,personality -enone "$@" > "$OUT"
[ "$(get_parent_pid < "$OUT")" -gt 0 ] &&
[ "$(get_tracer_pid < "$OUT")" -gt 0 ] &&
[ "$(get_parent_pid < "$OUT")" = "$(get_tracer_pid < "$OUT")" ] || {
cat < "$OUT" > "$LOG"
dump_log_and_fail_with "$STRACE $args: unexpected output"
}
match_diff
test_parent_tracer_pid()
{
local d parent_pid tracer_pid
d="$1"; shift
# -D/-DD/-DDD: PPid > 0, TracerPid > 0, PPid != TracerPid
run_strace $d -q -enone "$@" > "$OUT"
parent_pid="$(get_parent_pid < "$OUT")" &&
[ "$parent_pid" -gt 0 ] &&
tracer_pid="$(get_tracer_pid < "$OUT")" &&
[ "$tracer_pid" -gt 0 ] &&
[ "$parent_pid" != "$tracer_pid" ] || {
cat < "$OUT" > "$LOG"
dump_log_and_fail_with "$STRACE $args: unexpected output"
}
while kill -0 "$tracer_pid" 2> /dev/null; do
$SLEEP_A_BIT
done
match_diff
}
test_parent_tracer_pid -D "$@"
test_parent_tracer_pid -DD "$@"
test_parent_tracer_pid -DDD "$@"
|