gutils: stop g_get_home_dir() from reading passwd
authorRyan Lortie <desrt@desrt.ca>
Mon, 4 Feb 2013 13:41:25 +0000 (14:41 +0100)
committerRyan Lortie <desrt@desrt.ca>
Wed, 20 Feb 2013 11:09:30 +0000 (11:09 +0000)
commitcfafad5aefeeab1a4ee208cefa15e01d31932611
tree586493d71e5db4dd38264c63c26a12ef8b7a277e
parent167c73faf461cf84accffe190813ce0ab5ef6cdc
gutils: stop g_get_home_dir() from reading passwd

In the case that the "HOME" environment variable is set (as it is under
normal circumstances), we don't really need to be opening /etc/passwd.

For historical reasons (ie: how we used to ignore $HOME) and due to the
grouping of many unrelated things together (reading username, hostname,
home directory, tmpdir, etc.) into one function we were still opening
/etc/passwd in g_get_home_dir(), even if $HOME was set.

Since earlier commits removed code from it, all that remains in
g_get_any_init_do() is the logic for dealing with $HOME and reading the
password database.

We now split the logic to deal with $HOME into g_get_home_dir().  With
only the password database functionality remaining, g_get_any_init_do()
is renamed to g_get_user_database_entry() and modified not to set global
variables but rather return a struct.  If g_get_home_dir() cannot find
$HOME, it falls back to calling g_get_user_database_entry() and using
the home directory from there.

Use of the 'g_utils_global' lock is further reduced by using
g_once_init_enter() to protect the critical sections in each of
g_get_user_database_entry() and g_get_home_dir().

Finally, the g_get_user_name() and g_get_real_name() functions are
modified to use the new regime.

https://bugzilla.gnome.org/show_bug.cgi?id=693204
glib/gutils.c