projects/pwm

changeset 5:0b1bce8db371

Prevent misleading double error message

Display errors from the function where they occur. Only use warn(x) for system
errors.
author Guido Berhoerster <guido+pwm@berhoerster.name>
date Sun Feb 05 13:54:39 2017 +0100 (2017-02-05)
parents b5c4267a7182
children 4269feba381e
files pwfile.c pwm.c
line diff
     1.1 --- a/pwfile.c	Sun Feb 05 13:30:31 2017 +0100
     1.2 +++ b/pwfile.c	Sun Feb 05 13:54:39 2017 +0100
     1.3 @@ -172,7 +172,7 @@
     1.4  	struct record_id_entry *entry;
     1.5  
     1.6  	if (pws3_file_read_stream(ctx->file, ctx->password, fp) != 0) {
     1.7 -		warnx("failed to read password database: %s",
     1.8 +		fprintf(stderr, "failed to read password database: %s\n",
     1.9  		    pws3_file_get_error_message(ctx->file));
    1.10  		return (-1);
    1.11  	}
     2.1 --- a/pwm.c	Sun Feb 05 13:30:31 2017 +0100
     2.2 +++ b/pwm.c	Sun Feb 05 13:54:39 2017 +0100
     2.3 @@ -197,10 +197,12 @@
     2.4  		password_len--;
     2.5  		if (password_len == 0) {
     2.6  			/* first line is empty */
     2.7 +			fprintf(stderr, "malformed password file\n");
     2.8  			goto out;
     2.9  		}
    2.10  	} else if (!feof(fp)) {
    2.11  		/* the first line was truncated, password is too long */
    2.12 +		fprintf(stderr, "malformed password file\n");
    2.13  		goto out;
    2.14  	}
    2.15  	memcpy(password, buf, password_size);
    2.16 @@ -318,7 +320,6 @@
    2.17  	if (master_password_filename != NULL) {
    2.18  		if (read_password_from_file(master_password_filename,
    2.19  		    ctx.password, sizeof (ctx.password)) != 0) {
    2.20 -			fprintf(stderr, "malformed password database\n");
    2.21  			goto out;
    2.22  		}
    2.23  	} else {