diff options
author | Mattias Andrée <maandree@operamail.com> | 2014-04-21 04:36:35 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@operamail.com> | 2015-05-05 20:56:32 +0200 |
commit | 56207523113ee8e4479947cc2f90b9b88840a41f (patch) | |
tree | c771a21eea724ff91f484e5dc0845a1def802acc /src/config-ini.c | |
parent | Fix #174: Use nanosleep() instead of usleep() (diff) | |
download | redshift-ng-56207523113ee8e4479947cc2f90b9b88840a41f.tar.gz redshift-ng-56207523113ee8e4479947cc2f90b9b88840a41f.tar.bz2 redshift-ng-56207523113ee8e4479947cc2f90b9b88840a41f.tar.xz |
Support (but warn) that the user does not have an passwd entry or a home set in the passwd entry. Also, getpwent can fail: handle that.
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to 'src/config-ini.c')
-rw-r--r-- | src/config-ini.c | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/src/config-ini.c b/src/config-ini.c index 65751dd..51eeeca 100644 --- a/src/config-ini.c +++ b/src/config-ini.c @@ -85,10 +85,22 @@ 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.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.conf", home); + f = fopen(cp, "r"); + } else { + fprintf(stderr, _("It appear as if you are homeless.")); + } + } else if (errno) { + perror("getpwuid"); + } else { + fprintf(stderr, _("It appear as if you do not exist.")); + /* errno can either be set to any number of error codes, + or be zero if the user does not have a passwd entry. */ + } } if (f == NULL && (env = getenv("XDG_CONFIG_DIRS")) != NULL && |