mirror of
https://github.com/google/sandboxed-api.git
synced 2024-03-22 13:11:30 +08:00
Use Abseil hash maps instead of std::map<T>
PiperOrigin-RevId: 340807499 Change-Id: I2689bd1d32be45e3085dcc7a0ba4b8fedd7d53b0
This commit is contained in:
parent
2955d20c9f
commit
7c30aebe2d
|
@ -343,6 +343,7 @@ cc_library(
|
|||
"//sandboxed_api/sandbox2/util:strerror",
|
||||
"//sandboxed_api/util:raw_logging",
|
||||
"@com_google_absl//absl/base:core_headers",
|
||||
"@com_google_absl//absl/container:flat_hash_map",
|
||||
"@com_google_absl//absl/memory",
|
||||
"@com_google_absl//absl/strings",
|
||||
],
|
||||
|
|
|
@ -328,6 +328,7 @@ add_library(sandbox2_client STATIC
|
|||
add_library(sandbox2::client ALIAS sandbox2_client)
|
||||
target_link_libraries(sandbox2_client
|
||||
PRIVATE absl::core_headers
|
||||
absl::flat_hash_map
|
||||
absl::memory
|
||||
absl::strings
|
||||
sandbox2::logsink
|
||||
|
|
|
@ -46,22 +46,18 @@
|
|||
|
||||
namespace sandbox2 {
|
||||
|
||||
constexpr uint32_t Client::kClient2SandboxReady;
|
||||
constexpr uint32_t Client::kSandbox2ClientDone;
|
||||
constexpr const char* Client::kFDMapEnvVar;
|
||||
|
||||
Client::Client(Comms* comms) : comms_(comms) {
|
||||
char* fdmap_envvar = getenv(kFDMapEnvVar);
|
||||
if (!fdmap_envvar) {
|
||||
return;
|
||||
}
|
||||
std::map<absl::string_view, absl::string_view> vars =
|
||||
absl::flat_hash_map<absl::string_view, absl::string_view> vars =
|
||||
absl::StrSplit(fdmap_envvar, ',', absl::SkipEmpty());
|
||||
for (const auto& var : vars) {
|
||||
for (const auto& [name, mapped_fd] : vars) {
|
||||
int fd;
|
||||
SAPI_RAW_CHECK(absl::SimpleAtoi(var.second, &fd), "failed to parse fd map");
|
||||
SAPI_RAW_CHECK(fd_map_.emplace(std::string{var.first}, fd).second,
|
||||
"could not insert mapping into fd map (duplicate)");
|
||||
SAPI_RAW_CHECK(absl::SimpleAtoi(mapped_fd, &fd), "failed to parse fd map");
|
||||
SAPI_RAW_CHECK(fd_map_.emplace(std::string(name), fd).second,
|
||||
"could not insert mapping into fd map (duplicate)");
|
||||
}
|
||||
unsetenv(kFDMapEnvVar);
|
||||
}
|
||||
|
|
|
@ -19,10 +19,10 @@
|
|||
#define SANDBOXED_API_SANDBOX2_CLIENT_H_
|
||||
|
||||
#include <cstdint>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "absl/container/flat_hash_map.h"
|
||||
#include "sandboxed_api/sandbox2/comms.h"
|
||||
#include "sandboxed_api/sandbox2/logsink.h"
|
||||
#include "sandboxed_api/sandbox2/network_proxy/client.h"
|
||||
|
@ -87,7 +87,7 @@ class Client {
|
|||
// In the pre-execve case, the sandboxee has to pass the information about
|
||||
// file descriptors to the new process. We set an environment variable for
|
||||
// this case that is parsed in the Client constructor if present.
|
||||
std::map<std::string, int> fd_map_;
|
||||
absl::flat_hash_map<std::string, int> fd_map_;
|
||||
|
||||
std::string GetFdMapEnvVar() const;
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user