From: Filip Hejsek <[email protected]> Use a duplicate of stdin and stdout fds to avoid closing the standard descriptors when the stdio chardev is destroyed.
Signed-off-by: Filip Hejsek <[email protected]> Reviewed-by: Daniel P. Berrangé <[email protected]> Reviewed-by: Marc-André Lureau <[email protected]> Message-ID: <[email protected]> --- chardev/char-stdio.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/chardev/char-stdio.c b/chardev/char-stdio.c index f63bf413c741..16b49fd924d1 100644 --- a/chardev/char-stdio.c +++ b/chardev/char-stdio.c @@ -114,6 +114,7 @@ static bool stdio_chr_open(Chardev *chr, ChardevBackend *backend, Error **errp) StdioChardev *s = STDIO_CHARDEV(chr); ChardevStdio *opts = backend->u.stdio.data; struct sigaction act; + int fd_in, fd_out; if (is_daemonized()) { error_setg(errp, "cannot use stdio with -daemonize"); @@ -133,7 +134,20 @@ static bool stdio_chr_open(Chardev *chr, ChardevBackend *backend, Error **errp) return false; } - if (!qemu_chr_open_fd(chr, 0, 1, errp)) { + fd_in = qemu_dup(0); + if (fd_in < 0) { + error_setg_errno(errp, errno, "Failed to dup stdin fd"); + return false; + } + fd_out = qemu_dup(1); + if (fd_out < 0) { + error_setg_errno(errp, errno, "Failed to dup stdout fd"); + qemu_close(fd_in); + return false; + } + if (!qemu_chr_open_fd(chr, fd_in, fd_out, errp)) { + qemu_close(fd_in); + qemu_close(fd_out); return false; } -- 2.56.0.116.g6de20f6092dc
