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

Fix require failing in Termux on Android #80

merged 1 commit into from Jun 29, 2020

Commits on Jun 24, 2020

  1. Fix require failing in Termux on Android

    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
    ```
    ZimbiX committed Jun 24, 2020
    Copy the full SHA
    5b18f29 View commit details
    Browse the repository at this point in the history