OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/browser/zygote_host_linux.h" | 5 #include "chrome/browser/zygote_host_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> |
11 | 11 |
12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
13 #include "base/eintr_wrapper.h" | 13 #include "base/eintr_wrapper.h" |
14 #include "base/linux_util.h" | 14 #include "base/linux_util.h" |
15 #include "base/logging.h" | 15 #include "base/logging.h" |
16 #include "base/path_service.h" | 16 #include "base/path_service.h" |
17 #include "base/pickle.h" | 17 #include "base/pickle.h" |
18 #include "base/process_util.h" | 18 #include "base/process_util.h" |
| 19 #include "base/string_number_conversions.h" |
19 #include "base/string_util.h" | 20 #include "base/string_util.h" |
20 #include "base/unix_domain_socket_posix.h" | 21 #include "base/unix_domain_socket_posix.h" |
21 | 22 |
22 #include "chrome/browser/renderer_host/render_sandbox_host_linux.h" | 23 #include "chrome/browser/renderer_host/render_sandbox_host_linux.h" |
23 #include "chrome/common/chrome_constants.h" | 24 #include "chrome/common/chrome_constants.h" |
24 #include "chrome/common/chrome_switches.h" | 25 #include "chrome/common/chrome_switches.h" |
25 #include "chrome/common/process_watcher.h" | 26 #include "chrome/common/process_watcher.h" |
26 | 27 |
27 #include "sandbox/linux/suid/suid_unsafe_environment_variables.h" | 28 #include "sandbox/linux/suid/suid_unsafe_environment_variables.h" |
28 | 29 |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 | 150 |
150 std::string inode_output; | 151 std::string inode_output; |
151 ino_t inode = 0; | 152 ino_t inode = 0; |
152 // Figure out the inode for |dummy_fd|, close |dummy_fd| on our end, | 153 // Figure out the inode for |dummy_fd|, close |dummy_fd| on our end, |
153 // and find the zygote process holding |dummy_fd|. | 154 // and find the zygote process holding |dummy_fd|. |
154 if (base::FileDescriptorGetInode(&inode, dummy_fd)) { | 155 if (base::FileDescriptorGetInode(&inode, dummy_fd)) { |
155 close(dummy_fd); | 156 close(dummy_fd); |
156 std::vector<std::string> get_inode_cmdline; | 157 std::vector<std::string> get_inode_cmdline; |
157 get_inode_cmdline.push_back(sandbox_binary_); | 158 get_inode_cmdline.push_back(sandbox_binary_); |
158 get_inode_cmdline.push_back(base::kFindInodeSwitch); | 159 get_inode_cmdline.push_back(base::kFindInodeSwitch); |
159 get_inode_cmdline.push_back(Int64ToString(inode)); | 160 get_inode_cmdline.push_back(base::Int64ToString(inode)); |
160 CommandLine get_inode_cmd(get_inode_cmdline); | 161 CommandLine get_inode_cmd(get_inode_cmdline); |
161 if (base::GetAppOutput(get_inode_cmd, &inode_output)) { | 162 if (base::GetAppOutput(get_inode_cmd, &inode_output)) { |
162 StringToInt(inode_output, &pid_); | 163 StringToInt(inode_output, &pid_); |
163 } | 164 } |
164 } | 165 } |
165 CHECK(pid_ > 0) << "Did not find zygote process (using sandbox binary " | 166 CHECK(pid_ > 0) << "Did not find zygote process (using sandbox binary " |
166 << sandbox_binary_ << ")"; | 167 << sandbox_binary_ << ")"; |
167 | 168 |
168 if (process != pid_) { | 169 if (process != pid_) { |
169 // Reap the sandbox. | 170 // Reap the sandbox. |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 } | 266 } |
266 | 267 |
267 const int kRendererScore = 5; | 268 const int kRendererScore = 5; |
268 if (using_suid_sandbox_ && !selinux) { | 269 if (using_suid_sandbox_ && !selinux) { |
269 base::ProcessHandle sandbox_helper_process; | 270 base::ProcessHandle sandbox_helper_process; |
270 base::file_handle_mapping_vector dummy_map; | 271 base::file_handle_mapping_vector dummy_map; |
271 std::vector<std::string> adj_oom_score_cmdline; | 272 std::vector<std::string> adj_oom_score_cmdline; |
272 | 273 |
273 adj_oom_score_cmdline.push_back(sandbox_binary_); | 274 adj_oom_score_cmdline.push_back(sandbox_binary_); |
274 adj_oom_score_cmdline.push_back(base::kAdjustOOMScoreSwitch); | 275 adj_oom_score_cmdline.push_back(base::kAdjustOOMScoreSwitch); |
275 adj_oom_score_cmdline.push_back(Int64ToString(pid)); | 276 adj_oom_score_cmdline.push_back(base::Int64ToString(pid)); |
276 adj_oom_score_cmdline.push_back(IntToString(kRendererScore)); | 277 adj_oom_score_cmdline.push_back(base::IntToString(kRendererScore)); |
277 CommandLine adj_oom_score_cmd(adj_oom_score_cmdline); | 278 CommandLine adj_oom_score_cmd(adj_oom_score_cmdline); |
278 if (base::LaunchApp(adj_oom_score_cmdline, dummy_map, false, | 279 if (base::LaunchApp(adj_oom_score_cmdline, dummy_map, false, |
279 &sandbox_helper_process)) { | 280 &sandbox_helper_process)) { |
280 ProcessWatcher::EnsureProcessGetsReaped(sandbox_helper_process); | 281 ProcessWatcher::EnsureProcessGetsReaped(sandbox_helper_process); |
281 } | 282 } |
282 } else if (!using_suid_sandbox_) { | 283 } else if (!using_suid_sandbox_) { |
283 if (!base::AdjustOOMScore(pid, kRendererScore)) | 284 if (!base::AdjustOOMScore(pid, kRendererScore)) |
284 LOG(ERROR) << "Failed to adjust OOM score of renderer"; | 285 LOG(ERROR) << "Failed to adjust OOM score of renderer"; |
285 } | 286 } |
286 | 287 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 !read_pickle.ReadBool(&iter, &tmp_child_exited)) { | 332 !read_pickle.ReadBool(&iter, &tmp_child_exited)) { |
332 LOG(WARNING) << "Error parsing DidProcessCrash response from zygote."; | 333 LOG(WARNING) << "Error parsing DidProcessCrash response from zygote."; |
333 return false; | 334 return false; |
334 } | 335 } |
335 | 336 |
336 if (child_exited) | 337 if (child_exited) |
337 *child_exited = tmp_child_exited; | 338 *child_exited = tmp_child_exited; |
338 | 339 |
339 return did_crash; | 340 return did_crash; |
340 } | 341 } |
OLD | NEW |