| 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 AdjustRendererOOMScore(pid, kRendererScore); | 276 // only types of processes that will be started this way). It will |
| 277 // get adjusted as time goes on. (This is the same value as |
| 278 // chrome::kLowestRendererOomScore in chrome/chrome_constants.h, but |
| 279 // that's not something we can include here.) |
| 280 const int kLowestRendererOomScore = 300; |
| 281 AdjustRendererOOMScore(pid, kLowestRendererOomScore); |
| 277 | 282 |
| 278 return pid; | 283 return pid; |
| 279 } | 284 } |
| 280 | 285 |
| 281 void ZygoteHost::AdjustRendererOOMScore(base::ProcessHandle pid, int score) { | 286 void ZygoteHost::AdjustRendererOOMScore(base::ProcessHandle pid, int score) { |
| 282 // 1) You can't change the oom_adj of a non-dumpable process (EPERM) unless | 287 // 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 | 288 // (EPERM) unless you're root. Because of this, we can't set the |
| 284 // process. | 289 // oom_adj from the browser process. |
| 285 // | 290 // |
| 286 // 2) We can't set the oom_adj before entering the sandbox because the | 291 // 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 | 292 // because the zygote is in the sandbox and the zygote is as |
| 288 // process. Its oom_adj value shouldn't be changed. | 293 // critical as the browser process. Its oom_adj value shouldn't |
| 294 // be changed. |
| 289 // | 295 // |
| 290 // 3) A non-dumpable process can't even change its own oom_adj because it's | 296 // 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 | 297 // because it's root owned 0644. The sandboxed processes don't |
| 292 // could imagine passing in a descriptor from outside. | 298 // even have /proc, but one could imagine passing in a descriptor |
| 299 // from outside. |
| 293 // | 300 // |
| 294 // So, in the normal case, we use the SUID binary to change it for us. | 301 // 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 | 302 // However, Fedora (and other SELinux systems) don't like us touching other |
| 296 // process's oom_adj values | 303 // process's oom_score_adj (or oom_adj) values |
| 297 // (https://bugzilla.redhat.com/show_bug.cgi?id=581256). | 304 // (https://bugzilla.redhat.com/show_bug.cgi?id=581256). |
| 298 // | 305 // |
| 299 // The offical way to get the SELinux mode is selinux_getenforcemode, but I | 306 // 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 | 307 // don't want to add another library to the build as it's sure to cause |
| 301 // problems with other, non-SELinux distros. | 308 // problems with other, non-SELinux distros. |
| 302 // | 309 // |
| 303 // So we just check for /selinux. This isn't foolproof, but it's not bad | 310 // So we just check for /selinux. This isn't foolproof, but it's not bad |
| 304 // and it's easy. | 311 // and it's easy. |
| 305 | 312 |
| 306 static bool selinux; | 313 static bool selinux; |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 385 !read_pickle.ReadInt(&iter, &tmp_exit_code)) { | 392 !read_pickle.ReadInt(&iter, &tmp_exit_code)) { |
| 386 LOG(WARNING) << "Error parsing GetTerminationStatus response from zygote."; | 393 LOG(WARNING) << "Error parsing GetTerminationStatus response from zygote."; |
| 387 return base::TERMINATION_STATUS_NORMAL_TERMINATION; | 394 return base::TERMINATION_STATUS_NORMAL_TERMINATION; |
| 388 } | 395 } |
| 389 | 396 |
| 390 if (exit_code) | 397 if (exit_code) |
| 391 *exit_code = tmp_exit_code; | 398 *exit_code = tmp_exit_code; |
| 392 | 399 |
| 393 return static_cast<base::TerminationStatus>(status); | 400 return static_cast<base::TerminationStatus>(status); |
| 394 } | 401 } |
| OLD | NEW |