From fc38ad39b6e320862c2b62c110ee530493b35fb4 Mon Sep 17 00:00:00 2001 From: julianuziemblo Date: Wed, 17 Jun 2026 17:57:50 +0200 Subject: [PATCH] (pshapp, auth): use TCSADRAIN instead of TCSAFLUSH for termios setting Until now, before every command, input was going to be flushed (which was not implemented in libtty). When it is implemented, input before parsing a command should not be flushed as we don't want to lose any characters from before the prompt is displayed to the user. YT: RTOS-1355 --- psh/pshapp/auth.c | 6 +++--- psh/pshapp/pshapp.c | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/psh/pshapp/auth.c b/psh/pshapp/auth.c index 12a5c28f..97f899b0 100644 --- a/psh/pshapp/auth.c +++ b/psh/pshapp/auth.c @@ -41,7 +41,7 @@ static int psh_authcredentget(char *buff, int ispasswd, int maxinlen) else ttyattr.c_lflag |= (ICANON | ECHO | ISIG); - if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &ttyattr) < 0) { + if (tcsetattr(STDIN_FILENO, TCSADRAIN, &ttyattr) < 0) { fprintf(stderr, "psh: setting tty attributes fail\n"); return -ENOTTY; } @@ -90,11 +90,11 @@ static int psh_authcredentget(char *buff, int ispasswd, int maxinlen) if (ispasswd || inputlen < 0) fprintf(stdout, "\n"); - if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &origattr) < 0) { + if (tcsetattr(STDIN_FILENO, TCSADRAIN, &origattr) < 0) { fprintf(stderr, "psh: setting tty attributes fail\n"); return -ENOTTY; } - + if (inputlen >= 0) return inputlen; diff --git a/psh/pshapp/pshapp.c b/psh/pshapp/pshapp.c index 9550a100..57e7b838 100644 --- a/psh/pshapp/pshapp.c +++ b/psh/pshapp/pshapp.c @@ -597,7 +597,7 @@ static int psh_readcmd(struct termios *orig, psh_hist_t *cmdhist, char **cmd) /* Enable raw mode for command processing */ cfmakeraw(&raw); - if ((err = tcsetattr(STDIN_FILENO, TCSAFLUSH, &raw)) < 0) { + if ((err = tcsetattr(STDIN_FILENO, TCSADRAIN, &raw)) < 0) { fprintf(stderr, "\npsh: failed to enable raw mode\n"); free(*cmd); return err; @@ -1025,7 +1025,7 @@ static int psh_readcmd(struct termios *orig, psh_hist_t *cmdhist, char **cmd) } /* Restore original terminal settings */ - if ((esc = tcsetattr(STDIN_FILENO, TCSAFLUSH, orig)) < 0) { + if ((esc = tcsetattr(STDIN_FILENO, TCSADRAIN, orig)) < 0) { fprintf(stderr, "\r\npsh: failed to restore terminal settings\r\n"); if (err >= 0) err = esc; @@ -1452,7 +1452,7 @@ static int psh_reset(int argc, char **argv) term.c_iflag |= IXON | BRKINT | PARMRK; term.c_oflag |= OPOST; - if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &term) < 0) { + if (tcsetattr(STDIN_FILENO, TCSADRAIN, &term) < 0) { fprintf(stderr, "reset: failed to set cooked mode\n"); return EXIT_FAILURE; }