Commit e72831ca authored by jln@chromium.org's avatar jln@chromium.org

Zygote: create variables for magic fd numbers

The magic number "7" was used across source files to denote the file
descriptor for the dummy fd.

BUG=None
TEST=None
NOTRY=true


Review URL: https://chromiumcodereview.appspot.com/10392176

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@138269 0039d316-1c4b-4281-b951-d872f2087c98
parent 55bb2078
......@@ -103,7 +103,7 @@ void ZygoteHostImpl::Init(const std::string& sandbox_cmd) {
CHECK(socketpair(PF_UNIX, SOCK_SEQPACKET, 0, fds) == 0);
#endif
base::FileHandleMappingVector fds_to_map;
fds_to_map.push_back(std::make_pair(fds[1], 3));
fds_to_map.push_back(std::make_pair(fds[1], content::kZygoteSocketPairFd));
const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
if (browser_command_line.HasSwitch(switches::kZygoteCmdPrefix)) {
......@@ -161,13 +161,14 @@ void ZygoteHostImpl::Init(const std::string& sandbox_cmd) {
// Start up the sandbox host process and get the file descriptor for the
// renderers to talk to it.
const int sfd = RenderSandboxHostLinux::GetInstance()->GetRendererSocket();
fds_to_map.push_back(std::make_pair(sfd, 5));
fds_to_map.push_back(std::make_pair(sfd, content::kZygoteRendererSocketFd));
int dummy_fd = -1;
if (using_suid_sandbox_) {
dummy_fd = socket(PF_UNIX, SOCK_DGRAM, 0);
CHECK(dummy_fd >= 0);
fds_to_map.push_back(std::make_pair(dummy_fd, 7));
fds_to_map.push_back(std::make_pair(dummy_fd,
content::kZygoteIdFd));
}
base::ProcessHandle process = -1;
......
......@@ -11,6 +11,17 @@ namespace content {
// is ready to go.
static const char kZygoteHelloMessage[] = "ZYGOTE_OK";
// File descriptors initialized by the Zygote Host
const int kZygoteSocketPairFd = 3;
const int kZygoteRendererSocketFd = 5;
// This file descriptor is special. It is passed to the Zygote and a setuid
// helper will be called to locate the process of the Zygote on the system.
// This mechanism is used when multiple PID namespaces exist because of the
// setuid sandbox.
// It is very important that this file descriptor does not exist in multiple
// processes.
const int kZygoteIdFd = 7;
// These are the command codes used on the wire between the browser and the
// zygote.
enum {
......
......@@ -35,8 +35,6 @@ namespace content {
namespace {
const int kZygoteIdDescriptor = 7;
// NOP function. See below where this handler is installed.
void SIGCHLDHandler(int signal) {
}
......@@ -413,7 +411,7 @@ base::ProcessId Zygote::ReadArgsAndFork(const Pickle& pickle,
close(kBrowserDescriptor); // Our socket from the browser.
if (UsingSUIDSandbox())
close(kZygoteIdDescriptor); // Another socket from the browser.
close(kZygoteIdFd); // Another socket from the browser.
base::GlobalDescriptors::GetInstance()->Reset(mapping);
#if defined(CHROMIUM_SELINUX)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment