From 3e7d33ba2bc3d80b40e357c8359a179d7a48f483 Mon Sep 17 00:00:00 2001 From: eboasson Date: Mon, 25 Nov 2019 20:19:14 +0100 Subject: [PATCH] Use rcutils_get_env() instead of getenv() (#71) (#73) * Use rcutils_get_env() instead of getenv() (#71) Signed-off-by: Erik Boasson * Keep includes in alphabetical order Signed-off-by: Erik Boasson --- rmw_cyclonedds_cpp/src/rmw_node.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/rmw_cyclonedds_cpp/src/rmw_node.cpp b/rmw_cyclonedds_cpp/src/rmw_node.cpp index 35aec0a..f99810d 100644 --- a/rmw_cyclonedds_cpp/src/rmw_node.cpp +++ b/rmw_cyclonedds_cpp/src/rmw_node.cpp @@ -24,6 +24,7 @@ #include #include +#include "rcutils/get_env.h" #include "rcutils/logging_macros.h" #include "rcutils/strdup.h" @@ -590,9 +591,16 @@ static bool check_create_domain_locked(dds_domainid_t did, bool localhost_only) ""; /* Emulate default behaviour of Cyclone of reading CYCLONEDDS_URI */ - char * config_from_env = getenv("CYCLONEDDS_URI"); - if (config_from_env != nullptr) { + const char * get_env_error; + const char * config_from_env; + if ((get_env_error = rcutils_get_env("CYCLONEDDS_URI", &config_from_env)) == nullptr) { config += std::string(config_from_env); + } else { + RCUTILS_LOG_ERROR_NAMED("rmw_cyclonedds_cpp", + "rmw_create_node: failed to retrieve CYCLONEDDS_URI environment variable, error %s", + get_env_error); + node_gone_from_domain_locked(did); + return false; } if ((dom.domain_handle = dds_create_domain(did, config.c_str())) < 0) {