[patch] Hangs and/or multithreaded process left Stopped (T) on CTRL-C of strace

Jan Kratochvil jan.kratochvil at redhat.com
Thu May 24 09:37:31 UTC 2007


Roland,

patch updated.


Thanks,
Jan
-------------- next part --------------
2007-05-24  Jan Kratochvil  <jan.kratochvil at redhat.com>
	    Roland McGrath  <roland at redhat.com>

	* strace.c [LINUX] (my_tgkill): New definition.
	[LINUX] (detach): Use my_tgkill () instead of kill(2).
	Fixes RH#240962.

diff -u -rup strace-4.5.15-orig/strace.c strace-4.5.15-tkill/strace.c
--- strace-4.5.15-orig/strace.c	2006-12-13 22:55:39.000000000 +0100
+++ strace-4.5.15-tkill/strace.c	2007-05-24 11:26:18.000000000 +0200
@@ -46,6 +46,22 @@
 #include <limits.h>
 #include <dirent.h>
 
+#ifdef LINUX
+# include <unistd.h>
+# include <asm/unistd.h>
+# if defined __NR_tgkill
+#  define my_tgkill(pid, tid, sig) syscall (__NR_tgkill, (pid), (tid), (sig))
+# elif defined __NR_tkill
+#  define my_tgkill(pid, tid, sig) syscall (__NR_tkill, (tid), (sig))
+# else
+   /* kill() may choose arbitrarily the target task of the process group
+      while we later wait on a that specific TID.  PID process waits become
+      TID task specific waits for a process under ptrace(2).  */
+#  warning "Neither tkill(2) or tgkill(2) available, risk of strace hangs!"
+#  define my_tgkill(pid, tid, sig) kill ((tid), (sig))
+# endif
+#endif
+
 #if defined(IA64) && defined(LINUX)
 # include <asm/ptrace_offsets.h>
 #endif
@@ -1322,11 +1338,13 @@ int sig;
 		/* Shouldn't happen. */
 		perror("detach: ptrace(PTRACE_DETACH, ...)");
 	}
-	else if (kill(tcp->pid, 0) < 0) {
+	else if (my_tgkill((tcp->parent ? tcp->parent->pid : tcp->pid),
+			   tcp->pid, 0) < 0) {
 		if (errno != ESRCH)
 			perror("detach: checking sanity");
 	}
-	else if (kill(tcp->pid, SIGSTOP) < 0) {
+	else if (my_tgkill((tcp->parent ? tcp->parent->pid : tcp->pid),
+			   tcp->pid, SIGSTOP) < 0) {
 		if (errno != ESRCH)
 			perror("detach: stopping child");
 	}


More information about the Strace-devel mailing list