Hi On Thu, Dec 25, 2025 at 10:41 AM luzhipeng <[email protected]> wrote:
> In char_pty_chr_write(), when the PTY is not connected (s->connected == > false), the function attempts a non-blocking poll to check if the fd is > writable. However, even if the fd is not writable or if io_channel_send() > fails the function unconditionally returns 'len', falsely indicating that > all data was successfully written. > > Signed-off-by: luzhipeng <[email protected]> > > --- > chardev/char-pty.c | 6 +++++- > 1 file changed, 5 insertions(+), 1 deletion(-) > > diff --git a/chardev/char-pty.c b/chardev/char-pty.c > index 652b0bd9e7..37a20d5f4b 100644 > --- a/chardev/char-pty.c > +++ b/chardev/char-pty.c > @@ -124,11 +124,15 @@ static int char_pty_chr_write(Chardev *chr, const > uint8_t *buf, int len) > pfd.revents = 0; > rc = RETRY_ON_EINTR(g_poll(&pfd, 1, 0)); > g_assert(rc >= 0); > + if ((pfd.revents & G_IO_HUP) || !(pfd.revents & G_IO_OUT)) { > + return 0; > + } > if (!(pfd.revents & G_IO_HUP) && (pfd.revents & G_IO_OUT)) { > return io_channel_send(s->ioc, buf, len); > } > > - return len; > + int ret = io_channel_send(s->ioc, buf, len); > + return ret; > The 'ret' variable is probably unnecessary. I suppose this will return 0 in general (unless the fd state has changed after the poll) So this will likely conflict the behaviour change from: commit 1c64fdbc8177058802df205f5d7cd65edafa59a8 Author: Ed Swierk <[email protected]> Date: Tue Jan 31 05:45:29 2017 -0800 char: drop data written to a disconnected pty When a serial port writes data to a pty that's disconnected, drop the data and return the length dropped. This avoids triggering pointless retries in callers like the 16550A serial_xmit(), and causes qemu_chr_fe_write() to write all data to the log file, rather than logging only while a pty client like virsh console happens to be connected. Signed-off-by: Ed Swierk <[email protected]> Message-Id: < [email protected]> Signed-off-by: Paolo Bonzini <[email protected]> diff --git a/chardev/char-pty.c b/chardev/char-pty.c index 27eb85f505..ecf2c7a5c4 100644 --- a/chardev/char-pty.c +++ b/chardev/char-pty.c @@ -129,7 +129,7 @@ static int char_pty_chr_write(Chardev *chr, const uint8_t *buf, int len) /* guest sends data, check for (re-)connect */ pty_chr_update_read_handler_locked(chr); if (!s->connected) { - return 0; + return len;
