qemu-trivial.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-trivial] [PATCH] Keep pty slave file descriptor open until the master is closed
@ 2015-12-11 11:29 Ashley Jonathan
  2016-01-11  8:33 ` Michael Tokarev
  2016-01-11  9:16 ` [Qemu-trivial] " Paolo Bonzini
  0 siblings, 2 replies; 7+ messages in thread
From: Ashley Jonathan @ 2015-12-11 11:29 UTC (permalink / raw)
  To: qemu-devel@nongnu.org; +Cc: qemu-trivial@nongnu.org, pbonzini@redhat.com

I have experienced a minor difficulty using QEMU with the "-serial pty" option:

If a process opens the slave pts device, writes data to it, then immediately closes it, the data doesn't reliably get delivered to the emulated serial port. This seems to be because a read of the master pty device returns EIO on Linux if no process has the pts device open, even when data is waiting "in the pipe".

A fix seems to be for QEMU to keep the pts file descriptor open until the pty is closed, as per the below patch.

---
 qemu-char.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/qemu-char.c b/qemu-char.c
index 2969c44..ed03ba0 100644
--- a/qemu-char.c
+++ b/qemu-char.c
@@ -1198,6 +1198,7 @@ typedef struct {
     int connected;
     guint timer_tag;
     guint open_tag;
+    int slave_fd;
 } PtyCharDriver;
 
 static void pty_chr_update_read_handler_locked(CharDriverState *chr);
@@ -1373,6 +1374,7 @@ static void pty_chr_close(struct CharDriverState *chr)
 
     qemu_mutex_lock(&chr->chr_write_lock);
     pty_chr_state(chr, 0);
+    close(s->slave_fd);
     fd = g_io_channel_unix_get_fd(s->fd);
     g_io_channel_unref(s->fd);
     close(fd);
@@ -1401,7 +1403,6 @@ static CharDriverState *qemu_chr_open_pty(const char *id,
         return NULL;
     }
 
-    close(slave_fd);
     qemu_set_nonblock(master_fd);
 
     chr = qemu_chr_alloc();
@@ -1422,6 +1423,7 @@ static CharDriverState *qemu_chr_open_pty(const char *id,
     chr->explicit_be_open = true;
 
     s->fd = io_channel_from_fd(master_fd);
+    s->slave_fd = slave_fd;
     s->timer_tag = 0;
 
     return chr;
-- 
2.1.4



---
Jonathan Ashley 
jonathan.ashley AT altran.com


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2016-02-12 13:51 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-12-11 11:29 [Qemu-trivial] [PATCH] Keep pty slave file descriptor open until the master is closed Ashley Jonathan
2016-01-11  8:33 ` Michael Tokarev
2016-01-11  9:13   ` Paolo Bonzini
2016-02-12  2:29     ` [Qemu-trivial] [Qemu-devel] " Marc-André Lureau
2016-02-12 13:51       ` Marc-André Lureau
2016-01-11  9:16 ` [Qemu-trivial] " Paolo Bonzini
2016-01-11  9:29   ` Ashley Jonathan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).