From b74cf8839b2b29b3aa0626f4466ce6bf6b4593e0 Mon Sep 17 00:00:00 2001 From: Christian Blichmann Date: Mon, 5 Oct 2020 05:09:47 -0700 Subject: [PATCH] Minor `ForkClient` improvements - Use a `constexpr inline` string constant for the forkserver env var - Add annotation for the comms channel mutex PiperOrigin-RevId: 335395005 Change-Id: Ic058c19c3704f182aa7ed7b8e8964b2fc5082800 --- sandboxed_api/sandbox2/fork_client.cc | 2 -- sandboxed_api/sandbox2/fork_client.h | 11 ++++++----- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/sandboxed_api/sandbox2/fork_client.cc b/sandboxed_api/sandbox2/fork_client.cc index 567faa8..0cb1be9 100644 --- a/sandboxed_api/sandbox2/fork_client.cc +++ b/sandboxed_api/sandbox2/fork_client.cc @@ -20,8 +20,6 @@ namespace sandbox2 { -const char kForkServerDisableEnv[] = "SANDBOX2_NOFORKSERVER"; - pid_t ForkClient::SendRequest(const ForkRequest& request, int exec_fd, int comms_fd, int user_ns_fd, pid_t* init_pid) { // Acquire the channel ownership for this request (transaction). diff --git a/sandboxed_api/sandbox2/fork_client.h b/sandboxed_api/sandbox2/fork_client.h index cdfa3de..36d8d24 100644 --- a/sandboxed_api/sandbox2/fork_client.h +++ b/sandboxed_api/sandbox2/fork_client.h @@ -17,34 +17,35 @@ #include -#include "absl/base/attributes.h" +#include "absl/base/thread_annotations.h" #include "absl/synchronization/mutex.h" namespace sandbox2 { // Envvar indicating that this process should not start the fork-server. -ABSL_CONST_INIT extern const char kForkServerDisableEnv[]; +constexpr inline char kForkServerDisableEnv[] = "SANDBOX2_NOFORKSERVER"; class Comms; class ForkRequest; class ForkClient { public: + explicit ForkClient(Comms* comms) : comms_(comms) {} + ForkClient(const ForkClient&) = delete; ForkClient& operator=(const ForkClient&) = delete; - explicit ForkClient(Comms* comms) : comms_(comms) {} - // Sends the fork request over the supplied Comms channel. pid_t SendRequest(const ForkRequest& request, int exec_fd, int comms_fd, int user_ns_fd = -1, pid_t* init_pid = nullptr); private: // Comms channel connecting with the ForkServer. Not owned by the object. - Comms* comms_; + Comms* comms_ ABSL_GUARDED_BY(comms_mutex_); // Mutex locking transactions (requests) over the Comms channel. absl::Mutex comms_mutex_; }; + } // namespace sandbox2 #endif // SANDBOXED_API_SANDBOX2_FORK_CLIENT_H_