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

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: Addressing more feedback from jam@ 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 490 matching lines...) Expand 10 before | Expand all | Expand 10 after
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();
526 LOG(ERROR) << "Tried to use clone() on non-Linux system.";
darin (slow to review) 2011/06/24 16:32:19 it seems like we should only reach this code in a
Brad Chen 2011/06/24 16:52:12 Done.
527 #endif
528 } else {
529 pid = fork();
530 }
520 if (pid < 0) { 531 if (pid < 0) {
521 PLOG(ERROR) << "fork"; 532 PLOG(ERROR) << "fork";
522 return false; 533 return false;
523 } 534 }
524 if (pid == 0) { 535 if (pid == 0) {
525 // Child process 536 // Child process
526 537
527 // DANGER: fork() rule: in the child, if you don't end up doing exec*(), 538 // 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 539 // you call _exit() instead of exit(). This is because _exit() does not
529 // call any previously-registered (in the parent) exit handlers, which 540 // call any previously-registered (in the parent) exit handlers, which
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
610 return true; 621 return true;
611 } 622 }
612 623
613 bool LaunchApp( 624 bool LaunchApp(
614 const std::vector<std::string>& argv, 625 const std::vector<std::string>& argv,
615 const environment_vector& env_changes, 626 const environment_vector& env_changes,
616 const file_handle_mapping_vector& fds_to_remap, 627 const file_handle_mapping_vector& fds_to_remap,
617 bool wait, 628 bool wait,
618 ProcessHandle* process_handle) { 629 ProcessHandle* process_handle) {
619 return LaunchAppImpl(argv, env_changes, fds_to_remap, 630 return LaunchAppImpl(argv, env_changes, fds_to_remap,
620 wait, process_handle, false); 631 wait, process_handle,
632 false, // don't start new process group
633 false, // don't use clone()
634 0); // clone flags
621 } 635 }
622 636
623 bool LaunchAppInNewProcessGroup( 637 bool LaunchAppInNewProcessGroup(
624 const std::vector<std::string>& argv, 638 const std::vector<std::string>& argv,
625 const environment_vector& env_changes, 639 const environment_vector& env_changes,
626 const file_handle_mapping_vector& fds_to_remap, 640 const file_handle_mapping_vector& fds_to_remap,
627 bool wait, 641 bool wait,
628 ProcessHandle* process_handle) { 642 ProcessHandle* process_handle) {
629 return LaunchAppImpl(argv, env_changes, fds_to_remap, wait, 643 return LaunchAppImpl(argv, env_changes, fds_to_remap, wait,
630 process_handle, true); 644 process_handle,
645 true, // start new process group
646 false, // don't use clone()
647 0); // clone flags
648 }
649
650 BASE_API bool LaunchAppWithClone(const std::vector<std::string>& argv,
651 const file_handle_mapping_vector& fds_to_remap,
652 bool wait, ProcessHandle* process_handle,
653 int clone_flags) {
654 base::environment_vector no_env;
655 return LaunchAppImpl(argv, no_env, fds_to_remap, wait, process_handle,
656 false, // don't start new process group
657 true, // use clone()
darin (slow to review) 2011/06/24 16:32:19 nit: elsewhere, you stack the comments in a column
Brad Chen 2011/06/24 16:52:12 Fixed.
658 clone_flags);
631 } 659 }
632 660
633 bool LaunchApp(const std::vector<std::string>& argv, 661 bool LaunchApp(const std::vector<std::string>& argv,
634 const file_handle_mapping_vector& fds_to_remap, 662 const file_handle_mapping_vector& fds_to_remap,
635 bool wait, ProcessHandle* process_handle) { 663 bool wait, ProcessHandle* process_handle) {
636 base::environment_vector no_env; 664 base::environment_vector no_env;
637 return LaunchApp(argv, no_env, fds_to_remap, wait, process_handle); 665 return LaunchApp(argv, no_env, fds_to_remap, wait, process_handle);
638 } 666 }
639 667
640 bool LaunchApp(const CommandLine& cl, 668 bool LaunchApp(const CommandLine& cl,
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after
1005 const ProcessFilter* filter) { 1033 const ProcessFilter* filter) {
1006 bool exited_cleanly = 1034 bool exited_cleanly =
1007 WaitForProcessesToExit(executable_name, wait_milliseconds, 1035 WaitForProcessesToExit(executable_name, wait_milliseconds,
1008 filter); 1036 filter);
1009 if (!exited_cleanly) 1037 if (!exited_cleanly)
1010 KillProcesses(executable_name, exit_code, filter); 1038 KillProcesses(executable_name, exit_code, filter);
1011 return exited_cleanly; 1039 return exited_cleanly;
1012 } 1040 }
1013 1041
1014 } // namespace base 1042 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698