Skip to content

Commit

Permalink
enhance(scripts,main/android-tools,main/libllvm): replace `TERMUX_ENV…
Browse files Browse the repository at this point in the history
…__S_TERMUX` in patch files, currently for `$TERMUX_EXEC__PROC_SELF_EXE`

Related pull termux/termux-exec#24
  • Loading branch information
agnostic-apollo committed Dec 20, 2024
1 parent e1c81f1 commit c5c613e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions packages/android-tools/termux-exec.patch
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#if defined(__linux__)
std::string path;
- android::base::Readlink("/proc/self/exe", &path);
+ if (const char *tmp = std::getenv("TERMUX_EXEC__PROC_SELF_EXE"))
+ if (const char *tmp = std::getenv("@TERMUX_ENV__S_TERMUX_EXEC@PROC_SELF_EXE"))
+ path.assign(tmp);
+ else
+ android::base::Readlink("/proc/self/exe", &path);
Expand Down Expand Up @@ -35,7 +35,7 @@
- ssize_t exPathLen = readlink("/proc/self/exe", exPath, sizeof(exPath));
+ ssize_t exPathLen;
+ const char *tmp;
+ if (tmp = getenv("TERMUX_EXEC__PROC_SELF_EXE")) {
+ if (tmp = getenv("@TERMUX_ENV__S_TERMUX_EXEC@PROC_SELF_EXE")) {
+ strncpy(exPath, tmp, sizeof(exPath));
+ exPathLen = strlen(exPath)
+ } else {
Expand All @@ -51,7 +51,7 @@
bool RunAs::Prepare() {
// run-as can't run /data/local/tmp/simpleperf directly. So copy simpleperf binary if needed.
- if (!android::base::Readlink("/proc/self/exe", &simpleperf_path_)) {
+ if (const char *tmp = std::getenv("TERMUX_EXEC__PROC_SELF_EXE"))
+ if (const char *tmp = std::getenv("@TERMUX_ENV__S_TERMUX_EXEC@PROC_SELF_EXE"))
+ simpleperf_path_.assign(tmp);
+ else if (!android::base::Readlink("/proc/self/exe", &simpleperf_path_)) {
PLOG(ERROR) << "ReadLink failed";
Expand Down
2 changes: 1 addition & 1 deletion packages/libllvm/llvm-lib-Support-Unix-Path.inc.patch
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ diff -u -r ../orig-src/llvm/lib/Support/Unix/Path.inc ./llvm/lib/Support/Unix/Pa
if (getprogpath(exe_path, argv0) != NULL)
return exe_path;
+#elif defined(__ANDROID__) // termux-exec linker wrapping does not work with /proc/self/exe
+ const char *termux_self_exe = std::getenv("TERMUX_EXEC__PROC_SELF_EXE");
+ const char *termux_self_exe = std::getenv("@TERMUX_ENV__S_TERMUX_EXEC@PROC_SELF_EXE");
+ if (termux_self_exe != NULL) return std::string(termux_self_exe);
+ if (char *real_path = realpath("/proc/self/exe", nullptr)) {
+ std::string ret = std::string(real_path);
Expand Down

0 comments on commit c5c613e

Please sign in to comment.