termux / proot

An chroot-like implementation using ptrace.
https://wiki.termux.com/wiki/PRoot
Other
762 stars 160 forks source link

Implementation of semaphores? #79

Closed ghost closed 4 years ago

ghost commented 4 years ago

Some things break without them, like repo:

Traceback (most recent call last):
  File "/root/android/.repo/repo/main.py", line 47, in /<module>
    import event_log
  File "/root/android/.repo/repo/event_log.py", line 166, in <module>
    _EVENT_ID = multiprocessing.Value('i', 1)
  File "/usr/lib/python2.7/multiprocessing/__init__.py", line 253, in Value
    return Value(typecode_or_type, *args, **kwds)
  File "/usr/lib/python2.7/multiprocessing/sharedctypes.py", line 108, in Value
    lock = RLock()
  File "/usr/lib/python2.7/multiprocessing/__init__.py", line 183, in RLock
    return RLock()
  File "/usr/lib/python2.7/multiprocessing/synchronize.py", line 172, in __init__
    SemLock.__init__(self, RECURSIVE_MUTEX, 1, 1)
  File "/usr/lib/python2.7/multiprocessing/synchronize.py", line 75, in __init__
    sl = self._semlock = _multiprocessing.SemLock(kind, value, maxvalue)
OSError: [Errno 13] Permission denied

I'm unsure if this could be handle by proot, but I'm hoping it can :P

michalbednarski commented 4 years ago

Looks like this is actually caused by GLIBC being too strict about /dev/shm. Proot distro installation scripts usually mount /dev/shm as temporary directory (Living somewhere in /data, on Android there are no app-writable tmpfs, but normal (e.g. ext4) fs should work fine if above check would be bypassed.

Fixing this should only need changes in statfs to report /dev/shm as if it was tmpfs, but I yet have to implement and test them

ghost commented 4 years ago

wow

i wish i could help with proot, but i have no idea how it works lol, ptrace is confusing to me

michalbednarski commented 4 years ago

Just pushed to statfs-devshm, not fully tested yet but doesn't raise exception when constructing multiprocessing.Value("I")

ghost commented 4 years ago

i built the branch, now its function not implemented hmm

$ python2 `which repo` init -u https://android.googlesource.com/platform/manifest
Traceback (most recent call last):
  File "/home/kalmari/android/.repo/repo/main.py", line 47, in <module>
    import event_log
  File "/home/kalmari/android/.repo/repo/event_log.py", line 166, in <module>
    _EVENT_ID = multiprocessing.Value('i', 1)
  File "/data/data/com.termux/files/usr/lib/python2.7/multiprocessing/__init__.py", line 253, in Value
    return Value(typecode_or_type, *args, **kwds)
  File "/data/data/com.termux/files/usr/lib/python2.7/multiprocessing/sharedctypes.py", line 108, in Value
    lock = RLock()
  File "/data/data/com.termux/files/usr/lib/python2.7/multiprocessing/__init__.py", line 183, in RLock
    return RLock()
  File "/data/data/com.termux/files/usr/lib/python2.7/multiprocessing/synchronize.py", line 172, in __init__
    SemLock.__init__(self, RECURSIVE_MUTEX, 1, 1)
  File "/data/data/com.termux/files/usr/lib/python2.7/multiprocessing/synchronize.py", line 75, in __init__
    sl = self._semlock = _multiprocessing.SemLock(kind, value, maxvalue)
OSError: [Errno 38] Function not implemented
michalbednarski commented 4 years ago

Please check if you can reproduce error with

echo 'python2 -c "import multiprocessing as m;m.Value(chr(105),1)"' | ./start.sh

Replace ./start.sh with your proot launcher script and if reports same error please run following and post log

echo 'python2 -c "import multiprocessing as m;m.Value(chr(105),1)"' | PROOT_VERBOSE=9 ./start.sh >& log.txt

Also please post results of uname -a and dpkg --print-architecture

Also what guest distro do you use and where you've got it from

ghost commented 4 years ago

it has the same error

device: Samsung Galaxy S10+ kernel: Linux localhost 4.14.85-16887086 #1 SMP PREEMPT Wed Sep 18 17:13:35 KST 2019 aarch64 Android guest distro: http://os.archlinuxarm.org/os/ArchLinuxARM-aarch64-latest.tar.gz

$ stat -f /dev/shm
  File: "/dev/shm"
    ID: 3a1a11d0810ed8d2 Namelen: 255     Type: tmpfs
Block size: 4096       Fundamental block size: 4096
Blocks: Total: 245780064  Free: 225263820  Available: 225229772
Inodes: Total: 30973952   Free: 30077699

log.txt

michalbednarski commented 4 years ago

You'll need to add --link2symlink option to proot

ghost commented 4 years ago

ayy, it works!!!! thank you so much!

michalbednarski commented 4 years ago

Reporting of /dev/shm as tmpfs is now fixed in proot which is available in Termux apt repo; I'm closing this issue