18
18
#ifndef SANDBOXED_API_SANDBOX2_SANDBOX2_H_
19
19
#define SANDBOXED_API_SANDBOX2_SANDBOX2_H_
20
20
21
- #include < ctime>
22
21
#include < memory>
23
22
#include < utility>
24
23
25
24
#include " absl/base/attributes.h"
26
- #include " absl/base/macros.h"
27
- #include " absl/log/check.h"
25
+ #include " absl/log/die_if_null.h"
28
26
#include " absl/status/status.h"
29
27
#include " absl/status/statusor.h"
30
28
#include " absl/time/time.h"
@@ -45,12 +43,9 @@ class Sandbox2 final {
45
43
46
44
Sandbox2 (std::unique_ptr<Executor> executor, std::unique_ptr<Policy> policy,
47
45
std::unique_ptr<Notify> notify)
48
- : executor_(std::move(executor)),
49
- policy_ (std::move(policy)),
50
- notify_(std::move(notify)) {
51
- CHECK (executor_ != nullptr );
52
- CHECK (policy_ != nullptr );
53
- }
46
+ : executor_(std::move(ABSL_DIE_IF_NULL(executor))),
47
+ policy_ (std::move(ABSL_DIE_IF_NULL(policy))),
48
+ notify_(std::move(notify)) {}
54
49
55
50
Sandbox2 (const Sandbox2&) = delete;
56
51
Sandbox2& operator =(const Sandbox2&) = delete ;
@@ -66,6 +61,7 @@ class Sandbox2 final {
66
61
// Even if set-up fails AwaitResult can still used to get a more specific
67
62
// failure reason.
68
63
bool RunAsync ();
64
+
69
65
// Waits for sandbox execution to finish and returns the execution result.
70
66
ABSL_MUST_USE_RESULT Result AwaitResult ();
71
67
@@ -75,8 +71,8 @@ class Sandbox2 final {
75
71
absl::StatusOr<Result> AwaitResultWithTimeout (absl::Duration timeout);
76
72
77
73
// Requests termination of the sandboxee.
78
- // Sandbox should still waited with AwaitResult(), as it may finish for other
79
- // reason before the request is handled.
74
+ // The sandbox should still waited on using AwaitResult(), as it may finish
75
+ // for other reasons before the request is handled.
80
76
void Kill ();
81
77
82
78
// Dumps the main sandboxed process's stack trace to log.
@@ -85,7 +81,7 @@ class Sandbox2 final {
85
81
// Returns whether sandboxing task has ended.
86
82
bool IsTerminated () const ;
87
83
88
- // Sets a wall time limit on a running sandboxee, absl::ZeroDuration() to
84
+ // Sets a wall time limit on a running sandboxee. Use absl::ZeroDuration() to
89
85
// disarm. This can be useful in a persistent sandbox scenario, to impose a
90
86
// deadline for responses after each request and reset the deadline in
91
87
// between. Sandboxed API can be used to implement persistent sandboxes.
@@ -94,7 +90,7 @@ class Sandbox2 final {
94
90
// Returns the process id inside the executor.
95
91
pid_t pid () const { return monitor_ != nullptr ? monitor_->pid () : -1 ; }
96
92
97
- // Gets the comms inside the executor.
93
+ // Returns the comms object from the executor.
98
94
Comms* comms () {
99
95
return executor_ != nullptr ? executor_->ipc ()->comms () : nullptr ;
100
96
}
@@ -107,16 +103,9 @@ class Sandbox2 final {
107
103
108
104
std::unique_ptr<MonitorBase> CreateMonitor ();
109
105
110
- // Executor set by user - owned by Sandbox2.
111
106
std::unique_ptr<Executor> executor_;
112
-
113
- // Seccomp policy set by the user - owned by Sandbox2.
114
- std::unique_ptr<Policy> policy_;
115
-
116
- // Notify object - owned by Sandbox2.
107
+ std::unique_ptr<Policy> policy_; // Seccomp user policy
117
108
std::unique_ptr<Notify> notify_;
118
-
119
- // Monitor object - owned by Sandbox2.
120
109
std::unique_ptr<MonitorBase> monitor_;
121
110
122
111
bool use_unotify_monitor_ = false ;
0 commit comments