summaryrefslogtreecommitdiffstats
path: root/chardev
diff options
context:
space:
mode:
authorRoman Kagan2021-11-11 16:33:46 +0100
committerMichael S. Tsirkin2022-01-07 11:19:55 +0100
commite87975051ee6071dec12d318e45a28d4770c2dd0 (patch)
tree20596476904cccdc7d1a4e8e30347cb64d0998d8 /chardev
parentvhost-user-blk: reconnect on any error during realize (diff)
downloadqemu-e87975051ee6071dec12d318e45a28d4770c2dd0.tar.gz
qemu-e87975051ee6071dec12d318e45a28d4770c2dd0.tar.xz
qemu-e87975051ee6071dec12d318e45a28d4770c2dd0.zip
chardev/char-socket: tcp_chr_recv: don't clobber errno
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>
Diffstat (limited to 'chardev')
-rw-r--r--chardev/char-socket.c14
1 files 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;
}