[2826] in BarnOwl Developers

home help back first fref pref prev next nref lref last post

[PATCH] Check passwd entries to determine home dir

daemon@ATHENA.MIT.EDU (David Benjamin)
Wed Dec 15 15:59:50 2010

From: David Benjamin <davidben@MIT.EDU>
To: barnowl-dev@mit.edu
Date: Wed, 15 Dec 2010 15:59:37 -0500

Still manually check the HOME variable because g_get_home_dir prefers
passwd entries to environment variables. (Should we?)
---
 global.c |   10 ++++++++--
 1 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/global.c b/global.c
index 3b3bd78..f67eaa2 100644
--- a/global.c
+++ b/global.c
@@ -13,6 +13,7 @@ static void _owl_global_init_windows(owl_global *g);
 void owl_global_init(owl_global *g) {
   struct hostent *hent;
   char *cd;
+  const char *homedir;
 
   g_type_init();
 
@@ -76,8 +77,13 @@ void owl_global_init(owl_global *g) {
   g->nextmsgid=0;
 
   /* Fill in some variables which don't have constant defaults */
-  /* TODO: come back later and check passwd file first */
-  g->homedir=owl_strdup(getenv("HOME"));
+
+  /* glib's g_get_home_dir prefers passwd entries to $HOME, so we
+   * explicitly check getenv first. */
+  homedir = getenv("HOME");
+  if (!homedir)
+    homedir = g_get_home_dir();
+  g->homedir = owl_strdup(homedir);
 
   g->confdir = NULL;
   g->startupfile = NULL;
-- 
1.7.3.3.399.g06ddf


home help back first fref pref prev next nref lref last post