[darwinbuild-changes] [40] trunk
source_changes at macosforge.org
source_changes at macosforge.org
Wed Oct 4 01:40:28 PDT 2006
Revision: 40
http://trac.macosforge.org/projects/darwinbuild/changeset/40
Author: kevin
Date: 2006-10-04 01:40:28 -0700 (Wed, 04 Oct 2006)
Log Message:
-----------
- added darwintrace library
Added Paths:
-----------
trunk/darwintrace/
trunk/darwintrace/Makefile
trunk/darwintrace/darwintrace.c
Added: trunk/darwintrace/Makefile
===================================================================
--- trunk/darwintrace/Makefile (rev 0)
+++ trunk/darwintrace/Makefile 2006-10-04 08:40:28 UTC (rev 40)
@@ -0,0 +1,31 @@
+###
+### Variables for the 'install' phase
+###
+PREFIX=/usr/local
+DATDIR=$(PREFIX)/share/darwinbuild
+INSTALL=install
+INSTALL_EXE_FLAGS=-m 0755 -o root -g wheel
+INSTALL_DIR_FLAGS=$(INSTALL_EXE_FLAGS)
+INSTALL_DOC_FLAGS=-m 0644 -o root -g wheel
+
+all: darwintrace.dylib
+
+darwintrace.dylib: darwintrace.c
+ cc -o $@ \
+ -flat_namespace \
+ -fno-common \
+ -nostdlib \
+ -undefined suppress \
+ -dynamiclib \
+ $^
+clean:
+ rm -f darwintrace.dylib
+
+install: all
+ [ -d $(DATDIR) ] || \
+ $(INSTALL) -d $(INSTALL_DIR_FLAGS) $(DATDIR)
+ $(INSTALL) $(INSTALL_DOC_FLAGS) darwintrace.dylib $(DATDIR)
+
+uninstall:
+ rm -f $(DATDIR)/darwintrace.dylib
+ rmdir $(DATDIR)
Property changes on: trunk/darwintrace/Makefile
___________________________________________________________________
Name: svn:eol-style
+ native
Added: trunk/darwintrace/darwintrace.c
===================================================================
--- trunk/darwintrace/darwintrace.c (rev 0)
+++ trunk/darwintrace/darwintrace.c 2006-10-04 08:40:28 UTC (rev 40)
@@ -0,0 +1,69 @@
+#include <crt_externs.h>
+#include <fcntl.h>
+#include <stdarg.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <sys/stat.h>
+
+int __darwintrace_fd = -2;
+#define BUFFER_SIZE 1024
+char __darwintrace_buf[BUFFER_SIZE];
+
+// Log calls to open(2) into the file specified by DARWINTRACE_LOG.
+// Only logs if the DARWINTRACE_LOG environment variable is set.
+// Only logs files where the open succeeds.
+// Only logs files opened for read access, without the O_CREAT flag set.
+// The assumption is that any file that can be created isn't necessary
+// to build the project.
+
+int open(const char* path, int flags, ...) {
+// SYS_open 5
+#define open(x,y,z) syscall(5, (x), (y), (z))
+ va_list args;
+ va_start(args, flags);
+ mode_t mode = va_arg(args, int);
+ va_end(args);
+ int result = open(path, flags, mode);
+ if (result >= 0 && (flags & (O_CREAT | O_WRONLY /*O_RDWR*/)) == 0 ) {
+ if (__darwintrace_fd == -2) {
+ char* path = getenv("DARWINTRACE_LOG");
+ if (path != NULL) {
+ __darwintrace_fd = open(path,
+ O_CREAT | O_WRONLY | O_APPEND,
+ 0666);
+ fcntl(__darwintrace_fd, F_SETFD, 1); // close-on-exec
+ }
+ }
+ if (__darwintrace_fd >= 0) {
+ int size = snprintf(__darwintrace_buf, BUFFER_SIZE, "open\t%s\n", path );
+ write(__darwintrace_fd, __darwintrace_buf, size);
+ fsync(__darwintrace_fd);
+ }
+ }
+ return result;
+}
+
+int execve(const char* path, char* const argv[], char* const envp[]) {
+// SYS_execve 59
+#define execve(x,y,z) syscall(59, (x), (y), (z))
+ if (__darwintrace_fd == -2) {
+ char* path = getenv("DARWINTRACE_LOG");
+ if (path != NULL) {
+ __darwintrace_fd = open(path,
+ O_CREAT | O_WRONLY | O_APPEND,
+ 0666);
+ fcntl(__darwintrace_fd, F_SETFD, 1); // close-on-exec
+ }
+ }
+ if (__darwintrace_fd >= 0) {
+ struct stat sb;
+ if (stat(path, &sb) == 0) {
+ int size = snprintf(__darwintrace_buf, BUFFER_SIZE, "execve\t%s\n", path );
+ write(__darwintrace_fd, __darwintrace_buf, size);
+ fsync(__darwintrace_fd);
+ }
+ }
+ int result = execve(path, argv, envp);
+ return result;
+}
Property changes on: trunk/darwintrace/darwintrace.c
___________________________________________________________________
Name: svn:eol-style
+ native
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/darwinbuild-changes/attachments/20061004/cccd5947/attachment.html
More information about the darwinbuild-changes
mailing list