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 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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) { |
agl
2011/06/10 17:28:03
#if defined(OS_LINUX)
... your code ...
#else
Brad Chen
2011/06/14 00:16:01
Done.
| |
510 pid = fork(); | |
511 } else { | |
512 pid = syscall(__NR_clone, clone_flags, 0, 0, 0); | |
513 } | |
508 if (pid < 0) { | 514 if (pid < 0) { |
509 PLOG(ERROR) << "fork"; | 515 PLOG(ERROR) << "fork"; |
510 return false; | 516 return false; |
511 } | 517 } |
512 if (pid == 0) { | 518 if (pid == 0) { |
513 // Child process | 519 // Child process |
514 | 520 |
515 // DANGER: fork() rule: in the child, if you don't end up doing exec*(), | 521 // 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 | 522 // you call _exit() instead of exit(). This is because _exit() does not |
517 // call any previously-registered (in the parent) exit handlers, which | 523 // call any previously-registered (in the parent) exit handlers, which |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
598 return true; | 604 return true; |
599 } | 605 } |
600 | 606 |
601 bool LaunchApp( | 607 bool LaunchApp( |
602 const std::vector<std::string>& argv, | 608 const std::vector<std::string>& argv, |
603 const environment_vector& env_changes, | 609 const environment_vector& env_changes, |
604 const file_handle_mapping_vector& fds_to_remap, | 610 const file_handle_mapping_vector& fds_to_remap, |
605 bool wait, | 611 bool wait, |
606 ProcessHandle* process_handle) { | 612 ProcessHandle* process_handle) { |
607 return LaunchAppImpl(argv, env_changes, fds_to_remap, | 613 return LaunchAppImpl(argv, env_changes, fds_to_remap, |
608 wait, process_handle, false); | 614 wait, process_handle, false, false, 0); |
agl
2011/06/10 17:28:03
optional, personal nit. I like to comment magic va
Brad Chen
2011/06/14 00:16:01
Done.
| |
609 } | 615 } |
610 | 616 |
611 bool LaunchAppInNewProcessGroup( | 617 bool LaunchAppInNewProcessGroup( |
612 const std::vector<std::string>& argv, | 618 const std::vector<std::string>& argv, |
613 const environment_vector& env_changes, | 619 const environment_vector& env_changes, |
614 const file_handle_mapping_vector& fds_to_remap, | 620 const file_handle_mapping_vector& fds_to_remap, |
615 bool wait, | 621 bool wait, |
616 ProcessHandle* process_handle) { | 622 ProcessHandle* process_handle) { |
617 return LaunchAppImpl(argv, env_changes, fds_to_remap, wait, | 623 return LaunchAppImpl(argv, env_changes, fds_to_remap, wait, |
618 process_handle, true); | 624 process_handle, true, false, 0); |
625 } | |
626 | |
627 BASE_API bool LaunchAppWithClone(const std::vector<std::string>& argv, | |
628 const file_handle_mapping_vector& fds_to_remap, | |
629 bool wait, ProcessHandle* process_handle, | |
630 int clone_flags) { | |
631 base::environment_vector no_env; | |
632 return LaunchAppImpl(argv, no_env, fds_to_remap, wait, process_handle, | |
633 false, true, clone_flags); | |
619 } | 634 } |
620 | 635 |
621 bool LaunchApp(const std::vector<std::string>& argv, | 636 bool LaunchApp(const std::vector<std::string>& argv, |
622 const file_handle_mapping_vector& fds_to_remap, | 637 const file_handle_mapping_vector& fds_to_remap, |
623 bool wait, ProcessHandle* process_handle) { | 638 bool wait, ProcessHandle* process_handle) { |
624 base::environment_vector no_env; | 639 base::environment_vector no_env; |
625 return LaunchApp(argv, no_env, fds_to_remap, wait, process_handle); | 640 return LaunchApp(argv, no_env, fds_to_remap, wait, process_handle); |
626 } | 641 } |
627 | 642 |
628 bool LaunchApp(const CommandLine& cl, | 643 bool LaunchApp(const CommandLine& cl, |
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
993 const ProcessFilter* filter) { | 1008 const ProcessFilter* filter) { |
994 bool exited_cleanly = | 1009 bool exited_cleanly = |
995 WaitForProcessesToExit(executable_name, wait_milliseconds, | 1010 WaitForProcessesToExit(executable_name, wait_milliseconds, |
996 filter); | 1011 filter); |
997 if (!exited_cleanly) | 1012 if (!exited_cleanly) |
998 KillProcesses(executable_name, exit_code, filter); | 1013 KillProcesses(executable_name, exit_code, filter); |
999 return exited_cleanly; | 1014 return exited_cleanly; |
1000 } | 1015 } |
1001 | 1016 |
1002 } // namespace base | 1017 } // namespace base |
OLD | NEW |