[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL v2 15/55] chardev/char-socket: tcp_chr_recv: don't clobber errno
|
From: |
Michael S. Tsirkin |
|
Subject: |
[PULL v2 15/55] chardev/char-socket: tcp_chr_recv: don't clobber errno |
|
Date: |
Fri, 7 Jan 2022 06:03:48 -0500 |
From: Roman Kagan <rvkagan@yandex-team.ru>
tcp_chr_recv communicates the specific error condition to the caller via
errno. However, after setting it, it may call into some system calls or
library functions which can clobber the errno.
Avoid this by moving the errno assignment to the end of the function.
Signed-off-by: Roman Kagan <rvkagan@yandex-team.ru>
Message-Id: <20211111153354.18807-3-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 | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/chardev/char-socket.c b/chardev/char-socket.c
index d619088232..3ddd98ed49 100644
--- a/chardev/char-socket.c
+++ b/chardev/char-socket.c
@@ -290,13 +290,6 @@ static ssize_t tcp_chr_recv(Chardev *chr, char *buf,
size_t len)
NULL);
}
- if (ret == QIO_CHANNEL_ERR_BLOCK) {
- errno = EAGAIN;
- ret = -1;
- } else if (ret == -1) {
- errno = EIO;
- }
-
if (msgfds_num) {
/* close and clean read_msgfds */
for (i = 0; i < s->read_msgfds_num; i++) {
@@ -325,6 +318,13 @@ static ssize_t tcp_chr_recv(Chardev *chr, char *buf,
size_t len)
#endif
}
+ if (ret == QIO_CHANNEL_ERR_BLOCK) {
+ errno = EAGAIN;
+ ret = -1;
+ } else if (ret == -1) {
+ errno = EIO;
+ }
+
return ret;
}
--
MST
- [PULL v2 05/55] virtio-pci: decouple the single vector from the interrupt process, (continued)
- [PULL v2 05/55] virtio-pci: decouple the single vector from the interrupt process, Michael S. Tsirkin, 2022/01/07
- [PULL v2 06/55] vhost: introduce new VhostOps vhost_set_config_call, Michael S. Tsirkin, 2022/01/07
- [PULL v2 07/55] vhost-vdpa: add support for config interrupt, Michael S. Tsirkin, 2022/01/07
- [PULL v2 09/55] vhost: add support for configure interrupt, Michael S. Tsirkin, 2022/01/07
- [PULL v2 10/55] virtio-net: add support for configure interrupt, Michael S. Tsirkin, 2022/01/07
- [PULL v2 08/55] virtio: add support for configure interrupt, Michael S. Tsirkin, 2022/01/07
- [PULL v2 11/55] virtio-mmio: add support for configure interrupt, Michael S. Tsirkin, 2022/01/07
- [PULL v2 12/55] virtio-pci: add support for configure interrupt, Michael S. Tsirkin, 2022/01/07
- [PULL v2 13/55] trace-events,pci: unify trace events format, Michael S. Tsirkin, 2022/01/07
- [PULL v2 14/55] vhost-user-blk: reconnect on any error during realize, Michael S. Tsirkin, 2022/01/07
- [PULL v2 15/55] chardev/char-socket: tcp_chr_recv: don't clobber errno,
Michael S. Tsirkin <=
- [PULL v2 16/55] chardev/char-socket: tcp_chr_sync_read: don't clobber errno, Michael S. Tsirkin, 2022/01/07
- [PULL v2 17/55] vhost-backend: avoid overflow on memslots_limit, Michael S. Tsirkin, 2022/01/07
- [PULL v2 19/55] vhost-vdpa: stick to -errno error return convention, Michael S. Tsirkin, 2022/01/07
- [PULL v2 18/55] vhost-backend: stick to -errno error return convention, Michael S. Tsirkin, 2022/01/07
- [PULL v2 20/55] vhost-user: stick to -errno error return convention, Michael S. Tsirkin, 2022/01/07
- [PULL v2 21/55] vhost: stick to -errno error return convention, Michael S. Tsirkin, 2022/01/07
- [PULL v2 22/55] vhost-user-blk: propagate error return from generic vhost, Michael S. Tsirkin, 2022/01/07
- [PULL v2 23/55] pci: Export the pci_intx() function, Michael S. Tsirkin, 2022/01/07
- [PULL v2 24/55] pcie_aer: Don't trigger a LSI if none are defined, Michael S. Tsirkin, 2022/01/07
- [PULL v2 26/55] hw/smbios: Use qapi for SmbiosEntryPointType, Michael S. Tsirkin, 2022/01/07