> Patch 2: Remove TCB_ATTACH_DONE - it is possible to use TCB_STARTUP bit 
> instead.


diff -d -urpN strace.2/defs.h strace.3/defs.h
--- strace.2/defs.h     2011-09-01 16:18:18.000000000 +0200
+++ strace.3/defs.h     2011-09-01 20:17:13.712850718 +0200
@@ -458,9 +458,6 @@ struct tcb {
  */
 #define TCB_INSYSCALL  00004
 #define TCB_ATTACHED   00010   /* Process is not our own child */
-#ifdef LINUX
-#define TCB_ATTACH_DONE        00020   /* PTRACE_ATTACH was done on this 
tcb->pid */
-#endif
 #define TCB_BPTSET     00100   /* "Breakpoint" set after fork(2) */
 #define TCB_SIGTRAPPED 00200   /* Process wanted to block SIGTRAP */
 #define TCB_REPRINT    01000   /* We should reprint this syscall on exit */
diff -d -urpN strace.2/strace.c strace.3/strace.c
--- strace.2/strace.c   2011-09-02 16:08:29.976955668 +0200
+++ strace.3/strace.c   2011-09-02 16:06:04.360190184 +0200
@@ -444,12 +444,10 @@ startup_attach(void)
        for (tcbi = 0; tcbi < tcbtabsize; tcbi++) {
                tcp = tcbtab[tcbi];
 
-               if (!(tcp->flags & TCB_INUSE) || !(tcp->flags & TCB_ATTACHED))
-                       continue;
-#ifdef LINUX
-               if (tcp->flags & TCB_ATTACH_DONE)
-                       continue;
-#endif
+               /* Is this a process we should attach to, but not yet attached? 
*/
+               if ((tcp->flags & (TCB_INUSE | TCB_ATTACHED | TCB_STARTUP)) != 
(TCB_INUSE | TCB_ATTACHED))
+                       continue; /* no */
+
                /* Reinitialize the output since it may have changed. */
                tcp->outf = outf;
                newoutf(tcp);
@@ -471,8 +469,11 @@ startup_attach(void)
                        if (dir != NULL) {
                                unsigned int ntid = 0, nerr = 0;
                                struct dirent *de;
-                               int tid;
+
                                while ((de = readdir(dir)) != NULL) {
+                                       struct tcb *cur_tcp;
+                                       int tid;
+
                                        if (de->d_fileno == 0)
                                                continue;
                                        tid = atoi(de->d_name);
@@ -483,23 +484,22 @@ startup_attach(void)
                                                ++nerr;
                                                if (debug)
                                                        fprintf(stderr, "attach 
to pid %d failed\n", tid);
+                                               continue;
                                        }
-                                       else {
-                                               if (debug)
-                                                       fprintf(stderr, "attach 
to pid %d succeeded\n", tid);
-                                               if (tid != tcp->pid) {
-                                                       struct tcb *new_tcp = 
alloctcb(tid);
-                                                       new_tcp->flags |= 
TCB_ATTACHED|TCB_ATTACH_DONE|TCB_STARTUP;
-                                               }
-                                       }
-                                       if (interactive) {
-                                               sigprocmask(SIG_SETMASK, 
&empty_set, NULL);
-                                               if (interrupted)
-                                                       goto ret;
-                                               sigprocmask(SIG_BLOCK, 
&blocked_set, NULL);
-                                       }
+                                       if (debug)
+                                               fprintf(stderr, "attach to pid 
%d succeeded\n", tid);
+                                       cur_tcp = tcp;
+                                       if (tid != tcp->pid)
+                                               cur_tcp = alloctcb(tid);
+                                       cur_tcp->flags |= TCB_ATTACHED | 
TCB_STARTUP;
                                }
                                closedir(dir);
+                               if (interactive) {
+                                       sigprocmask(SIG_SETMASK, &empty_set, 
NULL);
+                                       if (interrupted)
+                                               goto ret;
+                                       sigprocmask(SIG_BLOCK, &blocked_set, 
NULL);
+                               }
                                ntid -= nerr;
                                if (ntid == 0) {
                                        perror("attach: ptrace(PTRACE_ATTACH, 
...)");
@@ -546,14 +546,6 @@ startup_attach(void)
        } /* for each tcbtab[] */
 
  ret:
-#ifdef LINUX
-       /* TCB_ATTACH_DONE flag is used only in this function */
-       for (tcbi = 0; tcbi < tcbtabsize; tcbi++) {
-               tcp = tcbtab[tcbi];
-               tcp->flags &= ~TCB_ATTACH_DONE;
-       }
-#endif
-
        if (interactive)
                sigprocmask(SIG_SETMASK, &empty_set, NULL);
 }



------------------------------------------------------------------------------
Special Offer -- Download ArcSight Logger for FREE!
Finally, a world-class log management solution at an even better 
price-free! And you'll get a free "Love Thy Logs" t-shirt when you
download Logger. Secure your free ArcSight Logger TODAY!
http://p.sf.net/sfu/arcsisghtdev2dev
_______________________________________________
Strace-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/strace-devel

Reply via email to