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

Jan Kratochvil jan.kratochvil at redhat.com
Thu May 24 15:05:44 UTC 2007


On Thu, 24 May 2007 11:54:00 +0200, Roland McGrath wrote:
> What is <unistd.h> for?

According to the syscall(2) man page and according to my local include files it
contains the prototype for the SYSCALL function itself:
/usr/include/unistd.h:
	extern long int syscall (long int __sysno, ...) __THROW;

It is not directly required there as it is included through "defs.h".

...
> 	(tcp->flags & TCB_CLONE_THREAD) ? tcp->parent->pid : tcp->pid

Sure, I am not aware of the codebase, sorry, 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.

--- 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 16:56:45.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) nor 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,15 @@ int sig;
 		/* Shouldn't happen. */
 		perror("detach: ptrace(PTRACE_DETACH, ...)");
 	}
-	else if (kill(tcp->pid, 0) < 0) {
+	else if (my_tgkill((tcp->flags & TCB_CLONE_THREAD ? 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->flags & TCB_CLONE_THREAD ? tcp->parent->pid
+							  : tcp->pid),
+			   tcp->pid, SIGSTOP) < 0) {
 		if (errno != ESRCH)
 			perror("detach: stopping child");
 	}


More information about the Strace-devel mailing list