Slight optimization and cleanup in trace():

- do not recalculate "cflag ? &ru : NULL" again and again
- do not clear errno unnecessarily
- consistently check wait errors as pid < 0, not pid == -1
- indent ifdefs for better readability
- remove comments after endif if ifdef/endif block is really tiny

Does it look ok to you?
-- 
vda


--- strace.4/strace.c   2011-06-24 22:42:24.625324956 +0200
+++ strace.5/strace.c   2011-06-24 22:44:31.179006034 +0200
@@ -2352,9 +2351,10 @@ trace()
        struct tcb *tcp;
 #ifdef LINUX
        struct rusage ru;
-#ifdef __WALL
+       struct rusage *rup = cflag ? &ru : NULL;
+# ifdef __WALL
        static int wait4_options = __WALL;
-#endif
+# endif
 #endif /* LINUX */
 
        while (nprocs != 0) {
@@ -2363,35 +2363,32 @@ trace()
                if (interactive)
                        sigprocmask(SIG_SETMASK, &empty_set, NULL);
 #ifdef LINUX
-#ifdef __WALL
-               pid = wait4(-1, &status, wait4_options, cflag ? &ru : NULL);
+# ifdef __WALL
+               pid = wait4(-1, &status, wait4_options, rup);
                if (pid < 0 && (wait4_options & __WALL) && errno == EINVAL) {
                        /* this kernel does not support __WALL */
                        wait4_options &= ~__WALL;
-                       errno = 0;
-                       pid = wait4(-1, &status, wait4_options,
-                                       cflag ? &ru : NULL);
+                       pid = wait4(-1, &status, wait4_options, rup);
                }
                if (pid < 0 && !(wait4_options & __WALL) && errno == ECHILD) {
                        /* most likely a "cloned" process */
-                       pid = wait4(-1, &status, __WCLONE,
-                                       cflag ? &ru : NULL);
-                       if (pid == -1) {
+                       pid = wait4(-1, &status, __WCLONE, rup);
+                       if (pid < 0) {
                                perror_msg("wait4(__WCLONE) failed");
                        }
                }
-#else
-               pid = wait4(-1, &status, 0, cflag ? &ru : NULL);
-#endif /* __WALL */
+# else
+               pid = wait4(-1, &status, 0, rup);
+# endif /* __WALL */
 #endif /* LINUX */
 #ifdef SUNOS4
                pid = wait(&status);
-#endif /* SUNOS4 */
+#endif
                wait_errno = errno;
                if (interactive)
                        sigprocmask(SIG_BLOCK, &blocked_set, NULL);
 
-               if (pid == -1) {
+               if (pid < 0) {
                        switch (wait_errno) {
                        case EINTR:
                                continue;



------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure contains a 
definitive record of customers, application performance, security 
threats, fraudulent activity and more. Splunk takes this data and makes 
sense of it. Business sense. IT sense. Common sense.. 
http://p.sf.net/sfu/splunk-d2d-c1
_______________________________________________
Strace-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/strace-devel

Reply via email to