Use an LD_PRELOAD library in place of symlink to /home.

Apart from dependency on native-code DLLs, the one other quirk of
running WiX under mono is that it doesn't seem to quite get the right
answers when combining $PWD with a Unix absolute path to one of its
own supporting files - it doesn't interpret the leading slash on the
latter as meaning $PWD should be ignored, so it tries to look for
/home/my/build/dir/home/my/wix/install/dir/some.file. Previously I was
bodging around that by having my build dir contain a symlink 'home'
pointing at /home; this is marginally less intrusive.
This commit is contained in:
Simon Tatham 2017-05-16 07:03:19 +01:00
parent 0985b382d3
commit decda92874
2 changed files with 45 additions and 1 deletions

View file

@ -2,7 +2,7 @@
.SUFFIXES: .c .lo .la
all: libwinterop.so.la libmsi.so.la
all: libwinterop.so.la libmsi.so.la libpreload.la
%.la:
libtool --mode=link gcc -o $@ $^ -rpath /usr/local/lib
@ -14,6 +14,8 @@ libwinterop.so.la: fake-winterop.lo fake-lib.lo
libmsi.so.la: fake-msi.lo fake-lib.lo
libpreload.la: preload.lo
clean:
rm -rf .libs
rm -f *.o *.lo *.la

42
preload.c Normal file
View file

@ -0,0 +1,42 @@
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <dlfcn.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
static const char *munge(const char *n) {
static const char *e = NULL;
static size_t elen;
if (!e) {
e = getenv("WIX");
if (!e)
return n;
elen = strlen(e);
}
const char *last_slash = strrchr(n, '/');
if (!last_slash)
return n;
if (last_slash - n > elen && !strncmp(last_slash - elen, e, elen))
return last_slash - elen;
return n;
}
#define dofunc(rettype,sym,proto,proto2) \
rettype sym proto { \
rettype (*real) proto; \
real = dlsym(RTLD_NEXT, #sym); \
fname = munge(fname); \
return real proto2; \
}
dofunc(int,open,(const char *fname,int flags,mode_t mode),(fname,flags,mode))
dofunc(int,open64,(const char *fname,int flags,mode_t mode),(fname,flags,mode))
dofunc(int,__open,(const char *fname,int flags,mode_t mode),(fname,flags,mode))
dofunc(int,__open64,(const char *fname,int flags,mode_t mode),(fname,flags,mode))
dofunc(int,stat,(const char *fname,struct stat *sbuf),(fname,sbuf))
dofunc(int,lstat,(const char *fname,struct stat *sbuf),(fname,sbuf))
dofunc(int,access,(const char *fname,int mode),(fname,mode))