summaryrefslogtreecommitdiffstats
path: root/chardev
diff options
context:
space:
mode:
authorRoman Kagan2021-11-11 16:33:47 +0100
committerMichael S. Tsirkin2022-01-07 11:19:55 +0100
commit666265036fec3fd3eed2d55ae828c915a084a1d6 (patch)
tree88857b1e14dd5002a5def6dcbe67c129f3b0047c /chardev
parentchardev/char-socket: tcp_chr_recv: don't clobber errno (diff)
downloadqemu-666265036fec3fd3eed2d55ae828c915a084a1d6.tar.gz
qemu-666265036fec3fd3eed2d55ae828c915a084a1d6.tar.xz
qemu-666265036fec3fd3eed2d55ae828c915a084a1d6.zip
chardev/char-socket: tcp_chr_sync_read: don't clobber errno
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> Message-Id: <20211111153354.18807-4-rvkagan@yandex-team.ru> Reviewed-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Diffstat (limited to 'chardev')
-rw-r--r--chardev/char-socket.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/chardev/char-socket.c b/chardev/char-socket.c
index 3ddd98ed49..fab2d791d4 100644
--- a/chardev/char-socket.c
+++ b/chardev/char-socket.c
@@ -525,6 +525,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;
@@ -532,6 +533,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);
}
@@ -540,6 +542,7 @@ static int tcp_chr_sync_read(Chardev *chr, const uint8_t *buf, int len)
tcp_chr_disconnect(chr);
}
+ errno = saved_errno;
return size;
}