From: Denys V. <dvl...@re...> - 2011-06-22 11:42:31
|
Hi, TCB_FOLLOWFORK flag seems to be unnecessary, because we either follow all [v]forks/clones or don't follow any, therefore global variable followfork is an already existing indicator of what we want to do. This patch drops all setting/clearing of TCB_FOLLOWFORK bit, and replaces checks for this bit by checks of followfork value. In internal_fork, check is moved to in front of if(), since the check is needed on both "entering" and "exiting" branch. Please review. -- vda diff -d -urpN strace.5/defs.h strace.6/defs.h --- strace.5/defs.h 2011-06-21 20:26:28.000000000 +0200 +++ strace.6/defs.h 2011-06-22 13:31:45.323884488 +0200 @@ -401,7 +401,6 @@ struct tcb { #define TCB_SUSPENDED 00040 /* Process can not be allowed to resume just now */ #define TCB_BPTSET 00100 /* "Breakpoint" set after fork(2) */ #define TCB_SIGTRAPPED 00200 /* Process wanted to block SIGTRAP */ -#define TCB_FOLLOWFORK 00400 /* Process should have forks followed */ #define TCB_REPRINT 01000 /* We should reprint this syscall on exit */ #define TCB_FILTERED 02000 /* This system call has been filtered out */ #ifdef LINUX diff -d -urpN strace.5/process.c strace.6/process.c --- strace.5/process.c 2011-06-22 00:20:26.130712767 +0200 +++ strace.6/process.c 2011-06-22 13:37:06.210864935 +0200 @@ -495,7 +495,6 @@ internal_fork(struct tcb *tcp) return 0; if (!followfork) return 0; - tcp->flags |= TCB_FOLLOWFORK; if (syserror(tcp)) return 0; tcpchild = alloctcb(tcp->u_rval); @@ -796,7 +795,6 @@ handle_new_child(struct tcb *tcp, int pi else #endif /* CLONE_PTRACE */ { - tcp->flags |= TCB_FOLLOWFORK; tcpchild = alloctcb(pid); } @@ -892,10 +890,10 @@ internal_fork(struct tcb *tcp) == (PTRACE_O_TRACECLONE | PTRACE_O_TRACEFORK | PTRACE_O_TRACEVFORK)) return 0; + if (!followfork) + return 0; + if (entering(tcp)) { - tcp->flags &= ~TCB_FOLLOWFORK; - if (!followfork) - return 0; /* * In occasion of using PTRACE_O_TRACECLONE, we won't see the * new child if clone is called with flag CLONE_UNTRACED, so @@ -904,15 +902,11 @@ internal_fork(struct tcb *tcp) if ((sysent[tcp->scno].sys_func == sys_clone) && (tcp->u_arg[ARG_FLAGS] & CLONE_UNTRACED)) return 0; - tcp->flags |= TCB_FOLLOWFORK; setbpt(tcp); } else { int pid; int bpt; - if (!(tcp->flags & TCB_FOLLOWFORK)) - return 0; - bpt = tcp->flags & TCB_BPTSET; if (syserror(tcp)) { @@ -944,17 +938,18 @@ internal_fork(struct tcb *tcp) dont_follow = 1; } #endif + + if (!followfork) + return 0; + if (entering(tcp)) { - if (!followfork || dont_follow) + if (dont_follow) return 0; - tcp->flags |= TCB_FOLLOWFORK; setbpt(tcp); } else { int bpt = tcp->flags & TCB_BPTSET; - if (!(tcp->flags & TCB_FOLLOWFORK)) - return 0; if (bpt) clearbpt(tcp); @@ -962,7 +957,6 @@ internal_fork(struct tcb *tcp) return 0; pid = tcp->u_rval; - tcp->flags |= TCB_FOLLOWFORK; tcpchild = alloctcb(pid); #ifdef SUNOS4 #ifdef oldway diff -d -urpN strace.5/strace.c strace.6/strace.c --- strace.5/strace.c 2011-06-21 23:18:34.278875859 +0200 +++ strace.6/strace.c 2011-06-21 23:36:06.105405997 +0200 @@ -480,7 +480,7 @@ startup_attach(void) ++nerr; else if (tid != tcbtab[tcbi]->pid) { tcp = alloctcb(tid); - tcp->flags |= TCB_ATTACHED|TCB_CLONE_THREAD|TCB_FOLLOWFORK; + tcp->flags |= TCB_ATTACHED|TCB_CLONE_THREAD; tcbtab[tcbi]->nclone_threads++; tcp->parent = tcbtab[tcbi]; } |