]> granicus.if.org Git - strace/commitdiff
2007-05-24 Jan Kratochvil <jan.kratochvil@redhat.com>
authorRoland McGrath <roland@redhat.com>
Sat, 2 Jun 2007 00:07:33 +0000 (00:07 +0000)
committerRoland McGrath <roland@redhat.com>
Sat, 2 Jun 2007 00:07:33 +0000 (00:07 +0000)
* strace.c [LINUX] (my_tgkill): New macro.
[LINUX] (detach): Use my_tgkill () instead of kill(2).
Fixes RH#240962.

strace.c

index 5e3b8757e6821033d875b5b835a846f2f3878f0d..1acfd0aad422dc85f263a23f6fd3c132150ede34 100644 (file)
--- a/strace.c
+++ b/strace.c
 #include <limits.h>
 #include <dirent.h>
 
+#ifdef LINUX
+# 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 +1337,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");
        }