diff options
| author | Colin Cross <ccross@android.com> | 2016-09-23 10:06:28 -0700 |
|---|---|---|
| committer | Colin Cross <ccross@android.com> | 2016-09-23 11:26:08 -0700 |
| commit | e8ffa449fdeb7a97131805c96a7acb35957242af (patch) | |
| tree | 0c672db958845b7fc7e1e0c8a4ac2950c2cbc644 | |
| parent | 6fc7eaaad0ff6193bb7499899a3e19c6c4660fb5 (diff) | |
| download | system_core-e8ffa449fdeb7a97131805c96a7acb35957242af.tar.gz system_core-e8ffa449fdeb7a97131805c96a7acb35957242af.tar.bz2 system_core-e8ffa449fdeb7a97131805c96a7acb35957242af.zip | |
Move android_get_control_socket out of line
android_get_control_socket has a warning from the implicit cast from
long to int. The warning was being hidden because cutils/sockets.h was
included with -isystem. Move android_get_control_socket to sockets.cpp,
since we don't want header only dependencies anyways, and fix the
warning with a range check and a static_cast.
Bug: 31492149
Test: m -j <module that uses sockets.h and -Wall>
Change-Id: I1f394ab26d4ec8a7dd0e7907c10416d7f8647624
| -rw-r--r-- | include/cutils/sockets.h | 23 | ||||
| -rw-r--r-- | libcutils/sockets.cpp | 21 | ||||
| -rw-r--r-- | lmkd/Android.mk | 2 |
3 files changed, 24 insertions, 22 deletions
diff --git a/include/cutils/sockets.h b/include/cutils/sockets.h index 783bd0bea..a93c8eaa4 100644 --- a/include/cutils/sockets.h +++ b/include/cutils/sockets.h @@ -18,6 +18,7 @@ #define __CUTILS_SOCKETS_H #include <errno.h> +#include <limits.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -51,28 +52,8 @@ extern "C" { * 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 * 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) -{ - 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; -} +int android_get_control_socket(const char* name); /* * See also android.os.LocalSocketAddress.Namespace diff --git a/libcutils/sockets.cpp b/libcutils/sockets.cpp index d9ab14611..bba63ac16 100644 --- a/libcutils/sockets.cpp +++ b/libcutils/sockets.cpp @@ -45,3 +45,24 @@ int socket_get_local_port(cutils_socket_t sock) { } 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); +} diff --git a/lmkd/Android.mk b/lmkd/Android.mk index 8c886613d..8980d1c84 100644 --- a/lmkd/Android.mk +++ b/lmkd/Android.mk @@ -2,7 +2,7 @@ LOCAL_PATH:= $(call my-dir) include $(CLEAR_VARS) LOCAL_SRC_FILES := lmkd.c -LOCAL_SHARED_LIBRARIES := liblog libm libc libprocessgroup +LOCAL_SHARED_LIBRARIES := liblog libm libc libprocessgroup libcutils LOCAL_CFLAGS := -Werror LOCAL_MODULE := lmkd |
