#include "content/browser/sandbox_host_linux.h"
#include <sys/socket.h>
#include <memory>
#include "base/no_destructor.h"
#include "base/posix/eintr_wrapper.h"
namespace content {
SandboxHostLinux::SandboxHostLinux() = default;
SandboxHostLinux* SandboxHostLinux::GetInstance() {
static base::NoDestructor<SandboxHostLinux> instance;
return instance.get();
}
void SandboxHostLinux::Init() {
DCHECK(!initialized_);
initialized_ = true;
int fds[2];
CHECK(socketpair(AF_UNIX, SOCK_SEQPACKET, 0, fds) == 0);
child_socket_ = fds[0];
PCHECK(0 == shutdown(child_socket_, SHUT_RD)) << "shutdown";
const int browser_socket = fds[1];
PCHECK(0 == shutdown(browser_socket, SHUT_WR)) << "shutdown";
int pipefds[2];
CHECK(0 == pipe(pipefds));
const int child_lifeline_fd = pipefds[0];
childs_lifeline_fd_ = pipefds[1];
ipc_handler_ =
std::make_unique<SandboxIPCHandler>(child_lifeline_fd, browser_socket);
ipc_thread_ = std::make_unique<base::DelegateSimpleThread>(
ipc_handler_.get(), "sandbox_ipc_thread");
ipc_thread_->Start();
}
}