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

Side by Side Diff: base/process_util_posix.cc

Issue 6995121: New NaCl zygote implementation 2 (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Fixing includes for checkdeps.py Created 9 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 | Annotate | Revision Log
OLDNEW
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 <dirent.h> 5 #include <dirent.h>
6 #include <errno.h> 6 #include <errno.h>
7 #include <fcntl.h> 7 #include <fcntl.h>
8 #include <signal.h> 8 #include <signal.h>
9 #include <stdlib.h> 9 #include <stdlib.h>
10 #include <sys/resource.h> 10 #include <sys/resource.h>
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 ret[k] = NULL; 489 ret[k] = NULL;
490 return ret; 490 return ret;
491 } 491 }
492 492
493 bool LaunchAppImpl( 493 bool LaunchAppImpl(
494 const std::vector<std::string>& argv, 494 const std::vector<std::string>& argv,
495 const environment_vector& env_changes, 495 const environment_vector& env_changes,
496 const file_handle_mapping_vector& fds_to_remap, 496 const file_handle_mapping_vector& fds_to_remap,
497 bool wait, 497 bool wait,
498 ProcessHandle* process_handle, 498 ProcessHandle* process_handle,
499 bool start_new_process_group) { 499 bool start_new_process_group,
500 bool use_clone,
501 int clone_flags) {
500 pid_t pid; 502 pid_t pid;
501 InjectiveMultimap fd_shuffle1, fd_shuffle2; 503 InjectiveMultimap fd_shuffle1, fd_shuffle2;
502 fd_shuffle1.reserve(fds_to_remap.size()); 504 fd_shuffle1.reserve(fds_to_remap.size());
503 fd_shuffle2.reserve(fds_to_remap.size()); 505 fd_shuffle2.reserve(fds_to_remap.size());
504 scoped_array<char*> argv_cstr(new char*[argv.size() + 1]); 506 scoped_array<char*> argv_cstr(new char*[argv.size() + 1]);
505 scoped_array<char*> new_environ(AlterEnvironment(env_changes, environ)); 507 scoped_array<char*> new_environ(AlterEnvironment(env_changes, environ));
506 508
507 pid = fork(); 509 if (use_clone) {
510 #if defined(OS_LINUX)
511 pid = syscall(__NR_clone, clone_flags, 0, 0, 0);
512 #else
513 NOTREACHED();
514 LOG(ERROR) << "Tried to use clone() on non-Linux system.";
515 #endif
516 } else {
517 pid = fork();
518 }
508 if (pid < 0) { 519 if (pid < 0) {
509 PLOG(ERROR) << "fork"; 520 PLOG(ERROR) << "fork";
510 return false; 521 return false;
511 } 522 }
512 if (pid == 0) { 523 if (pid == 0) {
513 // Child process 524 // Child process
514 525
515 // DANGER: fork() rule: in the child, if you don't end up doing exec*(), 526 // DANGER: fork() rule: in the child, if you don't end up doing exec*(),
516 // you call _exit() instead of exit(). This is because _exit() does not 527 // you call _exit() instead of exit(). This is because _exit() does not
517 // call any previously-registered (in the parent) exit handlers, which 528 // call any previously-registered (in the parent) exit handlers, which
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
598 return true; 609 return true;
599 } 610 }
600 611
601 bool LaunchApp( 612 bool LaunchApp(
602 const std::vector<std::string>& argv, 613 const std::vector<std::string>& argv,
603 const environment_vector& env_changes, 614 const environment_vector& env_changes,
604 const file_handle_mapping_vector& fds_to_remap, 615 const file_handle_mapping_vector& fds_to_remap,
605 bool wait, 616 bool wait,
606 ProcessHandle* process_handle) { 617 ProcessHandle* process_handle) {
607 return LaunchAppImpl(argv, env_changes, fds_to_remap, 618 return LaunchAppImpl(argv, env_changes, fds_to_remap,
608 wait, process_handle, false); 619 wait, process_handle,
620 false, // don't start new process group
621 false, // don't use clone()
622 0); // clone flags
609 } 623 }
610 624
611 bool LaunchAppInNewProcessGroup( 625 bool LaunchAppInNewProcessGroup(
612 const std::vector<std::string>& argv, 626 const std::vector<std::string>& argv,
613 const environment_vector& env_changes, 627 const environment_vector& env_changes,
614 const file_handle_mapping_vector& fds_to_remap, 628 const file_handle_mapping_vector& fds_to_remap,
615 bool wait, 629 bool wait,
616 ProcessHandle* process_handle) { 630 ProcessHandle* process_handle) {
617 return LaunchAppImpl(argv, env_changes, fds_to_remap, wait, 631 return LaunchAppImpl(argv, env_changes, fds_to_remap, wait,
618 process_handle, true); 632 process_handle,
633 true, // start new process group
634 false, // don't use clone()
635 0); // clone flags
636 }
637
638 BASE_API bool LaunchAppWithClone(const std::vector<std::string>& argv,
639 const file_handle_mapping_vector& fds_to_remap,
640 bool wait, ProcessHandle* process_handle,
641 int clone_flags) {
642 base::environment_vector no_env;
643 return LaunchAppImpl(argv, no_env, fds_to_remap, wait, process_handle,
644 false, // don't start new process group
645 true, // use clone()
646 clone_flags);
619 } 647 }
620 648
621 bool LaunchApp(const std::vector<std::string>& argv, 649 bool LaunchApp(const std::vector<std::string>& argv,
622 const file_handle_mapping_vector& fds_to_remap, 650 const file_handle_mapping_vector& fds_to_remap,
623 bool wait, ProcessHandle* process_handle) { 651 bool wait, ProcessHandle* process_handle) {
624 base::environment_vector no_env; 652 base::environment_vector no_env;
625 return LaunchApp(argv, no_env, fds_to_remap, wait, process_handle); 653 return LaunchApp(argv, no_env, fds_to_remap, wait, process_handle);
626 } 654 }
627 655
628 bool LaunchApp(const CommandLine& cl, 656 bool LaunchApp(const CommandLine& cl,
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after
993 const ProcessFilter* filter) { 1021 const ProcessFilter* filter) {
994 bool exited_cleanly = 1022 bool exited_cleanly =
995 WaitForProcessesToExit(executable_name, wait_milliseconds, 1023 WaitForProcessesToExit(executable_name, wait_milliseconds,
996 filter); 1024 filter);
997 if (!exited_cleanly) 1025 if (!exited_cleanly)
998 KillProcesses(executable_name, exit_code, filter); 1026 KillProcesses(executable_name, exit_code, filter);
999 return exited_cleanly; 1027 return exited_cleanly;
1000 } 1028 }
1001 1029
1002 } // namespace base 1030 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698