Skip to content

Commit

Permalink
chardev/char-socket: tcp_chr_recv: don't clobber errno
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
rvka authored and mstsirkin committed Jan 7, 2022
1 parent b7107e7 commit e879750
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions chardev/char-socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit e879750

Please sign in to comment.