qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] qemu-char: reset errno before qemu char write or read action
@ 2018-07-02  0:49 xinhua.Cao
  2018-07-02  1:42 ` Philippe Mathieu-Daudé
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: xinhua.Cao @ 2018-07-02  0:49 UTC (permalink / raw)
  To: pbonzini, marcandre.lureau, eblake, anton.nefedov, vsementsov
  Cc: weidong.huang, weifuqiang, king.wang, arei.gonglei, liuyongan,
	qemu-devel, xinhua.Cao

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 <caoxinhua@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) {
diff --git a/chardev/char.c b/chardev/char.c
index 76d866e..3387442 100644
--- a/chardev/char.c
+++ b/chardev/char.c
@@ -85,6 +85,7 @@ static void qemu_chr_write_log(Chardev *s, const uint8_t *buf, size_t len)
 
     while (done < len) {
     retry:
+        errno = 0;
         ret = write(s->logfd, buf + done, len - done);
         if (ret == -1 && errno == EAGAIN) {
             g_usleep(100);
@@ -109,6 +110,7 @@ static int qemu_chr_write_buffer(Chardev *s,
     qemu_mutex_lock(&s->chr_write_lock);
     while (*offset < len) {
     retry:
+        errno = 0;
         res = cc->chr_write(s, buf + *offset, len - *offset);
         if (res < 0 && errno == EAGAIN && write_all) {
             g_usleep(100);
-- 
2.8.3

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

end of thread, other threads:[~2018-07-04  4:13 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-07-02  0:49 [Qemu-devel] [PATCH] qemu-char: reset errno before qemu char write or read action xinhua.Cao
2018-07-02  1:42 ` Philippe Mathieu-Daudé
2018-07-02  8:46 ` Paolo Bonzini
2018-07-04  4:12   ` xinhua.Cao
2018-07-02 11:57 ` Eric Blake
2018-07-02 15:01 ` Stefan Hajnoczi
2018-07-04  2:10   ` xinhua.Cao

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).