From: Denys Vlasenko Date: Wed, 10 Jul 2013 12:33:05 +0000 (+0200) Subject: PTRACE_SEIZE can set ptrace options immediately, use this feature X-Git-Tag: v4.9~199 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c169d94718e0c3a980dbf352010e615daf2f4332;p=strace PTRACE_SEIZE can set ptrace options immediately, use this feature 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 --- diff --git a/strace.c b/strace.c index 42cfcb99..94706ad0 100644 --- 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 */