Merge pull request #3663 from GregorR/netplay-return-of-cloexec

Making all Netplay sockets should be cloexec
This commit is contained in:
Twinaphex 2016-09-26 05:29:09 +02:00 committed by GitHub
commit 2c0d8e8280
2 changed files with 17 additions and 12 deletions

View File

@ -826,6 +826,12 @@ static int init_tcp_connection(const struct addrinfo *res,
bool ret = true;
int fd = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
if (fd < 0)
{
ret = false;
goto end;
}
#if defined(IPPROTO_TCP) && defined(TCP_NODELAY)
{
int flag = 1;
@ -834,11 +840,11 @@ static int init_tcp_connection(const struct addrinfo *res,
}
#endif
if (fd < 0)
{
ret = false;
goto end;
}
#if defined(F_SETFD) && defined(FD_CLOEXEC)
/* Don't let any inherited processes keep open our port */
if (fcntl(fd, F_SETFD, FD_CLOEXEC) < 0)
RARCH_WARN("Cannot set Netplay port to close-on-exec. It may fail to reopen if the client disconnects.\n");
#endif
if (server)
{
@ -856,13 +862,6 @@ static int init_tcp_connection(const struct addrinfo *res,
ret = false;
goto end;
}
#if defined(F_SETFD) && defined(FD_CLOEXEC)
/* Don't let any inherited processes keep open our port */
if (fcntl(fd, F_SETFD, FD_CLOEXEC) < 0)
RARCH_WARN("Cannot set Netplay port to close-on-exec. It may fail to reopen if the client disconnects.\n");
#endif
}
end:

View File

@ -120,6 +120,12 @@ static bool netplay_net_pre_frame(netplay_t *netplay)
}
#endif
#if defined(F_SETFD) && defined(FD_CLOEXEC)
/* Don't let any inherited processes keep open our port */
if (fcntl(netplay->fd, F_SETFD, FD_CLOEXEC) < 0)
RARCH_WARN("Cannot set Netplay port to close-on-exec. It may fail to reopen if the client disconnects.\n");
#endif
/* Connection header */
if (netplay_get_info(netplay))
{