Skip to content

Use getpwuid instead of getlogin for config username

Erick Bajao requested to merge eb-use-etc-getpwuid into master

What does this Merge Request do?

I recently just updated my OSX to Catalina and then did a gdk update and gdk reconfigure. To my surprise, my gitlab.yml and other config files that used to have my username kratos, now shows root. Turns out there is something weird going on with Etc.getlogin. On the native OSX terminal app, I correctly get kratos, while on my other 3rd-party terminals such as Alacritty and Kitty, they both return root.

On Alacritty and Kitty:

~ ruby -e "require 'etc'; puts Etc.getpwuid.name"
kratos
~ ruby -e "require 'etc'; puts Etc.getlogin"     
root

On native terminal:

~ ruby -e "require 'etc'; puts Etc.getpwuid.name"
kratos
~ ruby -e "require 'etc'; puts Etc.getlogin"     
kratos

Not really sure what's going on internally here with my other 2 terminal apps but it looks like it's better to just use Etc.getpwuid.name as it is more accurate. Also, based on the Ruby getlogin docs it is better to avoid this method for security-related purposes. So I don't think we have anything to gain by using getlogin but please do shed some light if ever I'm missing something.

Merge Request checklist

  • Tests added for new functionality. If not, please raise Issue to follow-up.
  • This change is backward compatible. If not, please include steps to communicate to our users.
  • Documentation added/updated, if needed.
  • gdk doctor test added, if needed.
Edited by Erick Bajao

Merge request reports