[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 16/52] chardev/char-socket: tcp_chr_sync_read: don't clobber errno
From: |
Michael S. Tsirkin |
Subject: |
[PULL 16/52] chardev/char-socket: tcp_chr_sync_read: don't clobber errno |
Date: |
Thu, 6 Jan 2022 08:16:58 -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
- [PULL 06/52] vhost: introduce new VhostOps vhost_set_config_call, (continued)
- [PULL 06/52] vhost: introduce new VhostOps vhost_set_config_call, Michael S. Tsirkin, 2022/01/06
- [PULL 05/52] virtio-pci: decouple the single vector from the interrupt process, Michael S. Tsirkin, 2022/01/06
- [PULL 07/52] vhost-vdpa: add support for config interrupt, Michael S. Tsirkin, 2022/01/06
- [PULL 09/52] vhost: add support for configure interrupt, Michael S. Tsirkin, 2022/01/06
- [PULL 12/52] virtio-pci: add support for configure interrupt, Michael S. Tsirkin, 2022/01/06
- [PULL 08/52] virtio: add support for configure interrupt, Michael S. Tsirkin, 2022/01/06
- [PULL 10/52] virtio-net: add support for configure interrupt, Michael S. Tsirkin, 2022/01/06
- [PULL 11/52] virtio-mmio: add support for configure interrupt, Michael S. Tsirkin, 2022/01/06
- [PULL 13/52] trace-events,pci: unify trace events format, Michael S. Tsirkin, 2022/01/06
- [PULL 14/52] vhost-user-blk: reconnect on any error during realize, Michael S. Tsirkin, 2022/01/06
- [PULL 16/52] chardev/char-socket: tcp_chr_sync_read: don't clobber errno,
Michael S. Tsirkin <=
- [PULL 15/52] chardev/char-socket: tcp_chr_recv: don't clobber errno, Michael S. Tsirkin, 2022/01/06
- [PULL 17/52] vhost-backend: avoid overflow on memslots_limit, Michael S. Tsirkin, 2022/01/06
- [PULL 19/52] vhost-vdpa: stick to -errno error return convention, Michael S. Tsirkin, 2022/01/06
- [PULL 20/52] vhost-user: stick to -errno error return convention, Michael S. Tsirkin, 2022/01/06
- [PULL 22/52] vhost-user-blk: propagate error return from generic vhost, Michael S. Tsirkin, 2022/01/06
- [PULL 18/52] vhost-backend: stick to -errno error return convention, Michael S. Tsirkin, 2022/01/06
- [PULL 23/52] pci: Export the pci_intx() function, Michael S. Tsirkin, 2022/01/06
- [PULL 25/52] smbios: Rename SMBIOS_ENTRY_POINT_* enums, Michael S. Tsirkin, 2022/01/06
- [PULL 21/52] vhost: stick to -errno error return convention, Michael S. Tsirkin, 2022/01/06
- [PULL 26/52] hw/smbios: Use qapi for SmbiosEntryPointType, Michael S. Tsirkin, 2022/01/06