Skip to content

Commit 999ed37

Browse files
committed
@cxx/ClassCns.cxx:execves Reuse Termux LD_PRELOAD
as workaround (for termux-play-store/termux-issues#24 termux/termux-app#2155 termux/termux-app#4037 ). Fixes ``` ~/SubStack $ ./a.out cxx/Macros.hxx: pass execves(): pass execvex(): pass virusAnalysisTestsThrows(): pass assistantCnsTestsThrows(): /data/data/com.termux/files/usr/bin/sh: 1: wget: Permission denied /data/data/com.termux/files/usr/bin ``` , (to ``` conversationCnsTestsThrows(): --2024-06-15 18:22:01-- https://stackoverflow.com/robots.txt Resolving stackoverflow.com (stackoverflow.com)... 172.64.155.249, 104.18.32.7 Connecting to stackoverflow.com (stackoverflow.com)|172.64.155.249|:443... connected. HTTP request sent, awaiting response... 200 OK Length: unspecified [text/plain] Saving to: ‘robots.txt’ robots.txt [ <=> ] 1.99K --.-KB/s in 0.07s 2024-06-15 18:22:02 (27.4 KB/s) - ‘robots.txt’ saved [2036] ``` , as was)
1 parent f93af74 commit 999ed37

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

cxx/ClassCns.cxx

+12
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
#include <vector> /* std::vector */
66
#include <ctype.h> /* size_t */
77
#ifdef _POSIX_VERSION
8+
#include <stdlib.h> /* getenv */
9+
#include <stdio.h> /* asprintf */
810
#include <unistd.h> /* execve fork EXIT_FAILURE */
911
#include <sys/wait.h> /* waitpid */
1012
#endif /* def _POSIX_VERSION */
@@ -31,6 +33,16 @@ const int execves(const std::vector<const std::string> &argvS, const std::vector
3133
for(auto x = envpSmutable.begin(); envpSmutable.end() != x; ++x) {
3234
envp.push_back(const_cast<char *>(x->c_str()));
3335
}
36+
if(envp.empty()) {
37+
char* ld_preload = getenv("LD_PRELOAD");
38+
if (ld_preload) {
39+
// Keep LD_PRELOAD, necessary for now on the Google Play build of Termux.
40+
char* ld_preload_env;
41+
int allocated_bytes = asprintf(&ld_preload_env, "LD_PRELOAD=%s", ld_preload);
42+
assert(allocated_bytes > 0);
43+
envp.push_back(ld_preload_env);
44+
}
45+
}
3446
envp.push_back(NULL);
3547
execve(argv[0], &argv[0], &envp[0]); /* NORETURN */
3648
exit(EXIT_FAILURE);

0 commit comments

Comments
 (0)