[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL v3 16/55] chardev/char-socket: tcp_chr_sync_read: don't clobber er
From: |
Michael S. Tsirkin |
Subject: |
[PULL v3 16/55] chardev/char-socket: tcp_chr_sync_read: don't clobber errno |
Date: |
Fri, 7 Jan 2022 20:04:21 -0500 |
From: Roman Kagan <rvkagan@yandex-team.ru>
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>
---
chardev/char-socket.c | 3 +++
1 file changed, 3 insertions(+)
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;
}
--
MST
- Re: [PULL v3 12/55] virtio-pci: add support for configure interrupt, (continued)
- Re: [PULL v3 12/55] virtio-pci: add support for configure interrupt, Michael S. Tsirkin, 2022/01/09
- Re: [PULL v3 12/55] virtio-pci: add support for configure interrupt, Volker Rümelin, 2022/01/09
- Re: [PULL v3 12/55] virtio-pci: add support for configure interrupt, Michael S. Tsirkin, 2022/01/09
- Re: [PULL v3 12/55] virtio-pci: add support for configure interrupt, Volker Rümelin, 2022/01/09
- Re: [PULL v3 12/55] virtio-pci: add support for configure interrupt, Volker Rümelin, 2022/01/09
Re: [PULL v3 12/55] virtio-pci: add support for configure interrupt, Cédric Le Goater, 2022/01/09
[PULL v3 13/55] trace-events,pci: unify trace events format, Michael S. Tsirkin, 2022/01/07
[PULL v3 14/55] vhost-user-blk: reconnect on any error during realize, Michael S. Tsirkin, 2022/01/07
[PULL v3 15/55] chardev/char-socket: tcp_chr_recv: don't clobber errno, Michael S. Tsirkin, 2022/01/07
[PULL v3 16/55] chardev/char-socket: tcp_chr_sync_read: don't clobber errno,
Michael S. Tsirkin <=
[PULL v3 17/55] vhost-backend: avoid overflow on memslots_limit, Michael S. Tsirkin, 2022/01/07
[PULL v3 18/55] vhost-backend: stick to -errno error return convention, Michael S. Tsirkin, 2022/01/07
[PULL v3 20/55] vhost-user: stick to -errno error return convention, Michael S. Tsirkin, 2022/01/07
[PULL v3 19/55] vhost-vdpa: stick to -errno error return convention, Michael S. Tsirkin, 2022/01/07
[PULL v3 22/55] vhost-user-blk: propagate error return from generic vhost, Michael S. Tsirkin, 2022/01/07
[PULL v3 21/55] vhost: stick to -errno error return convention, Michael S. Tsirkin, 2022/01/07
[PULL v3 24/55] pcie_aer: Don't trigger a LSI if none are defined, Michael S. Tsirkin, 2022/01/07
[PULL v3 23/55] pci: Export the pci_intx() function, Michael S. Tsirkin, 2022/01/07
[PULL v3 26/55] hw/smbios: Use qapi for SmbiosEntryPointType, Michael S. Tsirkin, 2022/01/07
[PULL v3 25/55] smbios: Rename SMBIOS_ENTRY_POINT_* enums, Michael S. Tsirkin, 2022/01/07