OSDN Git Service

linker: remove libcutils dependency by re-implementing simpler socket_local_client.
authorDavid 'Digit' Turner <digit@google.com>
Fri, 11 Jun 2010 01:29:33 +0000 (18:29 -0700)
committerDavid 'Digit' Turner <digit@google.com>
Fri, 11 Jun 2010 05:58:22 +0000 (22:58 -0700)
Change-Id: I87f29fd59454d713b9ddfb13e6cf114822f52efd

linker/Android.mk
linker/debugger.c

index 4647c8f..27a6677 100644 (file)
@@ -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
 
index 1bd3cc8..abb383c 100644 (file)
@@ -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