Skip to content

Commit 837864a

Browse files
gentoo-rootMichael Tokarev
authored andcommitted
char-stdio: Restore blocking mode of stdout on exit
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 <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Paolo Bonzini <[email protected]> (cherry picked from commit a0124e3) Signed-off-by: Michael Tokarev <[email protected]>
1 parent 8c86d8a commit 837864a

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

chardev/char-stdio.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
/* init terminal so that we can grab keys */
4242
static struct termios oldtty;
4343
static int old_fd0_flags;
44+
static int old_fd1_flags;
4445
static bool stdio_in_use;
4546
static bool stdio_allow_signal;
4647
static bool stdio_echo_state;
@@ -50,6 +51,8 @@ static void term_exit(void)
5051
if (stdio_in_use) {
5152
tcsetattr(0, TCSANOW, &oldtty);
5253
fcntl(0, F_SETFL, old_fd0_flags);
54+
fcntl(1, F_SETFL, old_fd1_flags);
55+
stdio_in_use = false;
5356
}
5457
}
5558

@@ -102,6 +105,7 @@ static void qemu_chr_open_stdio(Chardev *chr,
102105

103106
stdio_in_use = true;
104107
old_fd0_flags = fcntl(0, F_GETFL);
108+
old_fd1_flags = fcntl(1, F_GETFL);
105109
tcgetattr(0, &oldtty);
106110
if (!g_unix_set_fd_nonblocking(0, true, NULL)) {
107111
error_setg_errno(errp, errno, "Failed to set FD nonblocking");

0 commit comments

Comments
 (0)