by avidiax · 2y ago · 0 comments
Android does this for most common shell commands. Toybox and busybox are examples of such implementations.
A lot of times you know you never called chdir(), in which case I'd actually recommend executing argv[0], as this is nicest thing for admins. If you are really worried, you can use /proc/self/exe for progname and pass argv[0] as-is, but that's overkill a lot of times.
I have fixed enough software that made this mistake that I'm confident to be absolute about it. It's a very easy mistake to make but it's really annoying when software makes it and someone needs to deal with it at a higher level. It's better for developers to know that argv[0] isn't the path to the executable it's what was used to invoke the executable.
I can’t find issue with exec(“/proc/self/exe”, [ program , … ).
$ perl myscript.pl a b c
$ARGV[0] is "a".