]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
terminal-util: Set OPOST when setting ONLCR
authorRay Strode <rstrode@redhat.com>
Wed, 30 Nov 2022 19:07:29 +0000 (14:07 -0500)
committerLennart Poettering <lennart@poettering.net>
Thu, 1 Dec 2022 10:29:21 +0000 (11:29 +0100)
reset_terminal_fd sets certain minimum required terminal attributes
that systemd relies on.

One of those attributes is `ONLCR` which ensures that when a new line
is sent to the terminal, that the cursor not only moves to the next
line, but also moves to the very beginning of that line.

In order for `ONLCR` to work, the terminal needs to perform output
post-processing. That requires an additional attribute, `OPOST`,
which reset_terminal_fd currently fails to ensure is set.

In most cases `OPOST` (and `ONLCR` actually) are both set anyway, so
it's not an issue, but it could be a problem if, e.g., the terminal was
put in raw mode by a program and the program unexpectedly died before
restoring settings.

This commit ensures when `ONLCR` is set `OPOST` is set too, which is
the only thing that really makes sense to do.

src/basic/terminal-util.c

index 8fa9986a768a4083be630510977d66646637f280..7bc2f71bcfd3624bda1b2d1ba503d5802138dab2 100644 (file)
@@ -268,7 +268,7 @@ int reset_terminal_fd(int fd, bool switch_to_text) {
 
         termios.c_iflag &= ~(IGNBRK | BRKINT | ISTRIP | INLCR | IGNCR | IUCLC);
         termios.c_iflag |= ICRNL | IMAXBEL | IUTF8;
-        termios.c_oflag |= ONLCR;
+        termios.c_oflag |= ONLCR | OPOST;
         termios.c_cflag |= CREAD;
         termios.c_lflag = ISIG | ICANON | IEXTEN | ECHO | ECHOE | ECHOK | ECHOCTL | ECHOPRT | ECHOKE;