fix: argv duplication happening on android termux#93
Open
DigiThax wants to merge 1 commit intoiximiuz:mainfrom
Open
fix: argv duplication happening on android termux#93DigiThax wants to merge 1 commit intoiximiuz:mainfrom
DigiThax wants to merge 1 commit intoiximiuz:mainfrom
Conversation
Author
|
@iximiuz Just wanted to take this opportunity to thank you so much for providing such a great platform to learn! And just a heads-up, this is my first time doing an OSS contribution, if theres any issue with the PR I'd be happy to correct |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Updated main.go with a condition to check if argv[1] is a duplicate of argv[0]
This happened on my instance on an Android tablet running termux. I had no issues setting it up but on running labctl it returned this error:
~ $ labctl
Error: unknown command "/data/data/com.termux/files/home/.iximiuz/labctl/bin/labctl" for "labctl"
Run 'labctl --help' for usage.
So I looked into it and it turns out there was some weird things going on with termux, I've summarized the gist of it here with the help of AI:
Why was it only Android/Termux?
It's a combination of three things colliding:
1. Android's linker behaviour
Android uses its own dynamic linker (/system/bin/linker64) instead of the standard glibc ld-linux. When the kernel executes an ELF binary, it actually runs the interpreter (linker) and passes the binary path as an argument to it. On standard Linux this is transparent — glibc's linker strips it before main() sees anything. Android's linker doesn't clean this up the same way.
2. Go's runtime on Android
Go does its own low-level os.Args initialisation by reading directly from the process's memory/aux vectors rather than relying on the C runtime to hand it a clean argv. On standard Linux this works perfectly. On Android, the Go runtime picks up the raw argv including the extra path that linker64 injected, and surfaces it as os.Args[1].
3. Termux specifically
If labctl were running inside a proper Android app sandbox or ADB shell, the environment is set up differently. Termux is unusual — it's a terminal emulator running in Android userspace without root, so it inherits Android's linker quirks without the usual Android app framework smoothing things over.