util: do not reset terminal in acquire_terminal()
Before, we'd always reset acquired terminals, which is not really desired, as we expose a setting TTYReset= which is supposed to control whether the TTY is reset or not. Previously that setting would only enable a second resetting of the TTY, which is of course pointless... Hence, move the implicit resetting out of acquire_terminal() and make the callers do it if they need it.
This commit is contained in:
parent
40e1f4ea74
commit
3d18b16755
|
@ -480,10 +480,6 @@ int acquire_terminal(
|
||||||
|
|
||||||
safe_close(notify);
|
safe_close(notify);
|
||||||
|
|
||||||
r = reset_terminal_fd(fd, true);
|
|
||||||
if (r < 0)
|
|
||||||
log_warning_errno(r, "Failed to reset terminal: %m");
|
|
||||||
|
|
||||||
return fd;
|
return fd;
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
|
@ -616,6 +612,10 @@ int make_console_stdio(void) {
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
return log_error_errno(fd, "Failed to acquire terminal: %m");
|
return log_error_errno(fd, "Failed to acquire terminal: %m");
|
||||||
|
|
||||||
|
r = reset_terminal_fd(fd, true);
|
||||||
|
if (r < 0)
|
||||||
|
log_warning_errno(r, "Failed to reset terminal, ignoring: %m");
|
||||||
|
|
||||||
r = make_stdio(fd);
|
r = make_stdio(fd);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return log_error_errno(r, "Failed to duplicate terminal fd: %m");
|
return log_error_errno(r, "Failed to duplicate terminal fd: %m");
|
||||||
|
|
|
@ -543,9 +543,9 @@ static int chown_terminal(int fd, uid_t uid) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int setup_confirm_stdio(int *_saved_stdin,
|
static int setup_confirm_stdio(int *_saved_stdin, int *_saved_stdout) {
|
||||||
int *_saved_stdout) {
|
_cleanup_close_ int fd = -1, saved_stdin = -1, saved_stdout = -1;
|
||||||
int fd = -1, saved_stdin, saved_stdout = -1, r;
|
int r;
|
||||||
|
|
||||||
assert(_saved_stdin);
|
assert(_saved_stdin);
|
||||||
assert(_saved_stdout);
|
assert(_saved_stdout);
|
||||||
|
@ -555,10 +555,8 @@ static int setup_confirm_stdio(int *_saved_stdin,
|
||||||
return -errno;
|
return -errno;
|
||||||
|
|
||||||
saved_stdout = fcntl(STDOUT_FILENO, F_DUPFD, 3);
|
saved_stdout = fcntl(STDOUT_FILENO, F_DUPFD, 3);
|
||||||
if (saved_stdout < 0) {
|
if (saved_stdout < 0)
|
||||||
r = errno;
|
return -errno;
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
fd = acquire_terminal(
|
fd = acquire_terminal(
|
||||||
"/dev/console",
|
"/dev/console",
|
||||||
|
@ -566,39 +564,33 @@ static int setup_confirm_stdio(int *_saved_stdin,
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
DEFAULT_CONFIRM_USEC);
|
DEFAULT_CONFIRM_USEC);
|
||||||
if (fd < 0) {
|
if (fd < 0)
|
||||||
r = fd;
|
return fd;
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
r = chown_terminal(fd, getuid());
|
r = chown_terminal(fd, getuid());
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
goto fail;
|
return r;
|
||||||
|
|
||||||
if (dup2(fd, STDIN_FILENO) < 0) {
|
r = reset_terminal_fd(fd, true);
|
||||||
r = -errno;
|
if (r < 0)
|
||||||
goto fail;
|
return r;
|
||||||
}
|
|
||||||
|
|
||||||
if (dup2(fd, STDOUT_FILENO) < 0) {
|
if (dup2(fd, STDIN_FILENO) < 0)
|
||||||
r = -errno;
|
return -errno;
|
||||||
goto fail;
|
|
||||||
}
|
if (dup2(fd, STDOUT_FILENO) < 0)
|
||||||
|
return -errno;
|
||||||
|
|
||||||
if (fd >= 2)
|
if (fd >= 2)
|
||||||
safe_close(fd);
|
safe_close(fd);
|
||||||
|
fd = -1;
|
||||||
|
|
||||||
*_saved_stdin = saved_stdin;
|
*_saved_stdin = saved_stdin;
|
||||||
*_saved_stdout = saved_stdout;
|
*_saved_stdout = saved_stdout;
|
||||||
|
|
||||||
|
saved_stdin = saved_stdout = -1;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
fail:
|
|
||||||
safe_close(saved_stdout);
|
|
||||||
safe_close(saved_stdin);
|
|
||||||
safe_close(fd);
|
|
||||||
|
|
||||||
return r;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_printf_(1, 2) static int write_confirm_message(const char *format, ...) {
|
_printf_(1, 2) static int write_confirm_message(const char *format, ...) {
|
||||||
|
@ -618,9 +610,7 @@ _printf_(1, 2) static int write_confirm_message(const char *format, ...) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int restore_confirm_stdio(int *saved_stdin,
|
static int restore_confirm_stdio(int *saved_stdin, int *saved_stdout) {
|
||||||
int *saved_stdout) {
|
|
||||||
|
|
||||||
int r = 0;
|
int r = 0;
|
||||||
|
|
||||||
assert(saved_stdin);
|
assert(saved_stdin);
|
||||||
|
@ -636,8 +626,8 @@ static int restore_confirm_stdio(int *saved_stdin,
|
||||||
if (dup2(*saved_stdout, STDOUT_FILENO) < 0)
|
if (dup2(*saved_stdout, STDOUT_FILENO) < 0)
|
||||||
r = -errno;
|
r = -errno;
|
||||||
|
|
||||||
safe_close(*saved_stdin);
|
*saved_stdin = safe_close(*saved_stdin);
|
||||||
safe_close(*saved_stdout);
|
*saved_stdout = safe_close(*saved_stdout);
|
||||||
|
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
|
@ -315,6 +315,10 @@ static int parse_password(const char *filename, char **wall) {
|
||||||
tty_fd = acquire_terminal("/dev/console", false, false, false, USEC_INFINITY);
|
tty_fd = acquire_terminal("/dev/console", false, false, false, USEC_INFINITY);
|
||||||
if (tty_fd < 0)
|
if (tty_fd < 0)
|
||||||
return log_error_errno(tty_fd, "Failed to acquire /dev/console: %m");
|
return log_error_errno(tty_fd, "Failed to acquire /dev/console: %m");
|
||||||
|
|
||||||
|
r = reset_terminal_fd(tty_fd, true);
|
||||||
|
if (r < 0)
|
||||||
|
log_warning_errno(r, "Failed to reset terminal, ignoring: %m");
|
||||||
}
|
}
|
||||||
|
|
||||||
r = ask_password_tty(message, NULL, not_after, echo ? ASK_PASSWORD_ECHO : 0, filename, &password);
|
r = ask_password_tty(message, NULL, not_after, echo ? ASK_PASSWORD_ECHO : 0, filename, &password);
|
||||||
|
|
Loading…
Reference in a new issue