Hi,

Sometime ago expand_tcbtab/alloc_tcb were modified
so that they never return failure (they will abort instead).

This opens up a possibility for further simplifications.

This patch gets 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 and tcbtabsize
variables static. (While at it, I nuked redundant extern char **environ
declaration: strace.c had *two* of them...)

Please review.

-- 
vda



diff -d -urpN strace.7/defs.h strace.8/defs.h
--- strace.7/defs.h     2011-06-21 16:03:18.011238717 +0200
+++ strace.8/defs.h     2011-06-21 20:10:16.722982152 +0200
@@ -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;
 
diff -d -urpN strace.7/process.c strace.8/process.c
--- strace.7/process.c  2011-06-21 16:00:55.384401476 +0200
+++ strace.8/process.c  2011-06-21 20:08:39.681173083 +0200
@@ -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 pi
        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;
                if (setbpt(tcp) < 0)
                        return 0;
        } else {
@@ -960,7 +948,7 @@ internal_fork(struct tcb *tcp)
        if (entering(tcp)) {
                if (!followfork || dont_follow)
                        return 0;
-               fork_tcb(tcp);
+               tcp->flags |= TCB_FOLLOWFORK;
                if (setbpt(tcp) < 0)
                        return 0;
        }
@@ -976,7 +964,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 -d -urpN strace.7/strace.c strace.8/strace.c
--- strace.7/strace.c   2011-06-21 20:11:27.220751557 +0200
+++ strace.8/strace.c   2011-06-21 20:11:31.876733125 +0200
@@ -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);


------------------------------------------------------------------------------
EditLive Enterprise is the world's most technically advanced content
authoring tool. Experience the power of Track Changes, Inline Image
Editing and ensure content is compliant with Accessibility Checking.
http://p.sf.net/sfu/ephox-dev2dev
_______________________________________________
Strace-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/strace-devel

Reply via email to