From 2b60c35b33cf22a88405c60db1e620880d05a7d4 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 22 Jun 2011 12:45:25 +0200 Subject: [PATCH] Delete fork_tcb() Get rid of fork_tcb() function. It used to do what the comment above it says, but now it doesn't do much: it only sets tcp->flags |= TCB_FOLLOWFORK and maybe calls expand_tcbtab(). The second operation is not necessary, since alloc_tcp() will do it itself when needed. This patch deletes fork_tcb(), open-coding tcp->flags |= TCB_FOLLOWFORK where it was formerly called. It also makes nprocs, tcbtabsize and expand_tcbtab() static. (While at it, I nuked redundant extern char **environ declaration: strace.c had *two* of them...) * defs.h: Remove declarations of nprocs, tcbtabsize and expand_tcbtab. * process.c (fork_tcb): Remove this function. (internal_fork): Open-code fork_tcb. (handle_new_child): Likewise. * strace.c: Remove redundant "extern char **environ". Declare nprocs and tcbtabsize static. (expand_tcbtab): Make it static. Signed-off-by: Denys Vlasenko --- defs.h | 2 -- process.c | 22 +++++----------------- strace.c | 5 ++--- 3 files changed, 7 insertions(+), 22 deletions(-) diff --git a/defs.h b/defs.h index ab24f7cf..23ed7832 100644 --- a/defs.h +++ b/defs.h @@ -510,7 +510,6 @@ extern unsigned int ptrace_setoptions; extern int dtime, xflag, qflag; extern cflag_t cflag; extern int acolumn; -extern unsigned int nprocs, tcbtabsize; extern int max_strlen; extern struct tcb *tcp_last; @@ -526,7 +525,6 @@ extern const char *xlookup(const struct xlat *, int); extern struct tcb *alloc_tcb(int, int); extern struct tcb *pid2tcb(int); extern void droptcb(struct tcb *); -extern void expand_tcbtab(void); #define alloctcb(pid) alloc_tcb((pid), 1) diff --git a/process.c b/process.c index 276ce20b..7aa5aa43 100644 --- a/process.c +++ b/process.c @@ -448,18 +448,6 @@ internal_exit(struct tcb *tcp) return 0; } -/* TCP is creating a child we want to follow. - If there will be space in tcbtab for it, set TCB_FOLLOWFORK and return 0. - If not, clear TCB_FOLLOWFORK, print an error, and return 1. */ -static void -fork_tcb(struct tcb *tcp) -{ - if (nprocs == tcbtabsize) - expand_tcbtab(); - - tcp->flags |= TCB_FOLLOWFORK; -} - #ifdef USE_PROCFS int @@ -507,7 +495,7 @@ internal_fork(struct tcb *tcp) return 0; if (!followfork) return 0; - fork_tcb(tcp); + tcp->flags |= TCB_FOLLOWFORK; if (syserror(tcp)) return 0; tcpchild = alloctcb(tcp->u_rval); @@ -808,7 +796,7 @@ handle_new_child(struct tcb *tcp, int pid, int bpt) else #endif /* CLONE_PTRACE */ { - fork_tcb(tcp); + tcp->flags |= TCB_FOLLOWFORK; tcpchild = alloctcb(pid); } @@ -916,7 +904,7 @@ internal_fork(struct tcb *tcp) if ((sysent[tcp->scno].sys_func == sys_clone) && (tcp->u_arg[ARG_FLAGS] & CLONE_UNTRACED)) return 0; - fork_tcb(tcp); + tcp->flags |= TCB_FOLLOWFORK; setbpt(tcp); } else { int pid; @@ -959,7 +947,7 @@ internal_fork(struct tcb *tcp) if (entering(tcp)) { if (!followfork || dont_follow) return 0; - fork_tcb(tcp); + tcp->flags |= TCB_FOLLOWFORK; setbpt(tcp); } else { @@ -974,7 +962,7 @@ internal_fork(struct tcb *tcp) return 0; pid = tcp->u_rval; - fork_tcb(tcp); + tcp->flags |= TCB_FOLLOWFORK; tcpchild = alloctcb(pid); #ifdef SUNOS4 #ifdef oldway diff --git a/strace.c b/strace.c index 3b393719..84fc1b77 100644 --- a/strace.c +++ b/strace.c @@ -127,9 +127,8 @@ static char *outfname = NULL; FILE *outf; static int curcol; struct tcb **tcbtab; -unsigned int nprocs, tcbtabsize; +static unsigned int nprocs, tcbtabsize; const char *progname; -extern char **environ; static int detach(struct tcb *tcp, int sig); static int trace(void); @@ -1244,7 +1243,7 @@ main(int argc, char *argv[]) exit(exit_code); } -void +static void expand_tcbtab(void) { /* Allocate some more TCBs and expand the table. -- 2.40.0