summaryrefslogtreecommitdiff
path: root/src/ask-password/ask-password.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2015-10-06 16:27:24 +0200
committerLennart Poettering <lennart@poettering.net>2015-10-06 16:27:24 +0200
commit0084360296429b2068c1a4d4d4263083a8963b02 (patch)
treeb69d8a0da04e8c36f954a2449d1112720a4819ef /src/ask-password/ask-password.c
parentc7ddad5148de6e41445f62a80fb6846dce1a6856 (diff)
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.
Diffstat (limited to 'src/ask-password/ask-password.c')
-rw-r--r--src/ask-password/ask-password.c42
1 files changed, 20 insertions, 22 deletions
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 <errno.h>
-#include <unistd.h>
#include <getopt.h>
#include <stddef.h>
+#include <unistd.h>
+#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;
}