diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2014-07-16 18:27:12 -0400 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2014-07-16 18:47:20 -0400 |
commit | 36f822c4bd077f9121757e24b6516e5c7ada63b5 (patch) | |
tree | 9201ba3d895aa08a00c17ada422a3dd399e456f9 /src/tty-ask-password-agent/tty-ask-password-agent.c | |
parent | e1bbf3d12f28b8e3d4394f2b257e1b7aea3d10fc (diff) |
Let config_parse open file where applicable
Special care is needed so that we get an error message if the
file failed to parse, but not when it is missing. To avoid duplicating
the same error check in every caller, add an additional 'warn' boolean
to tell config_parse whether a message should be issued.
This makes things both shorter and more robust wrt. to error reporting.
Diffstat (limited to 'src/tty-ask-password-agent/tty-ask-password-agent.c')
-rw-r--r-- | src/tty-ask-password-agent/tty-ask-password-agent.c | 23 |
1 files changed, 6 insertions, 17 deletions
diff --git a/src/tty-ask-password-agent/tty-ask-password-agent.c b/src/tty-ask-password-agent/tty-ask-password-agent.c index 0398a9d814..5852f71173 100644 --- a/src/tty-ask-password-agent/tty-ask-password-agent.c +++ b/src/tty-ask-password-agent/tty-ask-password-agent.c @@ -258,25 +258,16 @@ static int parse_password(const char *filename, char **wall) { { NULL, NULL, NULL, 0, NULL } }; - FILE *f; int r; assert(filename); - f = fopen(filename, "re"); - if (!f) { - if (errno == ENOENT) - return 0; - - log_error("open(%s): %m", filename); - return -errno; - } - - r = config_parse(NULL, filename, f, NULL, config_item_table_lookup, items, true, false, NULL); - if (r < 0) { - log_error("Failed to parse password file %s: %s", filename, strerror(-r)); - goto finish; - } + r = config_parse(NULL, filename, NULL, + NULL, + config_item_table_lookup, items, + true, false, true, NULL); + if (r < 0) + return r; if (!socket_name) { log_error("Invalid password file %s", filename); @@ -414,8 +405,6 @@ static int parse_password(const char *filename, char **wall) { } finish: - fclose(f); - safe_close(socket_fd); free(packet); |