From 183eb02508f538e8200b62bbefc1c48aa0675d28 Mon Sep 17 00:00:00 2001 From: Thomas Jarosch Date: Sat, 30 Jul 2016 23:42:53 +0200 Subject: libtrace: Add support for lstat() / lstat64() --- README | 1 + src/libtrace/libtrace.c | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/README b/README index 775a3f008..dfd101b7e 100644 --- a/README +++ b/README @@ -36,6 +36,7 @@ Thomas Jarosch (https://github.com/thomasjfox) - added uudeview profile - improved profile list - fixed small variable glitch in stat64() / lstat64() (libtracelog) + - added lstat() / lstat64() support to libtrace Niklas Haas (https://github.com/haasn) - blacklisting for keybase.io's client Aleksey Manevich (https://github.com/manevich) diff --git a/src/libtrace/libtrace.c b/src/libtrace/libtrace.c index 9f2622c00..dde3df2ea 100644 --- a/src/libtrace/libtrace.c +++ b/src/libtrace/libtrace.c @@ -432,6 +432,31 @@ int stat64(const char *pathname, struct stat64 *buf) { } #endif /* __GLIBC__ */ +// lstat +typedef int (*orig_lstat_t)(const char *pathname, struct stat *buf); +static orig_lstat_t orig_lstat = NULL; +int lstat(const char *pathname, struct stat *buf) { + if (!orig_lstat) + orig_lstat = (orig_lstat_t)dlsym(RTLD_NEXT, "lstat"); + + int rv = orig_lstat(pathname, buf); + printf("%u:%s:lstat %s:%d\n", pid(), name(), pathname, rv); + return rv; +} + +#ifdef __GLIBC__ +typedef int (*orig_lstat64_t)(const char *pathname, struct stat64 *buf); +static orig_lstat64_t orig_lstat64 = NULL; +int lstat64(const char *pathname, struct stat64 *buf) { + if (!orig_lstat64) + orig_lstat64 = (orig_lstat64_t)dlsym(RTLD_NEXT, "lstat64"); + + int rv = orig_lstat64(pathname, buf); + printf("%u:%s:lstat64 %s:%d\n", pid(), name(), pathname, rv); + return rv; +} +#endif /* __GLIBC__ */ + // opendir typedef DIR *(*orig_opendir_t)(const char *pathname); static orig_opendir_t orig_opendir = NULL; -- cgit v1.2.3-70-g09d2