Skip to content

Commit

Permalink
fix: preserve LD_PRELOAD, LD_LIBRARY_PATH and CLASSPATH for using wit…
Browse files Browse the repository at this point in the history
…h xstartup
  • Loading branch information
twaik committed Dec 23, 2024
1 parent e318297 commit b0d07af
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
9 changes: 6 additions & 3 deletions app/src/main/cpp/lorie/InitOutput.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,12 @@ static void* ddxReadyThread(unused void* cookie) {

if (!pid) {
char DISPLAY[16] = "";
sprintf(DISPLAY, ":%s", display);
setenv("DISPLAY", DISPLAY, 1);
unsetenv("CLASSPATH");
#define INHERIT_VAR(v) char *v = getenv("XSTARTUP_" #v); if (v && strlen(v)) setenv(#v, v, 1);
INHERIT_VAR(CLASSPATH)
INHERIT_VAR(LD_LIBRARY_PATH)
INHERIT_VAR(LD_PRELOAD)
#undef INHERIT_VAR

execlp(xstartup, xstartup, NULL);
execlp("sh", "sh", "-c", xstartup, NULL);
dprintf(2, "Failed to start command `sh -c \"%s\"`: %s\n", xstartup, strerror(errno));
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/cpp/lorie/cmdentrypoint.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ Java_com_termux_x11_CmdEntryPoint_start(JNIEnv *env, __unused jclass cls, jobjec
// No matter what tracer is attached.
// In the case of gdb or lldb LD_PRELOAD is already set.
// In the case of proot or proot-distro libtermux-exec in LD_PRELOAD will break linking.
if (access("/data/data/com.termux/files/usr/lib/libtermux-exec.so", F_OK) == 0 && !detectTracer())
if (access("/data/data/com.termux/files/usr/lib/libtermux-exec.so", F_OK) == 0 && !detectTracer()
&& !getenv("XSTARTUP_LD_PRELOAD"))
setenv("LD_PRELOAD", "/data/data/com.termux/files/usr/lib/libtermux-exec.so", 1);

// adb sets TMPDIR to /data/local/tmp which is pretty useless.
Expand Down
3 changes: 3 additions & 0 deletions termux-x11
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#!/data/data/com.termux/files/usr/bin/sh
[ -z "${LD_LIBRARY_PATH+x}" ] || export XSTARTUP_LD_LIBRARY_PATH="$LD_LIBRARY_PATH"
[ -z "${LD_PRELOAD+x}" ] || export XSTARTUP_LD_PRELOAD="$LD_PRELOAD"
[ -z "${CLASSPATH+x}" ] || export XSTARTUP_CLASSPATH="$CLASSPATH"
export CLASSPATH=/data/data/com.termux/files/usr/libexec/termux-x11/loader.apk
unset LD_LIBRARY_PATH LD_PRELOAD
exec /system/bin/app_process -Xnoimage-dex2oat / com.termux.x11.Loader "$@"

0 comments on commit b0d07af

Please sign in to comment.