[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 03/10] chardev/char-socket: tcp_chr_sync_read: don't clobber errn
From: |
Roman Kagan |
Subject: |
[PATCH 03/10] chardev/char-socket: tcp_chr_sync_read: don't clobber errno |
Date: |
Thu, 11 Nov 2021 18:33:47 +0300 |
After the return from tcp_chr_recv, tcp_chr_sync_read calls into a
function which eventually makes a system call and may clobber errno.
Make a copy of errno right after tcp_chr_recv and restore the errno on
return from tcp_chr_sync_read.
Signed-off-by: Roman Kagan <rvkagan@yandex-team.ru>
---
chardev/char-socket.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/chardev/char-socket.c b/chardev/char-socket.c
index 90054ce58c..cf7f2ba65a 100644
--- a/chardev/char-socket.c
+++ b/chardev/char-socket.c
@@ -581,6 +581,7 @@ static int tcp_chr_sync_read(Chardev *chr, const uint8_t
*buf, int len)
{
SocketChardev *s = SOCKET_CHARDEV(chr);
int size;
+ int saved_errno;
if (s->state != TCP_CHARDEV_STATE_CONNECTED) {
return 0;
@@ -588,6 +589,7 @@ static int tcp_chr_sync_read(Chardev *chr, const uint8_t
*buf, int len)
qio_channel_set_blocking(s->ioc, true, NULL);
size = tcp_chr_recv(chr, (void *) buf, len);
+ saved_errno = errno;
if (s->state != TCP_CHARDEV_STATE_DISCONNECTED) {
qio_channel_set_blocking(s->ioc, false, NULL);
}
@@ -596,6 +598,7 @@ static int tcp_chr_sync_read(Chardev *chr, const uint8_t
*buf, int len)
tcp_chr_disconnect(chr);
}
+ errno = saved_errno;
return size;
}
--
2.33.1
Re: [PATCH 01/10] vhost-user-blk: reconnect on any error during realize, Raphael Norwitz, 2021/11/29
[PATCH 03/10] chardev/char-socket: tcp_chr_sync_read: don't clobber errno,
Roman Kagan <=
[PATCH 02/10] chardev/char-socket: tcp_chr_recv: don't clobber errno, Roman Kagan, 2021/11/11
[PATCH 05/10] vhost-backend: avoid overflow on memslots_limit, Roman Kagan, 2021/11/11
[PATCH 07/10] vhost-vdpa: stick to -errno error return convention, Roman Kagan, 2021/11/11
[PATCH 06/10] vhost-backend: stick to -errno error return convention, Roman Kagan, 2021/11/11