GNOME Bugzilla – Bug 132238
glib uses /etc/pass instead of getenv("HOME")
Last modified: 2004-12-22 21:47:04 UTC
Many GTK based applications use the library routines to locate configuration files, lock files, etc. For business reasons we need to have multiple sets of configurations for a single unix username and select at program initiation time. The normal metod would be to define the environment variable HOME and this is the method documented in the comments on the routine g_get_home_dir g_get_home_dir is documented in the head comment as finding the user's home directory through an environmetn variable (such as HOME) first and if that fails to fall back to the underlying OS features (such as /etc/passwd). Looking deeper in the source this appears to be due to a choice in g_get_any_init. I quote: /* Return the home directory of the user. If there is a HOME * environment variable, its value is returned, otherwise use some * system-dependent way of finding it out. If no home directory can be * deduced, return NULL. */ however when it calls g_get_any_init the code does not do that. The patch below is one minimal change to accomplish that. The third change block is an incidental typo in the routine that I noticed in passing. The final changes guarentee that the home directory has SOME value if all the other logic has failed, admitedly highly unlikely. 760,762c760,762 < #ifdef G_OS_WIN32 < /* We check $HOME first for Win32, though it is a last resort for Unix < * where we prefer the results of getpwuid(). --- > /* We check $HOME first for Win32 and UNIX though we need > * to get results of getpwuid() on UNIX for other values stored > * only there. 764a765 > #ifdef G_OS_WIN32 813c814 < /* This reurns the maximum length */ --- > /* This returns the maximum length */ 900a902,904 > /* If all else fails use the temporary directory since it is > * always set to a plausible value above > */ 902c906 < g_home_dir = g_strdup (g_getenv ("HOME")); --- > g_home_dir = g_strdup(g_tmp_dir);
Bug 2311 has links to detailed discussion of the issue. It would take *very* convincing evidence to convince us to change it at this point ... switching back and forth is basically always worse than sticking with a decision. *** This bug has been marked as a duplicate of 2311 ***