[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 08/11] chardev: fix qemu_chr_open_fd() with fd_in==fd_out
From: |
marcandre . lureau |
Subject: |
[PATCH v2 08/11] chardev: fix qemu_chr_open_fd() with fd_in==fd_out |
Date: |
Wed, 4 Aug 2021 19:48:45 +0400 |
From: Marc-André Lureau <marcandre.lureau@redhat.com>
The "serial" chardev calls qemu_chr_open_fd() with the same fd. This
may lead to double-close as each QIOChannel owns the fd.
Instead, share the reference to the same QIOChannel.
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
chardev/char-fd.c | 19 +++++++++++++++----
1 file changed, 15 insertions(+), 4 deletions(-)
diff --git a/chardev/char-fd.c b/chardev/char-fd.c
index c11b1037f9..93c56913b4 100644
--- a/chardev/char-fd.c
+++ b/chardev/char-fd.c
@@ -211,20 +211,31 @@ void qemu_chr_open_fd(Chardev *chr,
int fd_in, int fd_out)
{
FDChardev *s = FD_CHARDEV(chr);
- char *name;
+ g_autofree char *name = NULL;
+
+ if (fd_out >= 0) {
+ qemu_set_nonblock(fd_out);
+ }
+
+ if (fd_out == fd_in && fd_in >= 0) {
+ s->ioc_in = QIO_CHANNEL(qio_channel_file_new_fd(fd_in));
+ name = g_strdup_printf("chardev-file-%s", chr->label);
+ qio_channel_set_name(QIO_CHANNEL(s->ioc_in), name);
+ s->ioc_out = QIO_CHANNEL(object_ref(s->ioc_in));
+ return;
+ }
if (fd_in >= 0) {
s->ioc_in = QIO_CHANNEL(qio_channel_file_new_fd(fd_in));
name = g_strdup_printf("chardev-file-in-%s", chr->label);
qio_channel_set_name(QIO_CHANNEL(s->ioc_in), name);
- g_free(name);
}
+
if (fd_out >= 0) {
s->ioc_out = QIO_CHANNEL(qio_channel_file_new_fd(fd_out));
+ g_free(name);
name = g_strdup_printf("chardev-file-out-%s", chr->label);
qio_channel_set_name(QIO_CHANNEL(s->ioc_out), name);
- g_free(name);
- qemu_set_nonblock(fd_out);
}
}
--
2.32.0.264.g75ae10bc75
- [PATCH v2 05/11] chardev: mark explicitly first argument as poisoned, (continued)
- [PATCH v2 01/11] util: fix abstract socket path copy, marcandre . lureau, 2021/08/04
- [PATCH v2 03/11] chardev: remove needless class method, marcandre . lureau, 2021/08/04
- [PATCH v2 07/11] chardev: fix qemu_chr_open_fd() being called with fd=-1, marcandre . lureau, 2021/08/04
- [PATCH v2 06/11] chardev: fix fd_chr_add_watch() when in != out, marcandre . lureau, 2021/08/04
- [PATCH v2 08/11] chardev: fix qemu_chr_open_fd() with fd_in==fd_out,
marcandre . lureau <=
- [PATCH v2 04/11] chardev: add some comments about the class methods, marcandre . lureau, 2021/08/04
- [PATCH v2 02/11] chardev/socket: print a more correct command-line address, marcandre . lureau, 2021/08/04
- [PATCH v2 11/11] chardev: reuse qmp_chardev_new(), marcandre . lureau, 2021/08/04
- [PATCH v2 09/11] chardev: give some context on chardev-add error, marcandre . lureau, 2021/08/04
- [PATCH v2 10/11] chardev: report a simpler error about duplicated id, marcandre . lureau, 2021/08/04