Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_linux.h" | 5 #include "content/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> |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 265 if (!UnixDomainSocket::SendMsg(control_fd_, pickle.data(), pickle.size(), | 265 if (!UnixDomainSocket::SendMsg(control_fd_, pickle.data(), pickle.size(), |
| 266 fds)) | 266 fds)) |
| 267 return base::kNullProcessHandle; | 267 return base::kNullProcessHandle; |
| 268 | 268 |
| 269 if (ReadReply(&pid, sizeof(pid)) != sizeof(pid)) | 269 if (ReadReply(&pid, sizeof(pid)) != sizeof(pid)) |
| 270 return base::kNullProcessHandle; | 270 return base::kNullProcessHandle; |
| 271 if (pid <= 0) | 271 if (pid <= 0) |
| 272 return base::kNullProcessHandle; | 272 return base::kNullProcessHandle; |
| 273 } | 273 } |
| 274 | 274 |
| 275 const int kRendererScore = 5; | 275 // This is just a starting score for a renderer or extension (the |
| 276 // only types of processes that will be started this way). It will | |
| 277 // get adjusted as time goes on. | |
| 278 const int kRendererScore = 300; | |
|
stevenjb
2011/08/18 00:20:07
One class to rule them all?
Greg Spencer (Chromium)
2011/08/18 23:10:50
OK, moved this to common/chrome_constants.h
| |
| 276 AdjustRendererOOMScore(pid, kRendererScore); | 279 AdjustRendererOOMScore(pid, kRendererScore); |
| 277 | 280 |
| 278 return pid; | 281 return pid; |
| 279 } | 282 } |
| 280 | 283 |
| 281 void ZygoteHost::AdjustRendererOOMScore(base::ProcessHandle pid, int score) { | 284 void ZygoteHost::AdjustRendererOOMScore(base::ProcessHandle pid, int score) { |
| 282 // 1) You can't change the oom_adj of a non-dumpable process (EPERM) unless | 285 // 1) You can't change the oom_score_adj of a non-dumpable process |
| 283 // you're root. Because of this, we can't set the oom_adj from the browser | 286 // (EPERM) unless you're root. Because of this, we can't set the |
| 284 // process. | 287 // oom_adj from the browser process. |
| 285 // | 288 // |
| 286 // 2) We can't set the oom_adj before entering the sandbox because the | 289 // 2) We can't set the oom_score_adj before entering the sandbox |
| 287 // zygote is in the sandbox and the zygote is as critical as the browser | 290 // because the zygote is in the sandbox and the zygote is as |
| 288 // process. Its oom_adj value shouldn't be changed. | 291 // critical as the browser process. Its oom_adj value shouldn't |
| 292 // be changed. | |
| 289 // | 293 // |
| 290 // 3) A non-dumpable process can't even change its own oom_adj because it's | 294 // 3) A non-dumpable process can't even change its own oom_score_adj |
| 291 // root owned 0644. The sandboxed processes don't even have /proc, but one | 295 // because it's root owned 0644. The sandboxed processes don't |
| 292 // could imagine passing in a descriptor from outside. | 296 // even have /proc, but one could imagine passing in a descriptor |
| 297 // from outside. | |
| 293 // | 298 // |
| 294 // So, in the normal case, we use the SUID binary to change it for us. | 299 // So, in the normal case, we use the SUID binary to change it for us. |
| 295 // However, Fedora (and other SELinux systems) don't like us touching other | 300 // However, Fedora (and other SELinux systems) don't like us touching other |
| 296 // process's oom_adj values | 301 // process's oom_score_adj values |
| 297 // (https://bugzilla.redhat.com/show_bug.cgi?id=581256). | 302 // (https://bugzilla.redhat.com/show_bug.cgi?id=581256). |
| 298 // | 303 // |
| 299 // The offical way to get the SELinux mode is selinux_getenforcemode, but I | 304 // The offical way to get the SELinux mode is selinux_getenforcemode, but I |
| 300 // don't want to add another library to the build as it's sure to cause | 305 // don't want to add another library to the build as it's sure to cause |
| 301 // problems with other, non-SELinux distros. | 306 // problems with other, non-SELinux distros. |
| 302 // | 307 // |
| 303 // So we just check for /selinux. This isn't foolproof, but it's not bad | 308 // So we just check for /selinux. This isn't foolproof, but it's not bad |
| 304 // and it's easy. | 309 // and it's easy. |
| 305 | 310 |
| 306 static bool selinux; | 311 static bool selinux; |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 385 !read_pickle.ReadInt(&iter, &tmp_exit_code)) { | 390 !read_pickle.ReadInt(&iter, &tmp_exit_code)) { |
| 386 LOG(WARNING) << "Error parsing GetTerminationStatus response from zygote."; | 391 LOG(WARNING) << "Error parsing GetTerminationStatus response from zygote."; |
| 387 return base::TERMINATION_STATUS_NORMAL_TERMINATION; | 392 return base::TERMINATION_STATUS_NORMAL_TERMINATION; |
| 388 } | 393 } |
| 389 | 394 |
| 390 if (exit_code) | 395 if (exit_code) |
| 391 *exit_code = tmp_exit_code; | 396 *exit_code = tmp_exit_code; |
| 392 | 397 |
| 393 return static_cast<base::TerminationStatus>(status); | 398 return static_cast<base::TerminationStatus>(status); |
| 394 } | 399 } |
| OLD | NEW |