tty-ask-password-agent: don't open terminal multiple times

We already have the terminal open, hence pass the fd we got to
ask_password_tty(), so that it doesn't have to reopen it a second time.

This is mostly an optimization, but it has the nice benefit of making us
independent from RLIMIT_NOFILE issues and so on, as we don't need to
allocate another fd needlessly.
This commit is contained in:
Lennart Poettering
2018-02-14 00:11:16 +01:00
parent 088dcd8e41
commit daa557208d
5 changed files with 12 additions and 9 deletions
+2 -2
View File
@@ -558,7 +558,7 @@ static int prompt_root_password(void) {
for (;;) {
_cleanup_string_free_erase_ char *a = NULL, *b = NULL;
r = ask_password_tty(msg1, NULL, 0, 0, NULL, &a);
r = ask_password_tty(-1, msg1, NULL, 0, 0, NULL, &a);
if (r < 0)
return log_error_errno(r, "Failed to query root password: %m");
@@ -567,7 +567,7 @@ static int prompt_root_password(void) {
break;
}
r = ask_password_tty(msg2, NULL, 0, 0, NULL, &b);
r = ask_password_tty(-1, msg2, NULL, 0, 0, NULL, &b);
if (r < 0)
return log_error_errno(r, "Failed to query root password: %m");