]> granicus.if.org Git - strace/commitdiff
strace: terminate itself if interrupted by a signal
authorDmitry V. Levin <ldv@altlinux.org>
Sat, 22 Dec 2018 22:16:03 +0000 (22:16 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Sat, 22 Dec 2018 22:16:03 +0000 (22:16 +0000)
* 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.

NEWS
strace.c
tests/detach-running.test
tests/detach-sleeping.test
tests/detach-stopped.test

diff --git a/NEWS b/NEWS
index 46f0b691799db478d5552b758ca44eac40a29609..041345d5c99b1baa069e98ade0a894ef5455d4ce 100644 (file)
--- 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)
 ===============================================
 
index e8e25161b51bd171ba65eed8f5cc10d76fcc45d5..d4aae01bf40e223650b779d79814046545f6a4e7 100644 (file)
--- 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};
index 583a0a9d48781ecb29da4807673989fb9ef2768d..62fea7e411a2b4be01b662879dc3a4c09fe2c8db 100755 (executable)
@@ -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
index 6b09d022079bce935b44993aefd10168235ba77b..ff2eed72abb9250abeb6ab56737289b9fe28108a 100755 (executable)
@@ -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 || {
index 72179a97e1c9fca28aea6b540572bb028bdf1c2a..e67436dcbe5e93863cc7ab4cc579f6b2a7fe804e 100755 (executable)
 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 || {