From b8fa2a7405e4e4ddeb35e9f6cf298944680fc52f Mon Sep 17 00:00:00 2001 From: Solar Flare Date: Tue, 5 Nov 2019 11:39:46 +0800 Subject: [PATCH] get own_dir by using dladdr() instead of argv[0] --- Makefile | 2 +- src/main.c | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index fe5f8c6..2dd9e9c 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/src/main.c b/src/main.c index dfe8894..d801b2c 100644 --- a/src/main.c +++ b/src/main.c @@ -19,6 +19,11 @@ #include #include +#ifdef IS_MAC +#define _DARWIN_C_SOURCE +#endif +#include + #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;