Fix symbol tests

This commit is contained in:
Ahmed Yarub Hani Al Nuaimi
2023-02-09 22:36:24 -03:00
parent ccef130aeb
commit 2e2b5c91da
4 changed files with 23 additions and 18 deletions

View File

@@ -1,5 +1,5 @@
include(CheckFunctionExists) include(CheckCXXSymbolExists)
check_function_exists(strndup HAVE_STRNDUP) check_cxx_symbol_exists(strndup "string.h" HAVE_STRNDUP)
check_function_exists(secure_getenv HAVE_SECURE_GETENV) check_cxx_symbol_exists(secure_getenv "stdlib.h" HAVE_SECURE_GETENV)
check_function_exists(getenv HAVE_GETENV) check_cxx_symbol_exists(getenv "stdlib.h" HAVE_GETENV)

View File

@@ -4,5 +4,6 @@ else()
set(WEBSOCKETS websockets) set(WEBSOCKETS websockets)
endif() endif()
target_include_directories(${pkgName} PRIVATE "${CMAKE_CURRENT_BINARY_DIR}")
target_link_libraries(${pkgName} PRIVATE yaml ${WEBSOCKETS}) target_link_libraries(${pkgName} PRIVATE yaml ${WEBSOCKETS})
set_target_properties(${pkgName} PROPERTIES LINKER_LANGUAGE C) set_target_properties(${pkgName} PROPERTIES LINKER_LANGUAGE C)

View File

@@ -45,19 +45,23 @@ static int setBasePathInCluster(char **pBasePath)
{ {
static char fname[] = "setBasePathInCluster()"; static char fname[] = "setBasePathInCluster()";
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__) || defined(__APPLE__) || !defined(HAVE_SECURE_GETENV) #if defined(HAVE_SECURE_GETENV)
const char *service_host_env = getenv(SERVICE_HOST_ENV_NAME);
#elif __linux || defined(__EMSCRIPTEN__)
const char *service_host_env = secure_getenv(SERVICE_HOST_ENV_NAME); 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 #endif
if (!service_host_env) { 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); fprintf(stderr, "%s: Cannot retrieve the kubernetes service host inside a pod by the env %s.\n", fname, SERVICE_HOST_ENV_NAME);
return -1; return -1;
} }
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__) || defined(__APPLE__) || !defined(HAVE_SECURE_GETENV) #if defined(HAVE_SECURE_GETENV)
const char *service_port_env = getenv(SERVICE_PORT_ENV_NAME);
#elif __linux || defined(__EMSCRIPTEN__)
const char *service_port_env = secure_getenv(SERVICE_PORT_ENV_NAME); 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 #endif
if (!service_port_env) { 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); fprintf(stderr, "%s: Cannot retrieve the kubernetes service port inside a pod by the env %s.\n", fname, SERVICE_PORT_ENV_NAME);

View File

@@ -1,3 +1,5 @@
#include <config.h>
#define _GNU_SOURCE #define _GNU_SOURCE
#include <stdlib.h> #include <stdlib.h>
#include <errno.h> #include <errno.h>
@@ -110,20 +112,18 @@ static char *getWorkingConfigFile(const char *configFileNamePassedIn)
if (configFileNamePassedIn) { if (configFileNamePassedIn) {
configFileName = strdup(configFileNamePassedIn); configFileName = strdup(configFileNamePassedIn);
} else { } else {
#if defined(HAVE_SECURE_GETENV)
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__) || defined(__APPLE__) || !defined(HAVE_SECURE_GETENV)
kubeconfig_env = getenv(ENV_KUBECONFIG);
#elif __linux || defined(__EMSCRIPTEN__)
kubeconfig_env = secure_getenv(ENV_KUBECONFIG); kubeconfig_env = secure_getenv(ENV_KUBECONFIG);
#elif defined(HAVE_GETENV)
kubeconfig_env = getenv(ENV_KUBECONFIG);
#endif #endif
if (kubeconfig_env) { if (kubeconfig_env) {
configFileName = strdup(kubeconfig_env); configFileName = strdup(kubeconfig_env);
} else { } else {
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__) || defined(__APPLE__) || !defined(HAVE_SECURE_GETENV) #if defined(HAVE_SECURE_GETENV)
homedir_env = getenv(ENV_HOME);
#elif __linux || defined(__EMSCRIPTEN__)
homedir_env = secure_getenv(ENV_HOME); homedir_env = secure_getenv(ENV_HOME);
#else #elif defined(HAVE_GETENV)
homedir_env = getenv(ENV_HOME);
#endif #endif
if (homedir_env) { if (homedir_env) {
int configFileNameSize = strlen(homedir_env) + strlen(KUBE_CONFIG_DEFAULT_LOCATION) + 1; int configFileNameSize = strlen(homedir_env) + strlen(KUBE_CONFIG_DEFAULT_LOCATION) + 1;