termux / termux-packages

A package build system for Termux.
https://termux.dev
Other
13.22k stars 3.04k forks source link

[Bug]: `tsu` Not Able to Run Certain Commands #18383

Open isrgish opened 12 months ago

isrgish commented 12 months ago

Problem description

There are some programs that I'm able to run in su but I'm not able to run in tsu. They seem to run but nothing happens. These are 2 of them that I remember off hand

  1. abx2xml & xml2abx (This is a command from /system/bin, it only works in su not in tsu).
  2. ro2rw (from xda Read Only to Read Write for android (RO2RW) | Auto converting SUPER "system partitions" to read/write mode this is a script and gets an error when in tsu but works fine in su)

What steps will reproduce the bug?

Typing tsu Then use abx2xml on a file it seems to work but it doesn't convert it.

What is the expected behavior?

It should work in tsu just like it works in su

System information

termux-info:

Termux Variables:
TERMUX_APK_RELEASE=F_DROID
TERMUX_APP_PACKAGE_MANAGER=apt
TERMUX_APP_PID=7544
TERMUX_IS_DEBUGGABLE_BUILD=0
TERMUX_VERSION=0.118.0
Packages CPU architecture:
aarch64
Subscribed repositories:
# sources.list
deb https://packages-cf.termux.dev/apt/termux-main/ stable main
# root-repo (sources.list.d/root.list)
deb https://packages-cf.termux.dev/apt/termux-root/ root stable
Updatable packages:
All packages up to date
termux-tools version:
1.39.3
Android version:
13
Kernel build information:
Linux localhost 4.19.157-perf+ #1 SMP PREEMPT Fri Aug 18 23:04:47 CST 2023 aarch64 Android
Device manufacturer:
unknown
Device model:
Phh-Treble GSI
LD Variables:
LD_LIBRARY_PATH=
LD_PRELOAD=/data/data/com.termux/files/usr/lib/libtermux-exec.so
Grimler91 commented 12 months ago

Add /system/bin to PATH if you want to use /system/bin utilities, or open a package request for abx2xml and xml2abx as those seem like they would be useful to have in termux.

What error did you get with ro2rw? Maybe error stems from that /system/bin is not in path also.

isrgish commented 12 months ago

/system/bin is in path. It recognizes the abx2xml command its just that nothing actually happens. ro2rw when it reaches the point where it extracts the partitions I get the following error.

- Detected partitions: odm_a product_a system_a
  system_ext_a vendor_a
- Copy odm_a.ext4. Waiting...
chcon: failed to change context of '/data/local/TMP_NEO/imgs/odm_a.img' to ‘u:object_r:media_rw_data_file:s0’: Operation not supported on transport endpoint
- Oops, something wrong with original odm_a.ext4,
  dont worry, starting mount odm_a and migrating
  to new odm_a.ext4. Waiting...
chcon: failed to change context of '/data/local/TMP_NEO/imgs/odm_a.img' to ‘u:object_r:media_rw_data_file:s0’: Operation not supported on transport endpoint

- There are problems with mounting images odm_a,
  you can continue without checking the odm_a
  images, in this case DFE will not be available
  if it vendor partition

  1) [Continue]
  2) [EXIT]
 - Select num:

I get this for each partition. But again when I run it in su it works fine.

Grimler91 commented 12 months ago

What does it mean that nothing actually happens? No text is printed at all? Does it exit with an error code (echo $?)?

Maybe selinux related. Check logcat output from a root or adb shell to see what android reports.

isrgish commented 12 months ago

When I run abx2xml packages.xml packages.xml.human I expect to get a converted copy of packages.xml to packages.xml.human that is human readable. When I run this command in su this is exactly what happens, but when I run it in tsu it doesn't do anything I don't get that converted file.

The result of echo $? after running the command in tsu is 0. This shows that everything went fine. But that isn't the case.

isrgish commented 12 months ago

Here sre the relevent results from logcat (I ran the command at 12:10:24) I don't see anything.

10-30 12:10:17.807  4181 23019 D Liv 11776 HttpProxyForwarder: (th:1299)    Trying to read from server data for clients4.google.com:443 and url clients4.google.com:443 of max len 1024
10-30 12:10:17.848  4181 23020 D Liv 11776 HttpProxyForwarder: (th:1300)    Receiving from client data for clients4.google.com:443 and url clients4.google.com:443 of len 39
10-30 12:10:17.849  4181 23020 D Liv 11776 HttpProxyForwarder: (th:1300)    Trying to read from client data for clients4.google.com:443 and url clients4.google.com:443 of max len 1024
10-30 12:10:17.860  2069  3080 D CoreBackPreview: Window{854f605 u0 PopupWindow:424b6d6}: Setting back callback OnBackInvokedCallbackInfo{mCallback=android.window.IOnBackInvokedCallback$Stub$Proxy@3de008b, mPriority=0}
10-30 12:10:17.936  2069  3080 D CoreBackPreview: Window{854f605 u0 PopupWindow:424b6d6}: Setting back callback null
10-30 12:10:17.937  2069  3080 W InputManager-JNI: Input channel object '854f605 PopupWindow:424b6d6 (client)' was disposed without first being removed with the input manager!
10-30 12:10:18.079  2069  2927 D CoreBackPreview: Window{b0fcbb9 u0 PopupWindow:424b6d6}: Setting back callback OnBackInvokedCallbackInfo{mCallback=android.window.IOnBackInvokedCallback$Stub$Proxy@af5ef5f, mPriority=0}
10-30 12:10:18.172  2069  3080 D CoreBackPreview: Window{b0fcbb9 u0 PopupWindow:424b6d6}: Setting back callback null
10-30 12:10:18.173  2069  3080 W InputManager-JNI: Input channel object 'b0fcbb9 PopupWindow:424b6d6 (client)' was disposed without first being removed with the input manager!
10-30 12:10:19.437  2069  2482 D ConnectivityService: NetReassign [no changes]
10-30 12:10:25.867  2069  3080 D CoreBackPreview: Window{78e65f3 u0 PopupWindow:424b6d6}: Setting back callback OnBackInvokedCallbackInfo{mCallback=android.window.IOnBackInvokedCallback$Stub$Proxy@5e1529, mPriority=0}
10-30 12:10:25.921  2069  3080 D CoreBackPreview: Window{78e65f3 u0 PopupWindow:424b6d6}: Setting back callback null
10-30 12:10:25.922  2069  3080 W InputManager-JNI: Input channel object '78e65f3 PopupWindow:424b6d6 (client)' was disposed without first being removed with the input manager!
10-30 12:10:25.975 23021 23021 D AndroidRuntime: >>>>>> START com.android.internal.os.RuntimeInit uid 0 <<<<<<
10-30 12:10:29.388  3716  4002 I azna    : (REDACTED) getHotwordActive::active query: %s, watch: %s, devices connected: %s
10-30 12:10:29.597  2069  2927 D CoreBackPreview: Window{674d847 u0 PopupWindow:424b6d6}: Setting back callback OnBackInvokedCallbackInfo{mCallback=android.window.IOnBackInvokedCallback$Stub$Proxy@ed1819d, mPriority=0}
10-30 12:10:29.658  2069  7359 D CoreBackPreview: Window{674d847 u0 PopupWindow:424b6d6}: Setting back callback null
10-30 12:10:29.659  2069  7359 W InputManager-JNI: Input channel object '674d847 PopupWindow:424b6d6 (client)' was disposed without first being removed with the input manager!
10-30 12:10:29.897  2069  2927 D CoreBackPreview: Window{cbc7a5b u0 PopupWindow:424b6d6}: Setting back callback OnBackInvokedCallbackInfo{mCallback=android.window.IOnBackInvokedCallback$Stub$Proxy@25b03d1, mPriority=0}
10-30 12:10:29.973  2069  7359 D CoreBackPreview: Window{cbc7a5b u0 PopupWindow:424b6d6}: Setting back callback null
10-30 12:10:29.975  2069  7359 W InputManager-JNI: Input channel object 'cbc7a5b PopupWindow:424b6d6 (client)' was disposed without first being removed with the input manager!
isrgish commented 12 months ago

I tried tsu -p which gave me context=u:r:magisk:s0 but the command still didn't work.

Besides I also didn't have my .bashrc additions.

romanovj commented 12 months ago

for abx2xml you need to patch tsu script, add adfitional exports

search for "Android specific exports: Need more testing."

add

EXP_ENV[ANDROID_I18N_ROOT]="$ANDROID_I18N_ROOT"
EXP_ENV[ANDROID_TZDATA_ROOT]="$ANDROID_TZDATA_ROOT"
EXP_ENV[ANDROID_ART_ROOT]="$ANDROID_ART_ROOT"
EXP_ENV[BOOTCLASSPATH]="$BOOTCLASSPATH"
agnostic-apollo commented 12 months ago

Can also try using https://github.com/agnostic-apollo/sudo

isrgish commented 12 months ago

for abx2xml you need to patch tsu script, add adfitional exports

search for "Android specific exports: Need more testing."

add

EXP_ENV[ANDROID_I18N_ROOT]="$ANDROID_I18N_ROOT"
EXP_ENV[ANDROID_TZDATA_ROOT]="$ANDROID_TZDATA_ROOT"
EXP_ENV[ANDROID_ART_ROOT]="$ANDROID_ART_ROOT"
EXP_ENV[BOOTCLASSPATH]="$BOOTCLASSPATH"

Can you explain what these additions do?

romanovj commented 12 months ago

@isrgish java related environment variables which are needed for running java code

isrgish commented 11 months ago

This does work can it be added for the next release? I don't know if I'm aloud too nor do I know how to do this. (If someone wants to guide me I am willing to learn.

Grimler91 commented 11 months ago

@isrgish it would be very helpful if you would like to look into it!

I forked the tsu repo now (should have been done before): https://github.com/termux/tsu I think we should check if the variables are set, and if they are then they can be exported. Check should probably be done in the env_path_helper function

isrgish commented 11 months ago

These variables are not set can I add into the script as @romanovj suggest into the repo and then commit and push it?

agnostic-apollo commented 11 months ago

Both magisk and supersu support su --preserve-environment flag, variables vary between devices, so much easier to pass that than exporting environment manually. Some su like lineageos that was removed many years ago doesn't have it though, but I haven't received any complaints.

https://github.com/agnostic-apollo/sudo/blob/743770c88680c1dbc00a0ade7840fab8c48ad0e2/sudo#L828

You can do a runtime check too.

https://github.com/agnostic-apollo/sudo/blob/743770c88680c1dbc00a0ade7840fab8c48ad0e2/sudo#L761