Commit 9cf50296 authored by Jon Siwek's avatar Jon Siwek

Add explicit close-on-exec check for sockets

To cover cases where SOCK_CLOEXEC is not defined or not implemented.
parent c7114f5c
...@@ -782,6 +782,7 @@ new_tcp_connection(const std::string& host, uint16_t port, ...@@ -782,6 +782,7 @@ new_tcp_connection(const std::string& host, uint16_t port,
#endif #endif
CALL_CFUN(fd, detail::cc_valid_socket, "socket", CALL_CFUN(fd, detail::cc_valid_socket, "socket",
socket(proto == ipv4 ? AF_INET : AF_INET6, socktype, 0)); socket(proto == ipv4 ? AF_INET : AF_INET6, socktype, 0));
child_process_inherit(fd, false);
detail::socket_guard sguard(fd); detail::socket_guard sguard(fd);
if (proto == ipv6) { if (proto == ipv6) {
if (ip_connect<AF_INET6>(fd, res->first, port)) { if (ip_connect<AF_INET6>(fd, res->first, port)) {
...@@ -837,6 +838,7 @@ expected<native_socket> new_ip_acceptor_impl(uint16_t port, const char* addr, ...@@ -837,6 +838,7 @@ expected<native_socket> new_ip_acceptor_impl(uint16_t port, const char* addr,
socktype |= SOCK_CLOEXEC; socktype |= SOCK_CLOEXEC;
#endif #endif
CALL_CFUN(fd, detail::cc_valid_socket, "socket", socket(Family, socktype, 0)); CALL_CFUN(fd, detail::cc_valid_socket, "socket", socket(Family, socktype, 0));
child_process_inherit(fd, false);
// sguard closes the socket in case of exception // sguard closes the socket in case of exception
detail::socket_guard sguard{fd}; detail::socket_guard sguard{fd};
if (reuse_addr) { if (reuse_addr) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment