projects/pwm

changeset 35:2a8298bafec2

Try to use $HOME for the user's home directory
author Guido Berhoerster <guido+pwm@berhoerster.name>
date Tue Aug 06 11:21:04 2019 +0200 (10 months ago)
parents 34ada71ff3e5
children f9501248b6bd
files pwm.c
line diff
     1.1 --- a/pwm.c	Wed Jul 31 11:21:54 2019 +0200
     1.2 +++ b/pwm.c	Tue Aug 06 11:21:04 2019 +0200
     1.3 @@ -341,6 +341,7 @@
     1.4  	const char	*master_password_filename = NULL;
     1.5  	struct pwm_ctx	ctx = { 0 };
     1.6  	struct passwd	*passwd;
     1.7 +	char		*home;
     1.8  	FILE		*fp = NULL;
     1.9  
    1.10  	setprogname(argv[0]);
    1.11 @@ -394,11 +395,15 @@
    1.12  		goto out;
    1.13  	}
    1.14  
    1.15 -	passwd = getpwuid(getuid());
    1.16 -	if (passwd == NULL) {
    1.17 -		err(1, "getpwuid");
    1.18 +	home = getenv("HOME");
    1.19 +	if (home == NULL) {
    1.20 +		passwd = getpwuid(getuid());
    1.21 +		if (passwd == NULL) {
    1.22 +			err(1, "getpwuid");
    1.23 +		}
    1.24 +		home = passwd->pw_dir;
    1.25  	}
    1.26 -	xasprintf(&ctx.dirname, "%s/.pwm", passwd->pw_dir);
    1.27 +	xasprintf(&ctx.dirname, "%s/.pwm", home);
    1.28  
    1.29  	/* create ~/.pwm directory if necessary */
    1.30  	if ((mkdir(ctx.dirname, S_IRWXU) != 0) && (errno != EEXIST)) {