Skip to content

Commit 488460f

Browse files
authored
Merge pull request #171 from ahmedyarub/ay/fix_android_build
Correct check for getenv()/secure_getenv()
2 parents 18431c6 + 2e2b5c9 commit 488460f

File tree

5 files changed

+24
-17
lines changed

5 files changed

+24
-17
lines changed

kubernetes/ConfigureChecks.cmake

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
include(CheckFunctionExists)
1+
include(CheckCXXSymbolExists)
22

3-
check_function_exists(strndup HAVE_STRNDUP)
4-
check_function_exists(secure_getenv HAVE_SECURE_GETENV)
3+
check_cxx_symbol_exists(strndup "string.h" HAVE_STRNDUP)
4+
check_cxx_symbol_exists(secure_getenv "stdlib.h" HAVE_SECURE_GETENV)
5+
check_cxx_symbol_exists(getenv "stdlib.h" HAVE_GETENV)

kubernetes/PostTarget.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ else()
44
set(WEBSOCKETS websockets)
55
endif()
66

7+
target_include_directories(${pkgName} PRIVATE "${CMAKE_CURRENT_BINARY_DIR}")
78
target_link_libraries(${pkgName} PRIVATE yaml ${WEBSOCKETS})
89
set_target_properties(${pkgName} PROPERTIES LINKER_LANGUAGE C)

kubernetes/config.h.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
#cmakedefine HAVE_STRNDUP
22
#cmakedefine HAVE_SECURE_GETENV
3+
#cmakedefine HAVE_GETENV

kubernetes/config/incluster_config.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,23 @@ static int setBasePathInCluster(char **pBasePath)
4545
{
4646
static char fname[] = "setBasePathInCluster()";
4747

48-
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__) || defined(__APPLE__) || !defined(HAVE_SECURE_GETENV)
49-
const char *service_host_env = getenv(SERVICE_HOST_ENV_NAME);
50-
#elif __linux || defined(__EMSCRIPTEN__)
48+
#if defined(HAVE_SECURE_GETENV)
5149
const char *service_host_env = secure_getenv(SERVICE_HOST_ENV_NAME);
50+
#elif defined(HAVE_GETENV)
51+
const char *service_host_env = getenv(SERVICE_HOST_ENV_NAME);
52+
#else
53+
const char *service_host_env = NULL;
5254
#endif
5355
if (!service_host_env) {
5456
fprintf(stderr, "%s: Cannot retrieve the kubernetes service host inside a pod by the env %s.\n", fname, SERVICE_HOST_ENV_NAME);
5557
return -1;
5658
}
57-
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__) || defined(__APPLE__) || !defined(HAVE_SECURE_GETENV)
58-
const char *service_port_env = getenv(SERVICE_PORT_ENV_NAME);
59-
#elif __linux || defined(__EMSCRIPTEN__)
59+
#if defined(HAVE_SECURE_GETENV)
6060
const char *service_port_env = secure_getenv(SERVICE_PORT_ENV_NAME);
61+
#elif defined(HAVE_GETENV)
62+
const char *service_port_env = getenv(SERVICE_PORT_ENV_NAME);
63+
#else
64+
const char *service_port_env = NULL;
6165
#endif
6266
if (!service_port_env) {
6367
fprintf(stderr, "%s: Cannot retrieve the kubernetes service port inside a pod by the env %s.\n", fname, SERVICE_PORT_ENV_NAME);

kubernetes/config/kube_config.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#include <config.h>
2+
13
#define _GNU_SOURCE
24
#include <stdlib.h>
35
#include <errno.h>
@@ -110,20 +112,18 @@ static char *getWorkingConfigFile(const char *configFileNamePassedIn)
110112
if (configFileNamePassedIn) {
111113
configFileName = strdup(configFileNamePassedIn);
112114
} else {
113-
114-
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__) || defined(__APPLE__) || !defined(HAVE_SECURE_GETENV)
115-
kubeconfig_env = getenv(ENV_KUBECONFIG);
116-
#elif __linux || defined(__EMSCRIPTEN__)
115+
#if defined(HAVE_SECURE_GETENV)
117116
kubeconfig_env = secure_getenv(ENV_KUBECONFIG);
117+
#elif defined(HAVE_GETENV)
118+
kubeconfig_env = getenv(ENV_KUBECONFIG);
118119
#endif
119120
if (kubeconfig_env) {
120121
configFileName = strdup(kubeconfig_env);
121122
} else {
122-
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__) || defined(__APPLE__) || !defined(HAVE_SECURE_GETENV)
123-
homedir_env = getenv(ENV_HOME);
124-
#elif __linux || defined(__EMSCRIPTEN__)
123+
#if defined(HAVE_SECURE_GETENV)
125124
homedir_env = secure_getenv(ENV_HOME);
126-
#else
125+
#elif defined(HAVE_GETENV)
126+
homedir_env = getenv(ENV_HOME);
127127
#endif
128128
if (homedir_env) {
129129
int configFileNameSize = strlen(homedir_env) + strlen(KUBE_CONFIG_DEFAULT_LOCATION) + 1;

0 commit comments

Comments
 (0)