am a37ffb0c: am a24bc688: Merge "linker: remove libcutils dependency by re-implementing simpler socket_local_client." into kraken

Merge commit 'a37ffb0c74445fc0bc727aec887990d713d20b8e'

* commit 'a37ffb0c74445fc0bc727aec887990d713d20b8e':
  linker: remove libcutils dependency by re-implementing simpler socket_local_client.
This commit is contained in:
David 'Digit' Turner 2010-06-15 07:03:55 -07:00 committed by Android Git Automerger
commit 9bd7922e5d
2 changed files with 44 additions and 4 deletions

View 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

View 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