Skip to content

fix: argv duplication happening on android termux#93

Open
DigiThax wants to merge 1 commit intoiximiuz:mainfrom
DigiThax:fix-argv-duplication-on-termux
Open

fix: argv duplication happening on android termux#93
DigiThax wants to merge 1 commit intoiximiuz:mainfrom
DigiThax:fix-argv-duplication-on-termux

Conversation

@DigiThax
Copy link
Copy Markdown

@DigiThax DigiThax commented Mar 23, 2026

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.

@DigiThax
Copy link
Copy Markdown
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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant