ryantimwilson / rpms / systemd

Forked from rpms/systemd a month ago
Clone
ac3a84
From c5e4b6b9b2a1dea35f58f3e1c3313bca76a90162 Mon Sep 17 00:00:00 2001
ac3a84
From: Ray Strode <rstrode@redhat.com>
ac3a84
Date: Wed, 30 Nov 2022 14:07:29 -0500
ac3a84
Subject: [PATCH] terminal-util: Set OPOST when setting ONLCR
ac3a84
ac3a84
reset_terminal_fd sets certain minimum required terminal attributes
ac3a84
that systemd relies on.
ac3a84
ac3a84
One of those attributes is `ONLCR` which ensures that when a new line
ac3a84
is sent to the terminal, that the cursor not only moves to the next
ac3a84
line, but also moves to the very beginning of that line.
ac3a84
ac3a84
In order for `ONLCR` to work, the terminal needs to perform output
ac3a84
post-processing. That requires an additional attribute, `OPOST`,
ac3a84
which reset_terminal_fd currently fails to ensure is set.
ac3a84
ac3a84
In most cases `OPOST` (and `ONLCR` actually) are both set anyway, so
ac3a84
it's not an issue, but it could be a problem if, e.g., the terminal was
ac3a84
put in raw mode by a program and the program unexpectedly died before
ac3a84
restoring settings.
ac3a84
ac3a84
This commit ensures when `ONLCR` is set `OPOST` is set too, which is
ac3a84
the only thing that really makes sense to do.
ac3a84
ac3a84
(cherry picked from commit 9fe26523a189435d75b9d745188e09c17928d89e)
ac3a84
ac3a84
Related: #2138081
ac3a84
---
ac3a84
 src/basic/terminal-util.c | 2 +-
ac3a84
 1 file changed, 1 insertion(+), 1 deletion(-)
ac3a84
ac3a84
diff --git a/src/basic/terminal-util.c b/src/basic/terminal-util.c
ac3a84
index 0c092597eb..a75234f354 100644
ac3a84
--- a/src/basic/terminal-util.c
ac3a84
+++ b/src/basic/terminal-util.c
ac3a84
@@ -269,7 +269,7 @@ int reset_terminal_fd(int fd, bool switch_to_text) {
ac3a84
 
ac3a84
         termios.c_iflag &= ~(IGNBRK | BRKINT | ISTRIP | INLCR | IGNCR | IUCLC);
ac3a84
         termios.c_iflag |= ICRNL | IMAXBEL | IUTF8;
ac3a84
-        termios.c_oflag |= ONLCR;
ac3a84
+        termios.c_oflag |= ONLCR | OPOST;
ac3a84
         termios.c_cflag |= CREAD;
ac3a84
         termios.c_lflag = ISIG | ICANON | IEXTEN | ECHO | ECHOE | ECHOK | ECHOCTL | ECHOPRT | ECHOKE;
ac3a84