get own_dir by using dladdr() instead of argv[0]

pull/307/head
Solar Flare 2019-11-05 11:39:46 +08:00 committed by soflare
parent 0a8663c845
commit b8fa2a7405
2 changed files with 9 additions and 2 deletions

View File

@ -86,7 +86,7 @@ $(LDSO_PATHNAME): $(LOBJS)
-shared -o $@ $(LOBJS) $(SOCKET_LIBS)
$(ALL_TOOLS): $(OBJS)
$(CC) src/main.o src/common.o $(USER_LDFLAGS) -o $(PXCHAINS)
$(CC) src/main.o src/common.o $(USER_LDFLAGS) $(LIBDL) -o $(PXCHAINS)
.PHONY: all clean install install-config install-libs install-tools

View File

@ -19,6 +19,11 @@
#include <sys/types.h>
#include <sys/wait.h>
#ifdef IS_MAC
#define _DARWIN_C_SOURCE
#endif
#include <dlfcn.h>
#include "common.h"
static int usage(char **argv) {
@ -111,7 +116,9 @@ int main(int argc, char *argv[]) {
// search DLL
set_own_dir(argv[0]);
Dl_info dli;
dladdr(own_dir, &dli);
set_own_dir(dli.dli_fname);
i = 0;