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

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

Issue 240673002: Simplify ZygoteForkDelegate API further (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Don't leak real PID to NaCl child processes Created 6 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « content/public/common/zygote_fork_delegate_linux.h ('k') | no next file » | 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 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 if (use_helper) { 326 if (use_helper) {
327 std::vector<int> fds; 327 std::vector<int> fds;
328 int ipc_channel_fd = LookUpFd(fd_mapping, kPrimaryIPCChannel); 328 int ipc_channel_fd = LookUpFd(fd_mapping, kPrimaryIPCChannel);
329 if (ipc_channel_fd < 0) { 329 if (ipc_channel_fd < 0) {
330 DLOG(ERROR) << "Failed to find kPrimaryIPCChannel in FD mapping"; 330 DLOG(ERROR) << "Failed to find kPrimaryIPCChannel in FD mapping";
331 goto error; 331 goto error;
332 } 332 }
333 fds.push_back(ipc_channel_fd); // kBrowserFDIndex 333 fds.push_back(ipc_channel_fd); // kBrowserFDIndex
334 fds.push_back(dummy_fd); // kDummyFDIndex 334 fds.push_back(dummy_fd); // kDummyFDIndex
335 fds.push_back(pipe_fds[0]); // kParentFDIndex 335 fds.push_back(pipe_fds[0]); // kParentFDIndex
336 pid = helper_->Fork(process_type, fds); 336 pid = helper_->Fork(process_type, fds, channel_id);
337 } else { 337 } else {
338 pid = fork(); 338 pid = fork();
339 } 339 }
340 if (pid < 0) { 340 if (pid < 0) {
341 goto error; 341 goto error;
342 } else if (pid == 0) { 342 } else if (pid == 0) {
343 // In the child process. 343 // In the child process.
344 close(pipe_fds[1]); 344 close(pipe_fds[1]);
345 base::ProcessId real_pid; 345 base::ProcessId real_pid;
346 // Wait until the parent process has discovered our PID. We 346 // Wait until the parent process has discovered our PID. We
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 } 403 }
404 404
405 // Now set-up this process to be tracked by the Zygote. 405 // Now set-up this process to be tracked by the Zygote.
406 if (process_info_map_.find(real_pid) != process_info_map_.end()) { 406 if (process_info_map_.find(real_pid) != process_info_map_.end()) {
407 LOG(ERROR) << "Already tracking PID " << real_pid; 407 LOG(ERROR) << "Already tracking PID " << real_pid;
408 NOTREACHED(); 408 NOTREACHED();
409 } 409 }
410 process_info_map_[real_pid].internal_pid = pid; 410 process_info_map_[real_pid].internal_pid = pid;
411 process_info_map_[real_pid].started_from_helper = use_helper; 411 process_info_map_[real_pid].started_from_helper = use_helper;
412 412
413 if (use_helper) { 413 // If we're using a helper, we still need to let the child process know
414 if (!helper_->AckChild(pipe_fds[1], channel_id)) { 414 // we've discovered its real PID, but we don't actually reveal the PID.
415 LOG(ERROR) << "Failed to synchronise with zygote fork helper"; 415 const base::ProcessId pid_for_child = use_helper ? 0 : real_pid;
416 goto error; 416 ssize_t written =
417 } 417 HANDLE_EINTR(write(pipe_fds[1], &pid_for_child, sizeof(pid_for_child)));
418 } else { 418 if (written != sizeof(pid_for_child)) {
419 int written = 419 LOG(ERROR) << "Failed to synchronise with child process";
420 HANDLE_EINTR(write(pipe_fds[1], &real_pid, sizeof(real_pid))); 420 goto error;
421 if (written != sizeof(real_pid)) {
422 LOG(ERROR) << "Failed to synchronise with child process";
423 goto error;
424 }
425 } 421 }
426 close(pipe_fds[1]); 422 close(pipe_fds[1]);
427 return real_pid; 423 return real_pid;
428 } 424 }
429 425
430 error: 426 error:
431 if (pid > 0) { 427 if (pid > 0) {
432 if (waitpid(pid, NULL, WNOHANG) == -1) 428 if (waitpid(pid, NULL, WNOHANG) == -1)
433 LOG(ERROR) << "Failed to wait for process"; 429 LOG(ERROR) << "Failed to wait for process";
434 } 430 }
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
556 PickleIterator iter) { 552 PickleIterator iter) {
557 if (HANDLE_EINTR(write(fd, &sandbox_flags_, sizeof(sandbox_flags_))) != 553 if (HANDLE_EINTR(write(fd, &sandbox_flags_, sizeof(sandbox_flags_))) !=
558 sizeof(sandbox_flags_)) { 554 sizeof(sandbox_flags_)) {
559 PLOG(ERROR) << "write"; 555 PLOG(ERROR) << "write";
560 } 556 }
561 557
562 return false; 558 return false;
563 } 559 }
564 560
565 } // namespace content 561 } // namespace content
OLDNEW
« no previous file with comments | « content/public/common/zygote_fork_delegate_linux.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698