shdown / luastatus

universal status bar content generator
GNU General Public License v3.0
295 stars 12 forks source link

Implement getting temperature of modern AMD CPUs #67

Closed Layerex closed 2 years ago

shdown commented 2 years ago
Layerex commented 2 years ago
  • io.popen itself invokes /bin/sh -c arg, so no shell invocation is required.

It seems to invoke user's login shell, whatever it is, not sh. On my machine it invokes zsh, at least. On other machine it could be something like fish, which is not POSIX-compliant at all, I thought.

> io.popen('echo $SHELL'):read()
/bin/zsh
Layerex commented 2 years ago

Yes, it launches fish, if I change shell to fish.

shdown commented 2 years ago

It seems to invoke user's login shell, whatever it is, not sh.

  1. The popen C function is required by POSIX to shell out to a POSIX sh-compatible shell. Lua’s os.popen simply calls the C function.
  2. glibc, fairly a standard on Linux, shells out to /bin/sh.
  3. Linux/glibc explicitly document in the manpage that popen shells out to /bin/sh: This command is passed to /bin/sh using the -c flag; interpretation, if any, is performed by the shell.
  4. On some systems, /bin/sh is a symlink to some other shell, be it bash, zsh, fish, or something else. But the convention is that the shell should read its argv[0] (“by which name was I invoked?”), and, if it is sh or /bin/sh, enable POSIX sh-compatibility mode. Any [Linux] system that has /bin/sh symlinked to something that does not do that would be pretty much broken. bash explicitly documents this in its manpage: When invoked as sh, bash enters posix mode after the startup files are read.
shdown commented 2 years ago

OK, so this will be merged after echo "$dir"/temp*_input is changed to printf '%s\n' "$dir"/temp*_input (in both widgets): it is possible that the glob here expands to multiple files, but the Lua code expects filenames separated by newlines.