mirror of
https://github.com/google/sandboxed-api.git
synced 2024-03-22 13:11:30 +08:00
Declare global forkserver start mode flag in header file so it can be overridden in code more easily.
PiperOrigin-RevId: 346588150 Change-Id: I1013b928a45bab164e7db28d49be8504353dc064
This commit is contained in:
parent
7ce4b24cb5
commit
c7d8e83d60
|
@ -240,13 +240,13 @@ target_link_libraries(sandbox2_global_forkserver
|
||||||
sandbox2::util
|
sandbox2::util
|
||||||
sapi::base
|
sapi::base
|
||||||
sapi::embed_file
|
sapi::embed_file
|
||||||
sapi::flags
|
|
||||||
sapi::raw_logging
|
sapi::raw_logging
|
||||||
PUBLIC absl::core_headers
|
PUBLIC absl::core_headers
|
||||||
absl::synchronization
|
absl::synchronization
|
||||||
sandbox2::comms
|
sandbox2::comms
|
||||||
sandbox2::fork_client
|
sandbox2::fork_client
|
||||||
sandbox2::forkserver_proto
|
sandbox2::forkserver_proto
|
||||||
|
sapi::flags
|
||||||
)
|
)
|
||||||
|
|
||||||
# sandboxed_api/sandbox2:start_global_forkserver_lib_constructor
|
# sandboxed_api/sandbox2:start_global_forkserver_lib_constructor
|
||||||
|
|
|
@ -22,7 +22,6 @@
|
||||||
#include <syscall.h>
|
#include <syscall.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include <bitset>
|
|
||||||
#include <csignal>
|
#include <csignal>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
@ -45,40 +44,6 @@
|
||||||
#include "sandboxed_api/util/raw_logging.h"
|
#include "sandboxed_api/util/raw_logging.h"
|
||||||
|
|
||||||
namespace sandbox2 {
|
namespace sandbox2 {
|
||||||
namespace {
|
|
||||||
enum class GlobalForkserverStartMode {
|
|
||||||
kOnDemand,
|
|
||||||
// MUST be the last element
|
|
||||||
kNumGlobalForkserverStartModes,
|
|
||||||
};
|
|
||||||
|
|
||||||
class GlobalForkserverStartModeSet {
|
|
||||||
public:
|
|
||||||
static constexpr size_t kSize = static_cast<size_t>(
|
|
||||||
GlobalForkserverStartMode::kNumGlobalForkserverStartModes);
|
|
||||||
|
|
||||||
GlobalForkserverStartModeSet() {}
|
|
||||||
explicit GlobalForkserverStartModeSet(GlobalForkserverStartMode value) {
|
|
||||||
value_[static_cast<size_t>(value)] = true;
|
|
||||||
}
|
|
||||||
GlobalForkserverStartModeSet& operator|=(GlobalForkserverStartMode value) {
|
|
||||||
value_[static_cast<size_t>(value)] = true;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
GlobalForkserverStartModeSet operator|(
|
|
||||||
GlobalForkserverStartMode value) const {
|
|
||||||
GlobalForkserverStartModeSet rv(*this);
|
|
||||||
rv |= value;
|
|
||||||
return rv;
|
|
||||||
}
|
|
||||||
bool contains(GlobalForkserverStartMode value) const {
|
|
||||||
return value_[static_cast<size_t>(value)];
|
|
||||||
}
|
|
||||||
bool empty() { return value_.none(); }
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::bitset<kSize> value_;
|
|
||||||
};
|
|
||||||
|
|
||||||
bool AbslParseFlag(absl::string_view text, GlobalForkserverStartModeSet* out,
|
bool AbslParseFlag(absl::string_view text, GlobalForkserverStartModeSet* out,
|
||||||
std::string* error) {
|
std::string* error) {
|
||||||
|
@ -98,6 +63,7 @@ bool AbslParseFlag(absl::string_view text, GlobalForkserverStartModeSet* out,
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace {
|
||||||
std::string ToString(GlobalForkserverStartMode mode) {
|
std::string ToString(GlobalForkserverStartMode mode) {
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
case GlobalForkserverStartMode::kOnDemand:
|
case GlobalForkserverStartMode::kOnDemand:
|
||||||
|
@ -106,6 +72,16 @@ std::string ToString(GlobalForkserverStartMode mode) {
|
||||||
return "unknown";
|
return "unknown";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
bool ValidateStartMode(const char*, const std::string& flag) {
|
||||||
|
GlobalForkserverStartModeSet unused;
|
||||||
|
std::string error;
|
||||||
|
if (!AbslParseFlag(flag, &unused, &error)) {
|
||||||
|
SAPI_RAW_LOG(ERROR, "%s", error);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} // namespace
|
||||||
|
|
||||||
std::string AbslUnparseFlag(GlobalForkserverStartModeSet in) {
|
std::string AbslUnparseFlag(GlobalForkserverStartModeSet in) {
|
||||||
std::vector<std::string> str_modes;
|
std::vector<std::string> str_modes;
|
||||||
|
@ -120,16 +96,7 @@ std::string AbslUnparseFlag(GlobalForkserverStartModeSet in) {
|
||||||
}
|
}
|
||||||
return absl::StrJoin(str_modes, ",");
|
return absl::StrJoin(str_modes, ",");
|
||||||
}
|
}
|
||||||
bool ValidateStartMode(const char*, const std::string& flag) {
|
|
||||||
GlobalForkserverStartModeSet unused;
|
|
||||||
std::string error;
|
|
||||||
if (!AbslParseFlag(flag, &unused, &error)) {
|
|
||||||
SAPI_RAW_LOG(ERROR, "%s", error);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
} // namespace
|
|
||||||
} // namespace sandbox2
|
} // namespace sandbox2
|
||||||
|
|
||||||
ABSL_FLAG(string, sandbox2_forkserver_start_mode, "ondemand",
|
ABSL_FLAG(string, sandbox2_forkserver_start_mode, "ondemand",
|
||||||
|
|
|
@ -20,7 +20,12 @@
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include <bitset>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include "absl/base/thread_annotations.h"
|
#include "absl/base/thread_annotations.h"
|
||||||
|
#include "sandboxed_api/util/flag.h"
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
#include "absl/synchronization/mutex.h"
|
#include "absl/synchronization/mutex.h"
|
||||||
#include "sandboxed_api/sandbox2/comms.h"
|
#include "sandboxed_api/sandbox2/comms.h"
|
||||||
#include "sandboxed_api/sandbox2/fork_client.h"
|
#include "sandboxed_api/sandbox2/fork_client.h"
|
||||||
|
@ -53,6 +58,46 @@ class GlobalForkClient {
|
||||||
ForkClient fork_client_;
|
ForkClient fork_client_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum class GlobalForkserverStartMode {
|
||||||
|
kOnDemand,
|
||||||
|
// MUST be the last element
|
||||||
|
kNumGlobalForkserverStartModes,
|
||||||
|
};
|
||||||
|
|
||||||
|
class GlobalForkserverStartModeSet {
|
||||||
|
public:
|
||||||
|
static constexpr size_t kSize = static_cast<size_t>(
|
||||||
|
GlobalForkserverStartMode::kNumGlobalForkserverStartModes);
|
||||||
|
|
||||||
|
GlobalForkserverStartModeSet() {}
|
||||||
|
explicit GlobalForkserverStartModeSet(GlobalForkserverStartMode value) {
|
||||||
|
value_[static_cast<size_t>(value)] = true;
|
||||||
|
}
|
||||||
|
GlobalForkserverStartModeSet& operator|=(GlobalForkserverStartMode value) {
|
||||||
|
value_[static_cast<size_t>(value)] = true;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
GlobalForkserverStartModeSet operator|(
|
||||||
|
GlobalForkserverStartMode value) const {
|
||||||
|
GlobalForkserverStartModeSet rv(*this);
|
||||||
|
rv |= value;
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
bool contains(GlobalForkserverStartMode value) const {
|
||||||
|
return value_[static_cast<size_t>(value)];
|
||||||
|
}
|
||||||
|
bool empty() { return value_.none(); }
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::bitset<kSize> value_;
|
||||||
|
};
|
||||||
|
|
||||||
|
bool AbslParseFlag(absl::string_view text, GlobalForkserverStartModeSet* out,
|
||||||
|
std::string* error);
|
||||||
|
std::string AbslUnparseFlag(GlobalForkserverStartModeSet in);
|
||||||
|
|
||||||
} // namespace sandbox2
|
} // namespace sandbox2
|
||||||
|
|
||||||
|
ABSL_DECLARE_FLAG(string, sandbox2_forkserver_start_mode);
|
||||||
|
|
||||||
#endif // SANDBOXED_API_SANDBOX2_GLOBAL_FORKCLIENT_H_
|
#endif // SANDBOXED_API_SANDBOX2_GLOBAL_FORKCLIENT_H_
|
||||||
|
|
Loading…
Reference in New Issue
Block a user