@@ -180,12 +180,9 @@ bool Socket::FindProtocolByScheme(const char *scheme,
180180 return false ;
181181}
182182
183- Socket::Socket (SocketProtocol protocol, bool should_close,
184- bool child_processes_inherit)
183+ Socket::Socket (SocketProtocol protocol, bool should_close)
185184 : IOObject(eFDTypeSocket), m_protocol(protocol),
186- m_socket(kInvalidSocketValue ),
187- m_child_processes_inherit(child_processes_inherit),
188- m_should_close_fd(should_close) {}
185+ m_socket(kInvalidSocketValue ), m_should_close_fd(should_close) {}
189186
190187Socket::~Socket () { Close (); }
191188
@@ -214,33 +211,29 @@ void Socket::Terminate() {
214211}
215212
216213std::unique_ptr<Socket> Socket::Create (const SocketProtocol protocol,
217- bool child_processes_inherit,
218214 Status &error) {
219215 error.Clear ();
220216
217+ const bool should_close = true ;
221218 std::unique_ptr<Socket> socket_up;
222219 switch (protocol) {
223220 case ProtocolTcp:
224- socket_up =
225- std::make_unique<TCPSocket>(true , child_processes_inherit);
221+ socket_up = std::make_unique<TCPSocket>(should_close);
226222 break ;
227223 case ProtocolUdp:
228- socket_up =
229- std::make_unique<UDPSocket>(true , child_processes_inherit);
224+ socket_up = std::make_unique<UDPSocket>(should_close);
230225 break ;
231226 case ProtocolUnixDomain:
232227#if LLDB_ENABLE_POSIX
233- socket_up =
234- std::make_unique<DomainSocket>(true , child_processes_inherit);
228+ socket_up = std::make_unique<DomainSocket>(should_close);
235229#else
236230 error = Status::FromErrorString (
237231 " Unix domain sockets are not supported on this platform." );
238232#endif
239233 break ;
240234 case ProtocolUnixAbstract:
241235#ifdef __linux__
242- socket_up =
243- std::make_unique<AbstractSocket>(child_processes_inherit);
236+ socket_up = std::make_unique<AbstractSocket>();
244237#else
245238 error = Status::FromErrorString (
246239 " Abstract domain sockets are not supported on this platform." );
@@ -255,14 +248,12 @@ std::unique_ptr<Socket> Socket::Create(const SocketProtocol protocol,
255248}
256249
257250llvm::Expected<std::unique_ptr<Socket>>
258- Socket::TcpConnect (llvm::StringRef host_and_port,
259- bool child_processes_inherit) {
251+ Socket::TcpConnect (llvm::StringRef host_and_port) {
260252 Log *log = GetLog (LLDBLog::Connection);
261253 LLDB_LOG (log, " host_and_port = {0}" , host_and_port);
262254
263255 Status error;
264- std::unique_ptr<Socket> connect_socket (
265- Create (ProtocolTcp, child_processes_inherit, error));
256+ std::unique_ptr<Socket> connect_socket = Create (ProtocolTcp, error);
266257 if (error.Fail ())
267258 return error.ToError ();
268259
@@ -274,13 +265,12 @@ Socket::TcpConnect(llvm::StringRef host_and_port,
274265}
275266
276267llvm::Expected<std::unique_ptr<TCPSocket>>
277- Socket::TcpListen (llvm::StringRef host_and_port, bool child_processes_inherit,
278- int backlog) {
268+ Socket::TcpListen (llvm::StringRef host_and_port, int backlog) {
279269 Log *log = GetLog (LLDBLog::Connection);
280270 LLDB_LOG (log, " host_and_port = {0}" , host_and_port);
281271
282272 std::unique_ptr<TCPSocket> listen_socket (
283- new TCPSocket (true , child_processes_inherit ));
273+ new TCPSocket (/* should_close= */ true ));
284274
285275 Status error = listen_socket->Listen (host_and_port, backlog);
286276 if (error.Fail ())
@@ -290,9 +280,8 @@ Socket::TcpListen(llvm::StringRef host_and_port, bool child_processes_inherit,
290280}
291281
292282llvm::Expected<std::unique_ptr<UDPSocket>>
293- Socket::UdpConnect (llvm::StringRef host_and_port,
294- bool child_processes_inherit) {
295- return UDPSocket::Connect (host_and_port, child_processes_inherit);
283+ Socket::UdpConnect (llvm::StringRef host_and_port) {
284+ return UDPSocket::CreateConnected (host_and_port);
296285}
297286
298287llvm::Expected<Socket::HostAndPort> Socket::DecodeHostAndPort (llvm::StringRef host_and_port) {
@@ -445,13 +434,11 @@ int Socket::CloseSocket(NativeSocket sockfd) {
445434}
446435
447436NativeSocket Socket::CreateSocket (const int domain, const int type,
448- const int protocol,
449- bool child_processes_inherit, Status &error) {
437+ const int protocol, Status &error) {
450438 error.Clear ();
451439 auto socket_type = type;
452440#ifdef SOCK_CLOEXEC
453- if (!child_processes_inherit)
454- socket_type |= SOCK_CLOEXEC;
441+ socket_type |= SOCK_CLOEXEC;
455442#endif
456443 auto sock = ::socket (domain, socket_type, protocol);
457444 if (sock == kInvalidSocketValue )
@@ -483,8 +470,7 @@ Status Socket::Accept(const Timeout<std::micro> &timeout, Socket *&socket) {
483470}
484471
485472NativeSocket Socket::AcceptSocket (NativeSocket sockfd, struct sockaddr *addr,
486- socklen_t *addrlen,
487- bool child_processes_inherit, Status &error) {
473+ socklen_t *addrlen, Status &error) {
488474 error.Clear ();
489475#if defined(ANDROID_USE_ACCEPT_WORKAROUND)
490476 // Hack:
@@ -494,7 +480,7 @@ NativeSocket Socket::AcceptSocket(NativeSocket sockfd, struct sockaddr *addr,
494480 // available in older kernels. Using an older libc would fix this issue, but
495481 // introduce other ones, as the old libraries were quite buggy.
496482 int fd = syscall (__NR_accept, sockfd, addr, addrlen);
497- if (fd >= 0 && !child_processes_inherit ) {
483+ if (fd >= 0 ) {
498484 int flags = ::fcntl (fd, F_GETFD);
499485 if (flags != -1 && ::fcntl (fd, F_SETFD, flags | FD_CLOEXEC) != -1 )
500486 return fd;
@@ -503,10 +489,7 @@ NativeSocket Socket::AcceptSocket(NativeSocket sockfd, struct sockaddr *addr,
503489 }
504490 return fd;
505491#elif defined(SOCK_CLOEXEC) && defined(HAVE_ACCEPT4)
506- int flags = 0 ;
507- if (!child_processes_inherit) {
508- flags |= SOCK_CLOEXEC;
509- }
492+ int flags = SOCK_CLOEXEC;
510493 NativeSocket fd = llvm::sys::RetryAfterSignal (
511494 static_cast <NativeSocket>(-1 ), ::accept4, sockfd, addr, addrlen, flags);
512495#else
0 commit comments