diff options
author | jln@chromium.org <jln@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-22 16:23:53 +0000 |
---|---|---|
committer | jln@chromium.org <jln@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-22 16:23:53 +0000 |
commit | e72831cac8859a56b03ec76b1c1d4b7fe7409b9d (patch) | |
tree | 3c94ac768191e1e02fc110e709346d3b63249373 | |
parent | 55bb20786708942e37293a525cc94a3dd7875086 (diff) | |
download | chromium_src-e72831cac8859a56b03ec76b1c1d4b7fe7409b9d.zip chromium_src-e72831cac8859a56b03ec76b1c1d4b7fe7409b9d.tar.gz chromium_src-e72831cac8859a56b03ec76b1c1d4b7fe7409b9d.tar.bz2 |
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
-rw-r--r-- | content/browser/zygote_host_impl_linux.cc | 7 | ||||
-rw-r--r-- | content/common/zygote_commands_linux.h | 11 | ||||
-rw-r--r-- | content/zygote/zygote_linux.cc | 4 |
3 files changed, 16 insertions, 6 deletions
diff --git a/content/browser/zygote_host_impl_linux.cc b/content/browser/zygote_host_impl_linux.cc index 0bcebd9..10214ec 100644 --- a/content/browser/zygote_host_impl_linux.cc +++ b/content/browser/zygote_host_impl_linux.cc @@ -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; diff --git a/content/common/zygote_commands_linux.h b/content/common/zygote_commands_linux.h index fbd767c..0745218 100644 --- a/content/common/zygote_commands_linux.h +++ b/content/common/zygote_commands_linux.h @@ -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 { diff --git a/content/zygote/zygote_linux.cc b/content/zygote/zygote_linux.cc index 9c6a329..cf57999 100644 --- a/content/zygote/zygote_linux.cc +++ b/content/zygote/zygote_linux.cc @@ -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) |