aboutsummaryrefslogtreecommitdiffstats
path: root/src/config-ini.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/config-ini.c')
-rw-r--r--src/config-ini.c32
1 files changed, 23 insertions, 9 deletions
diff --git a/src/config-ini.c b/src/config-ini.c
index 63c1f5e..4f12610 100644
--- a/src/config-ini.c
+++ b/src/config-ini.c
@@ -101,15 +101,29 @@ open_config_file(const char *filepath)
if (f == NULL) {
struct passwd *pwd = getpwuid(getuid());
- char *home = pwd->pw_dir;
- snprintf(cp, sizeof(cp),
- "%s/.config/redshift/redshift.conf", home);
- f = fopen(cp, "r");
- if (f == NULL) {
- /* Fall back to formerly used path. */
- snprintf(cp, sizeof(cp),
- "%s/.config/redshift.conf", home);
- f = fopen(cp, "r");
+ if (pwd != NULL) {
+ char *home = pwd->pw_dir;
+ if ((home != NULL) && (*home != '\0')) {
+ snprintf(cp, sizeof(cp),
+ "%s/.config/redshift/redshift.conf", home);
+ f = fopen(cp, "r");
+ if (f == NULL) {
+ /* Fall back to formerly used path. */
+ snprintf(cp, sizeof(cp),
+ "%s/.config/redshift.conf", home);
+ f = fopen(cp, "r");
+ }
+ } else {
+ fprintf(stderr, _("Cannot determine your home directory, "
+ "it is from the system's user table.\n"));
+ }
+ } else if (errno) {
+ perror("getpwuid");
+ } else {
+ fprintf(stderr, _("Cannot determine your home directory, "
+ "your user ID is missing from the system's user table.\n"));
+ /* errno can either be set to any number of error codes,
+ or be zero if the user does not have a passwd entry. */
}
}