From: Michael Tremer Date: Thu, 20 Mar 2025 16:47:16 +0000 (+0000) Subject: pty: Always disable character echoing X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=686da50a916bd848cee7c9b7a2c19ae7409b3982;p=pakfire.git pty: Always disable character echoing This usually happens later in case of the interactive version, but since we don't need to configure much in the pipe case, we can just set this as default. Signed-off-by: Michael Tremer --- diff --git a/src/pakfire/pty.c b/src/pakfire/pty.c index b565a6b8..8b4d5210 100644 --- a/src/pakfire/pty.c +++ b/src/pakfire/pty.c @@ -1335,6 +1335,30 @@ ERROR: return r; } +static int pakfire_pty_disable_echo(struct pakfire_pty* self, int fd) { + struct termios t = {}; + int r; + + // Fetch current attributes + r = tcgetattr(fd, &t); + if (r < 0) { + ERROR(self->ctx, "Failed to fetch terminal attributes from %d: %m\n", fd); + return -errno; + } + + // Disable echo + t.c_lflag &= ~ECHO; + + // Restore the changed attributes + r = tcsetattr(fd, TCSANOW, &t); + if (r < 0) { + ERROR(self->ctx, "Failed to restore terminal attributes to %d: %m\n", fd); + return -errno; + } + + return 0; +} + /* Sets up the terminal in the child process... */ @@ -1352,6 +1376,13 @@ static int pakfire_pty_setup_terminal(struct pakfire_pty* pty) { DEBUG(pty->ctx, "Opened a new terminal %d\n", fd); + // Disable echo + if (pty->stdin.callbacks.stdin_callback) { + r = pakfire_pty_disable_echo(pty, fd); + if (r < 0) + goto ERROR; + } + // Connect the new terminal to standard input if (pty->stdin.io & PAKFIRE_PTY_CONNECT) { r = dup2(fd, STDIN_FILENO);