unix: fix several instances of lost errno
This commit preserves errno properly in the following cases: - new_socket() was previously discarding errno in some cases, and replacing it with the result of getsockname(). - uv__close() was not preserving errno when __MVS__ is defined. Fixes: https://github.com/libuv/libuv/issues/1756 PR-URL: https://github.com/libuv/libuv/pull/1763 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
This commit is contained in:
parent
b7f649d308
commit
9ed3ed5fcb
@ -536,7 +536,7 @@ int uv__close_nocheckstdio(int fd) {
|
||||
int uv__close(int fd) {
|
||||
assert(fd > STDERR_FILENO); /* Catch stdio close bugs. */
|
||||
#if defined(__MVS__)
|
||||
epoll_file_close(fd);
|
||||
SAVE_ERRNO(epoll_file_close(fd));
|
||||
#endif
|
||||
return uv__close_nocheckstdio(fd);
|
||||
}
|
||||
|
||||
@ -190,7 +190,7 @@ int uv__cloexec_ioctl(int fd, int set);
|
||||
int uv__cloexec_fcntl(int fd, int set);
|
||||
int uv__nonblock_ioctl(int fd, int set);
|
||||
int uv__nonblock_fcntl(int fd, int set);
|
||||
int uv__close(int fd);
|
||||
int uv__close(int fd); /* preserves errno */
|
||||
int uv__close_nocheckstdio(int fd);
|
||||
int uv__socket(int domain, int type, int protocol);
|
||||
int uv__dup(int fd);
|
||||
|
||||
@ -49,16 +49,14 @@ static int new_socket(uv_tcp_t* handle, int domain, unsigned long flags) {
|
||||
/* Bind this new socket to an arbitrary port */
|
||||
slen = sizeof(saddr);
|
||||
memset(&saddr, 0, sizeof(saddr));
|
||||
err = getsockname(uv__stream_fd(handle), (struct sockaddr*) &saddr, &slen);
|
||||
if (err) {
|
||||
if (getsockname(uv__stream_fd(handle), (struct sockaddr*) &saddr, &slen)) {
|
||||
uv__close(sockfd);
|
||||
return err;
|
||||
return UV__ERR(errno);
|
||||
}
|
||||
|
||||
err = bind(uv__stream_fd(handle), (struct sockaddr*) &saddr, slen);
|
||||
if (err) {
|
||||
if (bind(uv__stream_fd(handle), (struct sockaddr*) &saddr, slen)) {
|
||||
uv__close(sockfd);
|
||||
return err;
|
||||
return UV__ERR(errno);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user