diff --git a/Makefile b/Makefile index 09d147b..ec698a2 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ CC ?= clang TERMUX_BASE_DIR ?= /data/data/com.termux/files CFLAGS += -Wall -Wextra -Werror -Wshadow -fvisibility=hidden -std=c17 -C_SOURCE := src/termux-exec.c src/exec-variants.c src/termux-readlink.c +C_SOURCE := src/termux-exec.c src/exec-variants.c src/termux-readlink.c src/termux-realpath.c CLANG_FORMAT := clang-format --sort-includes --style="{ColumnLimit: 120}" $(C_SOURCE) tests/fexecve.c tests/system-uname.c tests/print-argv0.c tests/popen.c CLANG_TIDY ?= clang-tidy diff --git a/src/termux-realpath.c b/src/termux-realpath.c new file mode 100644 index 0000000..2ee2aaa --- /dev/null +++ b/src/termux-realpath.c @@ -0,0 +1,21 @@ +#define _GNU_SOURCE +#include +#include +#include +#include +#include +#include + +__attribute__((visibility("default"))) char* _Nullable realpath(const char* _Nonnull path, char* _Nullable resolved) { + char* (*orig_realpath)(const char*, char*); + orig_realpath = dlsym(RTLD_NEXT, "realpath"); + + if (strcmp(path, "/proc/self/exe") == 0) { + const char *termux_self_exe = getenv("TERMUX_EXEC__PROC_SELF_EXE"); + if (termux_self_exe) { + path = termux_self_exe; + } + } + + return orig_realpath(path, resolved); +}