From 0084360296429b2068c1a4d4d4263083a8963b02 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 6 Oct 2015 16:27:24 +0200 Subject: ask-password: various modernizations Primarily clean-up error logging: log either all or no error messages in the various functions. Mostly this means the actual password querying calls no longer will log on their own, but the callers have to do so. Contains various other fixes too, for example ports some code over to use the clean-up macro. Should contain no functional changes. --- src/ask-password/ask-password.c | 42 ++++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 22 deletions(-) (limited to 'src/ask-password') diff --git a/src/ask-password/ask-password.c b/src/ask-password/ask-password.c index abfd545c79..bf3fa30f69 100644 --- a/src/ask-password/ask-password.c +++ b/src/ask-password/ask-password.c @@ -20,15 +20,15 @@ ***/ #include -#include #include #include +#include +#include "ask-password-api.h" +#include "def.h" #include "log.h" #include "macro.h" #include "strv.h" -#include "ask-password-api.h" -#include "def.h" static const char *arg_icon = NULL; static const char *arg_id = NULL; @@ -154,35 +154,33 @@ int main(int argc, char *argv[]) { timeout = 0; if (arg_use_tty && isatty(STDIN_FILENO)) { - char *password = NULL; + _cleanup_free_ char *password = NULL; - r = ask_password_tty(arg_message, timeout, arg_echo, NULL, - &password); - if (r >= 0) { - puts(password); - free(password); + r = ask_password_tty(arg_message, timeout, arg_echo, NULL, &password); + if (r < 0) { + log_error_errno(r, "Failed to ask for password on terminal: %m"); + goto finish; } + puts(password); } else { - char **l; + _cleanup_free_ char **l = NULL; + char **p; - r = ask_password_agent(arg_message, arg_icon, arg_id, timeout, - arg_echo, arg_accept_cached, &l); - if (r >= 0) { - char **p; + r = ask_password_agent(arg_message, arg_icon, arg_id, timeout, arg_echo, arg_accept_cached, &l); + if (r < 0) { + log_error_errno(r, "Failed to ask for password via agent: %m"); + goto finish; + } - STRV_FOREACH(p, l) { - puts(*p); + STRV_FOREACH(p, l) { + puts(*p); - if (!arg_multiple) - break; - } - - strv_free(l); + if (!arg_multiple) + break; } } finish: - return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS; } -- cgit v1.2.3-54-g00ecf