]> git.ipfire.org Git - pakfire.git/commitdiff
pty: Always disable character echoing
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 20 Mar 2025 16:47:16 +0000 (16:47 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 20 Mar 2025 16:50:53 +0000 (16:50 +0000)
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 <michael.tremer@ipfire.org>
src/pakfire/pty.c

index b565a6b895160d699b848cd7659f06cff32a4450..8b4d5210569c510682da6cc570dea9da215c328c 100644 (file)
@@ -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);