@@ -351,19 +351,11 @@ Optional<std::string> find_container_id_from_cgroup() {
351351} // namespace
352352
353353Optional<std::string> find_container_id (std::istream& source) {
354- constexpr std::string_view docker_str = " docker-" ;
355- static const std::string uuid_regex_str =
356- " [0-9a-f]{8}[-_][0-9a-f]{4}[-_][0-9a-f]{4}[-_][0-9a-f]{4}[-_][0-9a-f]{12}"
357- " |(?:[0-9a-f]{8}(?:-[0-9a-f]{4}){4}$)" ;
358- static const std::string container_regex_str = " [0-9a-f]{64}" ;
359- static const std::string task_regex_str = " [0-9a-f]{32}-\\ d+" ;
360- static const std::regex path_reg (" (?:.+)?(" + uuid_regex_str + " |" +
361- container_regex_str + " |" + task_regex_str +
362- " )(?:\\ .scope)?$" );
363-
364354 std::string line;
365355
366356 // Look for Docker container IDs in the basic format: `docker-<uuid>.scope`.
357+ constexpr std::string_view docker_str = " docker-" ;
358+
367359 while (std::getline (source, line)) {
368360 // Example:
369361 // `0::/system.slice/docker-abcdef0123456789abcdef0123456789.scope`
@@ -385,6 +377,15 @@ Optional<std::string> find_container_id(std::istream& source) {
385377
386378 // Perform a second pass using a regular expression for matching container IDs in a Fargate environment.
387379 // This two-step approach is used because STL `regex` is relatively slow, so we avoid using it unless necessary.
380+ static const std::string uuid_regex_str =
381+ " [0-9a-f]{8}[-_][0-9a-f]{4}[-_][0-9a-f]{4}[-_][0-9a-f]{4}[-_][0-9a-f]{12}"
382+ " |(?:[0-9a-f]{8}(?:-[0-9a-f]{4}){4}$)" ;
383+ static const std::string container_regex_str = " [0-9a-f]{64}" ;
384+ static const std::string task_regex_str = " [0-9a-f]{32}-\\ d+" ;
385+ static const std::regex path_reg (" (?:.+)?(" + uuid_regex_str + " |" +
386+ container_regex_str + " |" + task_regex_str +
387+ " )(?:\\ .scope)?$" );
388+
388389 while (std::getline (source, line)) {
389390 // Example:
390391 // `0::/system.slice/docker-abcdef0123456789abcdef0123456789.scope`
0 commit comments