terminal-util: add helper for disabling terminal echo in termios struct

This commit is contained in:
Lennart Poettering
2023-12-21 19:15:01 +01:00
parent b0936baf11
commit d02d4f83f0
3 changed files with 12 additions and 4 deletions
+8
View File
@@ -1551,3 +1551,11 @@ int set_terminal_cursor_position(int fd, unsigned int row, unsigned int column)
return 0;
}
void termios_disable_echo(struct termios *termios) {
assert(termios);
termios->c_lflag &= ~(ICANON|ECHO);
termios->c_cc[VMIN] = 1;
termios->c_cc[VTIME] = 0;
}
+3 -1
View File
@@ -6,6 +6,7 @@
#include <stdio.h>
#include <syslog.h>
#include <sys/types.h>
#include <termios.h>
#include "macro.h"
#include "time-util.h"
@@ -168,7 +169,6 @@ bool underline_enabled(void);
bool dev_console_colors_enabled(void);
static inline bool colors_enabled(void) {
/* Returns true if colors are considered supported on our stdout. */
return get_color_mode() != COLOR_OFF;
}
@@ -286,3 +286,5 @@ static inline const char* ansi_highlight_green_red(bool b) {
/* This assumes there is a 'tty' group */
#define TTY_MODE 0620
void termios_disable_echo(struct termios *termios);
+1 -3
View File
@@ -443,9 +443,7 @@ int ask_password_tty(
(void) loop_write(ttyfd, ANSI_NORMAL, SIZE_MAX);
new_termios = old_termios;
new_termios.c_lflag &= ~(ICANON|ECHO);
new_termios.c_cc[VMIN] = 1;
new_termios.c_cc[VTIME] = 0;
termios_disable_echo(&new_termios);
r = RET_NERRNO(tcsetattr(ttyfd, TCSADRAIN, &new_termios));
if (r < 0)