Merge "Move android_get_control_socket out of line"
This commit is contained in:
commit
4b5abcdba2
3 changed files with 24 additions and 22 deletions
|
|
@ -18,6 +18,7 @@
|
||||||
#define __CUTILS_SOCKETS_H
|
#define __CUTILS_SOCKETS_H
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <limits.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
@ -51,28 +52,8 @@ extern "C" {
|
||||||
* android_get_control_socket - simple helper function to get the file
|
* android_get_control_socket - simple helper function to get the file
|
||||||
* descriptor of our init-managed Unix domain socket. `name' is the name of the
|
* descriptor of our init-managed Unix domain socket. `name' is the name of the
|
||||||
* socket, as given in init.rc. Returns -1 on error.
|
* socket, as given in init.rc. Returns -1 on error.
|
||||||
*
|
|
||||||
* This is inline and not in libcutils proper because we want to use this in
|
|
||||||
* third-party daemons with minimal modification.
|
|
||||||
*/
|
*/
|
||||||
static inline int android_get_control_socket(const char* name)
|
int android_get_control_socket(const char* name);
|
||||||
{
|
|
||||||
char key[64];
|
|
||||||
snprintf(key, sizeof(key), ANDROID_SOCKET_ENV_PREFIX "%s", name);
|
|
||||||
|
|
||||||
const char* val = getenv(key);
|
|
||||||
if (!val) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
errno = 0;
|
|
||||||
int fd = strtol(val, NULL, 10);
|
|
||||||
if (errno) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return fd;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* See also android.os.LocalSocketAddress.Namespace
|
* See also android.os.LocalSocketAddress.Namespace
|
||||||
|
|
|
||||||
|
|
@ -45,3 +45,24 @@ int socket_get_local_port(cutils_socket_t sock) {
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int android_get_control_socket(const char* name) {
|
||||||
|
char key[64];
|
||||||
|
snprintf(key, sizeof(key), ANDROID_SOCKET_ENV_PREFIX "%s", name);
|
||||||
|
|
||||||
|
const char* val = getenv(key);
|
||||||
|
if (!val) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
errno = 0;
|
||||||
|
long ret = strtol(val, NULL, 10);
|
||||||
|
if (errno) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (ret < 0 || ret > INT_MAX) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return static_cast<int>(ret);
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ LOCAL_PATH:= $(call my-dir)
|
||||||
include $(CLEAR_VARS)
|
include $(CLEAR_VARS)
|
||||||
|
|
||||||
LOCAL_SRC_FILES := lmkd.c
|
LOCAL_SRC_FILES := lmkd.c
|
||||||
LOCAL_SHARED_LIBRARIES := liblog libm libc libprocessgroup
|
LOCAL_SHARED_LIBRARIES := liblog libm libc libprocessgroup libcutils
|
||||||
LOCAL_CFLAGS := -Werror
|
LOCAL_CFLAGS := -Werror
|
||||||
|
|
||||||
LOCAL_MODULE := lmkd
|
LOCAL_MODULE := lmkd
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue