fd = open(path, O_RDONLY, 0); if (fd != -1) { char buffer[MAXPATHLEN]; (void) read(fd, buffer, MAXPATHLEN); if (buffer[0] == '#' && buffer[1] == '!') { const char* interp = &buffer[2]; int i;  for (i = 2; i < (MAXPATHLEN-1); ++i) { if (buffer[i] != ' ' && buffer[i] != '\t') { interp = &buffer[i]; break; } }  for (; i < (MAXPATHLEN-1); ++i) { if (buffer[i] == ' ' || buffer[i] == '\t' || buffer[i] == '\n') { buffer[i] = 0; } }  if (interp) { #if DARWINTRACE_SHOW_PROCESS const char* procname = strrchr(argv[0], '/') + 1; if (procname == NULL) procname = argv[0]; int size = snprintf(__darwintrace_buf, BUFFER_SIZE, "%s[%d]\texecve\t%s\n", procname, 0, interp ); #else int size = snprintf(__darwintrace_buf, BUFFER_SIZE, "execve\t%s\n", interp ); #endif write(__darwintrace_fd, __darwintrace_buf, size); fsync(__darwintrace_fd); } } close(fd); }
int execve(const char* path, char* const argv[], char* const envp[]) {#define execve(x,y,z) syscall(SYS_execve, (x), (y), (z))	int result;		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);	  }	}	result = execve(path, argv, envp);	return result;}