qemu-char: Do not disconnect when there's data for reading
PATCH v3 1/1 qemu-char: Do not disconnect when there's data for reading
After commit 812c1057f6175ac9a9829fa2920a2b5783814193 (Handle G_IO_HUP in tcp_chr_read for tcp chardev), connections are disconnected when in G_IO_HUP condition.
However, it's possible that there is still data for reading in the channel. In that case, the remaining data is not handled.
I saw a related bug when running socat in write-only mode, after
$ echo "quit" | socat -u - UNIX-CONNECT:qemu-monitor
the monitor won't not run the 'quit' command.
Instead of GIOCondition, this patch uses the return value of tcp_chr_recv() to check the state of connection as suggested by Kirill.
---
Changes in v3: handle EWOULDBLOCK, remove inaccurate comment
qemu-char.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-)
qemu-char.c +2 -8
@@ -2692,12 +2692,6 @@ static gboolean tcp_chr_read(GIOChannel *chan, GIOCondition cond, void *opaque)uint8_t buf[READ_BUF_LEN ];int len, size; -if (cond &G_IO_HUP ) { -/* connection closed */ -tcp_chr_disconnect (chr); -return TRUE; - } -if (!s->connected || s->max_size <=0 ) {return TRUE; }
@@ -2705,8 +2699,8 @@ static gboolean tcp_chr_read(GIOChannel *chan, GIOCondition cond, void *opaque)if (len > s->max_size) len = s->max_size; size =tcp_chr_recv (chr, (void *)buf, len); -if (size ==0 ) { -/* connection closed */ +if (size ==0 || + (size <0 && !(errno ==EAGAIN || errno ==EWOULDBLOCK || errno ==EINTR ))) {tcp_chr_disconnect (chr); }else if (size >0 ) {if (s->do_telnetopt)
Signature · 1 line
2.1.0
Quoted 46 lines · Zifei Tong
After commit
812c1057f6175ac9a9829fa2920a2b5783814193(HandleG_IO_HUPintcp_chr_readfor tcp chardev), connections are disconnected when inG_IO_HUPcondition.However, it's possible that there is still data for reading in the channel. In that case, the remaining data is not handled.
I saw a related bug when running socat in write-only mode, after
$ echo "quit" | socat -u - UNIX-CONNECT:qemu-monitorthe monitor won't not run the 'quit' command.
Instead of GIOCondition, this patch uses the return value of
tcp_chr_recv()to check the state of connection as suggested by Kirill.Cc Kirill Batuzov <[email protected]>Cc Nikolay Nikolaev <[email protected]>Cc Markus Armbruster <[email protected]>Cc Anthony Liguori <[email protected]>Signed-off-by Zifei Tong <[email protected]>---
Changes in v3: handle EWOULDBLOCK, remove inaccurate commentqemu-char.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-)qemu-char.c +0
-6@@ -2692,12 +2692,6 @@ static gboolean tcp_chr_read(GIOChannel *chan, GIOCondition cond, void *opaque)uint8_t buf[READ_BUF_LEN ];int len, size; -if (cond &G_IO_HUP ) { -/* connection closed */ -tcp_chr_disconnect (chr); -return TRUE; - } -if (!s->connected || s->max_size <=0 ) {return TRUE; }
qemu-char.c static gboolean tcp_chr_read(GIOChannel *chan, GIOCondition cond, void *opaque) · line 2706
Quoted 10 lines
qemu-char.c +2
-2@@ -2705,8 +2699,8 @@ static gboolean tcp_chr_read(GIOChannel *chan, GIOCondition cond, void *opaque)if (len > s->max_size) len = s->max_size; size =tcp_chr_recv (chr, (void *)buf, len); -if (size ==0 ) { -/* connection closed */ +if (size ==0 || + (size <0 && !(errno ==EAGAIN || errno ==EWOULDBLOCK || errno ==EINTR ))) {tcp_chr_disconnect (chr); }else if (size >0 ) {if (s->do_telnetopt)
Looks good to me.
Signature · 1 line
Kirill
Friendly ping.
I've saw a couple of scripts affected by this bug.
Thanks,
Zifei
Quoted 71 lines · Kirill Batuzov
Quoted 58 lines · Zifei Tong
After commit
812c1057f6175ac9a9829fa2920a2b5783814193(HandleG_IO_HUPintcp_chr_readfor tcp chardev), connections are disconnected when inG_IO_HUPcondition.However, it's possible that there is still data for reading in the channel.
In that case, the remaining data is not handled.I saw a related bug when running socat in write-only mode, after
$ echo "quit" | socat -u - UNIX-CONNECT:qemu-monitorthe monitor won't not run the 'quit' command.
Instead of GIOCondition, this patch uses the return value of
tcp_chr_recv()
to check the state of connection as suggested by Kirill.Cc Kirill Batuzov <[email protected]>Cc Nikolay Nikolaev <[email protected]>Cc Markus Armbruster <[email protected]>Cc Anthony Liguori <[email protected]>Signed-off-by Zifei Tong <[email protected]>---
Changes in v3: handle EWOULDBLOCK, remove inaccurate commentqemu-char.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-)qemu-char.c +0
-6@@ -2692,12 +2692,6 @@ static gboolean tcp_chr_read(GIOChannel *chan, GIOCondition cond, void *opaque) uint8_t buf[READ_BUF_LEN];int len, size; -if (cond &G_IO_HUP ) { -/* connection closed */ -tcp_chr_disconnect (chr); -return TRUE; - } -if (!s->connected || s->max_size <=0 ) {return TRUE;}qemu-char.c +2
-2@@ -2705,8 +2699,8 @@ static gboolean tcp_chr_read(GIOChannel *chan, GIOCondition cond, void *opaque)if (len > s->max_size) len = s->max_size; size =tcp_chr_recv (chr, (void *)buf, len); -if (size ==0 ) { -/* connection closed */ +if (size ==0 || + (size <0 && !(errno ==EAGAIN || errno ==EWOULDBLOCK || errno ==EINTR ))) {tcp_chr_disconnect (chr);Quoted 4 lines
} else if (size > 0) { if (s->do_telnetopt)Looks good to me.
Reviewed-by Kirill Batuzov <[email protected]>--
Kirill
MAINTAINERS points to Anthony, and you duly cc'ed him, but he's effectively retired. Cc'ing recent committers include Paolo and Peter.
Quoted 55 lines · Zifei Tong
After commit
812c1057f6175ac9a9829fa2920a2b5783814193(HandleG_IO_HUPintcp_chr_readfor tcp chardev), connections are disconnected when inG_IO_HUPcondition.However, it's possible that there is still data for reading in the channel. In that case, the remaining data is not handled.
I saw a related bug when running socat in write-only mode, after
$ echo "quit" | socat -u - UNIX-CONNECT:qemu-monitorthe monitor won't not run the 'quit' command.
Instead of GIOCondition, this patch uses the return value of
tcp_chr_recv()to check the state of connection as suggested by Kirill.Cc Kirill Batuzov <[email protected]>Cc Nikolay Nikolaev <[email protected]>Cc Markus Armbruster <[email protected]>Cc Anthony Liguori <[email protected]>Signed-off-by Zifei Tong <[email protected]>---
Changes in v3: handle EWOULDBLOCK, remove inaccurate commentqemu-char.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-)qemu-char.c +2
-8@@ -2692,12 +2692,6 @@ static gboolean tcp_chr_read(GIOChannel *chan, GIOCondition cond, void *opaque)uint8_t buf[READ_BUF_LEN ];int len, size; -if (cond &G_IO_HUP ) { -/* connection closed */ -tcp_chr_disconnect (chr); -return TRUE; - } -if (!s->connected || s->max_size <=0 ) {return TRUE; }@@ -2705,8 +2699,8 @@ static gboolean tcp_chr_read(GIOChannel *chan, GIOCondition cond, void *opaque)if (len > s->max_size) len = s->max_size; size =tcp_chr_recv (chr, (void *)buf, len); -if (size ==0 ) { -/* connection closed */ +if (size ==0 || + (size <0 && !(errno ==EAGAIN || errno ==EWOULDBLOCK || errno ==EINTR ))) {tcp_chr_disconnect (chr); }else if (size >0 ) {if (s->do_telnetopt)
Quoted 4 lines · Markus Armbruster
MAINTAINERSpoints to Anthony, and you duly cc'ed him, but he's effectively retired. Cc'ing recent committers include Paolo and Peter.Zifei Tong <[email protected]> writes:
I merged the patch that broke this, so I'll merge the fix too.
Quoted 55 lines
Quoted 55 lines
After commit
812c1057f6175ac9a9829fa2920a2b5783814193(HandleG_IO_HUPintcp_chr_readfor tcp chardev), connections are disconnected when inG_IO_HUPcondition.However, it's possible that there is still data for reading in the channel. In that case, the remaining data is not handled.
I saw a related bug when running socat in write-only mode, after
$ echo "quit" | socat -u - UNIX-CONNECT:qemu-monitorthe monitor won't not run the 'quit' command.
Instead of GIOCondition, this patch uses the return value of
tcp_chr_recv()to check the state of connection as suggested by Kirill.Cc Kirill Batuzov <[email protected]>Cc Nikolay Nikolaev <[email protected]>Cc Markus Armbruster <[email protected]>Cc Anthony Liguori <[email protected]>Signed-off-by Zifei Tong <[email protected]>---
Changes in v3: handle EWOULDBLOCK, remove inaccurate commentqemu-char.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-)qemu-char.c +2
-8@@ -2692,12 +2692,6 @@ static gboolean tcp_chr_read(GIOChannel *chan, GIOCondition cond, void *opaque)uint8_t buf[READ_BUF_LEN ];int len, size; -if (cond &G_IO_HUP ) { -/* connection closed */ -tcp_chr_disconnect (chr); -return TRUE; - } -if (!s->connected || s->max_size <=0 ) {return TRUE; }@@ -2705,8 +2699,8 @@ static gboolean tcp_chr_read(GIOChannel *chan, GIOCondition cond, void *opaque)if (len > s->max_size) len = s->max_size; size =tcp_chr_recv (chr, (void *)buf, len); -if (size ==0 ) { -/* connection closed */ +if (size ==0 || + (size <0 && !(errno ==EAGAIN || errno ==EWOULDBLOCK || errno ==EINTR ))) {tcp_chr_disconnect (chr); }else if (size >0 ) {if (s->do_telnetopt)
Quoted 7 lines · Michael S. Tsirkin
Quoted 4 lines · Markus Armbruster
MAINTAINERSpoints to Anthony, and you duly cc'ed him, but he's effectively retired. Cc'ing recent committers include Paolo and Peter.Zifei Tong <[email protected]> writes:
I merged the patch that broke this, so I'll merge the fix too.
Oh, Paolo merged it already. Thanks Paolo!
Quoted 56 lines
Quoted 56 lines
Quoted 56 lines
After commit
812c1057f6175ac9a9829fa2920a2b5783814193(HandleG_IO_HUPintcp_chr_readfor tcp chardev), connections are disconnected when inG_IO_HUPcondition.However, it's possible that there is still data for reading in the channel. In that case, the remaining data is not handled.
I saw a related bug when running socat in write-only mode, after
$ echo "quit" | socat -u - UNIX-CONNECT:qemu-monitorthe monitor won't not run the 'quit' command.
Instead of GIOCondition, this patch uses the return value of
tcp_chr_recv()to check the state of connection as suggested by Kirill.Cc Kirill Batuzov <[email protected]>Cc Nikolay Nikolaev <[email protected]>Cc Markus Armbruster <[email protected]>Cc Anthony Liguori <[email protected]>Signed-off-by Zifei Tong <[email protected]>---
Changes in v3: handle EWOULDBLOCK, remove inaccurate commentqemu-char.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-)qemu-char.c +2
-8@@ -2692,12 +2692,6 @@ static gboolean tcp_chr_read(GIOChannel *chan, GIOCondition cond, void *opaque)uint8_t buf[READ_BUF_LEN ];int len, size; -if (cond &G_IO_HUP ) { -/* connection closed */ -tcp_chr_disconnect (chr); -return TRUE; - } -if (!s->connected || s->max_size <=0 ) {return TRUE; }@@ -2705,8 +2699,8 @@ static gboolean tcp_chr_read(GIOChannel *chan, GIOCondition cond, void *opaque)if (len > s->max_size) len = s->max_size; size =tcp_chr_recv (chr, (void *)buf, len); -if (size ==0 ) { -/* connection closed */ +if (size ==0 || + (size <0 && !(errno ==EAGAIN || errno ==EWOULDBLOCK || errno ==EINTR ))) {tcp_chr_disconnect (chr); }else if (size >0 ) {if (s->do_telnetopt)