summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid 'Digit' Turner <digit@google.com>2010-06-10 18:29:33 -0700
committerDavid 'Digit' Turner <digit@google.com>2010-06-10 22:58:22 -0700
commit8bff9a31aa13ff83ccaedd54ebda96770e6cf910 (patch)
treeb198c6d9535c41554620f5464e24017b066d35fb
parent038fbae518e904c7aba64779714a22dbeeb90887 (diff)
downloadbionic-8bff9a31aa13ff83ccaedd54ebda96770e6cf910.zip
bionic-8bff9a31aa13ff83ccaedd54ebda96770e6cf910.tar.gz
bionic-8bff9a31aa13ff83ccaedd54ebda96770e6cf910.tar.bz2
linker: remove libcutils dependency by re-implementing simpler socket_local_client.
Change-Id: I87f29fd59454d713b9ddfb13e6cf114822f52efd
-rw-r--r--linker/Android.mk2
-rw-r--r--linker/debugger.c46
2 files changed, 44 insertions, 4 deletions
diff --git a/linker/Android.mk b/linker/Android.mk
index 4647c8f..27a6677 100644
--- a/linker/Android.mk
+++ b/linker/Android.mk
@@ -60,7 +60,7 @@ endif
LOCAL_MODULE:= linker
-LOCAL_STATIC_LIBRARIES := libcutils libc_nomalloc
+LOCAL_STATIC_LIBRARIES := libc_nomalloc
#LOCAL_FORCE_STATIC_EXECUTABLE := true # not necessary when not including BUILD_EXECUTABLE
diff --git a/linker/debugger.c b/linker/debugger.c
index 1bd3cc8..abb383c 100644
--- a/linker/debugger.c
+++ b/linker/debugger.c
@@ -37,7 +37,7 @@
#include "linker.h"
#include <sys/socket.h>
-#include <cutils/sockets.h>
+#include <sys/un.h>
void notify_gdb_of_libraries();
@@ -46,6 +46,47 @@ void notify_gdb_of_libraries();
ret = (cond); \
} while (ret < 0 && errno == EINTR)
+
+static int socket_abstract_client(const char *name, int type)
+{
+ struct sockaddr_un addr;
+ size_t namelen;
+ socklen_t alen;
+ int s, err;
+
+ namelen = strlen(name);
+
+ // Test with length +1 for the *initial* '\0'.
+ if ((namelen + 1) > sizeof(addr.sun_path)) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ /* This is used for abstract socket namespace, we need
+ * an initial '\0' at the start of the Unix socket path.
+ *
+ * Note: The path in this case is *not* supposed to be
+ * '\0'-terminated. ("man 7 unix" for the gory details.)
+ */
+ memset (&addr, 0, sizeof addr);
+ addr.sun_family = AF_LOCAL;
+ addr.sun_path[0] = 0;
+ memcpy(addr.sun_path + 1, name, namelen);
+
+ alen = namelen + offsetof(struct sockaddr_un, sun_path) + 1;
+
+ s = socket(AF_LOCAL, type, 0);
+ if(s < 0) return -1;
+
+ RETRY_ON_EINTR(err,connect(s, (struct sockaddr *) &addr, alen));
+ if (err < 0) {
+ close(s);
+ s = -1;
+ }
+
+ return s;
+}
+
void debugger_signal_handler(int n)
{
unsigned tid;
@@ -55,8 +96,7 @@ void debugger_signal_handler(int n)
signal(SIGUSR1, SIG_IGN);
tid = gettid();
- s = socket_local_client("android:debuggerd",
- ANDROID_SOCKET_NAMESPACE_ABSTRACT, SOCK_STREAM);
+ s = socket_abstract_client("android:debuggerd", SOCK_STREAM);
if(s >= 0) {
/* debugger knows our pid from the credentials on the