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 Sep 25, 2015
2 parents 5da11d1 + cb9a594 commit 2b2f4e1
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions unix/fsatrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ dump(const char *path, char *p)
close(fd);
}

unsigned long
hash(unsigned char *str)
{
unsigned long h = 5381;
int c;
while ((c = *str++))
h = ((h << 5) + h) + c;
return h;
}

int
main(int argc, char **argv)
{
Expand All @@ -47,7 +57,7 @@ main(int argc, char **argv)
return rc;
}
out = argv[1];
snprintf(shname, sizeof(shname), "/%s", out);
snprintf(shname, sizeof(shname), "/%ld", hash((unsigned char *)out));
for (size_t i = 0, l = strlen(shname); i < l; i++)
if (shname[i] == '/')
shname[i] = '_';
Expand All @@ -69,7 +79,9 @@ main(int argc, char **argv)
execvp(argv[3], argv + 3);
assert(0);
}
wait(&rc);
r = wait(&rc);
assert(r >= 0);
rc = WEXITSTATUS(rc);
if (!rc)
dump(out, buf);
munmap(buf, LOGSZ);
Expand Down

0 comments on commit 2b2f4e1

Please sign in to comment.