Use of g_getenv("HOME")

Benedikt Meurer Benedikt.Meurer at unix-ag.uni-siegen.de
Wed Feb 26 00:06:50 CET 2003


Hello again(2),

During the xfce4 sources g_getenv("HOME") is used to determine the users
home directory. This is somewhat problematic as $HOME doesn't always
contain the correct home directory (e.g. using su(1) or sudo(8)).

g_get_home_dir() should be used instead to avoid the problem above. In
addition g_get_home_dir() is ment to be a portable way to determine the
home directory, in case a systems login or xinit program doesn't export
$HOME, the path can be easily archived from the systems user database
(e.g. on nearly all Unix systems /etc/passwd).

I've done a patch for xfce-utils so far; the other modules should also
be changed.

I've also thought of adding an utility library to xfce which provides
miscalleanous utility functions. For example xfce_get_user_dir() to
return the path to the users $HOME/.xfce4, which could also allow
the user to change this path by setting an enviroment variable (for
example KDE uses $KDEHOME, which is quite handy in certain conditions).

regards,
Benedikt

-- 
Those who do not understand Unix are condemned to reinvent it, poorly.
    -- Henry Spencer
-------------- next part --------------
--- ./xfrun/xfrun.c.orig	Fri Feb 14 11:40:34 2003
+++ ./xfrun/xfrun.c	Tue Feb 25 23:59:13 2003
@@ -123,7 +123,7 @@
 GList *get_history(void)
 {
     FILE *fp;
-    const char *home = g_getenv("HOME");
+    const char *home = g_get_home_dir();
     char *hfile = g_strconcat(home, "/", HFILE, NULL);
     GList *cbtemp = NULL;
     char line[DEFAULT_LENGTH];
@@ -164,7 +164,7 @@
 void put_history(const char *newest, GList * cb)
 {
     FILE *fp;
-    const char *home = g_getenv("HOME");
+    const char *home = g_get_home_dir();
     char *hfile = g_strconcat(home, "/", HFILE, NULL);
     GList *node;
     int i;
--- ./xftaskbar/plugin/xftaskbar_plugin.c.orig	Tue Feb 25 23:57:29 2003
+++ ./xftaskbar/plugin/xftaskbar_plugin.c	Tue Feb 25 23:58:23 2003
@@ -384,7 +384,7 @@
 {
     McsSetting *setting;
 
-    const gchar *home = g_getenv("HOME");
+    const gchar *home = g_get_home_dir();
     gchar *rcfile;
     
     rcfile = g_strconcat(home, G_DIR_SEPARATOR_S, ".xfce4", G_DIR_SEPARATOR_S, RCDIR, G_DIR_SEPARATOR_S, RCFILE, NULL);
@@ -449,7 +449,7 @@
 
 static gboolean write_options(McsPlugin * mcs_plugin)
 {
-    const gchar *home = g_getenv("HOME");
+    const gchar *home = g_get_home_dir();
     gchar *rcfile;
     gboolean result;
 


More information about the Xfce4-dev mailing list