4 ms·
The unix section is missing a case: when invoked from login, arg[0] has a '-' prepended. I understand not many people write a program suitable as a top level s
by gumby 9y ago
The unix section is missing a case: when invoked from login, arg[0] has a '-' prepended.
I understand not many people write a program suitable as a top level shell (for use in /etc/passwd) but for completeness...
- leni536 9y agoIs this an actual separate case? How are top level shells invoked? Isn't this just a specific call to execve?
- emmelaich 9y agoYeah, not a separate case but good to mention.
- gumby 9y agoI am not sure I understand your question. Of course /bin/login calls some version of exec. However /bin/login formats arg[0] differently. You can see this in ps. I suppose most people don't talk to /bin/login any more unless they ssh someplace.
- felipelemos 9y agoAfter Systemd/Linux we don't have /bin/login anymore.
- dfox 9y agoIt is good example that argv[0] is just another normal argument that is passed by the caller of execve() and does not necessarily have to be related to the actual filename of program executed in any way.
- TeMPOraL 9y agoNot sure if it still works that way, but years ago I used to overwrite the argv[0] param with my own data to change how the process appears on lists such as one shown by the 'w' utility.
- GauntletWizard 9y agoYep. There's a tool in djb's daemontools that uses this behavior - https://cr.yp.to/daemontools/readproctitle.html https://cr.yp.to/daemontools/readproctitle.html . It's kinda a pathological case, but it's a kinda cool way to assure that you can get some data from your processes, even on a totally horked system, as well as being fairly convenient from an old-school administration perspective (giving the ability to see what errors a program has encountered with just ps or top; Already likely to be the first commands run when something's wrong.)
- JdeBP 9y agoNo, it is not. This is not a distinct separate case when it comes to _command-line parameter parsing_, which is the topic of the article. The cases when it comes to parameter parsing on Linux and Unix operating systems are things like: * A POSIX-conformant shell parsing a command line, in a shell script or entered interactively, into an argument vector. * systemd parsing a string in ExecStart= in one of systemd's service definitions into an argument vector. * Things that parse .desktop files, as given in the article. * execlineb or nosh parsing a file into an argument vector. - http://skarnet.org/software/execline/grammar.html http://skarnet.org/software/execline/grammar.html - http://jdebp.eu./Softwares/nosh/guide/nosh.html http://jdebp.eu./Softwares/nosh/guide/nosh.html * init parsing single fields of records in /etc/ttys or /etc/inittab into argument vectors. * cron programs parsing fields in crontab records into argument vectors. and so forth. These are all subtly or blatantly different, and the headlined article has glossed over this to a degree.