From da18170924d7f99c28ca9d38c587a056657f1e54 Mon Sep 17 00:00:00 2001 From: Victor Romero Date: Fri, 7 Oct 2022 12:18:25 -0700 Subject: [PATCH 1/9] [wip] Implement Windows Container heuristics --- .gitignore | 1 + include/vcpkg/base/system.h | 4 ++++ src/vcpkg.cpp | 22 ++++++++++++++++++++++ src/vcpkg/base/system.cpp | 20 ++++++++++++++++++++ 4 files changed, 47 insertions(+) diff --git a/.gitignore b/.gitignore index d3738a5bc2..edafc23ef8 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,4 @@ node_modules/ /ce/test/vcpkg-ce.test.build.log /ce/common/temp /vcpkg-root +/CMakePresets.json diff --git a/include/vcpkg/base/system.h b/include/vcpkg/base/system.h index b98506f49a..2d2bbb59db 100644 --- a/include/vcpkg/base/system.h +++ b/include/vcpkg/base/system.h @@ -23,6 +23,10 @@ namespace vcpkg const ExpectedS& get_system_root() noexcept; const ExpectedS& get_system32() noexcept; + + std::string get_username(); + + bool test_registry_key(void* base_hkey, StringView sub_key); #endif Optional get_registry_string(void* base_hkey, StringView subkey, StringView valuename); diff --git a/src/vcpkg.cpp b/src/vcpkg.cpp index cdcc0b1273..2990692ca6 100644 --- a/src/vcpkg.cpp +++ b/src/vcpkg.cpp @@ -41,6 +41,26 @@ static void invalid_command(const std::string& cmd) Checks::exit_fail(VCPKG_LINE_INFO); } +static void try_container_heuristics() +{ +#if defined(_WIN32) + auto registry_heuristic = test_registry_key(HKEY_LOCAL_MACHINE, R"(SYSTEM\CurrentControlSet\Services\cexecsvc)"); + if (registry_heuristic) + { + Debug::println("Detected Container Execution Service"); + } + + auto username = get_username(); + Debug::println("USER is: ", username); +#else + auto file_heuristic = get_filesystem().exists("/.dockerenv", IgnoreErrors{}); + if (file_heuristic) + { + Debug::println("Detected /.dockerenv file"); + } +#endif +} + static void inner(vcpkg::Filesystem& fs, const VcpkgCmdArguments& args) { // track version on each invocation @@ -68,6 +88,8 @@ static void inner(vcpkg::Filesystem& fs, const VcpkgCmdArguments& args) } }; + try_container_heuristics(); + LockGuardPtr(g_metrics)->track_bool_property(BoolMetric::OptionOverlayPorts, !args.overlay_ports.empty()); if (const auto command_function = find_command(Commands::get_available_basic_commands())) diff --git a/src/vcpkg/base/system.cpp b/src/vcpkg/base/system.cpp index 7ee4ea399b..2ee095def4 100644 --- a/src/vcpkg/base/system.cpp +++ b/src/vcpkg/base/system.cpp @@ -13,6 +13,8 @@ #endif #if defined(_WIN32) +#include +#include // needed for mingw #include #else @@ -340,12 +342,30 @@ namespace vcpkg #endif } + #if defined(_WIN32) static bool is_string_keytype(const DWORD hkey_type) { return hkey_type == REG_SZ || hkey_type == REG_MULTI_SZ || hkey_type == REG_EXPAND_SZ; } + std::string get_username() + { + DWORD buffer_size = UNLEN + 1; + std::string buffer; + buffer.resize(static_cast(buffer_size)); + GetUserNameA(buffer.data(), &buffer_size); + return buffer; + } + + bool test_registry_key(void* base_hkey, StringView sub_key) + { + HKEY k = nullptr; + const LSTATUS ec = + RegOpenKeyExW(reinterpret_cast(base_hkey), Strings::to_utf16(sub_key).c_str(), 0, KEY_READ, &k); + return (ERROR_SUCCESS == ec); + } + Optional get_registry_string(void* base_hkey, StringView sub_key, StringView valuename) { HKEY k = nullptr; From f89107f5df8a144e8260068b271169fdbb766e4f Mon Sep 17 00:00:00 2001 From: Victor Romero Date: Fri, 7 Oct 2022 20:58:12 +0000 Subject: [PATCH 2/9] Add Linux containers heuristics --- src/vcpkg.cpp | 38 +++++++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/src/vcpkg.cpp b/src/vcpkg.cpp index 2990692ca6..953332a0e3 100644 --- a/src/vcpkg.cpp +++ b/src/vcpkg.cpp @@ -41,9 +41,10 @@ static void invalid_command(const std::string& cmd) Checks::exit_fail(VCPKG_LINE_INFO); } -static void try_container_heuristics() +static void try_container_heuristics(vcpkg::Filesystem& fs) { #if defined(_WIN32) + (void)fs; auto registry_heuristic = test_registry_key(HKEY_LOCAL_MACHINE, R"(SYSTEM\CurrentControlSet\Services\cexecsvc)"); if (registry_heuristic) { @@ -51,13 +52,40 @@ static void try_container_heuristics() } auto username = get_username(); - Debug::println("USER is: ", username); -#else - auto file_heuristic = get_filesystem().exists("/.dockerenv", IgnoreErrors{}); + if (Strings::case_insensitive_ascii_equals(username, "ContainerUser") || + Strings::case_insensitive_ascii_equals(username, "ContainerAdministrator")) + { + Debug::println("Detected container username"); + } +#elif defined(__linux__) + auto file_heuristic = fs.exists("/.dockerenv", IgnoreErrors{}); if (file_heuristic) { Debug::println("Detected /.dockerenv file"); } + + // check /proc/1/cgroup, if we're running in a container then the control group for each hierarchy will be: + // /docker/, or + // /lxc/ + // + // Example of /proc/1/cgroup contents: + // 2:memory:/docker/66a5f8000f3f2e2a19c3f7d60d870064d26996bdfe77e40df7e3fc955b811d14 + // 1:name=systemd:/docker/66a5f8000f3f2e2a19c3f7d60d870064d26996bdfe77e40df7e3fc955b811d14 + // 0::/docker/66a5f8000f3f2e2a19c3f7d60d870064d26996bdfe77e40df7e3fc955b811d14 + auto cgroup_contents = fs.read_contents("/proc/1/cgroup", IgnoreErrors{}); + for (auto&& line : Strings::split(cgroup_contents, '\n')) + { + auto idx = line.rfind(':'); + if (idx != std::string::npos) + { + auto&& cgroup = line.substr(idx); + if (Strings::starts_with(cgroup, ":/docker/") || Strings::starts_with(cgroup, ":/lxc/")) + { + Debug::println("Detected docker in cgroup"); + break; + } + } + } #endif } @@ -88,7 +116,7 @@ static void inner(vcpkg::Filesystem& fs, const VcpkgCmdArguments& args) } }; - try_container_heuristics(); + try_container_heuristics(fs); LockGuardPtr(g_metrics)->track_bool_property(BoolMetric::OptionOverlayPorts, !args.overlay_ports.empty()); From fbf8f6e4f1e0c968e0510f8a25a8f2f169c13e6e Mon Sep 17 00:00:00 2001 From: Victor Romero Date: Fri, 7 Oct 2022 17:18:43 -0700 Subject: [PATCH 3/9] Use GetUserNameW() on Windows --- include/vcpkg/base/system.h | 2 +- src/vcpkg.cpp | 5 ++--- src/vcpkg/base/system.cpp | 11 +++++------ 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/include/vcpkg/base/system.h b/include/vcpkg/base/system.h index 2d2bbb59db..469583f035 100644 --- a/include/vcpkg/base/system.h +++ b/include/vcpkg/base/system.h @@ -24,7 +24,7 @@ namespace vcpkg const ExpectedS& get_system32() noexcept; - std::string get_username(); + std::wstring get_username(); bool test_registry_key(void* base_hkey, StringView sub_key); #endif diff --git a/src/vcpkg.cpp b/src/vcpkg.cpp index 953332a0e3..57b72a03a1 100644 --- a/src/vcpkg.cpp +++ b/src/vcpkg.cpp @@ -43,8 +43,8 @@ static void invalid_command(const std::string& cmd) static void try_container_heuristics(vcpkg::Filesystem& fs) { -#if defined(_WIN32) (void)fs; +#if defined(_WIN32) auto registry_heuristic = test_registry_key(HKEY_LOCAL_MACHINE, R"(SYSTEM\CurrentControlSet\Services\cexecsvc)"); if (registry_heuristic) { @@ -52,8 +52,7 @@ static void try_container_heuristics(vcpkg::Filesystem& fs) } auto username = get_username(); - if (Strings::case_insensitive_ascii_equals(username, "ContainerUser") || - Strings::case_insensitive_ascii_equals(username, "ContainerAdministrator")) + if (!wcscmp(username.data(), L"ContainerUser") || !wcscmp(username.data(), L"ContainerAdministrator")) { Debug::println("Detected container username"); } diff --git a/src/vcpkg/base/system.cpp b/src/vcpkg/base/system.cpp index 2ee095def4..d5aea0e926 100644 --- a/src/vcpkg/base/system.cpp +++ b/src/vcpkg/base/system.cpp @@ -13,8 +13,8 @@ #endif #if defined(_WIN32) -#include #include +#include // needed for mingw #include #else @@ -342,19 +342,18 @@ namespace vcpkg #endif } - #if defined(_WIN32) static bool is_string_keytype(const DWORD hkey_type) { return hkey_type == REG_SZ || hkey_type == REG_MULTI_SZ || hkey_type == REG_EXPAND_SZ; } - std::string get_username() - { + std::wstring get_username() + { DWORD buffer_size = UNLEN + 1; - std::string buffer; + std::wstring buffer; buffer.resize(static_cast(buffer_size)); - GetUserNameA(buffer.data(), &buffer_size); + GetUserNameW(buffer.data(), &buffer_size); return buffer; } From a430870691882a792097f12765f31c4c13092563 Mon Sep 17 00:00:00 2001 From: Victor Romero Date: Sat, 8 Oct 2022 17:04:49 +0000 Subject: [PATCH 4/9] Add detected container metric --- include/vcpkg/metrics.h | 1 + src/vcpkg.cpp | 32 +++++++++++++++++++------------- src/vcpkg/base/system.cpp | 1 + src/vcpkg/metrics.cpp | 1 + 4 files changed, 22 insertions(+), 13 deletions(-) diff --git a/include/vcpkg/metrics.h b/include/vcpkg/metrics.h index 0f51c1fa12..7b9a04895a 100644 --- a/include/vcpkg/metrics.h +++ b/include/vcpkg/metrics.h @@ -80,6 +80,7 @@ namespace vcpkg { InstallManifestMode, OptionOverlayPorts, + DetectedContainerEnvironment, COUNT // always keep COUNT last }; diff --git a/src/vcpkg.cpp b/src/vcpkg.cpp index 57b72a03a1..b359875d52 100644 --- a/src/vcpkg.cpp +++ b/src/vcpkg.cpp @@ -41,26 +41,27 @@ static void invalid_command(const std::string& cmd) Checks::exit_fail(VCPKG_LINE_INFO); } -static void try_container_heuristics(vcpkg::Filesystem& fs) +static bool detect_container(vcpkg::Filesystem& fs) { (void)fs; #if defined(_WIN32) - auto registry_heuristic = test_registry_key(HKEY_LOCAL_MACHINE, R"(SYSTEM\CurrentControlSet\Services\cexecsvc)"); - if (registry_heuristic) + if (test_registry_key(HKEY_LOCAL_MACHINE, R"(SYSTEM\CurrentControlSet\Services\cexecsvc)")) { Debug::println("Detected Container Execution Service"); + return true; } auto username = get_username(); if (!wcscmp(username.data(), L"ContainerUser") || !wcscmp(username.data(), L"ContainerAdministrator")) { Debug::println("Detected container username"); + return true; } #elif defined(__linux__) - auto file_heuristic = fs.exists("/.dockerenv", IgnoreErrors{}); - if (file_heuristic) + if (fs.exists("/.dockerenv", IgnoreErrors{})) { Debug::println("Detected /.dockerenv file"); + return true; } // check /proc/1/cgroup, if we're running in a container then the control group for each hierarchy will be: @@ -75,17 +76,16 @@ static void try_container_heuristics(vcpkg::Filesystem& fs) for (auto&& line : Strings::split(cgroup_contents, '\n')) { auto idx = line.rfind(':'); - if (idx != std::string::npos) + if (idx == std::string::npos) continue; + auto&& cgroup = line.substr(idx); + if (Strings::starts_with(cgroup, ":/docker/") || Strings::starts_with(cgroup, ":/lxc/")) { - auto&& cgroup = line.substr(idx); - if (Strings::starts_with(cgroup, ":/docker/") || Strings::starts_with(cgroup, ":/lxc/")) - { - Debug::println("Detected docker in cgroup"); - break; - } + Debug::println("Detected docker in cgroup"); + return true; } } #endif + return false; } static void inner(vcpkg::Filesystem& fs, const VcpkgCmdArguments& args) @@ -115,7 +115,13 @@ static void inner(vcpkg::Filesystem& fs, const VcpkgCmdArguments& args) } }; - try_container_heuristics(fs); + { + auto metrics = LockGuardPtr(g_metrics); + if (metrics->metrics_enabled()) + { + metrics->track_bool_property(BoolMetric::DetectedContainerEnvironment, detect_container(fs)); + } + } LockGuardPtr(g_metrics)->track_bool_property(BoolMetric::OptionOverlayPorts, !args.overlay_ports.empty()); diff --git a/src/vcpkg/base/system.cpp b/src/vcpkg/base/system.cpp index d5aea0e926..7f9e7813a1 100644 --- a/src/vcpkg/base/system.cpp +++ b/src/vcpkg/base/system.cpp @@ -354,6 +354,7 @@ namespace vcpkg std::wstring buffer; buffer.resize(static_cast(buffer_size)); GetUserNameW(buffer.data(), &buffer_size); + buffer.resize(buffer_size); return buffer; } diff --git a/src/vcpkg/metrics.cpp b/src/vcpkg/metrics.cpp index a572ea04f4..3da507b1cd 100644 --- a/src/vcpkg/metrics.cpp +++ b/src/vcpkg/metrics.cpp @@ -90,6 +90,7 @@ namespace vcpkg const constexpr std::array(BoolMetric::COUNT)> all_bool_metrics{{ {BoolMetric::InstallManifestMode, "install_manifest_mode"}, {BoolMetric::OptionOverlayPorts, "option_overlay_ports"}, + {BoolMetric::DetectedContainerEnvironment, "detected_container_environment"}, }}; static std::string get_current_date_time_string() From caaab816a4b07644b170509fc861a04b8df0b0e3 Mon Sep 17 00:00:00 2001 From: Victor Romero Date: Sat, 8 Oct 2022 16:10:50 -0700 Subject: [PATCH 5/9] Reorder metrics --- include/vcpkg/metrics.h | 2 +- src/vcpkg/metrics.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/vcpkg/metrics.h b/include/vcpkg/metrics.h index 7b9a04895a..e667713d6c 100644 --- a/include/vcpkg/metrics.h +++ b/include/vcpkg/metrics.h @@ -78,9 +78,9 @@ namespace vcpkg enum class BoolMetric { + DetectedContainerEnvironment, InstallManifestMode, OptionOverlayPorts, - DetectedContainerEnvironment, COUNT // always keep COUNT last }; diff --git a/src/vcpkg/metrics.cpp b/src/vcpkg/metrics.cpp index 3da507b1cd..a9ab7d30fc 100644 --- a/src/vcpkg/metrics.cpp +++ b/src/vcpkg/metrics.cpp @@ -88,9 +88,9 @@ namespace vcpkg }}; const constexpr std::array(BoolMetric::COUNT)> all_bool_metrics{{ + {BoolMetric::DetectedContainerEnvironment, "detected_container_environment"}, {BoolMetric::InstallManifestMode, "install_manifest_mode"}, {BoolMetric::OptionOverlayPorts, "option_overlay_ports"}, - {BoolMetric::DetectedContainerEnvironment, "detected_container_environment"}, }}; static std::string get_current_date_time_string() From 9565707a098706d2a69750e1044a79d836394c78 Mon Sep 17 00:00:00 2001 From: Victor Romero Date: Tue, 11 Oct 2022 17:44:46 -0700 Subject: [PATCH 6/9] Test cgroup parser --- include/vcpkg/cgroup-parser.h | 21 ++++++++++ src/vcpkg-test/cgroup-parser.cpp | 66 ++++++++++++++++++++++++++++++ src/vcpkg.cpp | 13 ++---- src/vcpkg/cgroup-parser.cpp | 70 ++++++++++++++++++++++++++++++++ 4 files changed, 161 insertions(+), 9 deletions(-) create mode 100644 include/vcpkg/cgroup-parser.h create mode 100644 src/vcpkg-test/cgroup-parser.cpp create mode 100644 src/vcpkg/cgroup-parser.cpp diff --git a/include/vcpkg/cgroup-parser.h b/include/vcpkg/cgroup-parser.h new file mode 100644 index 0000000000..aef9aeabdb --- /dev/null +++ b/include/vcpkg/cgroup-parser.h @@ -0,0 +1,21 @@ +#pragma once + +#include + +#include + +namespace vcpkg +{ + struct ControlGroup + { + long hierarchy_id; + std::string subsystems; + std::string control_group; + + ControlGroup(long id, StringView s, StringView c); + }; + + std::vector parse_cgroup_file(StringView text, StringView origin); + + bool detect_docker_in_cgroup_file(StringView text, StringView origin); +} diff --git a/src/vcpkg-test/cgroup-parser.cpp b/src/vcpkg-test/cgroup-parser.cpp new file mode 100644 index 0000000000..331a60d9e6 --- /dev/null +++ b/src/vcpkg-test/cgroup-parser.cpp @@ -0,0 +1,66 @@ +#include + +#include + +#include + +using namespace vcpkg; + +TEST_CASE ("parse", "[cgroup-parser]") +{ + auto ok_text = R"( +3:cpu:/ +2:cpuset:/ +1:memory:/ +0::/ +)"; + + auto cgroups = parse_cgroup_file(ok_text, "ok_text"); + REQUIRE(cgroups.size() == 4); + CHECK(cgroups[0].hierarchy_id == 3); + CHECK(cgroups[0].subsystems == "cpu"); + CHECK(cgroups[0].control_group == "/"); + CHECK(cgroups[1].hierarchy_id == 2); + CHECK(cgroups[1].subsystems == "cpuset"); + CHECK(cgroups[1].control_group == "/"); + CHECK(cgroups[2].hierarchy_id == 1); + CHECK(cgroups[2].subsystems == "memory"); + CHECK(cgroups[2].control_group == "/"); + CHECK(cgroups[3].hierarchy_id == 0); + CHECK(cgroups[3].subsystems == ""); + CHECK(cgroups[3].control_group == "/"); + + auto cgroups_short = parse_cgroup_file("2::", "short_text"); + REQUIRE(cgroups_short.size() == 1); + CHECK(cgroups_short[0].hierarchy_id == 2); + CHECK(cgroups_short[0].subsystems == ""); + CHECK(cgroups_short[0].control_group == ""); + + auto cgroups_incomplete = parse_cgroup_file("0:/", "incomplete_text"); + CHECK(cgroups_incomplete.empty()); + + auto cgroups_bad_id = parse_cgroup_file("ab::", "non_numeric_id_text"); + CHECK(cgroups_bad_id.empty()); + + auto cgroups_empty = parse_cgroup_file("", "empty"); + CHECK(cgroups_empty.empty()); +} + +TEST_CASE ("detect docker", "[cgroup-parser]") +{ + auto with_docker = R"( +2:memory:/docker/66a5f8000f3f2e2a19c3f7d60d870064d26996bdfe77e40df7e3fc955b811d14 +1:name=systemd:/docker/66a5f8000f3f2e2a19c3f7d60d870064d26996bdfe77e40df7e3fc955b811d14 +0::/docker/66a5f8000f3f2e2a19c3f7d60d870064d26996bdfe77e40df7e3fc955b811d14 +)"; + + auto without_docker = R"( +3:cpu:/ +2:cpuset:/ +1:memory:/ +0::/ +)"; + + CHECK(detect_docker_in_cgroup_file(with_docker, "with_docker")); + CHECK(!detect_docker_in_cgroup_file(without_docker, "without_docker")); +} \ No newline at end of file diff --git a/src/vcpkg.cpp b/src/vcpkg.cpp index b359875d52..b37dfad1d4 100644 --- a/src/vcpkg.cpp +++ b/src/vcpkg.cpp @@ -8,6 +8,7 @@ #include #include +#include #include #include #include @@ -73,16 +74,10 @@ static bool detect_container(vcpkg::Filesystem& fs) // 1:name=systemd:/docker/66a5f8000f3f2e2a19c3f7d60d870064d26996bdfe77e40df7e3fc955b811d14 // 0::/docker/66a5f8000f3f2e2a19c3f7d60d870064d26996bdfe77e40df7e3fc955b811d14 auto cgroup_contents = fs.read_contents("/proc/1/cgroup", IgnoreErrors{}); - for (auto&& line : Strings::split(cgroup_contents, '\n')) + if (detect_docker_in_cgroup_file(cgroup_contents, "/proc/1/cgroup")) { - auto idx = line.rfind(':'); - if (idx == std::string::npos) continue; - auto&& cgroup = line.substr(idx); - if (Strings::starts_with(cgroup, ":/docker/") || Strings::starts_with(cgroup, ":/lxc/")) - { - Debug::println("Detected docker in cgroup"); - return true; - } + Debug::println("Detected docker in cgroup"); + return true; } #endif return false; diff --git a/src/vcpkg/cgroup-parser.cpp b/src/vcpkg/cgroup-parser.cpp new file mode 100644 index 0000000000..8339e7df7c --- /dev/null +++ b/src/vcpkg/cgroup-parser.cpp @@ -0,0 +1,70 @@ +#include +#include +#include +#include + +#include + +namespace vcpkg +{ + ControlGroup::ControlGroup(long id, StringView s, StringView c) + : hierarchy_id(id), subsystems(std::move(s.to_string())), control_group(std::move(c.to_string())) + { + } + + // parses /proc/[pid]/cgroup file as specified in https://linux.die.net/man/5/proc + // The file describes control groups to which the process/tasks belongs. + // For each cgroup hierarchy there is one entry + // containing colon-separated fields of the form: + // 5:cpuacct,cpu,cpuset:/daemos + // + // The colon separated fields are, from left to right: + // + // 1. hierarchy ID number + // 2. set of subsystems bound to the hierarchy + // 3. control group in the hierarchy to which the process belongs + std::vector parse_cgroup_file(StringView text, StringView origin) + { + using P = ParserBase; + constexpr auto is_separator_or_lineend = [](auto ch) { return ch == ':' || P::is_lineend(ch); }; + + auto parser = ParserBase(text, origin); + parser.skip_whitespace(); + + std::vector ret; + while (!parser.at_eof()) + { + auto id = parser.match_until(is_separator_or_lineend); + auto maybe_numeric_id = Strings::strto(id); + if (!maybe_numeric_id || P::is_lineend(parser.cur())) + { + ret.clear(); + break; + } + + parser.next(); + auto subsystems = parser.match_until(is_separator_or_lineend); + if (P::is_lineend(parser.cur())) + { + ret.clear(); + break; + } + + parser.next(); + auto control_group = parser.match_until(P::is_lineend); + parser.skip_whitespace(); + + ret.emplace_back(*maybe_numeric_id.get(), subsystems, control_group); + } + + return ret; + } + + bool detect_docker_in_cgroup_file(StringView text, StringView origin) + { + return Util::any_of(parse_cgroup_file(text, origin), [](auto&& cgroup) { + return Strings::starts_with(cgroup.control_group, "/docker") || + Strings::starts_with(cgroup.control_group, "/lxc"); + }); + } +} \ No newline at end of file From 988634b2010881a109ce675d23dff80d17c0550b Mon Sep 17 00:00:00 2001 From: Victor Romero Date: Tue, 11 Oct 2022 17:46:09 -0700 Subject: [PATCH 7/9] Apply suggestions from code review Co-authored-by: Billy O'Neal --- include/vcpkg/metrics.h | 2 +- src/vcpkg.cpp | 2 +- src/vcpkg/metrics.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/include/vcpkg/metrics.h b/include/vcpkg/metrics.h index e667713d6c..498a81b3f5 100644 --- a/include/vcpkg/metrics.h +++ b/include/vcpkg/metrics.h @@ -78,7 +78,7 @@ namespace vcpkg enum class BoolMetric { - DetectedContainerEnvironment, + DetectedContainer, InstallManifestMode, OptionOverlayPorts, COUNT // always keep COUNT last diff --git a/src/vcpkg.cpp b/src/vcpkg.cpp index b37dfad1d4..c3c7131686 100644 --- a/src/vcpkg.cpp +++ b/src/vcpkg.cpp @@ -53,7 +53,7 @@ static bool detect_container(vcpkg::Filesystem& fs) } auto username = get_username(); - if (!wcscmp(username.data(), L"ContainerUser") || !wcscmp(username.data(), L"ContainerAdministrator")) + if (username == L"ContainerUser" || username == L"ContainerAdministrator") { Debug::println("Detected container username"); return true; diff --git a/src/vcpkg/metrics.cpp b/src/vcpkg/metrics.cpp index a9ab7d30fc..ba3625aa40 100644 --- a/src/vcpkg/metrics.cpp +++ b/src/vcpkg/metrics.cpp @@ -88,7 +88,7 @@ namespace vcpkg }}; const constexpr std::array(BoolMetric::COUNT)> all_bool_metrics{{ - {BoolMetric::DetectedContainerEnvironment, "detected_container_environment"}, + {BoolMetric::DetectedContainer, "detected_container"}, {BoolMetric::InstallManifestMode, "install_manifest_mode"}, {BoolMetric::OptionOverlayPorts, "option_overlay_ports"}, }}; From c92f197fff0d907bf7dfb475e4d80a9ba5e342b1 Mon Sep 17 00:00:00 2001 From: Victor Romero Date: Tue, 11 Oct 2022 17:50:17 -0700 Subject: [PATCH 8/9] Update src/vcpkg.cpp --- src/vcpkg.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vcpkg.cpp b/src/vcpkg.cpp index c3c7131686..021d77eddd 100644 --- a/src/vcpkg.cpp +++ b/src/vcpkg.cpp @@ -114,7 +114,7 @@ static void inner(vcpkg::Filesystem& fs, const VcpkgCmdArguments& args) auto metrics = LockGuardPtr(g_metrics); if (metrics->metrics_enabled()) { - metrics->track_bool_property(BoolMetric::DetectedContainerEnvironment, detect_container(fs)); + metrics->track_bool_property(BoolMetric::DetectedContainer, detect_container(fs)); } } From 25a34471594e905be3dba5edc0d921214f23f971 Mon Sep 17 00:00:00 2001 From: Billy Robert O'Neal III Date: Tue, 11 Oct 2022 17:57:20 -0700 Subject: [PATCH 9/9] Fix osx build by removing unnecessary std::moves. --- src/vcpkg/cgroup-parser.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/vcpkg/cgroup-parser.cpp b/src/vcpkg/cgroup-parser.cpp index 8339e7df7c..06939dd2f6 100644 --- a/src/vcpkg/cgroup-parser.cpp +++ b/src/vcpkg/cgroup-parser.cpp @@ -8,7 +8,7 @@ namespace vcpkg { ControlGroup::ControlGroup(long id, StringView s, StringView c) - : hierarchy_id(id), subsystems(std::move(s.to_string())), control_group(std::move(c.to_string())) + : hierarchy_id(id), subsystems(s.data(), s.size()), control_group(c.data(), c.size()) { } @@ -67,4 +67,4 @@ namespace vcpkg Strings::starts_with(cgroup.control_group, "/lxc"); }); } -} \ No newline at end of file +}