[darwinbuild-changes] [79] trunk/darwintrace/darwintrace.c
source_changes at macosforge.org
source_changes at macosforge.org
Wed Oct 4 01:43:11 PDT 2006
Revision: 79
http://trac.macosforge.org/projects/darwinbuild/changeset/79
Author: kevin
Date: 2006-10-04 01:43:10 -0700 (Wed, 04 Oct 2006)
Log Message:
-----------
- added option to show process id and name in logfile
Modified Paths:
--------------
trunk/darwintrace/darwintrace.c
Modified: trunk/darwintrace/darwintrace.c
===================================================================
--- trunk/darwintrace/darwintrace.c 2005-07-13 20:41:35 UTC (rev 78)
+++ trunk/darwintrace/darwintrace.c 2006-10-04 08:43:10 UTC (rev 79)
@@ -3,6 +3,7 @@
#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
+#include <string.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/param.h>
@@ -10,7 +11,32 @@
int __darwintrace_fd = -2;
#define BUFFER_SIZE 1024
char __darwintrace_buf[BUFFER_SIZE];
+#if DARWINTRACE_SHOW_PROCESS
+char __darwintrace_progname[BUFFER_SIZE];
+pid_t __darwintrace_pid = -1;
+#endif
+inline void __darwintrace_setup() {
+ 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_SHOW_PROCESS
+ if (__darwintrace_pid == -1) {
+ __darwintrace_pid = getpid();
+ char** progname = _NSGetProgname();
+ if (progname && *progname) {
+ strcpy(__darwintrace_progname, *progname);
+ }
+ }
+#endif
+}
+
// 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.
@@ -27,26 +53,26 @@
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
- }
- }
+ __darwintrace_setup();
if (__darwintrace_fd >= 0) {
int size;
if(strncmp(path, "/.vol/", 6) == 0) {
char realpath[MAXPATHLEN];
if(0 == fcntl(result, F_GETPATH, realpath)) {
+#if DARWINTRACE_SHOW_PROCESS
+ size = snprintf(__darwintrace_buf, BUFFER_SIZE, "%s[%d]\topen\t%s\n", __darwintrace_progname, __darwintrace_pid, realpath );
+ // printf("resolved %s to %s\n", path, realpath);
+#else
size = snprintf(__darwintrace_buf, BUFFER_SIZE, "open\t%s\n", realpath );
- // printf("resolved %s to %s\n", path, realpath);
+#endif
}
// if we can't resolve it, ignore the volfs path
} else {
- size = snprintf(__darwintrace_buf, BUFFER_SIZE, "open\t%s\n", path );
+#if DARWINTRACE_SHOW_PROCESS
+ size = snprintf(__darwintrace_buf, BUFFER_SIZE, "%s[%d]\topen\t%s\n", __darwintrace_progname, __darwintrace_pid, path );
+#else
+ size = snprintf(__darwintrace_buf, BUFFER_SIZE, "open\t%s\n", path );
+#endif
}
write(__darwintrace_fd, __darwintrace_buf, size);
fsync(__darwintrace_fd);
@@ -58,19 +84,15 @@
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
- }
- }
+ __darwintrace_setup();
if (__darwintrace_fd >= 0) {
struct stat sb;
if (stat(path, &sb) == 0) {
+#if DARWINTRACE_SHOW_PROCESS
+ int size = snprintf(__darwintrace_buf, BUFFER_SIZE, "%s[%d]\texecve\t%s\n", __darwintrace_progname, __darwintrace_pid, path );
+#else
int size = snprintf(__darwintrace_buf, BUFFER_SIZE, "execve\t%s\n", path );
+#endif
write(__darwintrace_fd, __darwintrace_buf, size);
fsync(__darwintrace_fd);
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/darwinbuild-changes/attachments/20061004/8eb5c59f/attachment-0001.html
More information about the darwinbuild-changes
mailing list