From: Michael Tremer Date: Sat, 19 Oct 2024 10:18:44 +0000 (+0000) Subject: pty: Configure like SSH does it X-Git-Tag: 0.9.30~992 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=9490a3bf4cd9560833eb92d67ab6a9f3d0f1ca1f;p=pakfire.git pty: Configure like SSH does it Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/pty.c b/src/libpakfire/pty.c index ff83cf052..11d03a3bc 100644 --- a/src/libpakfire/pty.c +++ b/src/libpakfire/pty.c @@ -648,6 +648,82 @@ static int pakfire_pty_stdout(sd_event_source* source, int fd, uint32_t events, return pakfire_pty_activity(pty, &pty->stdout, events); } +static void pakfire_pty_make_raw(struct termios* termios) { + // Set input flags + termios->c_iflag |= ( + // Ignore framing errors and parity errors + IGNPAR + ); + + // Clear input flags + termios->c_iflag &= ~( + // Strip off eighth bit + ISTRIP | + + // Translate NL to CR on input + INLCR | + + // Ignore carriage return on input + IGNCR | + + // Translate carriage return to newline on input (unless IGNCR is set) + ICRNL | + + // Enable XON/XOFF flow control on output + IXON | + + // Typing any character will restart stopped output + IXANY | + + // Enable XON/XOFF flow control on input + IXOFF | + + // Map uppercase characters to lowercase on input + IUCLC + ); + + // Clear local flags + termios->c_lflag &= ~( + // Send the SIGTTOU signal to the process group of a background process + // which tries to write to its controlling terminal + TOSTOP | + + // When any of the characters INTR, QUIT, SUSP, or DSUSP are received, + // generate the corresponding signal + ISIG | + + // Enable canonical mode + ICANON | + + // Echo input characters + ECHO | + + // If ICANON is also set, the ERASE character erases the preceding input character, + // and WERASE erases the preceding word. + ECHOE | + + // If ICANON is also set, the KILL character erases the current line + ECHOK | + + // If ICANON is also set, echo the NL character even if ECHO is not set. + ECHONL | + + // Enable implementation-defined input processing. This flag, as well as ICANON + // must be enabled for the special characters EOL2, LNEXT, REPRINT, WERASE to be + // interpreted, and for the IUCLC flag to be effective. + IEXTEN + ); + + // Set output flags + termios->c_oflag |= ( + // Map NL to CR-NL on output + ONLCR | + + // Enable implementation-defined output processing + OPOST + ); +} + static int pakfire_pty_enable_raw_mode(struct pakfire_pty* pty) { struct termios raw_attrs; int same; @@ -672,7 +748,7 @@ static int pakfire_pty_enable_raw_mode(struct pakfire_pty* pty) { raw_attrs = pty->stdin.attrs; // Enable raw mode - cfmakeraw(&raw_attrs); + pakfire_pty_make_raw(&raw_attrs); if (!same) raw_attrs.c_oflag = pty->stdin.attrs.c_oflag; @@ -696,7 +772,7 @@ static int pakfire_pty_enable_raw_mode(struct pakfire_pty* pty) { raw_attrs = pty->stdout.attrs; // Enable raw mode - cfmakeraw(&raw_attrs); + pakfire_pty_make_raw(&raw_attrs); raw_attrs.c_iflag = pty->stdout.attrs.c_iflag; raw_attrs.c_lflag = pty->stdout.attrs.c_lflag;