OLD | NEW |
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 490 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
501 ret[k] = NULL; | 501 ret[k] = NULL; |
502 return ret; | 502 return ret; |
503 } | 503 } |
504 | 504 |
505 bool LaunchAppImpl( | 505 bool LaunchAppImpl( |
506 const std::vector<std::string>& argv, | 506 const std::vector<std::string>& argv, |
507 const environment_vector& env_changes, | 507 const environment_vector& env_changes, |
508 const file_handle_mapping_vector& fds_to_remap, | 508 const file_handle_mapping_vector& fds_to_remap, |
509 bool wait, | 509 bool wait, |
510 ProcessHandle* process_handle, | 510 ProcessHandle* process_handle, |
511 bool start_new_process_group) { | 511 bool start_new_process_group, |
| 512 bool use_clone, |
| 513 int clone_flags) { |
512 pid_t pid; | 514 pid_t pid; |
513 InjectiveMultimap fd_shuffle1, fd_shuffle2; | 515 InjectiveMultimap fd_shuffle1, fd_shuffle2; |
514 fd_shuffle1.reserve(fds_to_remap.size()); | 516 fd_shuffle1.reserve(fds_to_remap.size()); |
515 fd_shuffle2.reserve(fds_to_remap.size()); | 517 fd_shuffle2.reserve(fds_to_remap.size()); |
516 scoped_array<char*> argv_cstr(new char*[argv.size() + 1]); | 518 scoped_array<char*> argv_cstr(new char*[argv.size() + 1]); |
517 scoped_array<char*> new_environ(AlterEnvironment(env_changes, environ)); | 519 scoped_array<char*> new_environ(AlterEnvironment(env_changes, environ)); |
518 | 520 |
519 pid = fork(); | 521 if (use_clone) { |
| 522 #if defined(OS_LINUX) |
| 523 pid = syscall(__NR_clone, clone_flags, 0, 0, 0); |
| 524 #else |
| 525 NOTREACHED() << "Tried to use clone() on non-Linux system."; |
| 526 #endif |
| 527 } else { |
| 528 pid = fork(); |
| 529 } |
520 if (pid < 0) { | 530 if (pid < 0) { |
521 PLOG(ERROR) << "fork"; | 531 PLOG(ERROR) << "fork"; |
522 return false; | 532 return false; |
523 } | 533 } |
524 if (pid == 0) { | 534 if (pid == 0) { |
525 // Child process | 535 // Child process |
526 | 536 |
527 // DANGER: fork() rule: in the child, if you don't end up doing exec*(), | 537 // DANGER: fork() rule: in the child, if you don't end up doing exec*(), |
528 // you call _exit() instead of exit(). This is because _exit() does not | 538 // you call _exit() instead of exit(). This is because _exit() does not |
529 // call any previously-registered (in the parent) exit handlers, which | 539 // call any previously-registered (in the parent) exit handlers, which |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
610 return true; | 620 return true; |
611 } | 621 } |
612 | 622 |
613 bool LaunchApp( | 623 bool LaunchApp( |
614 const std::vector<std::string>& argv, | 624 const std::vector<std::string>& argv, |
615 const environment_vector& env_changes, | 625 const environment_vector& env_changes, |
616 const file_handle_mapping_vector& fds_to_remap, | 626 const file_handle_mapping_vector& fds_to_remap, |
617 bool wait, | 627 bool wait, |
618 ProcessHandle* process_handle) { | 628 ProcessHandle* process_handle) { |
619 return LaunchAppImpl(argv, env_changes, fds_to_remap, | 629 return LaunchAppImpl(argv, env_changes, fds_to_remap, |
620 wait, process_handle, false); | 630 wait, process_handle, |
| 631 false, // don't start new process group |
| 632 false, // don't use clone() |
| 633 0); // clone flags |
621 } | 634 } |
622 | 635 |
623 bool LaunchAppInNewProcessGroup( | 636 bool LaunchAppInNewProcessGroup( |
624 const std::vector<std::string>& argv, | 637 const std::vector<std::string>& argv, |
625 const environment_vector& env_changes, | 638 const environment_vector& env_changes, |
626 const file_handle_mapping_vector& fds_to_remap, | 639 const file_handle_mapping_vector& fds_to_remap, |
627 bool wait, | 640 bool wait, |
628 ProcessHandle* process_handle) { | 641 ProcessHandle* process_handle) { |
629 return LaunchAppImpl(argv, env_changes, fds_to_remap, wait, | 642 return LaunchAppImpl(argv, env_changes, fds_to_remap, wait, |
630 process_handle, true); | 643 process_handle, |
| 644 true, // start new process group |
| 645 false, // don't use clone() |
| 646 0); // clone flags |
| 647 } |
| 648 |
| 649 BASE_API bool LaunchAppWithClone(const std::vector<std::string>& argv, |
| 650 const file_handle_mapping_vector& fds_to_remap, |
| 651 bool wait, ProcessHandle* process_handle, |
| 652 int clone_flags) { |
| 653 base::environment_vector no_env; |
| 654 return LaunchAppImpl(argv, no_env, fds_to_remap, wait, process_handle, |
| 655 false, // don't start new process group |
| 656 true, // use clone() |
| 657 clone_flags); |
631 } | 658 } |
632 | 659 |
633 bool LaunchApp(const std::vector<std::string>& argv, | 660 bool LaunchApp(const std::vector<std::string>& argv, |
634 const file_handle_mapping_vector& fds_to_remap, | 661 const file_handle_mapping_vector& fds_to_remap, |
635 bool wait, ProcessHandle* process_handle) { | 662 bool wait, ProcessHandle* process_handle) { |
636 base::environment_vector no_env; | 663 base::environment_vector no_env; |
637 return LaunchApp(argv, no_env, fds_to_remap, wait, process_handle); | 664 return LaunchApp(argv, no_env, fds_to_remap, wait, process_handle); |
638 } | 665 } |
639 | 666 |
640 bool LaunchApp(const CommandLine& cl, | 667 bool LaunchApp(const CommandLine& cl, |
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1005 const ProcessFilter* filter) { | 1032 const ProcessFilter* filter) { |
1006 bool exited_cleanly = | 1033 bool exited_cleanly = |
1007 WaitForProcessesToExit(executable_name, wait_milliseconds, | 1034 WaitForProcessesToExit(executable_name, wait_milliseconds, |
1008 filter); | 1035 filter); |
1009 if (!exited_cleanly) | 1036 if (!exited_cleanly) |
1010 KillProcesses(executable_name, exit_code, filter); | 1037 KillProcesses(executable_name, exit_code, filter); |
1011 return exited_cleanly; | 1038 return exited_cleanly; |
1012 } | 1039 } |
1013 | 1040 |
1014 } // namespace base | 1041 } // namespace base |
OLD | NEW |