<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[924] branches/PR-8817822/darwintrace/darwintrace.c</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.macosforge.org/projects/darwinbuild/changeset/924">924</a></dd>
<dt>Author</dt> <dd>wsiegrist@apple.com</dd>
<dt>Date</dt> <dd>2011-02-08 10:53:50 -0800 (Tue, 08 Feb 2011)</dd>
</dl>

<h3>Log Message</h3>
<pre>Cleanup whitespace, switch from macros to inline functions, general cleanup</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#branchesPR8817822darwintracedarwintracec">branches/PR-8817822/darwintrace/darwintrace.c</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="branchesPR8817822darwintracedarwintracec"></a>
<div class="modfile"><h4>Modified: branches/PR-8817822/darwintrace/darwintrace.c (923 => 924)</h4>
<pre class="diff"><span>
<span class="info">--- branches/PR-8817822/darwintrace/darwintrace.c    2011-02-08 18:17:59 UTC (rev 923)
+++ branches/PR-8817822/darwintrace/darwintrace.c       2011-02-08 18:53:50 UTC (rev 924)
</span><span class="lines">@@ -46,43 +46,44 @@
</span><span class="cx"> 
</span><span class="cx"> #define DARWINTRACE_LOG_FULL_PATH 1
</span><span class="cx"> #define DARWINTRACE_DEBUG_OUTPUT 0
</span><del>-
</del><span class="cx"> #define START_FD 81
</span><del>-static int __darwintrace_fd = -2;
</del><span class="cx"> #define BUFFER_SIZE       1024
</span><span class="cx"> 
</span><del>-static char __darwintrace_progname[BUFFER_SIZE];
-static pid_t __darwintrace_pid = -1;
-
</del><span class="cx"> #if DARWINTRACE_DEBUG_OUTPUT
</span><span class="cx"> #define dprintf(...) fprintf(stderr, __VA_ARGS__)
</span><span class="cx"> #else
</span><span class="cx"> #define dprintf(...)
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><ins>+static int __darwintrace_fd = -2;
+static char __darwintrace_progname[BUFFER_SIZE];
+static pid_t __darwintrace_pid = -1;
+
</ins><span class="cx"> /**
</span><span class="cx">  * Redirect file access 
</span><span class="cx">  */
</span><span class="cx"> static char *__darwintrace_redirect = NULL; 
</span><span class="cx"> static char *__darwintrace_buildroot = NULL;
</span><del>-static const char *__redirect_exceptions[] = {"/Developer/Library/Private",
-                                             "/Developer/Library/Frameworks",
-                                             "/Developer/usr/bin/../../Library/Private",
-                                             "/Developer/usr/bin/../../Library/Frameworks",
-                                             "/Developer/Library/Xcode",
-                                             "/Developer/Platforms/",
-                                             "/Developer/usr/bin/xcode",
-                                             "/System/Library/Frameworks/Carbon",
-                                             "/Volumes/BuildRoot_",
-                                             "/usr/bin/xcrun",
-                                             "/usr/bin/xcode",
-                                             "/usr/local/share/darwin",
-                                             "/usr/share/xcode",
-                                             "/var/folders/",
-                                             "/var/tmp/",
-                                             "/.vol/",
-                                             "/tmp/",
-                                             "/dev/"};
</del><ins>+static const char *__redirect_exceptions[] = {
+  "/Developer/Library/Private",
+  "/Developer/Library/Frameworks",
+  "/Developer/usr/bin/../../Library/Private",
+  "/Developer/usr/bin/../../Library/Frameworks",
+  "/Developer/Library/Xcode",
+  "/Developer/Platforms/",
+  "/Developer/usr/bin/xcode",
+  "/System/Library/Frameworks/Carbon",
+  "/Volumes/BuildRoot_",
+  "/usr/bin/xcrun",
+  "/usr/bin/xcode",
+  "/usr/local/share/darwin",
+  "/usr/share/xcode",
+  "/var/folders/",
+  "/var/tmp/",
+  "/.vol/",
+  "/tmp/",
+  "/dev/",
+};
</ins><span class="cx"> 
</span><span class="cx"> /* check if str starts with one of the exceptions */
</span><span class="cx"> static inline bool __except(const char *str) {
</span><span class="lines">@@ -95,23 +96,25 @@
</span><span class="cx">   return false;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-/* create __darwintrace_path and write the potentially-redirected path to it */
-#define __redirect_path()                                              \
-  char *__darwintrace_path;                                            \
-  __darwintrace_path = (char *)path;                                   \
-  if (__darwintrace_redirect                                           \
-      && path[0] == '/'                                                        \
-      && !__except(path)                                               \
-      && strncmp(__darwintrace_buildroot, path, strlen(__darwintrace_buildroot))!=0 \
-      && strncmp(__darwintrace_redirect, path, strlen(__darwintrace_redirect))!=0 ) { \
-    asprintf(&__darwintrace_path, "%s%s%s", __darwintrace_redirect, (*path == '/' ? "" : "/"), path); \
-    dprintf("darwintrace: redirect %s -> %s\n", path, __darwintrace_path);                \
</del><ins>+/* apply redirection heuristic to path */
+static inline char* __redirect_path(const char* path) {        
+  char *redirpath;
+  redirpath = (char *)path;
+  if (__darwintrace_redirect
+      && path[0] == '/'
+      && !__except(path)
+      && strncmp(__darwintrace_buildroot, path, strlen(__darwintrace_buildroot))!=0
+      && strncmp(__darwintrace_redirect, path, strlen(__darwintrace_redirect))!=0 ) {
+    asprintf(&redirpath, "%s%s%s", __darwintrace_redirect, (*path == '/' ? "" : "/"), path);
+    dprintf("darwintrace: redirect %s -> %s\n", path, redirpath);
</ins><span class="cx">   }
</span><del>-#define __free_path()                              \
-  if (__darwintrace_path != path) {                \
-    free(__darwintrace_path);                      \
-  }
</del><ins>+  return redirpath;
+}
</ins><span class="cx"> 
</span><ins>+/* free path if not the same as test */
+static inline void __free_path(char* path, const char* test) {
+  if (path != test) free(path);
+}
</ins><span class="cx"> 
</span><span class="cx"> static inline void __darwintrace_setup() {
</span><span class="cx">  if (__darwintrace_fd == -2) {
</span><span class="lines">@@ -179,9 +182,9 @@
</span><span class="cx">   rsrclen = strlen(_PATH_RSRCFORKSPEC);
</span><span class="cx">   if(pathlen > rsrclen
</span><span class="cx">      && 0 == strncmp(path + pathlen - rsrclen,
</span><del>-                    _PATH_RSRCFORKSPEC, rsrclen)) {
-    path[pathlen - rsrclen] = '\0';
-    pathlen -= rsrclen;
</del><ins>+                     _PATH_RSRCFORKSPEC, rsrclen)) {
+       path[pathlen - rsrclen] = '\0';
+       pathlen -= rsrclen;
</ins><span class="cx">   }
</span><span class="cx"> 
</span><span class="cx">   /* for each position in string (including
</span><span class="lines">@@ -192,15 +195,15 @@
</span><span class="cx">   for(i=0, shiftamount=0; i <= pathlen; i++) {
</span><span class="cx">     if(state == SAWSLASH) {
</span><span class="cx">       if(path[i] == '/') {
</span><del>-       /* consume it */
-       shiftamount++;
</del><ins>+        /* consume it */
+        shiftamount++;
</ins><span class="cx">       } else {
</span><del>-       state = NOTHING;
-       path[i - shiftamount] = path[i];
</del><ins>+        state = NOTHING;
+        path[i - shiftamount] = path[i];
</ins><span class="cx">       }
</span><span class="cx">     } else {
</span><span class="cx">       if(path[i] == '/') {
</span><del>-       state = SAWSLASH;
</del><ins>+        state = SAWSLASH;
</ins><span class="cx">       }
</span><span class="cx">       path[i - shiftamount] = path[i];
</span><span class="cx">     }
</span><span class="lines">@@ -223,12 +226,12 @@
</span><span class="cx">  int result;
</span><span class="cx">  va_list args;
</span><span class="cx"> 
</span><del>-       __redirect_path();
</del><ins>+        char* redirpath = __redirect_path(path);
</ins><span class="cx"> 
</span><span class="cx">  va_start(args, flags);
</span><span class="cx">  mode = va_arg(args, int);
</span><span class="cx">  va_end(args);
</span><del>-       result = open(__darwintrace_path, flags, mode);
</del><ins>+        result = open(redirpath, flags, mode);
</ins><span class="cx">   if (result >= 0 && (flags & (O_CREAT | O_WRONLY /*O_RDWR*/)) == 0 ) {
</span><span class="cx">    __darwintrace_setup();
</span><span class="cx">    if (__darwintrace_fd >= 0) {
</span><span class="lines">@@ -239,35 +242,35 @@
</span><span class="cx">      int usegetpath = 0;
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><del>-           dprintf("darwintrace: original open path is %s\n", __darwintrace_path);
</del><ins>+            dprintf("darwintrace: original open path is %s\n", redirpath);
</ins><span class="cx"> 
</span><span class="cx">      /* for volfs paths, we need to do a GETPATH anyway */
</span><del>-           if(!usegetpath && strncmp(__darwintrace_path, "/.vol/", 6) == 0) {
</del><ins>+            if(!usegetpath && strncmp(redirpath, "/.vol/", 6) == 0) {
</ins><span class="cx">         usegetpath = 1;
</span><span class="cx">      }
</span><span class="cx">      
</span><span class="cx">      if(usegetpath) {
</span><del>-             if(0 == fcntl(result, F_GETPATH, realpath)) {
-               dprintf("darwintrace: resolved %s to %s\n", __darwintrace_path, realpath);
</del><ins>+        if(0 == fcntl(result, F_GETPATH, realpath)) {
+          dprintf("darwintrace: resolved %s to %s\n", redirpath, realpath);
</ins><span class="cx">         } else {
</span><del>-               /* use original path */
-               dprintf("darwintrace: failed to resolve %s\n", __darwintrace_path);
-               if (strlcpy(realpath, __darwintrace_path, sizeof(realpath)) >= sizeof(realpath)) {
-                 dprintf("darwintrace: in open: original path too long to copy: %s\n", __darwintrace_path);
-               }
-             }
-           } else {
-             if (strlcpy(realpath, __darwintrace_path, sizeof(realpath)) >= sizeof(realpath)) {
-               dprintf("darwintrace: in open (without getpath): path too long to copy: %s\n", __darwintrace_path);
-             }
-           }
</del><ins>+          /* use original path */
+          dprintf("darwintrace: failed to resolve %s\n", redirpath);
+          if (strlcpy(realpath, redirpath, sizeof(realpath)) >= sizeof(realpath)) {
+            dprintf("darwintrace: in open: original path too long to copy: %s\n", redirpath);
+          }
+        }
+      } else {
+             if (strlcpy(realpath, redirpath, sizeof(realpath)) >= sizeof(realpath)) {
+          dprintf("darwintrace: in open (without getpath): path too long to copy: %s\n", redirpath);
+        }
+      }
</ins><span class="cx"> 
</span><span class="cx">      __darwintrace_cleanup_path(realpath);
</span><del>-
</del><span class="cx">       __darwintrace_logpath(__darwintrace_fd, NULL, "open", realpath);
</span><span class="cx">    }
</span><span class="cx">  }
</span><del>-       __free_path();
</del><ins>+
+       __free_path(redirpath, path);
</ins><span class="cx">   return result;
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -280,25 +283,25 @@
</span><span class="cx"> #define readlink(x,y,z) syscall(SYS_readlink, (x), (y), (z))
</span><span class="cx">  ssize_t result;
</span><span class="cx"> 
</span><del>-       __redirect_path();
-       result = readlink(__darwintrace_path, buf, bufsiz);
</del><ins>+        char* redirpath = __redirect_path(path);
+       result = readlink(redirpath, buf, bufsiz);
</ins><span class="cx">   if (result >= 0) {
</span><span class="cx">    __darwintrace_setup();
</span><span class="cx">    if (__darwintrace_fd >= 0) {
</span><span class="cx">      char realpath[MAXPATHLEN];
</span><span class="cx"> 
</span><del>-           dprintf("darwintrace: original readlink path is %s\n", __darwintrace_path);
</del><ins>+            dprintf("darwintrace: original readlink path is %s\n", redirpath);
</ins><span class="cx"> 
</span><del>-           if (strlcpy(realpath, __darwintrace_path, sizeof(realpath)) >= sizeof(realpath)) {
-             dprintf("darwintrace: in readlink: path too long to copy: %s\n", __darwintrace_path);
</del><ins>+            if (strlcpy(realpath, redirpath, sizeof(realpath)) >= sizeof(realpath)) {
+             dprintf("darwintrace: in readlink: path too long to copy: %s\n", redirpath);
</ins><span class="cx">       }
</span><span class="cx">      
</span><span class="cx">      __darwintrace_cleanup_path(realpath);
</span><del>-
</del><span class="cx">       __darwintrace_logpath(__darwintrace_fd, NULL, "readlink", realpath);
</span><span class="cx">    }
</span><span class="cx">  }
</span><del>-       __free_path();
</del><ins>+  
+       __free_path(redirpath, path);
</ins><span class="cx">   return result;
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -306,7 +309,7 @@
</span><span class="cx"> #define execve(x,y,z) syscall(SYS_execve, (x), (y), (z))
</span><span class="cx">  int result;
</span><span class="cx">  
</span><del>-       __redirect_path();
</del><ins>+        char* redirpath = __redirect_path(path);
</ins><span class="cx">   __darwintrace_setup();
</span><span class="cx">  if (__darwintrace_fd >= 0) {
</span><span class="cx">    struct stat sb;
</span><span class="lines">@@ -320,15 +323,15 @@
</span><span class="cx">    int usegetpath = 0;
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><del>-         dprintf("darwintrace: original execve path is %s\n", __darwintrace_path);
</del><ins>+          dprintf("darwintrace: original execve path is %s\n", redirpath);
</ins><span class="cx"> 
</span><span class="cx">    /* for symlinks, we wan't to capture
</span><span class="cx">     * both the original path and the modified one,
</span><span class="cx">     * since for /usr/bin/gcc -> gcc-4.0,
</span><span class="cx">     * both "gcc_select" and "gcc" are contributors
</span><span class="cx">     */
</span><del>-         if (lstat(__darwintrace_path, &sb) == 0) {
-           if(__darwintrace_path[0] != '/') {
</del><ins>+          if (lstat(redirpath, &sb) == 0) {
+           if(redirpath[0] != '/') {
</ins><span class="cx">         /* for relative paths, only print full path */
</span><span class="cx">        printreal = 1;
</span><span class="cx">        printorig = 0;
</span><span class="lines">@@ -343,15 +346,15 @@
</span><span class="cx">      }
</span><span class="cx"> 
</span><span class="cx">      if(printorig) {
</span><del>-             if (strlcpy(realpath, __darwintrace_path, sizeof(realpath)) >= sizeof(realpath)) {
-               dprintf("darwintrace: in execve: path too long to copy: %s\n", __darwintrace_path);
</del><ins>+              if (strlcpy(realpath, redirpath, sizeof(realpath)) >= sizeof(realpath)) {
+          dprintf("darwintrace: in execve: path too long to copy: %s\n", redirpath);
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">        __darwintrace_cleanup_path(realpath);
</span><span class="cx">        __darwintrace_logpath(__darwintrace_fd, NULL, "execve", realpath);
</span><span class="cx">      }
</span><span class="cx">          
</span><del>-           fd = open(__darwintrace_path, O_RDONLY, 0);
</del><ins>+            fd = open(redirpath, O_RDONLY, 0);
</ins><span class="cx">       if (fd != -1) {
</span><span class="cx"> 
</span><span class="cx">        char buffer[MAXPATHLEN];
</span><span class="lines">@@ -359,73 +362,74 @@
</span><span class="cx"> 
</span><span class="cx">        /* once we have an open fd, if a full path was requested, do it */
</span><span class="cx">        if(printreal) {
</span><del>-               
-               if(usegetpath) {
-                 if(0 == fcntl(fd, F_GETPATH, realpath)) {
-                   dprintf("darwintrace: resolved execve path %s to %s\n", __darwintrace_path, realpath);
-                 } else {
-                   dprintf("darwintrace: failed to resolve %s\n", __darwintrace_path);
-                   if (strlcpy(realpath, __darwintrace_path, sizeof(realpath)) >= sizeof(realpath)) {
-                     dprintf("darwintrace: in execve: original path too long to copy: %s\n", __darwintrace_path);
-                   }
-                 }
-               } else {
-                 if (strlcpy(realpath, __darwintrace_path, sizeof(realpath)) >= sizeof(realpath)) {
-                   dprintf("darwintrace: in execve (without getpath): path too long to copy: %s\n", __darwintrace_path);
-                 }
-               }
-               __darwintrace_cleanup_path(realpath);
</del><span class="cx"> 
</span><del>-               __darwintrace_logpath(__darwintrace_fd, NULL, "execve", realpath);
</del><ins>+          if(usegetpath) {
+            if(0 == fcntl(fd, F_GETPATH, realpath)) {
+              dprintf("darwintrace: resolved execve path %s to %s\n", redirpath, realpath);
+            } else {
+              dprintf("darwintrace: failed to resolve %s\n", redirpath);
+              if (strlcpy(realpath, redirpath, sizeof(realpath)) >= sizeof(realpath)) {
+                dprintf("darwintrace: in execve: original path too long to copy: %s\n", redirpath);
+              }
+            }
+          } else {
+            if (strlcpy(realpath, redirpath, sizeof(realpath)) >= sizeof(realpath)) {
+              dprintf("darwintrace: in execve (without getpath): path too long to copy: %s\n", redirpath);
+            }
+          }
+          
+          __darwintrace_cleanup_path(realpath);
+          __darwintrace_logpath(__darwintrace_fd, NULL, "execve", realpath);
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">        bzero(buffer, sizeof(buffer));
</span><span class="cx"> 
</span><span class="cx">        bytes_read = read(fd, buffer, MAXPATHLEN);
</span><span class="cx">        if (bytes_read > 2 &&
</span><del>-                 buffer[0] == '#' && buffer[1] == '!') {
-               char* interp = &buffer[2];
-               int i;
-               /* skip past leading whitespace */
-               for (i = 2; i < bytes_read; ++i) {
-                 if (buffer[i] != ' ' && buffer[i] != '\t') {
-                   interp = &buffer[i];
-                   break;
-                 }
-               }
-               /* found interpreter (or ran out of data)
-                  skip until next whitespace, then terminate the string */
-               for (; i < bytes_read; ++i) {
-                 if (buffer[i] == ' ' || buffer[i] == '\t' || buffer[i] == '\n') {
-                   buffer[i] = 0;
-                   break;
-                 }
-               }
-               /* we have liftoff */
-               if (interp && interp[0] != '\0') {
-                 const char* procname = NULL;
</del><ins>+            buffer[0] == '#' && buffer[1] == '!') {
+          char* interp = &buffer[2];
+          int i;
+          /* skip past leading whitespace */
+          for (i = 2; i < bytes_read; ++i) {
+            if (buffer[i] != ' ' && buffer[i] != '\t') {
+              interp = &buffer[i];
+              break;
+            }
+          }
+          /* found interpreter (or ran out of data)
+           skip until next whitespace, then terminate the string */
+          for (; i < bytes_read; ++i) {
+            if (buffer[i] == ' ' || buffer[i] == '\t' || buffer[i] == '\n') {
+              buffer[i] = 0;
+              break;
+            }
+          }
+          /* we have liftoff */
+          if (interp && interp[0] != '\0') {
+            const char* procname = NULL;
</ins><span class="cx"> 
</span><del>-                 /* look for slash to get the basename */
-                 procname = strrchr(argv[0], '/');
-                 if (procname == NULL) {
-                   /* no slash found, so assume whole string is basename */
-                   procname = argv[0];
-                 } else {
-                   /* advance pointer to just after slash */
-                   procname++;
-                 }
</del><ins>+            /* look for slash to get the basename */
+            procname = strrchr(argv[0], '/');
+            if (procname == NULL) {
+              /* no slash found, so assume whole string is basename */
+              procname = argv[0];
+            } else {
+              /* advance pointer to just after slash */
+              procname++;
+            }
</ins><span class="cx"> 
</span><del>-                 __darwintrace_cleanup_path(interp);
-
-                 __darwintrace_logpath(__darwintrace_fd, procname, "execve", interp);
-               }
</del><ins>+            __darwintrace_cleanup_path(interp);
+            __darwintrace_logpath(__darwintrace_fd, procname, "execve", interp);
+          }
</ins><span class="cx">         }
</span><ins>+        
</ins><span class="cx">         close(fd);
</span><span class="cx">      }
</span><span class="cx">    }
</span><span class="cx">  }
</span><del>-       result = execve(__darwintrace_path, argv, envp);
-       __free_path();
</del><ins>+  
+       result = execve(redirpath, argv, envp);
+       __free_path(redirpath, path);
</ins><span class="cx">   return result;
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>