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

Fix require failing in Termux on Android #80

Merged
merged 1 commit into from Jun 29, 2020
Merged

Conversation

@ZimbiX
Copy link
Contributor

@ZimbiX ZimbiX commented Jun 24, 2020

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
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](https://linux.die.net/man/3/rindex) 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](https://stackoverflow.com/a/12628469) 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](https://github.com/termux/termux-packages/blob/8076aec21f8d4b0dd5f880af1af467961dcbbbbb/packages/util-linux/build.sh#L19) 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](https://www.indiegogo.com/projects/cosmo-communicator). 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:

```bash
$ gem build rbtrace.gemspec && gem install rbtrace-0.4.13.gem && ruby -r rbtrace -e puts
```
server.rb Show resolved Hide resolved
ext/rbtrace.c Show resolved Hide resolved
@SamSaffron SamSaffron merged commit 4b6b80c into tmm1:master Jun 29, 2020
@ZimbiX ZimbiX deleted the ZimbiX:fix-gem-require-in-termux-on-android branch Jun 29, 2020
@ZimbiX
Copy link
Contributor Author

@ZimbiX ZimbiX commented Jun 29, 2020

It seems SysV IPC is unsupported on Android

Ah, I see. Thanks very much for that info

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

Successfully merging this pull request may close these issues.

None yet

3 participants
You can’t perform that action at this time.