[darwinbuild-changes] [190] trunk/darwintrace/darwintrace.c
source_changes at macosforge.org
source_changes at macosforge.org
Wed Oct 4 01:56:31 PDT 2006
Revision: 190
http://trac.macosforge.org/projects/darwinbuild/changeset/190
Author: ssen
Date: 2006-10-04 01:56:31 -0700 (Wed, 04 Oct 2006)
Log Message:
-----------
Some projects have excessively clever shell scripts that
try to open specific file descriptors, which ends up stomping
redirecting the darwintrace data. So pick a file descriptor
in the stratosphere and use a reasonable hueristic to see if
it's available, and if so, dup2(2) to it. This isn't perfect,
but allows BerkerleyDB to build with dependencies successfully.
Modified Paths:
--------------
trunk/darwintrace/darwintrace.c
Modified: trunk/darwintrace/darwintrace.c
===================================================================
--- trunk/darwintrace/darwintrace.c 2005-08-24 02:20:23 UTC (rev 189)
+++ trunk/darwintrace/darwintrace.c 2006-10-04 08:56:31 UTC (rev 190)
@@ -41,11 +41,13 @@
#include <sys/param.h>
#include <sys/syscall.h>
#include <sys/paths.h>
+#include <errno.h>
#define DARWINTRACE_SHOW_PROCESS 0
#define DARWINTRACE_LOG_FULL_PATH 1
#define DARWINTRACE_DEBUG_OUTPUT 0
+#define START_FD 81
static int __darwintrace_fd = -2;
#define BUFFER_SIZE 1024
#if DARWINTRACE_SHOW_PROCESS
@@ -63,10 +65,21 @@
if (__darwintrace_fd == -2) {
char* path = getenv("DARWINTRACE_LOG");
if (path != NULL) {
- __darwintrace_fd = open(path,
- O_CREAT | O_WRONLY | O_APPEND,
- DEFFILEMODE);
- fcntl(__darwintrace_fd, F_SETFD, 1); /* close-on-exec */
+ int olderrno = errno;
+ int fd = open(path,
+ O_CREAT | O_WRONLY | O_APPEND,
+ DEFFILEMODE);
+ int newfd;
+ for(newfd = START_FD; newfd < 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;
}
}
#if DARWINTRACE_SHOW_PROCESS
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/darwinbuild-changes/attachments/20061004/8cb5516a/attachment-0001.html
More information about the darwinbuild-changes
mailing list