From: Dmitry V. Levin Date: Sat, 22 Dec 2018 22:16:03 +0000 (+0000) Subject: strace: terminate itself if interrupted by a signal X-Git-Tag: v4.26~37 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f6869581d44bd6e4bc8cad169451a9ad46169a4d;p=strace strace: terminate itself if interrupted by a signal * strace.c (terminate): Terminate itself if interrupted by a signal. * NEWS: Mention this change. * tests/detach-running.test: Check it. * tests/detach-sleeping.test: Likewise. * tests/detach-stopped.test: Likewise. --- diff --git a/NEWS b/NEWS index 46f0b691..041345d5 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,11 @@ Noteworthy changes in release ?.?? (????-??-??) =============================================== +* Changes in behavior + * If strace is interrupted by a signal it handles (currently + one of HUP, INT, QUIT, PIPE, or TERM), strace terminates + itself with this signal. + Noteworthy changes in release 4.25 (2018-10-30) =============================================== diff --git a/strace.c b/strace.c index e8e25161..d4aae01b 100644 --- a/strace.c +++ b/strace.c @@ -2669,6 +2669,9 @@ terminate(void) while (waitpid(popen_pid, NULL, 0) < 0 && errno == EINTR) ; } + if (interrupted) { + exit_code = 0x100 | interrupted; + } if (exit_code > 0xff) { /* Avoid potential core file clobbering. */ struct_rlimit rlim = {0, 0}; diff --git a/tests/detach-running.test b/tests/detach-running.test index 583a0a9d..62fea7e4 100755 --- a/tests/detach-running.test +++ b/tests/detach-running.test @@ -15,6 +15,12 @@ run_prog_skip_if_failed \ check_prog sleep +trap - TERM +sleep $TIMEOUT_DURATION & +kill -TERM $! +wait $! +expected_rc=$? + set -e ../set_ptracer_any sh -c "echo > $LOG; while :; do :; done" > /dev/null & @@ -45,13 +51,18 @@ while ! grep -F "Process $tracee_pid attached" "$LOG" > /dev/null; do $SLEEP_A_BIT done -kill -INT $! -wait $! +kill -TERM $! +wait $! && rc=0 || rc=$? grep -F "Process $tracee_pid detached" "$LOG" > /dev/null || { - cleanup - dump_log_and_fail_with "$STRACE -p failed to detach" - } + cleanup + dump_log_and_fail_with "$STRACE -p failed to detach" +} + +[ "$rc" = "$expected_rc" ] || { + cleanup + dump_log_and_fail_with "$STRACE -p failed to terminate itself" +} if [ -f /proc/self/status ]; then $SLEEP_A_BIT diff --git a/tests/detach-sleeping.test b/tests/detach-sleeping.test index 6b09d022..ff2eed72 100755 --- a/tests/detach-sleeping.test +++ b/tests/detach-sleeping.test @@ -15,6 +15,12 @@ run_prog_skip_if_failed \ check_prog sleep +trap - TERM +sleep $TIMEOUT_DURATION & +kill -TERM $! +wait $! +expected_rc=$? + set -e ../set_ptracer_any sleep $((2*$TIMEOUT_DURATION)) > "$LOG" & @@ -45,14 +51,19 @@ while ! grep -F "Process $tracee_pid attached" "$LOG" > /dev/null; do $SLEEP_A_BIT done -kill -INT $! -wait $! +kill -TERM $! +wait $! && rc=0 || rc=$? grep -F "Process $tracee_pid detached" "$LOG" > /dev/null || { cleanup dump_log_and_fail_with "$STRACE -p failed to detach" } +[ "$rc" = "$expected_rc" ] || { + cleanup + dump_log_and_fail_with "$STRACE -p failed to terminate itself" +} + if [ -f /proc/self/status ]; then $SLEEP_A_BIT test -d /proc/$tracee_pid || { diff --git a/tests/detach-stopped.test b/tests/detach-stopped.test index 72179a97..e67436dc 100755 --- a/tests/detach-stopped.test +++ b/tests/detach-stopped.test @@ -13,13 +13,19 @@ run_prog_skip_if_failed \ kill -0 $$ -check_prog sleep - $STRACE -d -enone / > /dev/null 2> "$LOG" if grep -x "[^:]*strace: PTRACE_SEIZE doesn't work" "$LOG" > /dev/null; then skip_ "PTRACE_SEIZE doesn't work" fi +check_prog sleep + +trap - TERM +sleep $TIMEOUT_DURATION & +kill -TERM $! +wait $! +expected_rc=$? + set -e > "$LOG" @@ -62,14 +68,19 @@ while ! grep -F -e '--- stopped by ' "$LOG" > /dev/null; do $SLEEP_A_BIT done -kill -INT $! -wait $! +kill -TERM $! +wait $! && rc=0 || rc=$? grep -F "Process $tracee_pid detached" "$LOG" > /dev/null || { cleanup dump_log_and_fail_with "$STRACE -p failed to detach" } +[ "$rc" = "$expected_rc" ] || { + cleanup + dump_log_and_fail_with "$STRACE -p failed to terminate itself" +} + if [ -f /proc/self/status ]; then $SLEEP_A_BIT test -d /proc/$tracee_pid || {