Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTOP, TOP and any other packages requiring /proc /data doesnt work within archlinux for termux (repost on request from sdrausty) #32

Closed
Root-voidX opened this issue Aug 12, 2018 · 15 comments

Comments

@Root-voidX
Copy link

I originally posted this on archtermux git, sdrausty the maintainer said it is related to proot on android 8.0 and as such requested me to repost this here. Bellow is the original submission:

Hey everyone, so I am using a Samsung Galaxy S9+ on Android 8.0 on a SD845 soc. So I noticed that top, htop and any other app requiring /proc or /data do not work. If I run the same htop and top command in Termux it works but within arch it doesn't? This also effects makepkg as well if you wanna note that down as well.

@michalbednarski
Copy link
Collaborator

This isn't really proot related, it's just that htop gives up and exits if it cannot open /proc/stat. Htop in Termux is patched, so it's not same htop as in TermuxArch.

It can be made working if /proc/stat is provided by adding -b fake_proc_stat:/proc/stat (grab fake_proc_stat by getting /proc/stat from another device or find example online) argument to proot. Possibly this could be added to TermuxArch (you'd need to add checking if real /proc/stat is readable and set up fake one if it isn't) /cc @SDRausty

There might be other files in /proc that would need similar faking. /data is Android-specific so I don't think anything from desktop Linux would need it.

Original issue: SDRausty/TermuxArch#103

@SDRausty

This comment was marked as spam.

@ghost
Copy link

ghost commented Aug 13, 2018

@SDRausty Just use this (filled with content from /proc/stat on my PC): fake_proc_stat.txt

Download file and use it like -b fake_proc_stat.txt:/proc/stat with proot.

@SDRausty

This comment was marked as spam.

@ghost
Copy link

ghost commented Aug 13, 2018

@SDRausty

  1. Download file
curl -LO https://github.com/termux/proot/files/2284584/fake_proc_stat.txt

Or try to copy this if can't download (???):

cpu  528909 2279885 770423 16623705 25398 200416 48153 0 0 974
cpu0 253914 1186503 381515 15533575 24381 151640 29523 0 0 612
cpu1 274994 1093381 388908 1090129 1016 48775 18630 0 0 361
intr 161467182 9 268723 0 0 0 0 0 0 1 40792 0 0 49954629 0 0 0 1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147383 0 17622049
  1. Execute proot:
proot --kill-on-exit --link2symlink -0 -r /data/data/com.termux/files/home/arch -b "$ANDROID_DATA" -b /dev/ -b "$EXTERNAL_STORAGE"  -b ${PWD}/fake_proc_stat.txt:/proc/stat  -b "$HOME" -b /proc/ -b /storage/ -b /sys/ -w "$PWD" /usr/bin/env -i HOME=/root TERM=xterm-256color  /bin/bash -l

@SDRausty

This comment was marked as spam.

@Root-voidX
Copy link
Author

Hello guys, i will check if the recent commit by sdrausty will work. Is setting up a fake /proc going to give accurate data?

Anyway so theoretically in proot I can run any packages then and utilize all of my cpu, ram, gpu even though top/htop couldnt read the file? Is there any limitation I should know?

@ghost
Copy link

ghost commented Aug 14, 2018

@Root-voidX Htop in Termux already patched: termux/termux-packages@04aea16 so it even don't read file /proc/stat.

For TermuxArch the only way to provide a fake file.

@SDRausty

This comment was marked as spam.

@michalbednarski
Copy link
Collaborator

This isn't really proot related, it's
provided by adding -b fake_proc_stat:/proc/stat

I am a little bit confused by the incongruity in the previous statements

These statements aren't contradictory

  • "This isn't really proot related" = This issue isn't caused by nor specially handled by proot. Proot just relays /proc access as specified with -b /proc option and contents of /proc are not altered in any way in this case.
  • "... is provided by adding -b fake_proc_stat:/proc/stat". -b host_path:guest_path option causes proot to map guest_path onto host_path. (if colon (:) is not specified then there's same host and guest path, as is in case of above mentioned -b /proc). -b option works regardless whenever it remaps directory, file or device (pseudofile). We use it here to put regular file in place where normally special file is.

So when I load htop, it shows me at least 5 distinct processes and only shows 2 cores..so I don't know how accurate that is.

There are two different mechanisms in question:

  1. SELinux blocking access to /proc/stat. This is what is being worked around with -b option. As we just provided completely fake file it's contents are not accurate. Which means htop will show number of cpus as defined in that file (you could see real amount in /proc/cpuinfo) and no cpu usage. Access to /proc/stat was intentionally blocked as information from it could be used to guess typed passwords.
  2. hidepid=2. This means you'll be only able to see processes having uid matching yours. (Or more precisely processes you'd be allowed to attach debugger to (which means you won't see ssh agent which opts out of being debuggable)

Can this feature resolve issues similar to termux/libandroid-shmem#3 too?

I'm not sure what above issue is actually about, but as far as shared memory is concerned there are two separate mechanisms (different programs might use different mechanisms)

  • System V shared memory (shmget). Syscall based. Implemented by libandroid-shmem which is usually linked as library in Termux, however it could probably work via LD_PRELOAD as well.
  • POSIX shared memory (shm_open). You could easily make it work by mounting temporary directory under /dev/shm.

And one more generic note: you should use fake /proc/stat only if real one is not available. You can determine if it's available with test -r /proc/stat.

@SDRausty

This comment was marked as spam.

@michalbednarski
Copy link
Collaborator

prootstmnt+="-b /dev/ashmem:/dev/shm "

Don't mount /dev/ashmem as /dev/shm, these are not compatible, /dev/shm should be directory and /dev/ashmem isn't (code in else looks okay)

if [[ -f /proc/stat ]] ; then
if [[ ! "$(head /proc/stat)" ]] ; then

You probably could fold that into [ -r /proc/stat ] (-r stands for readable) (Also avoids printed error message if /proc/stat is unreadable)


Nice idea with configurable binds in $installdir/var/binds/*.prs 👍

@SDRausty

This comment was marked as spam.

@michalbednarski
Copy link
Collaborator

I get one of these:

You can't perform this action at this time

Why do I get that misleading bmessage when trying to comment at the correct thread

Not sure what you're referring to here but I guess you've got error while commenting on pull request authored by tomty89 who you've blocked. If something works incorrectly with blocking users then GitHub's bugs needs to be reported to GitHub.

Currently proot6 in Termux relies on P_tmpdir (which is set in Termux to correct value). I've tested

Let's stay with the correct value.

Of course I'm not going to commit changes breaking common usage. (Nor that pull request breaks anything, this was generic note on P_tmpdir reliance and deprecatedness)


Looks like htop issue is resolved, so closing this issue.

@SDRausty

This comment was marked as spam.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants