From 3fcbed6bda344dbf16dd0db8930b28d95bc4b4b4 Mon Sep 17 00:00:00 2001 From: Greg Clayton Date: Tue, 19 Oct 2010 03:25:40 +0000 Subject: Stop the driver from handling SIGPIPE in case we communicate with stale sockets so the driver doesn't just crash. Added support for connecting to named sockets (unix IPC sockets) in ConnectionFileDescriptor. Modified the Host::LaunchInNewTerminal() for MacOSX to return the process ID of the inferior process instead of the process ID of the Terminal.app. This was done by modifying the "darwin-debug" executable to connect to lldb through a named unix socket which is passed down as an argument. This allows a quick handshake between "lldb" and "darwin-debug" so we can get the process ID of the inferior and then attach by process ID and avoid attaching to the inferior by process name since there could be more than one process with that name. This still has possible race conditions, those will be fixed in the near future. This fixes the SIGPIPE issues that were sometimes being seen when task_for_pid was failing. llvm-svn: 116792 --- lldb/source/Core/ConnectionFileDescriptor.cpp | 53 +++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) (limited to 'lldb/source/Core/ConnectionFileDescriptor.cpp') diff --git a/lldb/source/Core/ConnectionFileDescriptor.cpp b/lldb/source/Core/ConnectionFileDescriptor.cpp index 292bc746b0b..dc190a1b781 100644 --- a/lldb/source/Core/ConnectionFileDescriptor.cpp +++ b/lldb/source/Core/ConnectionFileDescriptor.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -85,6 +86,11 @@ ConnectionFileDescriptor::Connect (const char *s, Error *error_ptr) unsigned long listen_port = ::strtoul(s + strlen("listen://"), &end, 0); return SocketListen (listen_port, error_ptr); } + else if (strstr(s, "unix-accept://")) + { + // unix://SOCKNAME + return NamedSocketAccept (s + strlen("unix-accept://"), error_ptr); + } else if (strstr(s, "connect://")) { return SocketConnect (s + strlen("connect://"), error_ptr); @@ -399,6 +405,53 @@ ConnectionFileDescriptor::Close (int& fd, Error *error_ptr) return eConnectionStatusError; } +ConnectionStatus +ConnectionFileDescriptor::NamedSocketAccept (const char *socket_name, Error *error_ptr) +{ + ConnectionStatus result = eConnectionStatusError; + struct sockaddr_un saddr_un; + + m_is_socket = true; + + int listen_socket = ::socket (AF_UNIX, SOCK_STREAM, 0); + if (listen_socket == -1) + { + if (error_ptr) + error_ptr->SetErrorToErrno(); + return eConnectionStatusError; + } + + saddr_un.sun_family = AF_UNIX; + ::strncpy(saddr_un.sun_path, socket_name, sizeof(saddr_un.sun_path) - 1); + saddr_un.sun_path[sizeof(saddr_un.sun_path) - 1] = '\0'; + saddr_un.sun_len = SUN_LEN (&saddr_un); + + if (::bind (listen_socket, (struct sockaddr *)&saddr_un, SUN_LEN (&saddr_un)) == 0) + { + if (::listen (listen_socket, 5) == 0) + { + m_fd = ::accept (listen_socket, NULL, 0); + if (m_fd > 0) + { + m_should_close_fd = true; + + if (error_ptr) + error_ptr->Clear(); + result = eConnectionStatusSuccess; + } + } + } + + if (result != eConnectionStatusSuccess) + { + if (error_ptr) + error_ptr->SetErrorToErrno(); + } + // We are done with the listen port + Close (listen_socket, NULL); + return result; +} + ConnectionStatus ConnectionFileDescriptor::SocketListen (uint16_t listen_port_num, Error *error_ptr) { -- cgit v1.2.3