]> git.ipfire.org Git - pakfire.git/commitdiff
pty: Configure like SSH does it
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 19 Oct 2024 10:18:44 +0000 (10:18 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 19 Oct 2024 10:18:44 +0000 (10:18 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/pty.c

index ff83cf05210e9526df1ba3aeb36cf4891bd445ee..11d03a3bcac279d7b0c938f2d1369f08bf974481 100644 (file)
@@ -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;