win32: replace closesocket() with close() wrapper
Use a close() wrapper instead, so that we don't need to worry about closesocket() vs close() anymore, let's hope. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Reviewed-by: Stefan Berger <stefanb@linux.ibm.com> Message-Id: <20230221124802.4103554-17-marcandre.lureau@redhat.com>
This commit is contained in:
parent
b7e5374637
commit
25657fc6c1
@ -573,13 +573,13 @@ static int tpm_emulator_prepare_data_fd(TPMEmulator *tpm_emu)
|
|||||||
goto err_exit;
|
goto err_exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
closesocket(fds[1]);
|
close(fds[1]);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
err_exit:
|
err_exit:
|
||||||
closesocket(fds[0]);
|
close(fds[0]);
|
||||||
closesocket(fds[1]);
|
close(fds[1]);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,7 +59,7 @@ qcrypto_afalg_socket_bind(const char *type, const char *name,
|
|||||||
|
|
||||||
if (bind(sbind, (const struct sockaddr *)&salg, sizeof(salg)) != 0) {
|
if (bind(sbind, (const struct sockaddr *)&salg, sizeof(salg)) != 0) {
|
||||||
error_setg_errno(errp, errno, "Failed to bind socket");
|
error_setg_errno(errp, errno, "Failed to bind socket");
|
||||||
closesocket(sbind);
|
close(sbind);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,11 +105,11 @@ void qcrypto_afalg_comm_free(QCryptoAFAlg *afalg)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (afalg->tfmfd != -1) {
|
if (afalg->tfmfd != -1) {
|
||||||
closesocket(afalg->tfmfd);
|
close(afalg->tfmfd);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (afalg->opfd != -1) {
|
if (afalg->opfd != -1) {
|
||||||
closesocket(afalg->opfd);
|
close(afalg->opfd);
|
||||||
}
|
}
|
||||||
|
|
||||||
g_free(afalg);
|
g_free(afalg);
|
||||||
|
@ -340,7 +340,7 @@ static void hv_syndbg_realize(DeviceState *dev, Error **errp)
|
|||||||
syndbg->servaddr.sin_family = AF_INET;
|
syndbg->servaddr.sin_family = AF_INET;
|
||||||
if (connect(syndbg->socket, (struct sockaddr *)&syndbg->servaddr,
|
if (connect(syndbg->socket, (struct sockaddr *)&syndbg->servaddr,
|
||||||
sizeof(syndbg->servaddr)) < 0) {
|
sizeof(syndbg->servaddr)) < 0) {
|
||||||
closesocket(syndbg->socket);
|
close(syndbg->socket);
|
||||||
error_setg(errp, "%s failed to connect to socket", TYPE_HV_SYNDBG);
|
error_setg(errp, "%s failed to connect to socket", TYPE_HV_SYNDBG);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -357,7 +357,7 @@ static void hv_syndbg_unrealize(DeviceState *dev)
|
|||||||
|
|
||||||
if (syndbg->socket > 0) {
|
if (syndbg->socket > 0) {
|
||||||
qemu_set_fd_handler(syndbg->socket, NULL, NULL, NULL);
|
qemu_set_fd_handler(syndbg->socket, NULL, NULL, NULL);
|
||||||
closesocket(syndbg->socket);
|
close(syndbg->socket);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,8 +51,6 @@ void os_daemonize(void);
|
|||||||
void os_setup_post(void);
|
void os_setup_post(void);
|
||||||
int os_mlock(void);
|
int os_mlock(void);
|
||||||
|
|
||||||
#define closesocket(s) close(s)
|
|
||||||
|
|
||||||
int os_set_daemonize(bool d);
|
int os_set_daemonize(bool d);
|
||||||
bool is_daemonized(void);
|
bool is_daemonized(void);
|
||||||
|
|
||||||
|
@ -175,6 +175,10 @@ bool qemu_socket_unselect(int sockfd, Error **errp);
|
|||||||
* set errno based on WSAGetLastError()
|
* set errno based on WSAGetLastError()
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#undef close
|
||||||
|
#define close qemu_close_wrap
|
||||||
|
int qemu_close_wrap(int fd);
|
||||||
|
|
||||||
#undef connect
|
#undef connect
|
||||||
#define connect qemu_connect_wrap
|
#define connect qemu_connect_wrap
|
||||||
int qemu_connect_wrap(int sockfd, const struct sockaddr *addr,
|
int qemu_connect_wrap(int sockfd, const struct sockaddr *addr,
|
||||||
@ -206,10 +210,6 @@ int qemu_shutdown_wrap(int sockfd, int how);
|
|||||||
#define ioctlsocket qemu_ioctlsocket_wrap
|
#define ioctlsocket qemu_ioctlsocket_wrap
|
||||||
int qemu_ioctlsocket_wrap(int fd, int req, void *val);
|
int qemu_ioctlsocket_wrap(int fd, int req, void *val);
|
||||||
|
|
||||||
#undef closesocket
|
|
||||||
#define closesocket qemu_closesocket_wrap
|
|
||||||
int qemu_closesocket_wrap(int fd);
|
|
||||||
|
|
||||||
#undef getsockopt
|
#undef getsockopt
|
||||||
#define getsockopt qemu_getsockopt_wrap
|
#define getsockopt qemu_getsockopt_wrap
|
||||||
int qemu_getsockopt_wrap(int sockfd, int level, int optname,
|
int qemu_getsockopt_wrap(int sockfd, int level, int optname,
|
||||||
|
@ -159,7 +159,7 @@ int qio_channel_socket_connect_sync(QIOChannelSocket *ioc,
|
|||||||
|
|
||||||
trace_qio_channel_socket_connect_complete(ioc, fd);
|
trace_qio_channel_socket_connect_complete(ioc, fd);
|
||||||
if (qio_channel_socket_set_fd(ioc, fd, errp) < 0) {
|
if (qio_channel_socket_set_fd(ioc, fd, errp) < 0) {
|
||||||
closesocket(fd);
|
close(fd);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -233,7 +233,7 @@ int qio_channel_socket_listen_sync(QIOChannelSocket *ioc,
|
|||||||
|
|
||||||
trace_qio_channel_socket_listen_complete(ioc, fd);
|
trace_qio_channel_socket_listen_complete(ioc, fd);
|
||||||
if (qio_channel_socket_set_fd(ioc, fd, errp) < 0) {
|
if (qio_channel_socket_set_fd(ioc, fd, errp) < 0) {
|
||||||
closesocket(fd);
|
close(fd);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
qio_channel_set_feature(QIO_CHANNEL(ioc), QIO_CHANNEL_FEATURE_LISTEN);
|
qio_channel_set_feature(QIO_CHANNEL(ioc), QIO_CHANNEL_FEATURE_LISTEN);
|
||||||
@ -310,7 +310,7 @@ int qio_channel_socket_dgram_sync(QIOChannelSocket *ioc,
|
|||||||
|
|
||||||
trace_qio_channel_socket_dgram_complete(ioc, fd);
|
trace_qio_channel_socket_dgram_complete(ioc, fd);
|
||||||
if (qio_channel_socket_set_fd(ioc, fd, errp) < 0) {
|
if (qio_channel_socket_set_fd(ioc, fd, errp) < 0) {
|
||||||
closesocket(fd);
|
close(fd);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -444,7 +444,7 @@ static void qio_channel_socket_finalize(Object *obj)
|
|||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
qemu_socket_unselect(ioc->fd, NULL);
|
qemu_socket_unselect(ioc->fd, NULL);
|
||||||
#endif
|
#endif
|
||||||
closesocket(ioc->fd);
|
close(ioc->fd);
|
||||||
ioc->fd = -1;
|
ioc->fd = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -852,7 +852,7 @@ qio_channel_socket_close(QIOChannel *ioc,
|
|||||||
socket_listen_cleanup(sioc->fd, errp);
|
socket_listen_cleanup(sioc->fd, errp);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (closesocket(sioc->fd) < 0) {
|
if (close(sioc->fd) < 0) {
|
||||||
sioc->fd = -1;
|
sioc->fd = -1;
|
||||||
error_setg_errno(&err, errno, "Unable to close socket");
|
error_setg_errno(&err, errno, "Unable to close socket");
|
||||||
error_propagate(errp, err);
|
error_propagate(errp, err);
|
||||||
|
14
net/dgram.c
14
net/dgram.c
@ -230,7 +230,7 @@ static int net_dgram_mcast_create(struct sockaddr_in *mcastaddr,
|
|||||||
return fd;
|
return fd;
|
||||||
fail:
|
fail:
|
||||||
if (fd >= 0) {
|
if (fd >= 0) {
|
||||||
closesocket(fd);
|
close(fd);
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -352,7 +352,7 @@ static int net_dgram_mcast_init(NetClientState *peer,
|
|||||||
if (convert_host_port(saddr, local->u.inet.host, local->u.inet.port,
|
if (convert_host_port(saddr, local->u.inet.host, local->u.inet.port,
|
||||||
errp) < 0) {
|
errp) < 0) {
|
||||||
g_free(saddr);
|
g_free(saddr);
|
||||||
closesocket(fd);
|
close(fd);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -360,14 +360,14 @@ static int net_dgram_mcast_init(NetClientState *peer,
|
|||||||
if (saddr->sin_addr.s_addr == 0) {
|
if (saddr->sin_addr.s_addr == 0) {
|
||||||
error_setg(errp, "can't setup multicast destination address");
|
error_setg(errp, "can't setup multicast destination address");
|
||||||
g_free(saddr);
|
g_free(saddr);
|
||||||
closesocket(fd);
|
close(fd);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
/* clone dgram socket */
|
/* clone dgram socket */
|
||||||
newfd = net_dgram_mcast_create(saddr, NULL, errp);
|
newfd = net_dgram_mcast_create(saddr, NULL, errp);
|
||||||
if (newfd < 0) {
|
if (newfd < 0) {
|
||||||
g_free(saddr);
|
g_free(saddr);
|
||||||
closesocket(fd);
|
close(fd);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
/* clone newfd to fd, close newfd */
|
/* clone newfd to fd, close newfd */
|
||||||
@ -494,14 +494,14 @@ int net_init_dgram(const Netdev *netdev, const char *name,
|
|||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
error_setg_errno(errp, errno,
|
error_setg_errno(errp, errno,
|
||||||
"can't set socket option SO_REUSEADDR");
|
"can't set socket option SO_REUSEADDR");
|
||||||
closesocket(fd);
|
close(fd);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
ret = bind(fd, (struct sockaddr *)&laddr_in, sizeof(laddr_in));
|
ret = bind(fd, (struct sockaddr *)&laddr_in, sizeof(laddr_in));
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
error_setg_errno(errp, errno, "can't bind ip=%s to socket",
|
error_setg_errno(errp, errno, "can't bind ip=%s to socket",
|
||||||
inet_ntoa(laddr_in.sin_addr));
|
inet_ntoa(laddr_in.sin_addr));
|
||||||
closesocket(fd);
|
close(fd);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
qemu_socket_set_nonblock(fd);
|
qemu_socket_set_nonblock(fd);
|
||||||
@ -548,7 +548,7 @@ int net_init_dgram(const Netdev *netdev, const char *name,
|
|||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
error_setg_errno(errp, errno, "can't bind unix=%s to socket",
|
error_setg_errno(errp, errno, "can't bind unix=%s to socket",
|
||||||
laddr_un.sun_path);
|
laddr_un.sun_path);
|
||||||
closesocket(fd);
|
close(fd);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
qemu_socket_set_nonblock(fd);
|
qemu_socket_set_nonblock(fd);
|
||||||
|
22
net/socket.c
22
net/socket.c
@ -172,7 +172,7 @@ static void net_socket_send(void *opaque)
|
|||||||
if (s->listen_fd != -1) {
|
if (s->listen_fd != -1) {
|
||||||
qemu_set_fd_handler(s->listen_fd, net_socket_accept, NULL, s);
|
qemu_set_fd_handler(s->listen_fd, net_socket_accept, NULL, s);
|
||||||
}
|
}
|
||||||
closesocket(s->fd);
|
close(s->fd);
|
||||||
|
|
||||||
s->fd = -1;
|
s->fd = -1;
|
||||||
net_socket_rs_init(&s->rs, net_socket_rs_finalize, false);
|
net_socket_rs_init(&s->rs, net_socket_rs_finalize, false);
|
||||||
@ -299,7 +299,7 @@ static int net_socket_mcast_create(struct sockaddr_in *mcastaddr,
|
|||||||
return fd;
|
return fd;
|
||||||
fail:
|
fail:
|
||||||
if (fd >= 0)
|
if (fd >= 0)
|
||||||
closesocket(fd);
|
close(fd);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -314,7 +314,7 @@ static void net_socket_cleanup(NetClientState *nc)
|
|||||||
}
|
}
|
||||||
if (s->listen_fd != -1) {
|
if (s->listen_fd != -1) {
|
||||||
qemu_set_fd_handler(s->listen_fd, NULL, NULL, NULL);
|
qemu_set_fd_handler(s->listen_fd, NULL, NULL, NULL);
|
||||||
closesocket(s->listen_fd);
|
close(s->listen_fd);
|
||||||
s->listen_fd = -1;
|
s->listen_fd = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -399,7 +399,7 @@ static NetSocketState *net_socket_fd_init_dgram(NetClientState *peer,
|
|||||||
return s;
|
return s;
|
||||||
|
|
||||||
err:
|
err:
|
||||||
closesocket(fd);
|
close(fd);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -456,7 +456,7 @@ static NetSocketState *net_socket_fd_init(NetClientState *peer,
|
|||||||
if(getsockopt(fd, SOL_SOCKET, SO_TYPE, (char *)&so_type,
|
if(getsockopt(fd, SOL_SOCKET, SO_TYPE, (char *)&so_type,
|
||||||
(socklen_t *)&optlen)< 0) {
|
(socklen_t *)&optlen)< 0) {
|
||||||
error_setg(errp, "can't get socket option SO_TYPE");
|
error_setg(errp, "can't get socket option SO_TYPE");
|
||||||
closesocket(fd);
|
close(fd);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
switch(so_type) {
|
switch(so_type) {
|
||||||
@ -468,7 +468,7 @@ static NetSocketState *net_socket_fd_init(NetClientState *peer,
|
|||||||
default:
|
default:
|
||||||
error_setg(errp, "socket type=%d for fd=%d must be either"
|
error_setg(errp, "socket type=%d for fd=%d must be either"
|
||||||
" SOCK_DGRAM or SOCK_STREAM", so_type, fd);
|
" SOCK_DGRAM or SOCK_STREAM", so_type, fd);
|
||||||
closesocket(fd);
|
close(fd);
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -526,13 +526,13 @@ static int net_socket_listen_init(NetClientState *peer,
|
|||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
error_setg_errno(errp, errno, "can't bind ip=%s to socket",
|
error_setg_errno(errp, errno, "can't bind ip=%s to socket",
|
||||||
inet_ntoa(saddr.sin_addr));
|
inet_ntoa(saddr.sin_addr));
|
||||||
closesocket(fd);
|
close(fd);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
ret = listen(fd, 0);
|
ret = listen(fd, 0);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
error_setg_errno(errp, errno, "can't listen on socket");
|
error_setg_errno(errp, errno, "can't listen on socket");
|
||||||
closesocket(fd);
|
close(fd);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -579,7 +579,7 @@ static int net_socket_connect_init(NetClientState *peer,
|
|||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
error_setg_errno(errp, errno, "can't connect socket");
|
error_setg_errno(errp, errno, "can't connect socket");
|
||||||
closesocket(fd);
|
close(fd);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -671,14 +671,14 @@ static int net_socket_udp_init(NetClientState *peer,
|
|||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
error_setg_errno(errp, errno,
|
error_setg_errno(errp, errno,
|
||||||
"can't set socket option SO_REUSEADDR");
|
"can't set socket option SO_REUSEADDR");
|
||||||
closesocket(fd);
|
close(fd);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
ret = bind(fd, (struct sockaddr *)&laddr, sizeof(laddr));
|
ret = bind(fd, (struct sockaddr *)&laddr, sizeof(laddr));
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
error_setg_errno(errp, errno, "can't bind ip=%s to socket",
|
error_setg_errno(errp, errno, "can't bind ip=%s to socket",
|
||||||
inet_ntoa(laddr.sin_addr));
|
inet_ntoa(laddr.sin_addr));
|
||||||
closesocket(fd);
|
close(fd);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
qemu_socket_set_nonblock(fd);
|
qemu_socket_set_nonblock(fd);
|
||||||
|
@ -124,7 +124,7 @@ static int socket_accept(int sock)
|
|||||||
(void *)&timeout, sizeof(timeout))) {
|
(void *)&timeout, sizeof(timeout))) {
|
||||||
fprintf(stderr, "%s failed to set SO_RCVTIMEO: %s\n",
|
fprintf(stderr, "%s failed to set SO_RCVTIMEO: %s\n",
|
||||||
__func__, strerror(errno));
|
__func__, strerror(errno));
|
||||||
closesocket(sock);
|
close(sock);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -135,7 +135,7 @@ static int socket_accept(int sock)
|
|||||||
if (ret == -1) {
|
if (ret == -1) {
|
||||||
fprintf(stderr, "%s failed: %s\n", __func__, strerror(errno));
|
fprintf(stderr, "%s failed: %s\n", __func__, strerror(errno));
|
||||||
}
|
}
|
||||||
closesocket(sock);
|
close(sock);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -564,8 +564,8 @@ void qtest_quit(QTestState *s)
|
|||||||
qtest_remove_abrt_handler(s);
|
qtest_remove_abrt_handler(s);
|
||||||
|
|
||||||
qtest_kill_qemu(s);
|
qtest_kill_qemu(s);
|
||||||
closesocket(s->fd);
|
close(s->fd);
|
||||||
closesocket(s->qmp_fd);
|
close(s->qmp_fd);
|
||||||
g_string_free(s->rx, true);
|
g_string_free(s->rx, true);
|
||||||
|
|
||||||
for (GList *it = s->pending_events; it != NULL; it = it->next) {
|
for (GList *it = s->pending_events; it != NULL; it = it->next) {
|
||||||
|
@ -107,7 +107,7 @@ static void test_nrf51_uart(void)
|
|||||||
g_assert_true(recv(sock_fd, s, 10, 0) == 5);
|
g_assert_true(recv(sock_fd, s, 10, 0) == 5);
|
||||||
g_assert_true(memcmp(s, "world", 5) == 0);
|
g_assert_true(memcmp(s, "world", 5) == 0);
|
||||||
|
|
||||||
closesocket(sock_fd);
|
close(sock_fd);
|
||||||
|
|
||||||
qtest_quit(qts);
|
qtest_quit(qts);
|
||||||
}
|
}
|
||||||
|
@ -99,7 +99,7 @@ static int inet_get_free_port_multiple(int nb, int *port, bool ipv6)
|
|||||||
|
|
||||||
nb = i;
|
nb = i;
|
||||||
for (i = 0; i < nb; i++) {
|
for (i = 0; i < nb; i++) {
|
||||||
closesocket(sock[i]);
|
close(sock[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return nb;
|
return nb;
|
||||||
@ -361,8 +361,8 @@ static void test_stream_fd(void)
|
|||||||
qtest_quit(qts1);
|
qtest_quit(qts1);
|
||||||
qtest_quit(qts0);
|
qtest_quit(qts0);
|
||||||
|
|
||||||
closesocket(sock[0]);
|
close(sock[0]);
|
||||||
closesocket(sock[1]);
|
close(sock[1]);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -487,8 +487,8 @@ static void test_dgram_fd(void)
|
|||||||
qtest_quit(qts1);
|
qtest_quit(qts1);
|
||||||
qtest_quit(qts0);
|
qtest_quit(qts0);
|
||||||
|
|
||||||
closesocket(sv[0]);
|
close(sv[0]);
|
||||||
closesocket(sv[1]);
|
close(sv[1]);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -117,13 +117,13 @@ static int socket_can_bind_connect(const char *hostname, int family)
|
|||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
if (afd != -1) {
|
if (afd != -1) {
|
||||||
closesocket(afd);
|
close(afd);
|
||||||
}
|
}
|
||||||
if (cfd != -1) {
|
if (cfd != -1) {
|
||||||
closesocket(cfd);
|
close(cfd);
|
||||||
}
|
}
|
||||||
if (lfd != -1) {
|
if (lfd != -1) {
|
||||||
closesocket(lfd);
|
close(lfd);
|
||||||
}
|
}
|
||||||
if (res) {
|
if (res) {
|
||||||
freeaddrinfo(res);
|
freeaddrinfo(res);
|
||||||
@ -160,7 +160,7 @@ void socket_check_afunix_support(bool *has_afunix)
|
|||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
fd = socket(PF_UNIX, SOCK_STREAM, 0);
|
fd = socket(PF_UNIX, SOCK_STREAM, 0);
|
||||||
closesocket(fd);
|
close(fd);
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
*has_afunix = (fd != (int)INVALID_SOCKET);
|
*has_afunix = (fd != (int)INVALID_SOCKET);
|
||||||
|
@ -370,16 +370,15 @@ int qemu_bind_wrap(int sockfd, const struct sockaddr *addr,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#undef closesocket
|
#undef close
|
||||||
int qemu_closesocket_wrap(int fd)
|
int qemu_close_wrap(int fd)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
DWORD flags = 0;
|
DWORD flags = 0;
|
||||||
SOCKET s = _get_osfhandle(fd);
|
SOCKET s = INVALID_SOCKET;
|
||||||
|
|
||||||
if (s == INVALID_SOCKET) {
|
if (fd_is_socket(fd)) {
|
||||||
return -1;
|
s = _get_osfhandle(fd);
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If we were to just call _close on the descriptor, it would close the
|
* If we were to just call _close on the descriptor, it would close the
|
||||||
@ -399,10 +398,11 @@ int qemu_closesocket_wrap(int fd)
|
|||||||
errno = EACCES;
|
errno = EACCES;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ret = close(fd);
|
ret = close(fd);
|
||||||
|
|
||||||
if (!SetHandleInformation((HANDLE)s, flags, flags)) {
|
if (s != INVALID_SOCKET && !SetHandleInformation((HANDLE)s, flags, flags)) {
|
||||||
errno = EACCES;
|
errno = EACCES;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -411,14 +411,16 @@ int qemu_closesocket_wrap(int fd)
|
|||||||
* close() returns EBADF since we PROTECT_FROM_CLOSE the underlying handle,
|
* close() returns EBADF since we PROTECT_FROM_CLOSE the underlying handle,
|
||||||
* but the FD is actually freed
|
* but the FD is actually freed
|
||||||
*/
|
*/
|
||||||
if (ret < 0 && errno != EBADF) {
|
if (ret < 0 && (s == INVALID_SOCKET || errno != EBADF)) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (s != INVALID_SOCKET) {
|
||||||
ret = closesocket(s);
|
ret = closesocket(s);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
errno = socket_error();
|
errno = socket_error();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -326,7 +326,7 @@ static int inet_listen_saddr(InetSocketAddress *saddr,
|
|||||||
* recover from this situation, so we need to recreate the
|
* recover from this situation, so we need to recreate the
|
||||||
* socket to allow bind attempts for subsequent ports:
|
* socket to allow bind attempts for subsequent ports:
|
||||||
*/
|
*/
|
||||||
closesocket(slisten);
|
close(slisten);
|
||||||
slisten = -1;
|
slisten = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -337,7 +337,7 @@ static int inet_listen_saddr(InetSocketAddress *saddr,
|
|||||||
listen_failed:
|
listen_failed:
|
||||||
saved_errno = errno;
|
saved_errno = errno;
|
||||||
if (slisten >= 0) {
|
if (slisten >= 0) {
|
||||||
closesocket(slisten);
|
close(slisten);
|
||||||
}
|
}
|
||||||
freeaddrinfo(res);
|
freeaddrinfo(res);
|
||||||
errno = saved_errno;
|
errno = saved_errno;
|
||||||
@ -380,7 +380,7 @@ static int inet_connect_addr(const InetSocketAddress *saddr,
|
|||||||
if (rc < 0) {
|
if (rc < 0) {
|
||||||
error_setg_errno(errp, errno, "Failed to connect to '%s:%s'",
|
error_setg_errno(errp, errno, "Failed to connect to '%s:%s'",
|
||||||
saddr->host, saddr->port);
|
saddr->host, saddr->port);
|
||||||
closesocket(sock);
|
close(sock);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -483,7 +483,7 @@ int inet_connect_saddr(InetSocketAddress *saddr, Error **errp)
|
|||||||
|
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
error_setg_errno(errp, errno, "Unable to set KEEPALIVE");
|
error_setg_errno(errp, errno, "Unable to set KEEPALIVE");
|
||||||
closesocket(sock);
|
close(sock);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -580,7 +580,7 @@ static int inet_dgram_saddr(InetSocketAddress *sraddr,
|
|||||||
|
|
||||||
err:
|
err:
|
||||||
if (sock != -1) {
|
if (sock != -1) {
|
||||||
closesocket(sock);
|
close(sock);
|
||||||
}
|
}
|
||||||
if (local) {
|
if (local) {
|
||||||
freeaddrinfo(local);
|
freeaddrinfo(local);
|
||||||
@ -777,7 +777,7 @@ static int vsock_connect_addr(const VsockSocketAddress *vaddr,
|
|||||||
if (rc < 0) {
|
if (rc < 0) {
|
||||||
error_setg_errno(errp, errno, "Failed to connect to '%s:%s'",
|
error_setg_errno(errp, errno, "Failed to connect to '%s:%s'",
|
||||||
vaddr->cid, vaddr->port);
|
vaddr->cid, vaddr->port);
|
||||||
closesocket(sock);
|
close(sock);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -814,13 +814,13 @@ static int vsock_listen_saddr(VsockSocketAddress *vaddr,
|
|||||||
|
|
||||||
if (bind(slisten, (const struct sockaddr *)&svm, sizeof(svm)) != 0) {
|
if (bind(slisten, (const struct sockaddr *)&svm, sizeof(svm)) != 0) {
|
||||||
error_setg_errno(errp, errno, "Failed to bind socket");
|
error_setg_errno(errp, errno, "Failed to bind socket");
|
||||||
closesocket(slisten);
|
close(slisten);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (listen(slisten, num) != 0) {
|
if (listen(slisten, num) != 0) {
|
||||||
error_setg_errno(errp, errno, "Failed to listen on socket");
|
error_setg_errno(errp, errno, "Failed to listen on socket");
|
||||||
closesocket(slisten);
|
close(slisten);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
return slisten;
|
return slisten;
|
||||||
@ -978,7 +978,7 @@ static int unix_listen_saddr(UnixSocketAddress *saddr,
|
|||||||
|
|
||||||
err:
|
err:
|
||||||
g_free(pathbuf);
|
g_free(pathbuf);
|
||||||
closesocket(sock);
|
close(sock);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1041,7 +1041,7 @@ static int unix_connect_saddr(UnixSocketAddress *saddr, Error **errp)
|
|||||||
return sock;
|
return sock;
|
||||||
|
|
||||||
err:
|
err:
|
||||||
closesocket(sock);
|
close(sock);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1238,7 +1238,7 @@ int socket_listen(SocketAddress *addr, int num, Error **errp)
|
|||||||
*/
|
*/
|
||||||
if (listen(fd, num) != 0) {
|
if (listen(fd, num) != 0) {
|
||||||
error_setg_errno(errp, errno, "Failed to listen on fd socket");
|
error_setg_errno(errp, errno, "Failed to listen on fd socket");
|
||||||
closesocket(fd);
|
close(fd);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user