2828#include " absl/status/status.h"
2929#include " absl/status/status_macros.h"
3030#include " absl/status/statusor.h"
31+ #include " absl/strings/string_view.h"
3132#include " absl/time/time.h"
3233#include " absl/types/span.h"
3334#include " sandboxed_api/call.h"
3940#include " sandboxed_api/vars.h"
4041
4142namespace sapi {
43+
4244namespace sandbox_internal {
4345
4446class PtrOrCallable {
@@ -64,7 +66,7 @@ class PtrOrCallable {
6466// means to communicate with it (make function calls, transfer memory).
6567class SandboxBase {
6668 public:
67- SandboxBase () = default ;
69+ explicit SandboxBase (std::string name = " unknown " ) : name_(std::move(name)) {}
6870
6971 virtual ~SandboxBase () = default ;
7072
@@ -156,6 +158,8 @@ class SandboxBase {
156158 // sandboxee is not running or we're using an in-process sandbox.
157159 virtual absl::StatusOr<int > GetPid () const = 0;
158160
161+ const std::string& name () const { return name_; }
162+
159163 protected:
160164 // WrapCallStatus is called with the status returned by a Call. The default
161165 // implementation simply returns the status as is.
@@ -166,6 +170,7 @@ class SandboxBase {
166170 absl::Status Call (
167171 const std::string& func, v::Callable* ret,
168172 std::initializer_list<sandbox_internal::PtrOrCallable> args);
173+ std::string name_;
169174};
170175
171176// The Sandbox class represents the sandboxed library. It provides users with
@@ -174,23 +179,26 @@ template <typename Backend>
174179class Sandbox : public SandboxBase {
175180 public:
176181 explicit Sandbox (SandboxConfig config)
177- : SandboxBase(), backend_(std::move(config), [this] {
182+ : SandboxBase(config.name ), backend_(std::move(config), [this] {
178183 return CreateNotifier (); // NOLINT
179184 }) {}
180185
181186 // This constructor should only be used for special cases, e.g. when using the
182187 // CreateNotifier() method of the Sandbox2Backend. Otherwise, prefer to use
183188 // the SandboxConfig constructor above.
184189 explicit Sandbox (Backend backend)
185- : SandboxBase(), backend_(std::move(backend)) {}
190+ : SandboxBase(backend.name() ), backend_(std::move(backend)) {}
186191
187192 Sandbox (const Sandbox&) = delete ;
188193 Sandbox& operator =(const Sandbox&) = delete ;
189194
190195 virtual ~Sandbox () = default ;
191196
192197 // Initializes a new sandboxing session.
193- absl::Status Init () override { return backend ().Init (); }
198+ absl::Status Init () override {
199+ ABSL_RETURN_IF_ERROR (backend ().Init ());
200+ return absl::OkStatus ();
201+ }
194202
195203 // Returns whether the current sandboxing session is active.
196204 bool is_active () const override { return backend ().is_active (); }
0 commit comments