From 63353ee6f7b0f11a856bd74a5f2a7ea6860ad4d0 Mon Sep 17 00:00:00 2001 From: Stephan Zuercher Date: Thu, 3 Aug 2017 11:01:09 -0700 Subject: [PATCH 1/2] osx: UUID generation, fix CLI arg parsing, fix trivial shutdown bug source/common/runtime: use libuuid for UUID generation on OS X source/server: fix crash on shutdown (when no config is specified) build: set HAVE_LONG_LONG to allow TCLAP to support uint64_T flags --- bazel/envoy_build_system.bzl | 4 ++++ source/common/runtime/runtime_impl.cc | 14 ++++++++++++++ source/server/server.cc | 1 + 3 files changed, 19 insertions(+) diff --git a/bazel/envoy_build_system.bzl b/bazel/envoy_build_system.bzl index 639519ddd4215..17586d55edf56 100644 --- a/bazel/envoy_build_system.bzl +++ b/bazel/envoy_build_system.bzl @@ -24,6 +24,10 @@ def envoy_copts(repository, test = False): }) + select({ repository + "//bazel:disable_signal_trace": [], "//conditions:default": ["-DENVOY_HANDLE_SIGNALS"], + }) + select({ + # TCLAP command line parser needs this to support int64_t/uint64_t + "@bazel_tools//tools/osx:darwin": ["-DHAVE_LONG_LONG"], + "//conditions:default": [], }) # Compute the final linkopts based on various options. diff --git a/source/common/runtime/runtime_impl.cc b/source/common/runtime/runtime_impl.cc index 924b884a06e1c..47bc67a5e0711 100644 --- a/source/common/runtime/runtime_impl.cc +++ b/source/common/runtime/runtime_impl.cc @@ -3,6 +3,10 @@ #include #include +#ifdef __APPLE__ +#include +#endif + #include #include #include @@ -22,6 +26,15 @@ namespace Runtime { const size_t RandomGeneratorImpl::UUID_LENGTH = 36; std::string RandomGeneratorImpl::uuid() { +#ifdef __APPLE__ + // TODO (zuercher): factor out a sensible interface for UUID generation to make it easier + // to put a faster implementation in later. + char generated_uuid[UUID_LENGTH + 1]; + uuid_t uuid; + uuid_generate_random(uuid); + uuid_unparse(uuid, generated_uuid); + return std::string(generated_uuid); +#else int fd = open("/proc/sys/kernel/random/uuid", O_RDONLY); if (-1 == fd) { throw EnvoyException(fmt::format("unable to open uuid, errno: {}", strerror(errno))); @@ -38,6 +51,7 @@ std::string RandomGeneratorImpl::uuid() { } return std::string(generated_uuid); +#endif } SnapshotImpl::SnapshotImpl(const std::string& root_path, const std::string& override_path, diff --git a/source/server/server.cc b/source/server/server.cc index d3e3cc2f00bef..1b32be46787fe 100644 --- a/source/server/server.cc +++ b/source/server/server.cc @@ -61,6 +61,7 @@ InstanceImpl::InstanceImpl(Options& options, TestHooks& hooks, HotRestart& resta } catch (const EnvoyException& e) { ENVOY_LOG(critical, "error initializing configuration '{}': {}", options.configPath(), e.what()); + thread_local_.shutdownGlobalThreading(); thread_local_.shutdownThread(); exit(1); } From 2b8f51025f7f2b02c54f227e4122767e8edc9c94 Mon Sep 17 00:00:00 2001 From: Stephan Zuercher Date: Thu, 3 Aug 2017 11:47:04 -0700 Subject: [PATCH 2/2] review comment --- source/common/runtime/runtime_impl.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/common/runtime/runtime_impl.cc b/source/common/runtime/runtime_impl.cc index 47bc67a5e0711..39348ab832a1d 100644 --- a/source/common/runtime/runtime_impl.cc +++ b/source/common/runtime/runtime_impl.cc @@ -27,7 +27,7 @@ const size_t RandomGeneratorImpl::UUID_LENGTH = 36; std::string RandomGeneratorImpl::uuid() { #ifdef __APPLE__ - // TODO (zuercher): factor out a sensible interface for UUID generation to make it easier + // TODO(zuercher): factor out a sensible interface for UUID generation to make it easier // to put a faster implementation in later. char generated_uuid[UUID_LENGTH + 1]; uuid_t uuid;