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

View File

@ -120,6 +120,12 @@ static bool netplay_net_pre_frame(netplay_t *netplay)
} }
#endif #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 */ /* Connection header */
if (netplay_get_info(netplay)) if (netplay_get_info(netplay))
{ {