[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 14/16] char-stdio: Restore blocking mode of stdout on exit
From: |
Paolo Bonzini |
Subject: |
[PULL 14/16] char-stdio: Restore blocking mode of stdout on exit |
Date: |
Thu, 4 Jul 2024 11:58:04 +0200 |
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>
---
chardev/char-stdio.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/chardev/char-stdio.c b/chardev/char-stdio.c
index 3c648678ab1..b960ddd4e4c 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.45.2
- [PULL 03/16] meson: merge plugin_ldflags into emulator_link_args, (continued)
- [PULL 03/16] meson: merge plugin_ldflags into emulator_link_args, Paolo Bonzini, 2024/07/04
- [PULL 04/16] meson: Pass objects and dependencies to declare_dependency(), Paolo Bonzini, 2024/07/04
- [PULL 05/16] Revert "meson: Propagate gnutls dependency", Paolo Bonzini, 2024/07/04
- [PULL 06/16] meson: Drop the .fa library suffix, Paolo Bonzini, 2024/07/04
- [PULL 07/16] target/i386: pass X86CPU to x86_cpu_get_supported_feature_word, Paolo Bonzini, 2024/07/04
- [PULL 08/16] target/i386: drop AMD machine check bits from Intel CPUID, Paolo Bonzini, 2024/07/04
- [PULL 11/16] i386/sev: Fix error message in sev_get_capabilities(), Paolo Bonzini, 2024/07/04
- [PULL 10/16] target/i386: do not include undefined bits in the AMD topoext leaf, Paolo Bonzini, 2024/07/04
- [PULL 13/16] target/i386: add avx-vnni-int16 feature, Paolo Bonzini, 2024/07/04
- [PULL 09/16] target/i386: SEV: fix formatting of CPUID mismatch message, Paolo Bonzini, 2024/07/04
- [PULL 14/16] char-stdio: Restore blocking mode of stdout on exit,
Paolo Bonzini <=
- [PULL 12/16] i386/sev: Fallback to the default SEV device if none provided in sev_get_capabilities(), Paolo Bonzini, 2024/07/04
- [PULL 15/16] target/i386: add support for masking CPUID features in confidential guests, Paolo Bonzini, 2024/07/04
- [PULL 16/16] target/i386/SEV: implement mask_cpuid_features, Paolo Bonzini, 2024/07/04
- Re: [PULL 00/16] meson, i386 changes for 2024-07-04, Richard Henderson, 2024/07/04