OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/browser/zygote_host_impl_linux.h" | 5 #include "content/browser/zygote_host_impl_linux.h" |
6 | 6 |
7 #include <sys/socket.h> | 7 #include <sys/socket.h> |
8 #include <sys/stat.h> | 8 #include <sys/stat.h> |
9 #include <sys/types.h> | 9 #include <sys/types.h> |
10 #include <unistd.h> | 10 #include <unistd.h> |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 int fds[2]; | 96 int fds[2]; |
97 #if defined(OS_FREEBSD) || defined(OS_OPENBSD) | 97 #if defined(OS_FREEBSD) || defined(OS_OPENBSD) |
98 // The BSDs often don't support SOCK_SEQPACKET yet, so fall back to | 98 // The BSDs often don't support SOCK_SEQPACKET yet, so fall back to |
99 // SOCK_DGRAM if necessary. | 99 // SOCK_DGRAM if necessary. |
100 if (socketpair(PF_UNIX, SOCK_SEQPACKET, 0, fds) != 0) | 100 if (socketpair(PF_UNIX, SOCK_SEQPACKET, 0, fds) != 0) |
101 CHECK(socketpair(PF_UNIX, SOCK_DGRAM, 0, fds) == 0); | 101 CHECK(socketpair(PF_UNIX, SOCK_DGRAM, 0, fds) == 0); |
102 #else | 102 #else |
103 CHECK(socketpair(PF_UNIX, SOCK_SEQPACKET, 0, fds) == 0); | 103 CHECK(socketpair(PF_UNIX, SOCK_SEQPACKET, 0, fds) == 0); |
104 #endif | 104 #endif |
105 base::FileHandleMappingVector fds_to_map; | 105 base::FileHandleMappingVector fds_to_map; |
106 fds_to_map.push_back(std::make_pair(fds[1], 3)); | 106 fds_to_map.push_back(std::make_pair(fds[1], content::kZygoteSocketPairFd)); |
107 | 107 |
108 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess(); | 108 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess(); |
109 if (browser_command_line.HasSwitch(switches::kZygoteCmdPrefix)) { | 109 if (browser_command_line.HasSwitch(switches::kZygoteCmdPrefix)) { |
110 cmd_line.PrependWrapper( | 110 cmd_line.PrependWrapper( |
111 browser_command_line.GetSwitchValueNative(switches::kZygoteCmdPrefix)); | 111 browser_command_line.GetSwitchValueNative(switches::kZygoteCmdPrefix)); |
112 } | 112 } |
113 // Append any switches from the browser process that need to be forwarded on | 113 // Append any switches from the browser process that need to be forwarded on |
114 // to the zygote/renderers. | 114 // to the zygote/renderers. |
115 // Should this list be obtained from browser_render_process_host.cc? | 115 // Should this list be obtained from browser_render_process_host.cc? |
116 static const char* kForwardSwitches[] = { | 116 static const char* kForwardSwitches[] = { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 } | 154 } |
155 } else { | 155 } else { |
156 LOG(WARNING) << "Running without the SUID sandbox! See " | 156 LOG(WARNING) << "Running without the SUID sandbox! See " |
157 "http://code.google.com/p/chromium/wiki/LinuxSUIDSandboxDevelopment " | 157 "http://code.google.com/p/chromium/wiki/LinuxSUIDSandboxDevelopment " |
158 "for more information on developing with the sandbox on."; | 158 "for more information on developing with the sandbox on."; |
159 } | 159 } |
160 | 160 |
161 // Start up the sandbox host process and get the file descriptor for the | 161 // Start up the sandbox host process and get the file descriptor for the |
162 // renderers to talk to it. | 162 // renderers to talk to it. |
163 const int sfd = RenderSandboxHostLinux::GetInstance()->GetRendererSocket(); | 163 const int sfd = RenderSandboxHostLinux::GetInstance()->GetRendererSocket(); |
164 fds_to_map.push_back(std::make_pair(sfd, 5)); | 164 fds_to_map.push_back(std::make_pair(sfd, content::kZygoteRendererSocketFd)); |
165 | 165 |
166 int dummy_fd = -1; | 166 int dummy_fd = -1; |
167 if (using_suid_sandbox_) { | 167 if (using_suid_sandbox_) { |
168 dummy_fd = socket(PF_UNIX, SOCK_DGRAM, 0); | 168 dummy_fd = socket(PF_UNIX, SOCK_DGRAM, 0); |
169 CHECK(dummy_fd >= 0); | 169 CHECK(dummy_fd >= 0); |
170 fds_to_map.push_back(std::make_pair(dummy_fd, 7)); | 170 fds_to_map.push_back(std::make_pair(dummy_fd, |
| 171 content::kZygoteIdFd)); |
171 } | 172 } |
172 | 173 |
173 base::ProcessHandle process = -1; | 174 base::ProcessHandle process = -1; |
174 base::LaunchOptions options; | 175 base::LaunchOptions options; |
175 options.fds_to_remap = &fds_to_map; | 176 options.fds_to_remap = &fds_to_map; |
176 base::LaunchProcess(cmd_line.argv(), options, &process); | 177 base::LaunchProcess(cmd_line.argv(), options, &process); |
177 CHECK(process != -1) << "Failed to launch zygote process"; | 178 CHECK(process != -1) << "Failed to launch zygote process"; |
178 | 179 |
179 if (using_suid_sandbox_) { | 180 if (using_suid_sandbox_) { |
180 // In the SUID sandbox, the real zygote is forked from the sandbox. | 181 // In the SUID sandbox, the real zygote is forked from the sandbox. |
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
490 | 491 |
491 pid_t ZygoteHostImpl::GetSandboxHelperPid() const { | 492 pid_t ZygoteHostImpl::GetSandboxHelperPid() const { |
492 return RenderSandboxHostLinux::GetInstance()->pid(); | 493 return RenderSandboxHostLinux::GetInstance()->pid(); |
493 } | 494 } |
494 | 495 |
495 int ZygoteHostImpl::GetSandboxStatus() const { | 496 int ZygoteHostImpl::GetSandboxStatus() const { |
496 if (have_read_sandbox_status_word_) | 497 if (have_read_sandbox_status_word_) |
497 return sandbox_status_; | 498 return sandbox_status_; |
498 return 0; | 499 return 0; |
499 } | 500 } |
OLD | NEW |