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/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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 // We need to accept SIGCHLD, even though our handler is a no-op because | 76 // We need to accept SIGCHLD, even though our handler is a no-op because |
77 // otherwise we cannot wait on children. (According to POSIX 2001.) | 77 // otherwise we cannot wait on children. (According to POSIX 2001.) |
78 struct sigaction action; | 78 struct sigaction action; |
79 memset(&action, 0, sizeof(action)); | 79 memset(&action, 0, sizeof(action)); |
80 action.sa_handler = &SIGCHLDHandler; | 80 action.sa_handler = &SIGCHLDHandler; |
81 CHECK(sigaction(SIGCHLD, &action, NULL) == 0); | 81 CHECK(sigaction(SIGCHLD, &action, NULL) == 0); |
82 | 82 |
83 if (UsingSUIDSandbox()) { | 83 if (UsingSUIDSandbox()) { |
84 // Let the ZygoteHost know we are ready to go. | 84 // Let the ZygoteHost know we are ready to go. |
85 // The receiving code is in content/browser/zygote_host_linux.cc. | 85 // The receiving code is in content/browser/zygote_host_linux.cc. |
86 std::vector<int> empty; | |
87 bool r = UnixDomainSocket::SendMsg(kZygoteSocketPairFd, | 86 bool r = UnixDomainSocket::SendMsg(kZygoteSocketPairFd, |
88 kZygoteHelloMessage, | 87 kZygoteHelloMessage, |
89 sizeof(kZygoteHelloMessage), empty); | 88 sizeof(kZygoteHelloMessage), |
| 89 std::vector<int>()); |
90 #if defined(OS_CHROMEOS) | 90 #if defined(OS_CHROMEOS) |
91 LOG_IF(WARNING, !r) << "Sending zygote magic failed"; | 91 LOG_IF(WARNING, !r) << "Sending zygote magic failed"; |
92 // Exit normally on chromeos because session manager may send SIGTERM | 92 // Exit normally on chromeos because session manager may send SIGTERM |
93 // right after the process starts and it may fail to send zygote magic | 93 // right after the process starts and it may fail to send zygote magic |
94 // number to browser process. | 94 // number to browser process. |
95 if (!r) | 95 if (!r) |
96 _exit(RESULT_CODE_NORMAL_EXIT); | 96 _exit(RESULT_CODE_NORMAL_EXIT); |
97 #else | 97 #else |
98 CHECK(r) << "Sending zygote magic failed"; | 98 CHECK(r) << "Sending zygote magic failed"; |
99 #endif | 99 #endif |
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
482 static_cast<uint32_t>(kSandboxIPCChannel), GetSandboxFD())); | 482 static_cast<uint32_t>(kSandboxIPCChannel), GetSandboxFD())); |
483 | 483 |
484 // Returns twice, once per process. | 484 // Returns twice, once per process. |
485 base::ProcessId child_pid = ForkWithRealPid(process_type, mapping, channel_id, | 485 base::ProcessId child_pid = ForkWithRealPid(process_type, mapping, channel_id, |
486 uma_name, uma_sample, | 486 uma_name, uma_sample, |
487 uma_boundary_value); | 487 uma_boundary_value); |
488 if (!child_pid) { | 488 if (!child_pid) { |
489 // This is the child process. | 489 // This is the child process. |
490 | 490 |
491 close(kZygoteSocketPairFd); // Our socket from the browser. | 491 close(kZygoteSocketPairFd); // Our socket from the browser. |
492 if (UsingSUIDSandbox()) | |
493 close(kZygoteIdFd); // Another socket from the browser. | |
494 base::GlobalDescriptors::GetInstance()->Reset(mapping); | 492 base::GlobalDescriptors::GetInstance()->Reset(mapping); |
495 | 493 |
496 // Reset the process-wide command line to our new command line. | 494 // Reset the process-wide command line to our new command line. |
497 CommandLine::Reset(); | 495 CommandLine::Reset(); |
498 CommandLine::Init(0, NULL); | 496 CommandLine::Init(0, NULL); |
499 CommandLine::ForCurrentProcess()->InitFromArgv(args); | 497 CommandLine::ForCurrentProcess()->InitFromArgv(args); |
500 | 498 |
501 // Update the process title. The argv was already cached by the call to | 499 // Update the process title. The argv was already cached by the call to |
502 // SetProcessTitleFromCommandLine in ChromeMain, so we can pass NULL here | 500 // SetProcessTitleFromCommandLine in ChromeMain, so we can pass NULL here |
503 // (we don't have the original argv at this point). | 501 // (we don't have the original argv at this point). |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
552 PickleIterator iter) { | 550 PickleIterator iter) { |
553 if (HANDLE_EINTR(write(fd, &sandbox_flags_, sizeof(sandbox_flags_))) != | 551 if (HANDLE_EINTR(write(fd, &sandbox_flags_, sizeof(sandbox_flags_))) != |
554 sizeof(sandbox_flags_)) { | 552 sizeof(sandbox_flags_)) { |
555 PLOG(ERROR) << "write"; | 553 PLOG(ERROR) << "write"; |
556 } | 554 } |
557 | 555 |
558 return false; | 556 return false; |
559 } | 557 } |
560 | 558 |
561 } // namespace content | 559 } // namespace content |
OLD | NEW |