diff --git a/defs.h b/defs.h index b2ca9233..75b002dc 100644 --- a/defs.h +++ b/defs.h @@ -508,8 +508,7 @@ typedef enum { extern struct tcb **tcbtab; extern int *qual_flags; extern int debug, followfork; -extern unsigned int ptrace_setoptions_followfork; -extern unsigned int ptrace_setoptions_for_all; +extern unsigned int ptrace_setoptions; extern int dtime, xflag, qflag; extern cflag_t cflag; extern int acolumn; diff --git a/process.c b/process.c index fc5fa90c..0584f547 100644 --- a/process.c +++ b/process.c @@ -904,7 +904,7 @@ Process %u resumed (parent %d ready)\n", int internal_fork(struct tcb *tcp) { - if ((ptrace_setoptions_followfork + if ((ptrace_setoptions & (PTRACE_O_TRACECLONE | PTRACE_O_TRACEFORK | PTRACE_O_TRACEVFORK)) == (PTRACE_O_TRACECLONE | PTRACE_O_TRACEFORK | PTRACE_O_TRACEVFORK)) return 0; @@ -1751,7 +1751,7 @@ internal_exec(struct tcb *tcp) tcp->flags &= ~TCB_WAITEXECVE; else { /* Maybe we have post-execve SIGTRAP suppressed? */ - if (!(ptrace_setoptions_for_all & PTRACE_O_TRACEEXEC)) + if (!(ptrace_setoptions & PTRACE_O_TRACEEXEC)) tcp->flags |= TCB_WAITEXECVE; /* no */ } #endif /* LINUX && TCB_WAITEXECVE */ diff --git a/strace.c b/strace.c index 3298795a..93e6d29f 100644 --- a/strace.c +++ b/strace.c @@ -84,8 +84,7 @@ extern char *optarg; int debug = 0, followfork = 0; -unsigned int ptrace_setoptions_followfork = 0; -unsigned int ptrace_setoptions_for_all = 0; +unsigned int ptrace_setoptions = 0; /* Which WSTOPSIG(status) value marks syscall traps? */ static unsigned int syscall_trap_sig = SIGTRAP; int dtime = 0, xflag = 0, qflag = 0; @@ -826,7 +825,7 @@ test_ptrace_setoptions_followfork(void) } } if (expected_grandchild && expected_grandchild == found_grandchild) - ptrace_setoptions_followfork |= test_options; + ptrace_setoptions |= test_options; return 0; } @@ -907,10 +906,10 @@ test_ptrace_setoptions_for_all(void) if (it_worked) { syscall_trap_sig = (SIGTRAP | 0x80); - ptrace_setoptions_for_all = test_options; + ptrace_setoptions |= test_options; if (debug) - fprintf(stderr, "ptrace_setoptions_for_all = %#x\n", - ptrace_setoptions_for_all); + fprintf(stderr, "ptrace_setoptions = %#x\n", + ptrace_setoptions); return; } @@ -1136,11 +1135,11 @@ main(int argc, char *argv[]) fprintf(stderr, "Test for options supported by PTRACE_SETOPTIONS " "failed, giving up using this feature.\n"); - ptrace_setoptions_followfork = 0; + ptrace_setoptions = 0; } if (debug) - fprintf(stderr, "ptrace_setoptions_followfork = %#x\n", - ptrace_setoptions_followfork); + fprintf(stderr, "ptrace_setoptions = %#x\n", + ptrace_setoptions); } test_ptrace_setoptions_for_all(); #endif @@ -2679,16 +2678,16 @@ Process %d attached (waiting for parent)\n", } } #ifdef LINUX - int options = ptrace_setoptions_for_all; - if (followfork && (tcp->parent == NULL)) - options |= ptrace_setoptions_followfork; - if (options) { - if (debug) - fprintf(stderr, "setting opts %x on pid %d\n", options, tcp->pid); - if (ptrace(PTRACE_SETOPTIONS, tcp->pid, NULL, options) < 0) { - if (errno != ESRCH) { - /* Should never happen, really */ - perror_msg_and_die("PTRACE_SETOPTIONS"); + /* If options were not set for this tracee yet */ + if (tcp->parent == NULL) { + if (ptrace_setoptions) { + if (debug) + fprintf(stderr, "setting opts %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 */ + perror_msg_and_die("PTRACE_SETOPTIONS"); + } } } }