1
1
# termux-exec
2
- A ` execve() ` wrapper to fix two problems with exec-ing files in Termux.
2
+ A ` execve(3) ` (and exec family of functions) wrapper to fix two problems with exec-ing files in Termux.
3
3
4
4
# Problem 1: Cannot execute files not part of the APK
5
5
Android 10 started blocking executing files under the app data directory, as
@@ -14,7 +14,7 @@ While there is merit in that general principle, this prevents using Termux and A
14
14
as a general computing device, where it should be possible for users to create executable
15
15
scripts and binaries.
16
16
17
- # Solution 1: Cannot execute files not part of the APK
17
+ ## Solution
18
18
Create an ` exec ` interceptor using [ LD_PRELOAD] ( https://en.wikipedia.org/wiki/DLL_injection#Approaches_on_Unix-like_systems ) ,
19
19
that instead of executing an ELF file directly, executes ` /system/bin/linker64 /path/to/elf ` .
20
20
Explanation follows below.
@@ -62,11 +62,6 @@ We could also consider patching this exec interception into the build process of
62
62
** NOTE** : The above example used ` /system/bin/linker64 ` - on 32-bit systems, the corresponding
63
63
path is ` /system/bin/linker ` .
64
64
65
- ** NOTE** : While this circumvents the technical restriction, it still might be considered
66
- violating [ Google Play policy] ( https://support.google.com/googleplay/android-developer/answer/9888379 ) .
67
- So this workaround is not guaranteed to enable Play store distribution of Termux - but it's
68
- worth an attempt, and regardless of Play store distribution, updating the targetSdk is necessary.
69
-
70
65
# Problem 2: Shebang paths
71
66
A lot of Linux software is written with the assumption that ` /bin/sh ` , ` /usr/bin/env `
72
67
and similar file exists. This is not the case on Android where neither ` /bin/ ` nor ` /usr/ `
@@ -75,19 +70,16 @@ exists.
75
70
When building packages for Termux those hard-coded assumptions are patched away - but this
76
71
does not help with installing scripts and programs from other sources than Termux packages.
77
72
78
- # Solution 2: Shebang paths
73
+ ## Solution
79
74
Create an ` execve() ` wrapper that rewrites calls to execute files under ` /bin/ ` and ` /usr/bin `
80
75
into the matching Termux executables under ` $PREFIX/bin/ ` and inject that into processes
81
76
using ` LD_PRELOAD ` .
82
77
83
- # How to install
84
- 1 . Install with ` pkg install termux-exec ` .
85
- 2 . Exit your current session and start a new one.
86
- 3 . From now on shebangs such as ` /bin/sh ` and ` /usr/bin/env python ` should work.
87
-
88
- # Where is LD_PRELOAD set?
89
- The ` $PREFIX/bin/login ` program which is used to create new Termux sessions checks for
90
- ` $PREFIX/lib/libtermux-exec.so ` and if so sets up ` LD_PRELOAD ` before launching the login shell.
78
+ # Usage in Termux
79
+ This ` termux-exec ` package comes preinstalled as an essential package in Termux. Each time a
80
+ process is spawned by the app, the ` LD_PRELOAD=$PREFIX/lib/libtermux-exec.so ` environment variable
81
+ is setup by the Android app. This environment variable needs to be kept at all times when executing
82
+ files inside Termux.
91
83
92
- Soon, when making a switch to target Android 10+, this will be setup by the Termux app even before
93
- launching any process, as ` LD_PRELOAD ` will be necessary for anything non-system to execute .
84
+ In the future the linker ` --wrap ` functionaliy might be used to avoid having to rely on ` LD_PRELOAD `
85
+ always being present .
0 commit comments