]> granicus.if.org Git - strace/commitdiff
PTRACE_SEIZE can set ptrace options immediately, use this feature
authorDenys Vlasenko <dvlasenk@redhat.com>
Wed, 10 Jul 2013 12:33:05 +0000 (14:33 +0200)
committerDenys Vlasenko <dvlasenk@redhat.com>
Wed, 10 Jul 2013 12:36:28 +0000 (14:36 +0200)
This eliminates some rare bugs, such as post-execve SIGTRAP
generation when we attach to a process, and it manages to finish
execve'ing before we set TRACEEXEC option to suppress that.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
strace.c

index 42cfcb99c546d290a83474ae01dc79b21b9ae48f..94706ad0d00561c8c5f4c8ed8c424b3cb44c77bf 100644 (file)
--- a/strace.c
+++ b/strace.c
@@ -335,11 +335,11 @@ ptrace_attach_or_seize(int pid)
 {
        int r;
        if (!use_seize)
-               return ptrace(PTRACE_ATTACH, pid, 0, 0);
-       r = ptrace(PTRACE_SEIZE, pid, 0, 0);
+               return ptrace(PTRACE_ATTACH, pid, 0L, 0L);
+       r = ptrace(PTRACE_SEIZE, pid, 0L, (unsigned long)ptrace_setoptions);
        if (r)
                return r;
-       r = ptrace(PTRACE_INTERRUPT, pid, 0, 0);
+       r = ptrace(PTRACE_INTERRUPT, pid, 0L, 0L);
        return r;
 }
 #else
@@ -2224,9 +2224,9 @@ trace(void)
                                        return;
                                }
                        }
-                       if (ptrace_setoptions) {
+                       if (!use_seize && ptrace_setoptions) {
                                if (debug_flag)
-                                       fprintf(stderr, "setting opts %x on pid %d\n", ptrace_setoptions, tcp->pid);
+                                       fprintf(stderr, "setting opts 0x%x on pid %d\n", ptrace_setoptions, tcp->pid);
                                if (ptrace(PTRACE_SETOPTIONS, tcp->pid, NULL, ptrace_setoptions) < 0) {
                                        if (errno != ESRCH) {
                                                /* Should never happen, really */