[PATCH] USE_SEIZE: fix detaching from stopped processes

Dmitry V. Levin ldv at altlinux.org
Mon Jun 10 14:55:53 UTC 2013


* strace.c (detach) [USE_SEIZE]: If PTRACE_SEIZE API is in use, stop
the tracee using PTRACE_INTERRUPT instead of sending it a SIGSTOP.
* tests/detach: New test.
* tests/Makefile.am (TESTS): Add it.

Reported-by: Raghavendra D Prabhu <raghu.prabhu13 at gmail.com>
---
Denys, please have a look whether this fix is correct.

 strace.c          | 10 +++++++++-
 tests/Makefile.am |  2 +-
 tests/detach      | 38 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 48 insertions(+), 2 deletions(-)
 create mode 100755 tests/detach

diff --git a/strace.c b/strace.c
index 6eab600..e46d7a6 100644
--- a/strace.c
+++ b/strace.c
@@ -769,7 +769,15 @@ detach(struct tcb *tcp)
 			if (errno != ESRCH)
 				perror_msg("detach: checking sanity");
 		}
-		else if (!sigstop_expected && my_tkill(tcp->pid, SIGSTOP) < 0) {
+#if USE_SEIZE
+		else if (!sigstop_expected && use_seize
+			 && ptrace(PTRACE_INTERRUPT, tcp->pid, 0, 0) < 0) {
+			if (errno != ESRCH)
+				perror_msg("detach: ptrace(PTRACE_INTERRUPT, ...)");
+		}
+#endif
+		else if (!sigstop_expected && !use_seize
+			 && my_tkill(tcp->pid, SIGSTOP) < 0) {
 			if (errno != ESRCH)
 				perror_msg("detach: stopping child");
 		}
diff --git a/tests/Makefile.am b/tests/Makefile.am
index a7f584d..debf2b0 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -4,7 +4,7 @@ AM_CFLAGS = $(WARN_CFLAGS)
 
 check_PROGRAMS = net-accept-connect
 
-TESTS = ptrace_setoptions strace-f qual_syscall stat net
+TESTS = ptrace_setoptions strace-f qual_syscall stat net detach
 
 EXTRA_DIST = init.sh $(TESTS)
 
diff --git a/tests/detach b/tests/detach
new file mode 100755
index 0000000..4b20c2c
--- /dev/null
+++ b/tests/detach
@@ -0,0 +1,38 @@
+#!/bin/sh
+
+# Ensure that strace can detach.
+
+. "${srcdir=.}/init.sh"
+
+check_strace
+check_timeout
+check_prog sleep
+check_prog grep
+
+exec > check.log 2>&1
+set -e
+
+sleep 60 &
+tracee_pid=$!
+kill -STOP $tracee_pid
+
+$TIMEOUT $STRACE -p $tracee_pid &
+
+while ! grep '^--- stopped by ' check.log > /dev/null; do
+	if grep -F Killed check.log > /dev/null; then
+		exit 1
+	fi
+	sleep 1
+done
+
+kill -INT $!
+wait $!
+
+kill $tracee_pid
+kill -CONT $tracee_pid
+wait
+
+grep -F "Process $tracee_pid detached" check.log > /dev/null ||
+	exit 1
+
+exit 0

-- 
ldv
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: <http://lists.strace.io/pipermail/strace-devel/attachments/20130610/d9f7964b/attachment.bin>


More information about the Strace-devel mailing list