Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I think argv[0] is fine. It sounds like there is a lot of bad security scanning software that doesn't understand how the `exec` syscall works. That sounds like their problem and not a fundamental problem with argv[0].

Most people use argv[0] so they can do something like:

   $ mycommand help
   Type `mycommand foo bar` to foo bars.

   $ mycommand1.2.3 help
   Type `mycommand1.2.3 foo bar` to foo bars.
This is admittedly less fun when mycommand is /home/jrockway/.cache/bazel/_bazel_jrockway/7f95bd5e6dcc2e75a861133ddc7aee82/execroot/_main/bazel-out/k8-fastbuild/mycommand/mycommand_/mycommand` however.


I routinely use basename(arg0) in my programs.


I don't think argv[0] includes the full path (or at least some programming language strip the whole path and keep only the last part)


I stand corrected - C, Go and Python are all consistent here and show the full path.

I seem to recall there was a language that only provided the stripped part - but I guess my memory is failing me here. Sorry for the wrong information above.


It depends on the caller not on the language of the program being called. If you execute something via $PATH then most shells will only pass the command you typed and not the full path. Similarly, when you use a relative path like ./command then usually your argv0 will be that relative path and not the full path to the executable. So in practice argv may or may not be a full path and if it does not contain a slash then it generally isn't even a relative path (well, not relative to the current directory anyway).

For the help case in gp I think it makes sens for programs to always strip away anything up to including the last slash from argv0.


Languages might remove the dirname part, but argv[0] is not necessarily a path, it's just a string passed to the exec system call that is also passed to main(int argc, char *argv). While many languges don't call their main function that, somewhere in the runtime that's what it gets.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: