tmm1 / rbtrace

like strace, but for ruby code
MIT License
1.71k stars 65 forks source link

Fix require failing in Termux on Android #80

Closed ZimbiX closed 4 years ago

ZimbiX commented 4 years ago

Note that this change does not make rbtrace actually work in Termux - it just allows an app to start up without an exception when it has require 'rbtrace'.

The exception is:

$ ruby -r rbtrace -e puts
Traceback (most recent call last):
        1: from /data/data/com.termux/files/usr/lib/ruby/site_ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
/data/data/com.termux/files/usr/lib/ruby/site_ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require': cannot load such file -- rbtrace (LoadError)
        2: from /data/data/com.termux/files/usr/lib/ruby/site_ruby/2.6.0/rubygems/core_ext/kernel_require.rb:34:in `require'
        1: from /data/data/com.termux/files/usr/lib/ruby/site_ruby/2.6.0/rubygems/core_ext/kernel_require.rb:130:in `rescue in require'
/data/data/com.termux/files/usr/lib/ruby/site_ruby/2.6.0/rubygems/core_ext/kernel_require.rb:130:in `require': dlopen failed: cannot locate symbol "rindex" referenced by "/data/data/com.termux/files/usr/lib/ruby/gems/2.6.0/gems/rbtrace-0.4.13/lib/rbtrace.so"... - /data/data/com.termux/files/usr/lib/ruby/gems/2.6.0/gems/rbtrace-0.4.13/lib/rbtrace.so (LoadError)

It turns out that Android (9, at least) does not include rindex - I believe because it has been deprecated for many years; strrchr is apparently a drop-in replacement.

After that, there was another exception about the SUN_LEN symbol missing. I added this definition for the macro. That then got the gem able to be required without error.

I would have liked to get rbtrace working in Termux, but this is as far as I've been able to progress for now. I'm having trouble with the ipcs binary. It's deliberately not provided by Termux's util-linux package for some reason. With root, I can run Stericson Busybox's ipcs, but it just returns this:

$ su -c /sbin/ipcs

kernel not configured for message queues

kernel not configured for shared memory

kernel not configured for semaphores

I'm hoping that's not just a quirk of the particular kernel on my device. But perhaps the shared memory functionality is not actually suppported on Android? I don't yet know. Anyway.

test.sh does not work since rbtrace itself does not yet work on Android. The tmpdir change in there gets it one step closer at least - /tmp does not exist on Android.

This commit was tested by simply:

$ gem build rbtrace.gemspec && gem install rbtrace-0.4.13.gem && ruby -r rbtrace -e puts
tmm1 commented 4 years ago

It seems SysV IPC is unsupported on Android: https://android.googlesource.com/platform/ndk/+/4e159d95ebf23b5f72bb707b0cb1518ef96b3d03/docs/system/libc/SYSV-IPC.TXT#1

ZimbiX commented 4 years ago

It seems SysV IPC is unsupported on Android

Ah, I see. Thanks very much for that info