Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/jacereda/fsatrace
Browse files Browse the repository at this point in the history
  • Loading branch information
jacereda committed Nov 17, 2015
2 parents 19b6df8 + 2dc173d commit a72c0b4
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions unix/fsatrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
#include <stdarg.h>
#include <fcntl.h>
#include <limits.h>
#if !defined __linux__
#include <libproc.h>
#endif
#include "fsatrace.h"

extern char **environ;
Expand Down Expand Up @@ -60,6 +63,7 @@ main(int argc, char **argv)
int r;
char so [PATH_MAX];
char shname [PATH_MAX];
char fullpath [PATH_MAX];
int rc = EXIT_FAILURE;
int child;
const char *out;
Expand All @@ -75,13 +79,19 @@ main(int argc, char **argv)
r = ftruncate(fd, LOGSZ);
assert(!r);
buf = mmap(0, LOGSZ, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
#ifdef __APPLE__
snprintf(so, sizeof(so), "%s.dylib", argv[0]);
#if defined __linux__
{
char exepath [64];
snprintf(exepath, sizeof(exepath), "/proc/%d/exe", getpid());
readlink(exepath, fullpath, sizeof(fullpath));
snprintf(so, sizeof(so), "%s.so", fullpath);
setenv("LD_PRELOAD", so, 1);
}
#else
proc_pidpath(getpid(), fullpath, sizeof(fullpath));
snprintf(so, sizeof(so), "%s.dylib", fullpath);
setenv("DYLD_INSERT_LIBRARIES", so, 1);
setenv("DYLD_FORCE_FLAT_NAMESPACE", "1", 1);
#else
snprintf(so, sizeof(so), "%s.so", argv[0]);
setenv("LD_PRELOAD", so, 1);
#endif
setenv(ENVOUT, shname, 1);
child = fork();
Expand Down

0 comments on commit a72c0b4

Please sign in to comment.