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

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

Issue 1146813011: Move UnixDomainSocket to base namespace (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 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
« no previous file with comments | « content/common/send_zygote_child_ping_linux.cc ('k') | content/zygote/zygote_main_linux.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 // We need to accept SIGCHLD, even though our handler is a no-op because 112 // We need to accept SIGCHLD, even though our handler is a no-op because
113 // otherwise we cannot wait on children. (According to POSIX 2001.) 113 // otherwise we cannot wait on children. (According to POSIX 2001.)
114 struct sigaction action; 114 struct sigaction action;
115 memset(&action, 0, sizeof(action)); 115 memset(&action, 0, sizeof(action));
116 action.sa_handler = &SIGCHLDHandler; 116 action.sa_handler = &SIGCHLDHandler;
117 PCHECK(sigaction(SIGCHLD, &action, NULL) == 0); 117 PCHECK(sigaction(SIGCHLD, &action, NULL) == 0);
118 118
119 if (UsingSUIDSandbox() || UsingNSSandbox()) { 119 if (UsingSUIDSandbox() || UsingNSSandbox()) {
120 // Let the ZygoteHost know we are ready to go. 120 // Let the ZygoteHost know we are ready to go.
121 // The receiving code is in content/browser/zygote_host_linux.cc. 121 // The receiving code is in content/browser/zygote_host_linux.cc.
122 bool r = UnixDomainSocket::SendMsg(kZygoteSocketPairFd, 122 bool r = base::UnixDomainSocket::SendMsg(kZygoteSocketPairFd,
123 kZygoteHelloMessage, 123 kZygoteHelloMessage,
124 sizeof(kZygoteHelloMessage), 124 sizeof(kZygoteHelloMessage),
125 std::vector<int>()); 125 std::vector<int>());
126 #if defined(OS_CHROMEOS) 126 #if defined(OS_CHROMEOS)
127 LOG_IF(WARNING, !r) << "Sending zygote magic failed"; 127 LOG_IF(WARNING, !r) << "Sending zygote magic failed";
128 // Exit normally on chromeos because session manager may send SIGTERM 128 // Exit normally on chromeos because session manager may send SIGTERM
129 // right after the process starts and it may fail to send zygote magic 129 // right after the process starts and it may fail to send zygote magic
130 // number to browser process. 130 // number to browser process.
131 if (!r) 131 if (!r)
132 _exit(RESULT_CODE_NORMAL_EXIT); 132 _exit(RESULT_CODE_NORMAL_EXIT);
133 #else 133 #else
134 CHECK(r) << "Sending zygote magic failed"; 134 CHECK(r) << "Sending zygote magic failed";
135 #endif 135 #endif
(...skipping 21 matching lines...) Expand all
157 return sandbox_flags_ & kSandboxLinuxSUID; 157 return sandbox_flags_ & kSandboxLinuxSUID;
158 } 158 }
159 159
160 bool Zygote::UsingNSSandbox() const { 160 bool Zygote::UsingNSSandbox() const {
161 return sandbox_flags_ & kSandboxLinuxUserNS; 161 return sandbox_flags_ & kSandboxLinuxUserNS;
162 } 162 }
163 163
164 bool Zygote::HandleRequestFromBrowser(int fd) { 164 bool Zygote::HandleRequestFromBrowser(int fd) {
165 ScopedVector<base::ScopedFD> fds; 165 ScopedVector<base::ScopedFD> fds;
166 char buf[kZygoteMaxMessageLength]; 166 char buf[kZygoteMaxMessageLength];
167 const ssize_t len = UnixDomainSocket::RecvMsg(fd, buf, sizeof(buf), &fds); 167 const ssize_t len = base::UnixDomainSocket::RecvMsg(
168 fd, buf, sizeof(buf), &fds);
168 169
169 if (len == 0 || (len == -1 && errno == ECONNRESET)) { 170 if (len == 0 || (len == -1 && errno == ECONNRESET)) {
170 // EOF from the browser. We should die. 171 // EOF from the browser. We should die.
171 // TODO(earthdok): call __sanititizer_cov_dump() here to obtain code 172 // TODO(earthdok): call __sanititizer_cov_dump() here to obtain code
172 // coverage for the Zygote. Currently it's not possible because of 173 // coverage for the Zygote. Currently it's not possible because of
173 // confusion over who is responsible for closing the file descriptor. 174 // confusion over who is responsible for closing the file descriptor.
174 for (std::vector<int>::iterator it = extra_fds_.begin(); 175 for (std::vector<int>::iterator it = extra_fds_.begin();
175 it < extra_fds_.end(); ++it) { 176 it < extra_fds_.end(); ++it) {
176 PCHECK(0 == IGNORE_EINTR(close(*it))); 177 PCHECK(0 == IGNORE_EINTR(close(*it)));
177 } 178 }
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 // In the parent process. 449 // In the parent process.
449 read_pipe.reset(); 450 read_pipe.reset();
450 pid_oracle.reset(); 451 pid_oracle.reset();
451 452
452 // Always receive a real PID from the zygote host, though it might 453 // Always receive a real PID from the zygote host, though it might
453 // be invalid (see below). 454 // be invalid (see below).
454 base::ProcessId real_pid; 455 base::ProcessId real_pid;
455 { 456 {
456 ScopedVector<base::ScopedFD> recv_fds; 457 ScopedVector<base::ScopedFD> recv_fds;
457 char buf[kZygoteMaxMessageLength]; 458 char buf[kZygoteMaxMessageLength];
458 const ssize_t len = UnixDomainSocket::RecvMsg( 459 const ssize_t len = base::UnixDomainSocket::RecvMsg(
459 kZygoteSocketPairFd, buf, sizeof(buf), &recv_fds); 460 kZygoteSocketPairFd, buf, sizeof(buf), &recv_fds);
460 CHECK_GT(len, 0); 461 CHECK_GT(len, 0);
461 CHECK(recv_fds.empty()); 462 CHECK(recv_fds.empty());
462 463
463 Pickle pickle(buf, len); 464 Pickle pickle(buf, len);
464 PickleIterator iter(pickle); 465 PickleIterator iter(pickle);
465 466
466 int kind; 467 int kind;
467 CHECK(iter.ReadInt(&kind)); 468 CHECK(iter.ReadInt(&kind));
468 CHECK(kind == kZygoteCommandForkRealPID); 469 CHECK(kind == kZygoteCommandForkRealPID);
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
621 PickleIterator iter) { 622 PickleIterator iter) {
622 if (HANDLE_EINTR(write(fd, &sandbox_flags_, sizeof(sandbox_flags_))) != 623 if (HANDLE_EINTR(write(fd, &sandbox_flags_, sizeof(sandbox_flags_))) !=
623 sizeof(sandbox_flags_)) { 624 sizeof(sandbox_flags_)) {
624 PLOG(ERROR) << "write"; 625 PLOG(ERROR) << "write";
625 } 626 }
626 627
627 return false; 628 return false;
628 } 629 }
629 630
630 } // namespace content 631 } // namespace content
OLDNEW
« no previous file with comments | « content/common/send_zygote_child_ping_linux.cc ('k') | content/zygote/zygote_main_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698