summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJérémie Courrèges-Anglas <jca@wxcvbn.org>2014-03-04 02:44:15 +0100
committerJérémie Courrèges-Anglas <jca@wxcvbn.org>2014-03-04 02:44:15 +0100
commitc51dd419f9d40facf516558510704891c0cf66b6 (patch)
treec25a9fc19be6332c66cdb800c94e31200eac6f64 /src
parentf010d26cbad242f2a98c2d67e5100bdf9387addb (diff)
downloadratpoison-c51dd419f9d40facf516558510704891c0cf66b6.zip
get_homedir(), checks HOME and the password database
* ensures that the resulting home directory isn't the empty string (else returns NULL)
Diffstat (limited to 'src')
-rw-r--r--src/main.c40
-rw-r--r--src/ratpoison.h1
2 files changed, 29 insertions, 12 deletions
diff --git a/src/main.c b/src/main.c
index 0593b64..a64d284 100644
--- a/src/main.c
+++ b/src/main.c
@@ -404,10 +404,35 @@ read_rc_file (FILE *file)
free (line);
}
+const char *
+get_homedir (void)
+{
+ char *homedir;
+
+ homedir = getenv ("HOME");
+ if (homedir != NULL && homedir[0] == '\0')
+ homedir = NULL;
+
+#if defined (HAVE_PWD_H) && defined (HAVE_GETPWUID)
+ if (homedir == NULL)
+ {
+ struct passwd *pw;
+
+ pw = getpwuid (getuid ());
+ if (pw != NULL)
+ homedir = pw->pw_dir;
+
+ if (homedir != NULL && homedir[0] == '\0')
+ homedir = NULL;
+ }
+#endif
+
+ return homedir;
+}
+
static int
read_startup_files (char *alt_rcfile)
{
- char *homedir;
FILE *fileptr = NULL;
if (alt_rcfile)
@@ -423,18 +448,9 @@ read_startup_files (char *alt_rcfile)
{
/* first check $HOME/.ratpoisonrc and if that does not exist then try
$sysconfdir/ratpoisonrc */
+ const char *homedir;
- homedir = getenv ("HOME");
-#if defined (HAVE_PWD_H) && defined (HAVE_GETPWUID)
- if (!homedir)
- {
- struct passwd *pw;
-
- pw = getpwuid (getuid ());
- if (pw)
- homedir = pw->pw_dir;
- }
-#endif
+ homedir = get_homedir ();
if (!homedir)
PRINT_ERROR (("ratpoison: no home directory!?\n"));
diff --git a/src/ratpoison.h b/src/ratpoison.h
index 2c829ef..5ff7c44 100644
--- a/src/ratpoison.h
+++ b/src/ratpoison.h
@@ -85,6 +85,7 @@ void clean_up (void);
rp_screen *find_screen (Window w);
void set_close_on_exec (int fd);
+const char *get_homedir (void);
void read_rc_file (FILE *file);
void fatal (const char *msg);