From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49114) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aIXvP-0001kC-E2 for qemu-devel@nongnu.org; Mon, 11 Jan 2016 03:34:04 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aIXvM-00077b-60 for qemu-devel@nongnu.org; Mon, 11 Jan 2016 03:34:03 -0500 References: From: Michael Tokarev Message-ID: <569368F6.3050704@msgid.tls.msk.ru> Date: Mon, 11 Jan 2016 11:33:58 +0300 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH] Keep pty slave file descriptor open until the master is closed List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Ashley Jonathan , "qemu-devel@nongnu.org" Cc: "qemu-trivial@nongnu.org" , "pbonzini@redhat.com" 11.12.2015 14:29, Ashley Jonathan wrote: > 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. The patch looks fine, so Reviewed-by: Michael Tokarev but I'd love to have an ACK from the maintainer about this one, or for it to pick it up. Thanks, /mjt > --- > 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; >