Commit 859d2d28 authored by Nils Goroll's avatar Nils Goroll

interposer working

parent 7c743d1f
......@@ -15,7 +15,7 @@ SUBDIRS = include
AM_CPPFLAGS = -Iinclude
CLEANFILES = cscope.in.out cscope.out cscope.po.out
EXTRA_DIST = LICENSE autogen.sh varnishapi.pc.in
EXTRA_DIST = LICENSE autogen.sh
DISTCHECK_CONFIGURE_FLAGS = \
--enable-developer-warnings \
......@@ -28,12 +28,15 @@ DISTCHECK_CONFIGURE_FLAGS = \
AM_LDFLAGS = $(AM_LT_LDFLAGS)
lib_LTLIBRARIES = liblongpath.la liblongpath_unsafe.la
lib_LTLIBRARIES = liblongpath.la liblongpath_unsafe.la liblongpath_interpose.la
liblongpath_includes = \
include/longpath/longpath.h \
include/longpath/longpath.h \
include/longpath/longpath_common.h \
include/longpath/longpath_config.h
## liblongpath
liblongpath_la_CFLAGS = $(AM_CFLAGS) $(PTHREAD_CFLAGS)
liblongpath_la_LDFLAGS = $(AM_LDFLAGS) $(PTHREAD_LDLAGS) \
......@@ -43,6 +46,8 @@ liblongpath_la_SOURCES = \
$(liblongpath_includes) \
longpath.c
## liblongpath_unsafe
liblongpath_unsafe_la_CFLAGS = $(AM_CFLAGS) -DUSE_CHDIR_FALLBACK
liblongpath_unsafe_la_LDFLAGS = $(AM_LDFLAGS) \
......@@ -50,6 +55,16 @@ liblongpath_unsafe_la_LDFLAGS = $(AM_LDFLAGS) \
liblongpath_unsafe_la_SOURCES = $(liblongpath_la_SOURCES)
## liblongpath_interpose
liblongpath_interpose_la_CFLAGS = $(AM_CFLAGS) -DINTERPOSE \
-DOWN_PATH=\"$(libdir)/liblongpath_interpose.so\"
liblongpath_interpose_la_LDFLAGS = $(AM_LDFLAGS) \
-export-dynamic -avoid-version -shared -ldl
liblongpath_interpose_la_SOURCES = $(liblongpath_la_SOURCES)
## TEST - XXX make a proper test directory etc
bin_PROGRAMS = longpath_test longpath_unsafe_test
......
......@@ -68,3 +68,7 @@ FUNCTION(ssize_t, lgetxattr, const char *, const char *, void *, size_t)
FUNCTION(int, setxattr, const char *, const char *, const void *, size_t, int)
FUNCTION(int, lsetxattr, const char *, const char *, const void *, size_t, int)
#endif
#if defined(INTERPOSE) && defined(TRACE)
FUNCTION(void *, dlopen, const char *, int mode)
#endif
......@@ -82,14 +82,18 @@
# ifdef HAVE__XSTAT
# ifdef HAVE_SYS_STAT_IMPL_H
# define _SYS_STAT_IMPL_H
#include <fcntl.h>
extern int mknod(const char *, mode_t, dev_t);
extern int stat(const char *, struct stat *);
extern int lstat(const char *, struct stat *);
extern int fstatat(int, const char *, struct stat *, int);
# else
# error This machine probably needs different _xstat handling
# endif
# endif
#endif
# endif /* HAVE__XSTAT */
#ifdef INTERPOSE
# include <longpath/longpath_common.h>
# define real(x) real_ ## x
# if defined(_LP64)
# define real64(x) real_ ## x
......@@ -102,6 +106,97 @@
# else
# define our64(x) x ## 64
# endif
/*
* declaration of real() function pointers
*/
# define FUNCTION(type, name, ...) static type (* real(name))(__VA_ARGS__);
# if ! defined(_LP64)
# define FUNCTION64(type, name, ...) static type (* real64(name))(__VA_ARGS__);
# else
# define FUNCTION64(type, name, ...)
# endif /* _LP64 */
# include <longpath/longpath_tbl_functions.h>
# include <longpath/longpath_tbl_functions64.h>
# undef FUNCTION
# undef FUNCTION64
# include <dlfcn.h>
# include <stdio.h>
# define init_dlsym(fptr, name) do { \
if (! (fptr = dlsym(RTLD_NEXT, #name))) { \
perror("looking up symbol " #name " failed"); \
exit(1); \
} \
} while(0)
#ifdef TRACE
static int tracefd;
static pid_t pid;
//static void *my_dl_handle;
#include <unistd.h>
#endif
/*
* init real() function ponters
*/
void __attribute__ ((constructor)) longpath_init(void);
void __attribute__ ((constructor))
longpath_init(void) {
# define FUNCTION(type, name, ...) init_dlsym(real(name), name);
# if ! defined(_LP64)
# define FUNCTION64(type, name, ...) init_dlsym(real64(name), name ## 64);
# else
# define FUNCTION64(type, name, ...)
# endif /* _LP64 */
# include <longpath/longpath_tbl_functions.h>
# include <longpath/longpath_tbl_functions64.h>
# undef FUNCTION
# undef FUNCTION64
#ifdef TRACE
tracefd = real(open)("/tmp/lptrace", O_WRONLY|O_CREAT|O_APPEND, 0600);
if (tracefd == -1) {
perror("trace file ");
exit(1);
}
pid = getpid();
#endif /* TRACE */
}
#ifdef TRACE
#define TRACELEN 1024
#define trace(fmt, ...) do { \
char _buf[TRACELEN]; \
int _l = snprintf(_buf, TRACELEN, "%d: " fmt, pid, ##__VA_ARGS__); \
if ((_l > 0) && (_l < TRACELEN)) \
(void)write(tracefd, _buf, _l); \
} while(0)
#include <stdio.h>
#include <string.h>
void *
our(dlopen)(const char *pathname, int mode) {
trace("dlopen(%s, 0x%x)\n", pathname ? pathname : "(null)", mode);
if (pathname && strstr(pathname, "libc.so")) {
// const int nmode = RTLD_GROUP|RTLD_FIRST;
trace("returning dlopen(%s, 0x%x)\n", OWN_PATH, mode);
return real(dlopen)(OWN_PATH, mode);
}
if (mode & RTLD_GLOBAL) {
const int nmode = RTLD_NOW|RTLD_GLOBAL;
void *r;
trace("actual dlopen(%s, 0x%x)\n", OWN_PATH, mode|RTLD_PARENT);
r = real(dlopen)(pathname, mode|RTLD_PARENT);
trace("doing additional dlopen(%s, 0x%x)\n", OWN_PATH, nmode);
(void) real(dlopen)(OWN_PATH, nmode);
return r;
}
return real(dlopen)(pathname, mode);
}
#endif /* TRACE */
#else /* ! INTERPOSE */
# include <longpath/longpath.h>
# define real(x) x
......@@ -676,7 +771,7 @@ int
our(chmod)(const char *path, mode_t mode) {
int fd;
Xfl(path, 0, -1,
fd, real(fchmod), mode);
fd, fchmod, mode);
return fd;
}
......@@ -1142,7 +1237,7 @@ our(futimesat)(int filedes, const char *path, const struct timeval tv[2]) {
tv2ts(&tsp, tv);
if (path == NULL)
return real(futimens)(filedes, tsp);
return futimens(filedes, tsp);
return our(utimensat)(filedes, path, tsp, 0);
}
......@@ -1196,7 +1291,7 @@ our(opendir)(const char *dirname) {
if (fd == -1)
return NULL;
return real(fdopendir)(fd);
return fdopendir(fd);
}
#ifdef NEED_CHDIR
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment