diff options
author | Mark Salyzyn <salyzyn@google.com> | 2016-11-07 09:39:30 -0800 |
---|---|---|
committer | Mark Salyzyn <salyzyn@google.com> | 2016-11-16 15:56:56 -0800 |
commit | 52bd37e63373b410c009e8611508191dfbf31d30 (patch) | |
tree | 32ed2ad56a69bb6d00b2193eaaed07d813e46982 /libcutils/sockets_unix.cpp | |
parent | e631e470e059d84388f3aacfe11a3fa60a584ba7 (diff) |
libcutils: move cutils/files.h to cutils/android_get_control_file.h
files.[h|cpp] is bound to be abused with junk, replace with
android_get_control_file.[h|cpp]. Plus some sundry cleanup.
Test: gTest libcutils-tests, logd-unit-tests, liblog-unit-tests,
logcat-unit-tests and init_tests
Bug: 32450474
Change-Id: Ibd4a7aa4624ea19a43d1f98a3c71ac37805d36b5
Diffstat (limited to 'libcutils/sockets_unix.cpp')
-rw-r--r-- | libcutils/sockets_unix.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/libcutils/sockets_unix.cpp b/libcutils/sockets_unix.cpp index 3545403aa..948d09c60 100644 --- a/libcutils/sockets_unix.cpp +++ b/libcutils/sockets_unix.cpp @@ -16,13 +16,21 @@ #define LOG_TAG "socket-unix" +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <sys/socket.h> #include <sys/uio.h> +#include <sys/un.h> #include <time.h> #include <unistd.h> #include <android/log.h> +#include <cutils/android_get_control_file.h> #include <cutils/sockets.h> +#include "android_get_control_env.h" + #if defined(__ANDROID__) /* For the socket trust (credentials) check */ #include <private/android_filesystem_config.h> @@ -80,3 +88,24 @@ ssize_t socket_send_buffers(cutils_socket_t sock, return writev(sock, iovec_buffers, num_buffers); } + +int android_get_control_socket(const char* name) { + int fd = __android_get_control_from_env(ANDROID_SOCKET_ENV_PREFIX, name); + + if (fd < 0) return fd; + + // Compare to UNIX domain socket name, must match! + struct sockaddr_un addr; + socklen_t addrlen = sizeof(addr); + int ret = TEMP_FAILURE_RETRY(getsockname(fd, (struct sockaddr *)&addr, &addrlen)); + if (ret < 0) return -1; + char *path = NULL; + if (asprintf(&path, ANDROID_SOCKET_DIR "/%s", name) < 0) return -1; + if (!path) return -1; + int cmp = strcmp(addr.sun_path, path); + free(path); + if (cmp != 0) return -1; + + // It is what we think it is + return fd; +} |