Mercurial > projects > pwm
changeset 35:2a8298bafec2
Try to use $HOME for the user's home directory
author | Guido Berhoerster <guido+pwm@berhoerster.name> |
---|---|
date | Tue, 06 Aug 2019 11:21:04 +0200 |
parents | 34ada71ff3e5 |
children | f9501248b6bd |
files | pwm.c |
diffstat | 1 files changed, 9 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/pwm.c Wed Jul 31 11:21:54 2019 +0200 +++ b/pwm.c Tue Aug 06 11:21:04 2019 +0200 @@ -341,6 +341,7 @@ const char *master_password_filename = NULL; struct pwm_ctx ctx = { 0 }; struct passwd *passwd; + char *home; FILE *fp = NULL; setprogname(argv[0]); @@ -394,11 +395,15 @@ goto out; } - passwd = getpwuid(getuid()); - if (passwd == NULL) { - err(1, "getpwuid"); + home = getenv("HOME"); + if (home == NULL) { + passwd = getpwuid(getuid()); + if (passwd == NULL) { + err(1, "getpwuid"); + } + home = passwd->pw_dir; } - xasprintf(&ctx.dirname, "%s/.pwm", passwd->pw_dir); + xasprintf(&ctx.dirname, "%s/.pwm", home); /* create ~/.pwm directory if necessary */ if ((mkdir(ctx.dirname, S_IRWXU) != 0) && (errno != EEXIST)) {