Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(795)

Side by Side Diff: content/zygote/zygote_linux.cc

Issue 23956010: Define magic descriptors in one place. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/zygote/zygote_linux.h" 5 #include "content/zygote/zygote_linux.h"
6 6
7 #include <fcntl.h> 7 #include <fcntl.h>
8 #include <string.h> 8 #include <string.h>
9 #include <sys/socket.h> 9 #include <sys/socket.h>
10 #include <sys/types.h> 10 #include <sys/types.h>
(...skipping 24 matching lines...) Expand all
35 namespace content { 35 namespace content {
36 36
37 namespace { 37 namespace {
38 38
39 // NOP function. See below where this handler is installed. 39 // NOP function. See below where this handler is installed.
40 void SIGCHLDHandler(int signal) { 40 void SIGCHLDHandler(int signal) {
41 } 41 }
42 42
43 } // namespace 43 } // namespace
44 44
45 const int Zygote::kMagicSandboxIPCDescriptor;
46
47 Zygote::Zygote(int sandbox_flags, 45 Zygote::Zygote(int sandbox_flags,
48 ZygoteForkDelegate* helper) 46 ZygoteForkDelegate* helper)
49 : sandbox_flags_(sandbox_flags), 47 : sandbox_flags_(sandbox_flags),
50 helper_(helper), 48 helper_(helper),
51 initial_uma_sample_(0), 49 initial_uma_sample_(0),
52 initial_uma_boundary_value_(0) { 50 initial_uma_boundary_value_(0) {
53 if (helper_) { 51 if (helper_) {
54 helper_->InitialUMA(&initial_uma_name_, 52 helper_->InitialUMA(&initial_uma_name_,
55 &initial_uma_sample_, 53 &initial_uma_sample_,
56 &initial_uma_boundary_value_); 54 &initial_uma_boundary_value_);
(...skipping 13 matching lines...) Expand all
70 // otherwise we cannot wait on children. (According to POSIX 2001.) 68 // otherwise we cannot wait on children. (According to POSIX 2001.)
71 struct sigaction action; 69 struct sigaction action;
72 memset(&action, 0, sizeof(action)); 70 memset(&action, 0, sizeof(action));
73 action.sa_handler = &SIGCHLDHandler; 71 action.sa_handler = &SIGCHLDHandler;
74 CHECK(sigaction(SIGCHLD, &action, NULL) == 0); 72 CHECK(sigaction(SIGCHLD, &action, NULL) == 0);
75 73
76 if (UsingSUIDSandbox()) { 74 if (UsingSUIDSandbox()) {
77 // Let the ZygoteHost know we are ready to go. 75 // Let the ZygoteHost know we are ready to go.
78 // The receiving code is in content/browser/zygote_host_linux.cc. 76 // The receiving code is in content/browser/zygote_host_linux.cc.
79 std::vector<int> empty; 77 std::vector<int> empty;
80 bool r = UnixDomainSocket::SendMsg(kBrowserDescriptor, 78 bool r = UnixDomainSocket::SendMsg(kMagicZygoteDescriptor,
81 kZygoteHelloMessage, 79 kZygoteHelloMessage,
82 sizeof(kZygoteHelloMessage), empty); 80 sizeof(kZygoteHelloMessage), empty);
83 #if defined(OS_CHROMEOS) 81 #if defined(OS_CHROMEOS)
84 LOG_IF(WARNING, !r) << "Sending zygote magic failed"; 82 LOG_IF(WARNING, !r) << "Sending zygote magic failed";
85 // Exit normally on chromeos because session manager may send SIGTERM 83 // Exit normally on chromeos because session manager may send SIGTERM
86 // right after the process starts and it may fail to send zygote magic 84 // right after the process starts and it may fail to send zygote magic
87 // number to browser process. 85 // number to browser process.
88 if (!r) 86 if (!r)
89 _exit(RESULT_CODE_NORMAL_EXIT); 87 _exit(RESULT_CODE_NORMAL_EXIT);
90 #else 88 #else
91 CHECK(r) << "Sending zygote magic failed"; 89 CHECK(r) << "Sending zygote magic failed";
92 #endif 90 #endif
93 } 91 }
94 92
95 for (;;) { 93 for (;;) {
96 // This function call can return multiple times, once per fork(). 94 // This function call can return multiple times, once per fork().
97 if (HandleRequestFromBrowser(kBrowserDescriptor)) 95 if (HandleRequestFromBrowser(kMagicZygoteDescriptor))
98 return true; 96 return true;
99 } 97 }
100 } 98 }
101 99
102 bool Zygote::GetProcessInfo(base::ProcessHandle pid, 100 bool Zygote::GetProcessInfo(base::ProcessHandle pid,
103 ZygoteProcessInfo* process_info) { 101 ZygoteProcessInfo* process_info) {
104 DCHECK(process_info); 102 DCHECK(process_info);
105 const ZygoteProcessMap::const_iterator it = process_info_map_.find(pid); 103 const ZygoteProcessMap::const_iterator it = process_info_map_.find(pid);
106 if (it == process_info_map_.end()) { 104 if (it == process_info_map_.end()) {
107 return false; 105 return false;
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 mapping.push_back(std::make_pair( 466 mapping.push_back(std::make_pair(
469 static_cast<uint32_t>(kSandboxIPCChannel), kMagicSandboxIPCDescriptor)); 467 static_cast<uint32_t>(kSandboxIPCChannel), kMagicSandboxIPCDescriptor));
470 468
471 // Returns twice, once per process. 469 // Returns twice, once per process.
472 base::ProcessId child_pid = ForkWithRealPid(process_type, fds, channel_id, 470 base::ProcessId child_pid = ForkWithRealPid(process_type, fds, channel_id,
473 uma_name, uma_sample, 471 uma_name, uma_sample,
474 uma_boundary_value); 472 uma_boundary_value);
475 if (!child_pid) { 473 if (!child_pid) {
476 // This is the child process. 474 // This is the child process.
477 475
478 close(kBrowserDescriptor); // Our socket from the browser. 476 close(kMagicZygoteDescriptor); // Our socket from the browser.
479 if (UsingSUIDSandbox()) 477 if (UsingSUIDSandbox())
480 close(kZygoteIdFd); // Another socket from the browser. 478 close(kZygoteIdFd); // Another socket from the browser.
481 base::GlobalDescriptors::GetInstance()->Reset(mapping); 479 base::GlobalDescriptors::GetInstance()->Reset(mapping);
482 480
483 // Reset the process-wide command line to our new command line. 481 // Reset the process-wide command line to our new command line.
484 CommandLine::Reset(); 482 CommandLine::Reset();
485 CommandLine::Init(0, NULL); 483 CommandLine::Init(0, NULL);
486 CommandLine::ForCurrentProcess()->InitFromArgv(args); 484 CommandLine::ForCurrentProcess()->InitFromArgv(args);
487 485
488 // Update the process title. The argv was already cached by the call to 486 // Update the process title. The argv was already cached by the call to
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
539 PickleIterator iter) { 537 PickleIterator iter) {
540 if (HANDLE_EINTR(write(fd, &sandbox_flags_, sizeof(sandbox_flags_))) != 538 if (HANDLE_EINTR(write(fd, &sandbox_flags_, sizeof(sandbox_flags_))) !=
541 sizeof(sandbox_flags_)) { 539 sizeof(sandbox_flags_)) {
542 PLOG(ERROR) << "write"; 540 PLOG(ERROR) << "write";
543 } 541 }
544 542
545 return false; 543 return false;
546 } 544 }
547 545
548 } // namespace content 546 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698