From c1dff7152592f1beee9059ee8e2cb3cc68baea4d Mon Sep 17 00:00:00 2001 From: Pavel Labath Date: Thu, 28 Nov 2024 08:27:36 +0100 Subject: [PATCH] [lldb] Remove child_process_inherit from the socket classes (#117699) It's never set to true. Also, using inheritable FDs in a multithreaded process pretty much guarantees descriptor leaks. It's better to explicitly pass a specific FD to a specific subprocess, which we already mostly can do using the ProcessLaunchInfo FileActions. --- lldb/include/lldb/Host/Socket.h | 18 +++---- lldb/include/lldb/Host/common/TCPSocket.h | 5 +- lldb/include/lldb/Host/common/UDPSocket.h | 4 +- lldb/include/lldb/Host/linux/AbstractSocket.h | 2 +- lldb/include/lldb/Host/posix/DomainSocket.h | 7 ++- lldb/source/Host/common/Socket.cpp | 53 +++++++------------ lldb/source/Host/common/TCPSocket.cpp | 25 ++++----- lldb/source/Host/common/UDPSocket.cpp | 14 ++--- lldb/source/Host/linux/AbstractSocket.cpp | 3 +- .../posix/ConnectionFileDescriptorPosix.cpp | 10 ++-- lldb/source/Host/posix/DomainSocket.cpp | 28 ++++------ .../gdb-remote/GDBRemoteCommunication.cpp | 3 +- lldb/tools/lldb-server/lldb-platform.cpp | 12 ++--- lldb/unittests/Host/MainLoopTest.cpp | 7 +-- lldb/unittests/Host/SocketTest.cpp | 15 +++--- .../Host/SocketTestUtilities.cpp | 10 ++-- lldb/unittests/debugserver/RNBSocketTest.cpp | 2 +- .../tools/lldb-server/tests/TestClient.cpp | 2 +- 18 files changed, 83 insertions(+), 137 deletions(-) diff --git a/lldb/include/lldb/Host/Socket.h b/lldb/include/lldb/Host/Socket.h index 0e542b05a085c6..e98797b36c8a5d 100644 --- a/lldb/include/lldb/Host/Socket.h +++ b/lldb/include/lldb/Host/Socket.h @@ -94,7 +94,6 @@ class Socket : public IOObject { static void Terminate(); static std::unique_ptr Create(const SocketProtocol protocol, - bool child_processes_inherit, Status &error); virtual Status Connect(llvm::StringRef name) = 0; @@ -115,14 +114,13 @@ class Socket : public IOObject { // implemented separately because the caller may wish to manipulate or query // the socket after it is initialized, but before entering a blocking accept. static llvm::Expected> - TcpListen(llvm::StringRef host_and_port, bool child_processes_inherit, - int backlog = 5); + TcpListen(llvm::StringRef host_and_port, int backlog = 5); static llvm::Expected> - TcpConnect(llvm::StringRef host_and_port, bool child_processes_inherit); + TcpConnect(llvm::StringRef host_and_port); static llvm::Expected> - UdpConnect(llvm::StringRef host_and_port, bool child_processes_inherit); + UdpConnect(llvm::StringRef host_and_port); static int GetOption(NativeSocket sockfd, int level, int option_name, int &option_value); @@ -154,8 +152,7 @@ class Socket : public IOObject { virtual std::string GetRemoteConnectionURI() const { return ""; }; protected: - Socket(SocketProtocol protocol, bool should_close, - bool m_child_process_inherit); + Socket(SocketProtocol protocol, bool should_close); virtual size_t Send(const void *buf, const size_t num_bytes); @@ -163,15 +160,12 @@ class Socket : public IOObject { static Status GetLastError(); static void SetLastError(Status &error); static NativeSocket CreateSocket(const int domain, const int type, - const int protocol, - bool child_processes_inherit, Status &error); + const int protocol, Status &error); static NativeSocket AcceptSocket(NativeSocket sockfd, struct sockaddr *addr, - socklen_t *addrlen, - bool child_processes_inherit, Status &error); + socklen_t *addrlen, Status &error); SocketProtocol m_protocol; NativeSocket m_socket; - bool m_child_processes_inherit; bool m_should_close_fd; }; diff --git a/lldb/include/lldb/Host/common/TCPSocket.h b/lldb/include/lldb/Host/common/TCPSocket.h index eefe0240fe4a95..ca36622691fe9a 100644 --- a/lldb/include/lldb/Host/common/TCPSocket.h +++ b/lldb/include/lldb/Host/common/TCPSocket.h @@ -17,9 +17,8 @@ namespace lldb_private { class TCPSocket : public Socket { public: - TCPSocket(bool should_close, bool child_processes_inherit); - TCPSocket(NativeSocket socket, bool should_close, - bool child_processes_inherit); + explicit TCPSocket(bool should_close); + TCPSocket(NativeSocket socket, bool should_close); ~TCPSocket() override; // returns port number or 0 if error diff --git a/lldb/include/lldb/Host/common/UDPSocket.h b/lldb/include/lldb/Host/common/UDPSocket.h index 7348010d02ada2..63012d4fb6025f 100644 --- a/lldb/include/lldb/Host/common/UDPSocket.h +++ b/lldb/include/lldb/Host/common/UDPSocket.h @@ -14,10 +14,10 @@ namespace lldb_private { class UDPSocket : public Socket { public: - UDPSocket(bool should_close, bool child_processes_inherit); + explicit UDPSocket(bool should_close); static llvm::Expected> - Connect(llvm::StringRef name, bool child_processes_inherit); + CreateConnected(llvm::StringRef name); std::string GetRemoteConnectionURI() const override; diff --git a/lldb/include/lldb/Host/linux/AbstractSocket.h b/lldb/include/lldb/Host/linux/AbstractSocket.h index 78a567a6b90953..accfd01457a5e0 100644 --- a/lldb/include/lldb/Host/linux/AbstractSocket.h +++ b/lldb/include/lldb/Host/linux/AbstractSocket.h @@ -14,7 +14,7 @@ namespace lldb_private { class AbstractSocket : public DomainSocket { public: - AbstractSocket(bool child_processes_inherit); + AbstractSocket(); protected: size_t GetNameOffset() const override; diff --git a/lldb/include/lldb/Host/posix/DomainSocket.h b/lldb/include/lldb/Host/posix/DomainSocket.h index 983f43bd633719..d4e0d43ee169c1 100644 --- a/lldb/include/lldb/Host/posix/DomainSocket.h +++ b/lldb/include/lldb/Host/posix/DomainSocket.h @@ -14,9 +14,8 @@ namespace lldb_private { class DomainSocket : public Socket { public: - DomainSocket(NativeSocket socket, bool should_close, - bool child_processes_inherit); - DomainSocket(bool should_close, bool child_processes_inherit); + DomainSocket(NativeSocket socket, bool should_close); + explicit DomainSocket(bool should_close); Status Connect(llvm::StringRef name) override; Status Listen(llvm::StringRef name, int backlog) override; @@ -29,7 +28,7 @@ class DomainSocket : public Socket { std::string GetRemoteConnectionURI() const override; protected: - DomainSocket(SocketProtocol protocol, bool child_processes_inherit); + DomainSocket(SocketProtocol protocol); virtual size_t GetNameOffset() const; virtual void DeleteSocketFile(llvm::StringRef name); diff --git a/lldb/source/Host/common/Socket.cpp b/lldb/source/Host/common/Socket.cpp index 63396f7b4abc9c..0ccff41a552068 100644 --- a/lldb/source/Host/common/Socket.cpp +++ b/lldb/source/Host/common/Socket.cpp @@ -180,12 +180,9 @@ bool Socket::FindProtocolByScheme(const char *scheme, return false; } -Socket::Socket(SocketProtocol protocol, bool should_close, - bool child_processes_inherit) +Socket::Socket(SocketProtocol protocol, bool should_close) : IOObject(eFDTypeSocket), m_protocol(protocol), - m_socket(kInvalidSocketValue), - m_child_processes_inherit(child_processes_inherit), - m_should_close_fd(should_close) {} + m_socket(kInvalidSocketValue), m_should_close_fd(should_close) {} Socket::~Socket() { Close(); } @@ -214,24 +211,21 @@ void Socket::Terminate() { } std::unique_ptr Socket::Create(const SocketProtocol protocol, - bool child_processes_inherit, Status &error) { error.Clear(); + const bool should_close = true; std::unique_ptr socket_up; switch (protocol) { case ProtocolTcp: - socket_up = - std::make_unique(true, child_processes_inherit); + socket_up = std::make_unique(should_close); break; case ProtocolUdp: - socket_up = - std::make_unique(true, child_processes_inherit); + socket_up = std::make_unique(should_close); break; case ProtocolUnixDomain: #if LLDB_ENABLE_POSIX - socket_up = - std::make_unique(true, child_processes_inherit); + socket_up = std::make_unique(should_close); #else error = Status::FromErrorString( "Unix domain sockets are not supported on this platform."); @@ -239,8 +233,7 @@ std::unique_ptr Socket::Create(const SocketProtocol protocol, break; case ProtocolUnixAbstract: #ifdef __linux__ - socket_up = - std::make_unique(child_processes_inherit); + socket_up = std::make_unique(); #else error = Status::FromErrorString( "Abstract domain sockets are not supported on this platform."); @@ -255,14 +248,12 @@ std::unique_ptr Socket::Create(const SocketProtocol protocol, } llvm::Expected> -Socket::TcpConnect(llvm::StringRef host_and_port, - bool child_processes_inherit) { +Socket::TcpConnect(llvm::StringRef host_and_port) { Log *log = GetLog(LLDBLog::Connection); LLDB_LOG(log, "host_and_port = {0}", host_and_port); Status error; - std::unique_ptr connect_socket( - Create(ProtocolTcp, child_processes_inherit, error)); + std::unique_ptr connect_socket = Create(ProtocolTcp, error); if (error.Fail()) return error.ToError(); @@ -274,13 +265,12 @@ Socket::TcpConnect(llvm::StringRef host_and_port, } llvm::Expected> -Socket::TcpListen(llvm::StringRef host_and_port, bool child_processes_inherit, - int backlog) { +Socket::TcpListen(llvm::StringRef host_and_port, int backlog) { Log *log = GetLog(LLDBLog::Connection); LLDB_LOG(log, "host_and_port = {0}", host_and_port); std::unique_ptr listen_socket( - new TCPSocket(true, child_processes_inherit)); + new TCPSocket(/*should_close=*/true)); Status error = listen_socket->Listen(host_and_port, backlog); if (error.Fail()) @@ -290,9 +280,8 @@ Socket::TcpListen(llvm::StringRef host_and_port, bool child_processes_inherit, } llvm::Expected> -Socket::UdpConnect(llvm::StringRef host_and_port, - bool child_processes_inherit) { - return UDPSocket::Connect(host_and_port, child_processes_inherit); +Socket::UdpConnect(llvm::StringRef host_and_port) { + return UDPSocket::CreateConnected(host_and_port); } llvm::Expected Socket::DecodeHostAndPort(llvm::StringRef host_and_port) { @@ -445,13 +434,11 @@ int Socket::CloseSocket(NativeSocket sockfd) { } NativeSocket Socket::CreateSocket(const int domain, const int type, - const int protocol, - bool child_processes_inherit, Status &error) { + const int protocol, Status &error) { error.Clear(); auto socket_type = type; #ifdef SOCK_CLOEXEC - if (!child_processes_inherit) - socket_type |= SOCK_CLOEXEC; + socket_type |= SOCK_CLOEXEC; #endif auto sock = ::socket(domain, socket_type, protocol); if (sock == kInvalidSocketValue) @@ -483,8 +470,7 @@ Status Socket::Accept(const Timeout &timeout, Socket *&socket) { } NativeSocket Socket::AcceptSocket(NativeSocket sockfd, struct sockaddr *addr, - socklen_t *addrlen, - bool child_processes_inherit, Status &error) { + socklen_t *addrlen, Status &error) { error.Clear(); #if defined(ANDROID_USE_ACCEPT_WORKAROUND) // Hack: @@ -494,7 +480,7 @@ NativeSocket Socket::AcceptSocket(NativeSocket sockfd, struct sockaddr *addr, // available in older kernels. Using an older libc would fix this issue, but // introduce other ones, as the old libraries were quite buggy. int fd = syscall(__NR_accept, sockfd, addr, addrlen); - if (fd >= 0 && !child_processes_inherit) { + if (fd >= 0) { int flags = ::fcntl(fd, F_GETFD); if (flags != -1 && ::fcntl(fd, F_SETFD, flags | FD_CLOEXEC) != -1) return fd; @@ -503,10 +489,7 @@ NativeSocket Socket::AcceptSocket(NativeSocket sockfd, struct sockaddr *addr, } return fd; #elif defined(SOCK_CLOEXEC) && defined(HAVE_ACCEPT4) - int flags = 0; - if (!child_processes_inherit) { - flags |= SOCK_CLOEXEC; - } + int flags = SOCK_CLOEXEC; NativeSocket fd = llvm::sys::RetryAfterSignal( static_cast(-1), ::accept4, sockfd, addr, addrlen, flags); #else diff --git a/lldb/source/Host/common/TCPSocket.cpp b/lldb/source/Host/common/TCPSocket.cpp index 2d16b605af9497..5d863954ee8868 100644 --- a/lldb/source/Host/common/TCPSocket.cpp +++ b/lldb/source/Host/common/TCPSocket.cpp @@ -38,18 +38,15 @@ using namespace lldb_private; static const int kType = SOCK_STREAM; -TCPSocket::TCPSocket(bool should_close, bool child_processes_inherit) - : Socket(ProtocolTcp, should_close, child_processes_inherit) {} +TCPSocket::TCPSocket(bool should_close) : Socket(ProtocolTcp, should_close) {} TCPSocket::TCPSocket(NativeSocket socket, const TCPSocket &listen_socket) - : Socket(ProtocolTcp, listen_socket.m_should_close_fd, - listen_socket.m_child_processes_inherit) { + : Socket(ProtocolTcp, listen_socket.m_should_close_fd) { m_socket = socket; } -TCPSocket::TCPSocket(NativeSocket socket, bool should_close, - bool child_processes_inherit) - : Socket(ProtocolTcp, should_close, child_processes_inherit) { +TCPSocket::TCPSocket(NativeSocket socket, bool should_close) + : Socket(ProtocolTcp, should_close) { m_socket = socket; } @@ -124,8 +121,7 @@ Status TCPSocket::CreateSocket(int domain) { error = Close(); if (error.Fail()) return error; - m_socket = Socket::CreateSocket(domain, kType, IPPROTO_TCP, - m_child_processes_inherit, error); + m_socket = Socket::CreateSocket(domain, kType, IPPROTO_TCP, error); return error; } @@ -183,8 +179,8 @@ Status TCPSocket::Listen(llvm::StringRef name, int backlog) { std::vector addresses = SocketAddress::GetAddressInfo( host_port->hostname.c_str(), nullptr, AF_UNSPEC, SOCK_STREAM, IPPROTO_TCP); for (SocketAddress &address : addresses) { - int fd = Socket::CreateSocket(address.GetFamily(), kType, IPPROTO_TCP, - m_child_processes_inherit, error); + int fd = + Socket::CreateSocket(address.GetFamily(), kType, IPPROTO_TCP, error); if (error.Fail() || fd < 0) continue; @@ -241,14 +237,13 @@ TCPSocket::Accept(MainLoopBase &loop, std::vector handles; for (auto socket : m_listen_sockets) { auto fd = socket.first; - auto io_sp = - std::make_shared(fd, false, this->m_child_processes_inherit); + auto io_sp = std::make_shared(fd, false); auto cb = [this, fd, sock_cb](MainLoopBase &loop) { lldb_private::SocketAddress AcceptAddr; socklen_t sa_len = AcceptAddr.GetMaxLength(); Status error; - NativeSocket sock = AcceptSocket(fd, &AcceptAddr.sockaddr(), &sa_len, - m_child_processes_inherit, error); + NativeSocket sock = + AcceptSocket(fd, &AcceptAddr.sockaddr(), &sa_len, error); Log *log = GetLog(LLDBLog::Host); if (error.Fail()) { LLDB_LOG(log, "AcceptSocket({0}): {1}", fd, error); diff --git a/lldb/source/Host/common/UDPSocket.cpp b/lldb/source/Host/common/UDPSocket.cpp index 05d7b2e6506027..f394bda346e1d7 100644 --- a/lldb/source/Host/common/UDPSocket.cpp +++ b/lldb/source/Host/common/UDPSocket.cpp @@ -27,12 +27,12 @@ static const int kType = SOCK_DGRAM; static const char *g_not_supported_error = "Not supported"; -UDPSocket::UDPSocket(NativeSocket socket) : Socket(ProtocolUdp, true, true) { +UDPSocket::UDPSocket(NativeSocket socket) + : Socket(ProtocolUdp, /*should_close=*/true) { m_socket = socket; } -UDPSocket::UDPSocket(bool should_close, bool child_processes_inherit) - : Socket(ProtocolUdp, should_close, child_processes_inherit) {} +UDPSocket::UDPSocket(bool should_close) : Socket(ProtocolUdp, should_close) {} size_t UDPSocket::Send(const void *buf, const size_t num_bytes) { return ::sendto(m_socket, static_cast(buf), num_bytes, 0, @@ -48,7 +48,7 @@ Status UDPSocket::Listen(llvm::StringRef name, int backlog) { } llvm::Expected> -UDPSocket::Connect(llvm::StringRef name, bool child_processes_inherit) { +UDPSocket::CreateConnected(llvm::StringRef name) { std::unique_ptr socket; Log *log = GetLog(LLDBLog::Connection); @@ -84,9 +84,9 @@ UDPSocket::Connect(llvm::StringRef name, bool child_processes_inherit) { for (struct addrinfo *service_info_ptr = service_info_list; service_info_ptr != nullptr; service_info_ptr = service_info_ptr->ai_next) { - auto send_fd = CreateSocket( - service_info_ptr->ai_family, service_info_ptr->ai_socktype, - service_info_ptr->ai_protocol, child_processes_inherit, error); + auto send_fd = + CreateSocket(service_info_ptr->ai_family, service_info_ptr->ai_socktype, + service_info_ptr->ai_protocol, error); if (error.Success()) { socket.reset(new UDPSocket(send_fd)); socket->m_sockaddr = service_info_ptr; diff --git a/lldb/source/Host/linux/AbstractSocket.cpp b/lldb/source/Host/linux/AbstractSocket.cpp index 833234028c865b..8393a80e86e723 100644 --- a/lldb/source/Host/linux/AbstractSocket.cpp +++ b/lldb/source/Host/linux/AbstractSocket.cpp @@ -13,8 +13,7 @@ using namespace lldb; using namespace lldb_private; -AbstractSocket::AbstractSocket(bool child_processes_inherit) - : DomainSocket(ProtocolUnixAbstract, child_processes_inherit) {} +AbstractSocket::AbstractSocket() : DomainSocket(ProtocolUnixAbstract) {} size_t AbstractSocket::GetNameOffset() const { return 1; } diff --git a/lldb/source/Host/posix/ConnectionFileDescriptorPosix.cpp b/lldb/source/Host/posix/ConnectionFileDescriptorPosix.cpp index 903bfc50def3aa..6bdc33f8923281 100644 --- a/lldb/source/Host/posix/ConnectionFileDescriptorPosix.cpp +++ b/lldb/source/Host/posix/ConnectionFileDescriptorPosix.cpp @@ -535,7 +535,7 @@ lldb::ConnectionStatus ConnectionFileDescriptor::AcceptSocket( Status *error_ptr) { Status error; std::unique_ptr listening_socket = - Socket::Create(socket_protocol, /*child_processes_inherit=*/false, error); + Socket::Create(socket_protocol, error); Socket *accepted_socket; if (!error.Fail()) @@ -562,8 +562,7 @@ ConnectionFileDescriptor::ConnectSocket(Socket::SocketProtocol socket_protocol, llvm::StringRef socket_name, Status *error_ptr) { Status error; - std::unique_ptr socket = - Socket::Create(socket_protocol, /*child_processes_inherit=*/false, error); + std::unique_ptr socket = Socket::Create(socket_protocol, error); if (!error.Fail()) error = socket->Connect(socket_name); @@ -644,8 +643,7 @@ ConnectionFileDescriptor::ConnectUDP(llvm::StringRef s, Status *error_ptr) { if (error_ptr) *error_ptr = Status(); - llvm::Expected> socket = - Socket::UdpConnect(s, /*child_processes_inherit=*/false); + llvm::Expected> socket = Socket::UdpConnect(s); if (!socket) { if (error_ptr) *error_ptr = Status::FromError(socket.takeError()); @@ -690,7 +688,7 @@ ConnectionFileDescriptor::ConnectFD(llvm::StringRef s, // this. For now, we assume we must assume we don't own it. std::unique_ptr tcp_socket; - tcp_socket = std::make_unique(fd, false, false); + tcp_socket = std::make_unique(fd, /*should_close=*/false); // Try and get a socket option from this file descriptor to see if // this is a socket and set m_is_socket accordingly. int resuse; diff --git a/lldb/source/Host/posix/DomainSocket.cpp b/lldb/source/Host/posix/DomainSocket.cpp index 369123f2239302..0451834630d33f 100644 --- a/lldb/source/Host/posix/DomainSocket.cpp +++ b/lldb/source/Host/posix/DomainSocket.cpp @@ -58,24 +58,20 @@ static bool SetSockAddr(llvm::StringRef name, const size_t name_offset, return true; } -DomainSocket::DomainSocket(bool should_close, bool child_processes_inherit) - : DomainSocket(kInvalidSocketValue, should_close, child_processes_inherit) { -} +DomainSocket::DomainSocket(bool should_close) + : DomainSocket(kInvalidSocketValue, should_close) {} -DomainSocket::DomainSocket(NativeSocket socket, bool should_close, - bool child_processes_inherit) - : Socket(ProtocolUnixDomain, should_close, child_processes_inherit) { +DomainSocket::DomainSocket(NativeSocket socket, bool should_close) + : Socket(ProtocolUnixDomain, should_close) { m_socket = socket; } -DomainSocket::DomainSocket(SocketProtocol protocol, - bool child_processes_inherit) - : Socket(protocol, true, child_processes_inherit) {} +DomainSocket::DomainSocket(SocketProtocol protocol) + : Socket(protocol, /*should_close=*/true) {} DomainSocket::DomainSocket(NativeSocket socket, const DomainSocket &listen_socket) - : Socket(ProtocolUnixDomain, listen_socket.m_should_close_fd, - listen_socket.m_child_processes_inherit) { + : Socket(ProtocolUnixDomain, listen_socket.m_should_close_fd) { m_socket = socket; } @@ -86,7 +82,7 @@ Status DomainSocket::Connect(llvm::StringRef name) { return Status::FromErrorString("Failed to set socket address"); Status error; - m_socket = CreateSocket(kDomain, kType, 0, m_child_processes_inherit, error); + m_socket = CreateSocket(kDomain, kType, 0, error); if (error.Fail()) return error; if (llvm::sys::RetryAfterSignal(-1, ::connect, GetNativeSocket(), @@ -105,7 +101,7 @@ Status DomainSocket::Listen(llvm::StringRef name, int backlog) { DeleteSocketFile(name); Status error; - m_socket = CreateSocket(kDomain, kType, 0, m_child_processes_inherit, error); + m_socket = CreateSocket(kDomain, kType, 0, error); if (error.Fail()) return error; if (::bind(GetNativeSocket(), (struct sockaddr *)&saddr_un, saddr_un_len) == @@ -121,13 +117,11 @@ llvm::Expected> DomainSocket::Accept( MainLoopBase &loop, std::function socket)> sock_cb) { // TODO: Refactor MainLoop to avoid the shared_ptr requirement. - auto io_sp = std::make_shared(GetNativeSocket(), false, - m_child_processes_inherit); + auto io_sp = std::make_shared(GetNativeSocket(), false); auto cb = [this, sock_cb](MainLoopBase &loop) { Log *log = GetLog(LLDBLog::Host); Status error; - auto conn_fd = AcceptSocket(GetNativeSocket(), nullptr, nullptr, - m_child_processes_inherit, error); + auto conn_fd = AcceptSocket(GetNativeSocket(), nullptr, nullptr, error); if (error.Fail()) { LLDB_LOG(log, "AcceptSocket({0}): {1}", GetNativeSocket(), error); return; diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp index 67b41b1e77a533..f746ced1ff4130 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp @@ -1216,9 +1216,8 @@ void GDBRemoteCommunication::DumpHistory(Stream &strm) { m_history.Dump(strm); } llvm::Error GDBRemoteCommunication::ConnectLocally(GDBRemoteCommunication &client, GDBRemoteCommunication &server) { - const bool child_processes_inherit = false; const int backlog = 5; - TCPSocket listen_socket(true, child_processes_inherit); + TCPSocket listen_socket(true); if (llvm::Error error = listen_socket.Listen("localhost:0", backlog).ToError()) return error; diff --git a/lldb/tools/lldb-server/lldb-platform.cpp b/lldb/tools/lldb-server/lldb-platform.cpp index 735a558810da58..880b45b989b9c7 100644 --- a/lldb/tools/lldb-server/lldb-platform.cpp +++ b/lldb/tools/lldb-server/lldb-platform.cpp @@ -181,8 +181,7 @@ static Status ListenGdbConnectionsIfNeeded( if (protocol != Socket::ProtocolTcp) return Status(); - gdb_sock = std::make_unique( - /*should_close=*/true, /*child_processes_inherit=*/false); + gdb_sock = std::make_unique(/*should_close=*/true); Status error = gdb_sock->Listen(gdb_address, backlog); if (error.Fail()) return error; @@ -474,12 +473,10 @@ int main_platform(int argc, char *argv[]) { GDBRemoteCommunicationServerPlatform platform(protocol, gdbserver_port); Socket *socket; if (protocol == Socket::ProtocolTcp) - socket = new TCPSocket(sockfd, /*should_close=*/true, - /*child_processes_inherit=*/false); + socket = new TCPSocket(sockfd, /*should_close=*/true); else { #if LLDB_ENABLE_POSIX - socket = new DomainSocket(sockfd, /*should_close=*/true, - /*child_processes_inherit=*/false); + socket = new DomainSocket(sockfd, /*should_close=*/true); #else WithColor::error() << "lldb-platform child: Unix domain sockets are not " "supported on this platform."; @@ -510,8 +507,7 @@ int main_platform(int argc, char *argv[]) { return socket_error; } - std::unique_ptr platform_sock = - Socket::Create(protocol, /*child_processes_inherit=*/false, error); + std::unique_ptr platform_sock = Socket::Create(protocol, error); if (error.Fail()) { printf("Failed to create platform socket: %s\n", error.AsCString()); return socket_error; diff --git a/lldb/unittests/Host/MainLoopTest.cpp b/lldb/unittests/Host/MainLoopTest.cpp index 462aae50850438..e18489978e90c0 100644 --- a/lldb/unittests/Host/MainLoopTest.cpp +++ b/lldb/unittests/Host/MainLoopTest.cpp @@ -27,17 +27,14 @@ class MainLoopTest : public testing::Test { SubsystemRAII subsystems; void SetUp() override { - bool child_processes_inherit = false; Status error; - std::unique_ptr listen_socket_up( - new TCPSocket(true, child_processes_inherit)); + auto listen_socket_up = std::make_unique(true); ASSERT_TRUE(error.Success()); error = listen_socket_up->Listen("localhost:0", 5); ASSERT_TRUE(error.Success()); Socket *accept_socket; - std::unique_ptr connect_socket_up( - new TCPSocket(true, child_processes_inherit)); + auto connect_socket_up = std::make_unique(true); error = connect_socket_up->Connect( llvm::formatv("localhost:{0}", listen_socket_up->GetLocalPortNumber()) .str()); diff --git a/lldb/unittests/Host/SocketTest.cpp b/lldb/unittests/Host/SocketTest.cpp index c020f1bff04798..b20cfe54640285 100644 --- a/lldb/unittests/Host/SocketTest.cpp +++ b/lldb/unittests/Host/SocketTest.cpp @@ -100,7 +100,7 @@ TEST_P(SocketTest, DomainMainLoopAccept) { return; auto listen_socket_up = std::make_unique( - /*should_close=*/true, /*child_process_inherit=*/false); + /*should_close=*/true); Status error = listen_socket_up->Listen(Path, 5); ASSERT_THAT_ERROR(error.ToError(), llvm::Succeeded()); ASSERT_TRUE(listen_socket_up->IsValid()); @@ -115,7 +115,7 @@ TEST_P(SocketTest, DomainMainLoopAccept) { ASSERT_THAT_EXPECTED(expected_handles, llvm::Succeeded()); auto connect_socket_up = std::make_unique( - /*should_close=*/true, /*child_process_inherit=*/false); + /*should_close=*/true); ASSERT_THAT_ERROR(connect_socket_up->Connect(Path).ToError(), llvm::Succeeded()); ASSERT_TRUE(connect_socket_up->IsValid()); @@ -160,9 +160,7 @@ TEST_P(SocketTest, TCPMainLoopAccept) { if (!HostSupportsProtocol()) return; - const bool child_processes_inherit = false; - auto listen_socket_up = - std::make_unique(true, child_processes_inherit); + auto listen_socket_up = std::make_unique(true); Status error = listen_socket_up->Listen( llvm::formatv("[{0}]:0", GetParam().localhost_ip).str(), 5); ASSERT_THAT_ERROR(error.ToError(), llvm::Succeeded()); @@ -177,8 +175,7 @@ TEST_P(SocketTest, TCPMainLoopAccept) { }); ASSERT_THAT_EXPECTED(expected_handles, llvm::Succeeded()); - std::unique_ptr connect_socket_up( - new TCPSocket(true, child_processes_inherit)); + auto connect_socket_up = std::make_unique(true); ASSERT_THAT_ERROR( connect_socket_up ->Connect(llvm::formatv("[{0}]:{1}", GetParam().localhost_ip, @@ -218,7 +215,7 @@ TEST_P(SocketTest, UDPConnect) { if (!HostSupportsIPv4()) return; llvm::Expected> socket = - UDPSocket::Connect("127.0.0.1:0", /*child_processes_inherit=*/false); + UDPSocket::CreateConnected("127.0.0.1:0"); ASSERT_THAT_EXPECTED(socket, llvm::Succeeded()); EXPECT_TRUE(socket.get()->IsValid()); @@ -253,7 +250,7 @@ TEST_P(SocketTest, UDPGetConnectURI) { if (!HostSupportsIPv4()) return; llvm::Expected> socket = - UDPSocket::Connect("127.0.0.1:0", /*child_processes_inherit=*/false); + UDPSocket::CreateConnected("127.0.0.1:0"); ASSERT_THAT_EXPECTED(socket, llvm::Succeeded()); std::string uri = socket.get()->GetRemoteConnectionURI(); diff --git a/lldb/unittests/TestingSupport/Host/SocketTestUtilities.cpp b/lldb/unittests/TestingSupport/Host/SocketTestUtilities.cpp index 417900e7674dca..eb5bda0fabc770 100644 --- a/lldb/unittests/TestingSupport/Host/SocketTestUtilities.cpp +++ b/lldb/unittests/TestingSupport/Host/SocketTestUtilities.cpp @@ -24,18 +24,15 @@ void lldb_private::CreateConnectedSockets( llvm::StringRef listen_remote_address, const std::function &get_connect_addr, std::unique_ptr *a_up, std::unique_ptr *b_up) { - bool child_processes_inherit = false; Status error; - std::unique_ptr listen_socket_up( - new SocketType(true, child_processes_inherit)); + auto listen_socket_up = std::make_unique(true); ASSERT_THAT_ERROR(error.ToError(), llvm::Succeeded()); error = listen_socket_up->Listen(listen_remote_address, 5); ASSERT_THAT_ERROR(error.ToError(), llvm::Succeeded()); ASSERT_TRUE(listen_socket_up->IsValid()); std::string connect_remote_address = get_connect_addr(*listen_socket_up); - std::unique_ptr connect_socket_up( - new SocketType(true, child_processes_inherit)); + auto connect_socket_up = std::make_unique(true); ASSERT_THAT_ERROR(error.ToError(), llvm::Succeeded()); error = connect_socket_up->Connect(connect_remote_address); ASSERT_THAT_ERROR(error.ToError(), llvm::Succeeded()); @@ -85,8 +82,7 @@ void lldb_private::CreateDomainConnectedSockets( #endif static bool CheckIPSupport(llvm::StringRef Proto, llvm::StringRef Addr) { - llvm::Expected> Sock = Socket::TcpListen( - Addr, /*child_processes_inherit=*/false); + llvm::Expected> Sock = Socket::TcpListen(Addr); if (Sock) return true; llvm::Error Err = Sock.takeError(); diff --git a/lldb/unittests/debugserver/RNBSocketTest.cpp b/lldb/unittests/debugserver/RNBSocketTest.cpp index fe2e79e1fedf97..342ae10979973c 100644 --- a/lldb/unittests/debugserver/RNBSocketTest.cpp +++ b/lldb/unittests/debugserver/RNBSocketTest.cpp @@ -29,7 +29,7 @@ static void ServerCallbackv4(const void *baton, in_port_t port) { char addr_buffer[256]; sprintf(addr_buffer, "%s:%d", (const char *)baton, port); llvm::Expected> socket_or_err = - Socket::TcpConnect(addr_buffer, false); + Socket::TcpConnect(addr_buffer); ASSERT_THAT_EXPECTED(socket_or_err, llvm::Succeeded()); Socket *client_socket = socket_or_err->get(); diff --git a/lldb/unittests/tools/lldb-server/tests/TestClient.cpp b/lldb/unittests/tools/lldb-server/tests/TestClient.cpp index 9cbdf5278816d1..48e089bc0fcff7 100644 --- a/lldb/unittests/tools/lldb-server/tests/TestClient.cpp +++ b/lldb/unittests/tools/lldb-server/tests/TestClient.cpp @@ -87,7 +87,7 @@ TestClient::launchCustom(StringRef Log, bool disable_stdio, const std::string &LocalhostIP = *LocalhostIPOrErr; Status status; - TCPSocket listen_socket(true, false); + TCPSocket listen_socket(true); status = listen_socket.Listen(LocalhostIP + ":0", 5); if (status.Fail()) return status.ToError();