From b9c2830ebc16d2d3e9e63dfa85bfadc67a6af971 Mon Sep 17 00:00:00 2001 From: Christian Blichmann Date: Fri, 7 Oct 2022 02:07:33 -0700 Subject: [PATCH] Use new sandbox2::Comms ctor for default connection params This change allows Sandbox2 to change how the default FD for comms is chosen. PiperOrigin-RevId: 479526309 Change-Id: I69add85a244bc0385eaa164ab0ea3b036503c6d3 --- sandboxed_api/sandbox2/examples/crc4/crc4bin.cc | 2 +- .../sandbox2/examples/custom_fork/custom_fork_bin.cc | 2 +- sandboxed_api/sandbox2/examples/network/network_bin.cc | 2 +- .../sandbox2/examples/network_proxy/networkproxy_bin.cc | 2 +- sandboxed_api/sandbox2/forkserver.cc | 2 +- sandboxed_api/sandbox2/forkserver_bin.cc | 2 +- sandboxed_api/sandbox2/testcases/buffer.cc | 2 +- sandboxed_api/sandbox2/testcases/ipc.cc | 4 ++-- sandboxed_api/sandbox2/testcases/pidcomms.cc | 2 +- sandboxed_api/sandbox2/testcases/tsync.cc | 2 +- 10 files changed, 11 insertions(+), 11 deletions(-) diff --git a/sandboxed_api/sandbox2/examples/crc4/crc4bin.cc b/sandboxed_api/sandbox2/examples/crc4/crc4bin.cc index 0bd7d3b..f55d863 100644 --- a/sandboxed_api/sandbox2/examples/crc4/crc4bin.cc +++ b/sandboxed_api/sandbox2/examples/crc4/crc4bin.cc @@ -48,7 +48,7 @@ int main(int argc, char* argv[]) { gflags::ParseCommandLineFlags(&argc, &argv, false); // Set-up the sandbox2::Client object, using a file descriptor (1023). - sandbox2::Comms comms(sandbox2::Comms::kSandbox2ClientCommsFD); + sandbox2::Comms comms(sandbox2::Comms::kDefaultConnection); sandbox2::Client sandbox2_client(&comms); // Enable sandboxing from here. sandbox2_client.SandboxMeHere(); diff --git a/sandboxed_api/sandbox2/examples/custom_fork/custom_fork_bin.cc b/sandboxed_api/sandbox2/examples/custom_fork/custom_fork_bin.cc index ca10a45..0ccfd8b 100644 --- a/sandboxed_api/sandbox2/examples/custom_fork/custom_fork_bin.cc +++ b/sandboxed_api/sandbox2/examples/custom_fork/custom_fork_bin.cc @@ -44,7 +44,7 @@ int main(int argc, char* argv[]) { gflags::ParseCommandLineFlags(&argc, &argv, false); // Instantiate Comms channel with the parent Executor - sandbox2::Comms comms(sandbox2::Comms::kSandbox2ClientCommsFD); + sandbox2::Comms comms(sandbox2::Comms::kDefaultConnection); sandbox2::ForkingClient s2client(&comms); for (;;) { diff --git a/sandboxed_api/sandbox2/examples/network/network_bin.cc b/sandboxed_api/sandbox2/examples/network/network_bin.cc index 1a5ab98..2afac93 100644 --- a/sandboxed_api/sandbox2/examples/network/network_bin.cc +++ b/sandboxed_api/sandbox2/examples/network/network_bin.cc @@ -62,7 +62,7 @@ static bool CommunicationTest(int sock) { int main(int argc, char* argv[]) { // Set-up the sandbox2::Client object, using a file descriptor (1023). - sandbox2::Comms comms(sandbox2::Comms::kSandbox2ClientCommsFD); + sandbox2::Comms comms(sandbox2::Comms::kDefaultConnection); sandbox2::Client sandbox2_client(&comms); // Enable sandboxing from here. sandbox2_client.SandboxMeHere(); diff --git a/sandboxed_api/sandbox2/examples/network_proxy/networkproxy_bin.cc b/sandboxed_api/sandbox2/examples/network_proxy/networkproxy_bin.cc index cc48e04..ad2cbb9 100644 --- a/sandboxed_api/sandbox2/examples/network_proxy/networkproxy_bin.cc +++ b/sandboxed_api/sandbox2/examples/network_proxy/networkproxy_bin.cc @@ -108,7 +108,7 @@ int main(int argc, char* argv[]) { gflags::ParseCommandLineFlags(&argc, &argv, false); // Set-up the sandbox2::Client object, using a file descriptor (1023). - sandbox2::Comms comms(sandbox2::Comms::kSandbox2ClientCommsFD); + sandbox2::Comms comms(sandbox2::Comms::kDefaultConnection); sandbox2::Client sandbox2_client(&comms); // Enable sandboxing from here. diff --git a/sandboxed_api/sandbox2/forkserver.cc b/sandboxed_api/sandbox2/forkserver.cc index de64732..0976b34 100644 --- a/sandboxed_api/sandbox2/forkserver.cc +++ b/sandboxed_api/sandbox2/forkserver.cc @@ -346,7 +346,7 @@ void ForkServer::LaunchChild(const ForkRequest& request, int execve_fd, // Create a Comms object here and not above, as we know we will execve and // therefore not call the Comms destructor, which would otherwise close the // comms file descriptor, which we do not want for the general case. - Comms client_comms(Comms::kSandbox2ClientCommsFD); + Comms client_comms(Comms::kDefaultConnection); Client c(&client_comms); // The following client calls are basically SandboxMeHere. We split it so diff --git a/sandboxed_api/sandbox2/forkserver_bin.cc b/sandboxed_api/sandbox2/forkserver_bin.cc index f3e65c6..29834c6 100644 --- a/sandboxed_api/sandbox2/forkserver_bin.cc +++ b/sandboxed_api/sandbox2/forkserver_bin.cc @@ -59,7 +59,7 @@ int main() { SAPI_RAW_PLOG(WARNING, "sigaction(SIGTERM, sa_handler=SIG_IGN)"); } - sandbox2::Comms comms(sandbox2::Comms::kSandbox2ClientCommsFD); + sandbox2::Comms comms(sandbox2::Comms::kDefaultConnection); sandbox2::ForkServer fork_server(&comms); while (true) { diff --git a/sandboxed_api/sandbox2/testcases/buffer.cc b/sandboxed_api/sandbox2/testcases/buffer.cc index 89c58d6..d4f62b8 100644 --- a/sandboxed_api/sandbox2/testcases/buffer.cc +++ b/sandboxed_api/sandbox2/testcases/buffer.cc @@ -46,7 +46,7 @@ int main(int argc, char* argv[]) { } case 2: { // Send and receive FD - sandbox2::Comms comms(sandbox2::Comms::kSandbox2ClientCommsFD); + sandbox2::Comms comms(sandbox2::Comms::kDefaultConnection); int fd; if (!comms.RecvFD(&fd)) { return EXIT_FAILURE; diff --git a/sandboxed_api/sandbox2/testcases/ipc.cc b/sandboxed_api/sandbox2/testcases/ipc.cc index 059e27e..d54c26d 100644 --- a/sandboxed_api/sandbox2/testcases/ipc.cc +++ b/sandboxed_api/sandbox2/testcases/ipc.cc @@ -30,8 +30,8 @@ int main(int argc, char* argv[]) { return EXIT_FAILURE; } - sandbox2::Comms sb_comms(sandbox2::Comms::kSandbox2ClientCommsFD); - sandbox2::Client client(&sb_comms); + sandbox2::Comms default_comms(sandbox2::Comms::kDefaultConnection); + sandbox2::Client client(&default_comms); int testno; SAPI_RAW_CHECK(absl::SimpleAtoi(argv[1], &testno), "testno is not a number"); diff --git a/sandboxed_api/sandbox2/testcases/pidcomms.cc b/sandboxed_api/sandbox2/testcases/pidcomms.cc index 40ba92f..c8a736e 100644 --- a/sandboxed_api/sandbox2/testcases/pidcomms.cc +++ b/sandboxed_api/sandbox2/testcases/pidcomms.cc @@ -19,7 +19,7 @@ #include "sandboxed_api/util/raw_logging.h" int main(int argc, char* argv[]) { - sandbox2::Comms comms(sandbox2::Comms::kSandbox2ClientCommsFD); + sandbox2::Comms comms(sandbox2::Comms::kDefaultConnection); // Exchange data with sandbox sandbox (parent) before sandboxing is enabled. SAPI_RAW_CHECK(comms.SendBool(true), "Sending data to the executor"); diff --git a/sandboxed_api/sandbox2/testcases/tsync.cc b/sandboxed_api/sandbox2/testcases/tsync.cc index 194a34c6..8c7ee2c 100644 --- a/sandboxed_api/sandbox2/testcases/tsync.cc +++ b/sandboxed_api/sandbox2/testcases/tsync.cc @@ -51,7 +51,7 @@ int main(int argc, char* argv[]) { // Wait to make sure that the sleepy-thread is up and running. pthread_barrier_wait(&g_barrier); - sandbox2::Comms comms(sandbox2::Comms::kSandbox2ClientCommsFD); + sandbox2::Comms comms(sandbox2::Comms::kDefaultConnection); sandbox2::Client sandbox2_client(&comms); sandbox2_client.SandboxMeHere();