[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Stable-9.0.2 25/27] char-stdio: Restore blocking mode of stdout on exit
From: |
Michael Tokarev |
Subject: |
[Stable-9.0.2 25/27] char-stdio: Restore blocking mode of stdout on exit |
Date: |
Mon, 15 Jul 2024 12:34:32 +0300 |
From: Maxim Mikityanskiy <maxtram95@gmail.com>
qemu_chr_open_fd() sets stdout into non-blocking mode. Restore the old
fd flags on exit to avoid breaking unsuspecting applications that run on
the same terminal after qemu and don't expect to get EAGAIN.
While at at, also ensure term_exit is called once (at the moment it's
called both from char_stdio_finalize() and as the atexit() hook.
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2423
Signed-off-by: Maxim Mikityanskiy <maxtram95@gmail.com>
Link: 20240703190812.3459514-1-maxtram95@gmail.com">https://lore.kernel.org/r/20240703190812.3459514-1-maxtram95@gmail.com
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
(cherry picked from commit a0124e333e2176640f233e5ea57a2f413985d9b5)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
diff --git a/chardev/char-stdio.c b/chardev/char-stdio.c
index 3c648678ab..b960ddd4e4 100644
--- a/chardev/char-stdio.c
+++ b/chardev/char-stdio.c
@@ -41,6 +41,7 @@
/* init terminal so that we can grab keys */
static struct termios oldtty;
static int old_fd0_flags;
+static int old_fd1_flags;
static bool stdio_in_use;
static bool stdio_allow_signal;
static bool stdio_echo_state;
@@ -50,6 +51,8 @@ static void term_exit(void)
if (stdio_in_use) {
tcsetattr(0, TCSANOW, &oldtty);
fcntl(0, F_SETFL, old_fd0_flags);
+ fcntl(1, F_SETFL, old_fd1_flags);
+ stdio_in_use = false;
}
}
@@ -102,6 +105,7 @@ static void qemu_chr_open_stdio(Chardev *chr,
stdio_in_use = true;
old_fd0_flags = fcntl(0, F_GETFL);
+ old_fd1_flags = fcntl(1, F_GETFL);
tcgetattr(0, &oldtty);
if (!g_unix_set_fd_nonblocking(0, true, NULL)) {
error_setg_errno(errp, errno, "Failed to set FD nonblocking");
--
2.39.2
- [Stable-9.0.2 00/27] Patch Round-up for stable 9.0.2, frozen on 2024-07-14, Michael Tokarev, 2024/07/15
- [Stable-9.0.2 23/27] virtio-pci: Fix the failure process in kvm_virtio_pci_vector_use_one(), Michael Tokarev, 2024/07/15
- [Stable-9.0.2 25/27] char-stdio: Restore blocking mode of stdout on exit,
Michael Tokarev <=
- [Stable-9.0.2 27/27] hw/nvme: fix number of PIDs for FDP RUH update, Michael Tokarev, 2024/07/15
- [Stable-9.0.2 26/27] sphinx/qapidoc: Fix to generate doc for explicit, unboxed arguments, Michael Tokarev, 2024/07/15
- [Stable-9.0.2 24/27] virtio: remove virtio_tswap16s() call in vring_packed_event_read(), Michael Tokarev, 2024/07/15