diff --git a/kubernetes/ConfigureChecks.cmake b/kubernetes/ConfigureChecks.cmake index 5cfba58..c9cda1a 100644 --- a/kubernetes/ConfigureChecks.cmake +++ b/kubernetes/ConfigureChecks.cmake @@ -1,4 +1,5 @@ -include(CheckFunctionExists) +include(CheckCXXSymbolExists) -check_function_exists(strndup HAVE_STRNDUP) -check_function_exists(secure_getenv HAVE_SECURE_GETENV) +check_cxx_symbol_exists(strndup "string.h" HAVE_STRNDUP) +check_cxx_symbol_exists(secure_getenv "stdlib.h" HAVE_SECURE_GETENV) +check_cxx_symbol_exists(getenv "stdlib.h" HAVE_GETENV) diff --git a/kubernetes/PostTarget.cmake b/kubernetes/PostTarget.cmake index 1ef9cc3..73df36a 100644 --- a/kubernetes/PostTarget.cmake +++ b/kubernetes/PostTarget.cmake @@ -4,5 +4,6 @@ else() set(WEBSOCKETS websockets) endif() +target_include_directories(${pkgName} PRIVATE "${CMAKE_CURRENT_BINARY_DIR}") target_link_libraries(${pkgName} PRIVATE yaml ${WEBSOCKETS}) set_target_properties(${pkgName} PROPERTIES LINKER_LANGUAGE C) \ No newline at end of file diff --git a/kubernetes/config.h.in b/kubernetes/config.h.in index 4ccae38..35cba3c 100644 --- a/kubernetes/config.h.in +++ b/kubernetes/config.h.in @@ -1,2 +1,3 @@ #cmakedefine HAVE_STRNDUP #cmakedefine HAVE_SECURE_GETENV +#cmakedefine HAVE_GETENV \ No newline at end of file diff --git a/kubernetes/config/incluster_config.c b/kubernetes/config/incluster_config.c index 3e1708e..9f521b5 100644 --- a/kubernetes/config/incluster_config.c +++ b/kubernetes/config/incluster_config.c @@ -45,19 +45,23 @@ static int setBasePathInCluster(char **pBasePath) { static char fname[] = "setBasePathInCluster()"; -#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__) || defined(__APPLE__) || !defined(HAVE_SECURE_GETENV) - const char *service_host_env = getenv(SERVICE_HOST_ENV_NAME); -#elif __linux || defined(__EMSCRIPTEN__) +#if defined(HAVE_SECURE_GETENV) const char *service_host_env = secure_getenv(SERVICE_HOST_ENV_NAME); +#elif defined(HAVE_GETENV) + const char *service_host_env = getenv(SERVICE_HOST_ENV_NAME); +#else + const char *service_host_env = NULL; #endif if (!service_host_env) { fprintf(stderr, "%s: Cannot retrieve the kubernetes service host inside a pod by the env %s.\n", fname, SERVICE_HOST_ENV_NAME); return -1; } -#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__) || defined(__APPLE__) || !defined(HAVE_SECURE_GETENV) - const char *service_port_env = getenv(SERVICE_PORT_ENV_NAME); -#elif __linux || defined(__EMSCRIPTEN__) +#if defined(HAVE_SECURE_GETENV) const char *service_port_env = secure_getenv(SERVICE_PORT_ENV_NAME); +#elif defined(HAVE_GETENV) + const char *service_port_env = getenv(SERVICE_PORT_ENV_NAME); +#else + const char *service_port_env = NULL; #endif if (!service_port_env) { fprintf(stderr, "%s: Cannot retrieve the kubernetes service port inside a pod by the env %s.\n", fname, SERVICE_PORT_ENV_NAME); diff --git a/kubernetes/config/kube_config.c b/kubernetes/config/kube_config.c index f5dcb0d..0f51cfb 100644 --- a/kubernetes/config/kube_config.c +++ b/kubernetes/config/kube_config.c @@ -1,3 +1,5 @@ +#include + #define _GNU_SOURCE #include #include @@ -110,20 +112,18 @@ static char *getWorkingConfigFile(const char *configFileNamePassedIn) if (configFileNamePassedIn) { configFileName = strdup(configFileNamePassedIn); } else { - -#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__) || defined(__APPLE__) || !defined(HAVE_SECURE_GETENV) - kubeconfig_env = getenv(ENV_KUBECONFIG); -#elif __linux || defined(__EMSCRIPTEN__) +#if defined(HAVE_SECURE_GETENV) kubeconfig_env = secure_getenv(ENV_KUBECONFIG); +#elif defined(HAVE_GETENV) + kubeconfig_env = getenv(ENV_KUBECONFIG); #endif if (kubeconfig_env) { configFileName = strdup(kubeconfig_env); } else { -#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__) || defined(__APPLE__) || !defined(HAVE_SECURE_GETENV) - homedir_env = getenv(ENV_HOME); -#elif __linux || defined(__EMSCRIPTEN__) +#if defined(HAVE_SECURE_GETENV) homedir_env = secure_getenv(ENV_HOME); -#else +#elif defined(HAVE_GETENV) + homedir_env = getenv(ENV_HOME); #endif if (homedir_env) { int configFileNameSize = strlen(homedir_env) + strlen(KUBE_CONFIG_DEFAULT_LOCATION) + 1;