On 07/01/2018 07:49 PM, xinhua.Cao wrote:
In the tcp_chr_write function, we checked errno,
but errno was not reset before a read or write operation.
Therefore, this check of errno's actions is often
incorrect after EAGAIN has occurred.
We reset errno before reading and writing to
ensure the correctness of errno's judgment

Signed-off-by: xinhua.Cao <caoxin...@huawei.com>
---
  chardev/char-fe.c | 1 +
  chardev/char.c    | 2 ++
  2 files changed, 3 insertions(+)

diff --git a/chardev/char-fe.c b/chardev/char-fe.c
index b1f228e..d96ca6f 100644
--- a/chardev/char-fe.c
+++ b/chardev/char-fe.c
@@ -69,6 +69,7 @@ int qemu_chr_fe_read_all(CharBackend *be, uint8_t *buf, int 
len)
while (offset < len) {
      retry:
+        errno = 0;
          res = CHARDEV_GET_CLASS(s)->chr_sync_read(s, buf + offset,
                                                    len - offset);
          if (res == -1 && errno == EAGAIN) {

NACK. read() is guaranteed to have set errno if res is -1, and we don't check errno unless we first checked that res was -1. Thus, the EAGAIN check is not confused by a stale errno value.


--
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org

Reply via email to