[darwinbuild-changes] [929] branches/PR-8817822/darwintrace/darwintrace.c

source_changes at macosforge.org source_changes at macosforge.org
Tue Feb 8 12:07:22 PST 2011


Revision: 929
          http://trac.macosforge.org/projects/darwinbuild/changeset/929
Author:   wsiegrist at apple.com
Date:     2011-02-08 12:07:22 -0800 (Tue, 08 Feb 2011)
Log Message:
-----------
Dont bother fsyncing and return sooner from setup when setup already done

Modified Paths:
--------------
    branches/PR-8817822/darwintrace/darwintrace.c

Modified: branches/PR-8817822/darwintrace/darwintrace.c
===================================================================
--- branches/PR-8817822/darwintrace/darwintrace.c	2011-02-08 19:58:24 UTC (rev 928)
+++ branches/PR-8817822/darwintrace/darwintrace.c	2011-02-08 20:07:22 UTC (rev 929)
@@ -123,40 +123,37 @@
 }
 
 static inline void darwintrace_setup() {
-	if (darwintrace_fd == -2) {
-	  char* path = getenv("DARWINTRACE_LOG");
-	  if (path != NULL) {
-      int olderrno = errno;
-      int fd = open(path,
-                    O_CREAT | O_WRONLY | O_APPEND,
-                    DEFFILEMODE);
-      int newfd;
-      for(newfd = DARWINTRACE_START_FD; newfd < DARWINTRACE_START_FD + 21; newfd++) {
-        if(-1 == write(newfd, "", 0) && errno == EBADF) {
-          if(-1 != dup2(fd, newfd))
-            darwintrace_fd = newfd;
-          close(fd);
-          fcntl(darwintrace_fd, F_SETFD, 1); /* close-on-exec */
-          break;
-        }
+	if (darwintrace_fd != -2) return;
+  
+  char* path = getenv("DARWINTRACE_LOG");
+  if (path != NULL) {
+    int olderrno = errno;
+    int fd = open(path,
+                  O_CREAT | O_WRONLY | O_APPEND,
+                  DEFFILEMODE);
+    int newfd;
+    for(newfd = DARWINTRACE_START_FD; newfd < DARWINTRACE_START_FD + 21; newfd++) {
+      if(-1 == write(newfd, "", 0) && errno == EBADF) {
+        if(-1 != dup2(fd, newfd)) darwintrace_fd = newfd;
+        close(fd);
+        fcntl(darwintrace_fd, F_SETFD, 1); /* close-on-exec */
+        break;
       }
-      errno = olderrno;
-	  }
+    }
+    errno = olderrno;
+  }
 
-	  /* read env vars needed for redirection */
-	  darwintrace_redirect = getenv("DARWINTRACE_REDIRECT");
-	  darwintrace_buildroot = getenv("DARWIN_BUILDROOT");
-	}
+  /* read env vars needed for redirection */
+  darwintrace_redirect = getenv("DARWINTRACE_REDIRECT");
+  darwintrace_buildroot = getenv("DARWIN_BUILDROOT");
 
-	if (darwintrace_pid == -1) {
-		darwintrace_pid = getpid();
-		char** progname = _NSGetProgname();
-		if (progname && *progname) {
-		  if (strlcpy(darwintrace_progname, *progname, sizeof(darwintrace_progname)) >= sizeof(darwintrace_progname)) {
-		    dprintf("darwintrace: progname too long to copy: %s\n", *progname);
-		  }
-		}
-	}
+  darwintrace_pid = getpid();
+  char** progname = _NSGetProgname();
+  if (progname && *progname) {
+    if (strlcpy(darwintrace_progname, *progname, sizeof(darwintrace_progname)) >= sizeof(darwintrace_progname)) {
+      dprintf("darwintrace: progname too long to copy: %s\n", *progname);
+    }
+  }
 }
 
 /* darwintrace_setup must have been called already */
@@ -167,7 +164,6 @@
                       procname ? procname : darwintrace_progname, darwintrace_pid,
                       tag, path);
   write(fd, darwintrace_buf, size);
-  fsync(fd);
 }
 
 /* remap resource fork access to the data fork.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/darwinbuild-changes/attachments/20110208/1680a58d/attachment-0001.html>


More information about the darwinbuild-changes mailing list