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

Side by Side Diff: base/process_util_posix.cc

Issue 7230057: Revert 90805 - I am submitting this with LGTMs from agl@ and evanm@. I'm marking this as TBR=jam@... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 5 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 | « base/process_util.h ('k') | chrome/app/chrome_main.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:mergeinfo
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, 512 pid_t pid;
513 int clone_flags) {
514 pid_t pid = -1;
515 InjectiveMultimap fd_shuffle1, fd_shuffle2; 513 InjectiveMultimap fd_shuffle1, fd_shuffle2;
516 fd_shuffle1.reserve(fds_to_remap.size()); 514 fd_shuffle1.reserve(fds_to_remap.size());
517 fd_shuffle2.reserve(fds_to_remap.size()); 515 fd_shuffle2.reserve(fds_to_remap.size());
518 scoped_array<char*> argv_cstr(new char*[argv.size() + 1]); 516 scoped_array<char*> argv_cstr(new char*[argv.size() + 1]);
519 scoped_array<char*> new_environ(AlterEnvironment(env_changes, environ)); 517 scoped_array<char*> new_environ(AlterEnvironment(env_changes, environ));
520 518
521 if (use_clone) { 519 pid = fork();
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 }
530 if (pid < 0) { 520 if (pid < 0) {
531 PLOG(ERROR) << "fork"; 521 PLOG(ERROR) << "fork";
532 return false; 522 return false;
533 } 523 }
534 if (pid == 0) { 524 if (pid == 0) {
535 // Child process 525 // Child process
536 526
537 // DANGER: fork() rule: in the child, if you don't end up doing exec*(), 527 // DANGER: fork() rule: in the child, if you don't end up doing exec*(),
538 // you call _exit() instead of exit(). This is because _exit() does not 528 // you call _exit() instead of exit(). This is because _exit() does not
539 // call any previously-registered (in the parent) exit handlers, which 529 // call any previously-registered (in the parent) exit handlers, which
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
620 return true; 610 return true;
621 } 611 }
622 612
623 bool LaunchApp( 613 bool LaunchApp(
624 const std::vector<std::string>& argv, 614 const std::vector<std::string>& argv,
625 const environment_vector& env_changes, 615 const environment_vector& env_changes,
626 const file_handle_mapping_vector& fds_to_remap, 616 const file_handle_mapping_vector& fds_to_remap,
627 bool wait, 617 bool wait,
628 ProcessHandle* process_handle) { 618 ProcessHandle* process_handle) {
629 return LaunchAppImpl(argv, env_changes, fds_to_remap, 619 return LaunchAppImpl(argv, env_changes, fds_to_remap,
630 wait, process_handle, 620 wait, process_handle, false);
631 false, // don't start new process group
632 false, // don't use clone()
633 0); // clone flags
634 } 621 }
635 622
636 bool LaunchAppInNewProcessGroup( 623 bool LaunchAppInNewProcessGroup(
637 const std::vector<std::string>& argv, 624 const std::vector<std::string>& argv,
638 const environment_vector& env_changes, 625 const environment_vector& env_changes,
639 const file_handle_mapping_vector& fds_to_remap, 626 const file_handle_mapping_vector& fds_to_remap,
640 bool wait, 627 bool wait,
641 ProcessHandle* process_handle) { 628 ProcessHandle* process_handle) {
642 return LaunchAppImpl(argv, env_changes, fds_to_remap, wait, 629 return LaunchAppImpl(argv, env_changes, fds_to_remap, wait,
643 process_handle, 630 process_handle, true);
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);
658 } 631 }
659 632
660 bool LaunchApp(const std::vector<std::string>& argv, 633 bool LaunchApp(const std::vector<std::string>& argv,
661 const file_handle_mapping_vector& fds_to_remap, 634 const file_handle_mapping_vector& fds_to_remap,
662 bool wait, ProcessHandle* process_handle) { 635 bool wait, ProcessHandle* process_handle) {
663 base::environment_vector no_env; 636 base::environment_vector no_env;
664 return LaunchApp(argv, no_env, fds_to_remap, wait, process_handle); 637 return LaunchApp(argv, no_env, fds_to_remap, wait, process_handle);
665 } 638 }
666 639
667 bool LaunchApp(const CommandLine& cl, 640 bool LaunchApp(const CommandLine& cl,
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after
1032 const ProcessFilter* filter) { 1005 const ProcessFilter* filter) {
1033 bool exited_cleanly = 1006 bool exited_cleanly =
1034 WaitForProcessesToExit(executable_name, wait_milliseconds, 1007 WaitForProcessesToExit(executable_name, wait_milliseconds,
1035 filter); 1008 filter);
1036 if (!exited_cleanly) 1009 if (!exited_cleanly)
1037 KillProcesses(executable_name, exit_code, filter); 1010 KillProcesses(executable_name, exit_code, filter);
1038 return exited_cleanly; 1011 return exited_cleanly;
1039 } 1012 }
1040 1013
1041 } // namespace base 1014 } // namespace base
OLDNEW
« no previous file with comments | « base/process_util.h ('k') | chrome/app/chrome_main.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698