OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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> |
11 #include <sys/time.h> | 11 #include <sys/time.h> |
12 #include <sys/types.h> | 12 #include <sys/types.h> |
13 #include <sys/wait.h> | 13 #include <sys/wait.h> |
14 #include <unistd.h> | 14 #include <unistd.h> |
15 | 15 |
16 #include <iterator> | 16 #include <iterator> |
17 #include <limits> | 17 #include <limits> |
18 #include <set> | 18 #include <set> |
19 | 19 |
| 20 #include "base/allocator/type_profiler_control.h" |
20 #include "base/command_line.h" | 21 #include "base/command_line.h" |
21 #include "base/compiler_specific.h" | 22 #include "base/compiler_specific.h" |
22 #include "base/debug/debugger.h" | 23 #include "base/debug/debugger.h" |
23 #include "base/debug/stack_trace.h" | 24 #include "base/debug/stack_trace.h" |
24 #include "base/eintr_wrapper.h" | 25 #include "base/eintr_wrapper.h" |
25 #include "base/file_util.h" | 26 #include "base/file_util.h" |
26 #include "base/files/dir_reader_posix.h" | 27 #include "base/files/dir_reader_posix.h" |
27 #include "base/logging.h" | 28 #include "base/logging.h" |
28 #include "base/memory/scoped_ptr.h" | 29 #include "base/memory/scoped_ptr.h" |
29 #include "base/process_util.h" | 30 #include "base/process_util.h" |
(...skipping 602 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
632 | 633 |
633 if (options.new_process_group) { | 634 if (options.new_process_group) { |
634 // Instead of inheriting the process group ID of the parent, the child | 635 // Instead of inheriting the process group ID of the parent, the child |
635 // starts off a new process group with pgid equal to its process ID. | 636 // starts off a new process group with pgid equal to its process ID. |
636 if (setpgid(0, 0) < 0) { | 637 if (setpgid(0, 0) < 0) { |
637 RAW_LOG(ERROR, "setpgid failed"); | 638 RAW_LOG(ERROR, "setpgid failed"); |
638 _exit(127); | 639 _exit(127); |
639 } | 640 } |
640 } | 641 } |
641 | 642 |
| 643 // Stop type-profiler. |
| 644 // The profiler should be stopped between fork and exec since it inserts |
| 645 // locks at new/delete expressions. See http://crbug.com/36678. |
| 646 base::type_profiler::Controller::Stop(); |
| 647 |
642 if (options.maximize_rlimits) { | 648 if (options.maximize_rlimits) { |
643 // Some resource limits need to be maximal in this child. | 649 // Some resource limits need to be maximal in this child. |
644 std::set<int>::const_iterator resource; | 650 std::set<int>::const_iterator resource; |
645 for (resource = options.maximize_rlimits->begin(); | 651 for (resource = options.maximize_rlimits->begin(); |
646 resource != options.maximize_rlimits->end(); | 652 resource != options.maximize_rlimits->end(); |
647 ++resource) { | 653 ++resource) { |
648 struct rlimit limit; | 654 struct rlimit limit; |
649 if (getrlimit(*resource, &limit) < 0) { | 655 if (getrlimit(*resource, &limit) < 0) { |
650 RAW_LOG(WARNING, "getrlimit failed"); | 656 RAW_LOG(WARNING, "getrlimit failed"); |
651 } else if (limit.rlim_cur < limit.rlim_max) { | 657 } else if (limit.rlim_cur < limit.rlim_max) { |
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1100 | 1106 |
1101 // Obscure fork() rule: in the child, if you don't end up doing exec*(), | 1107 // Obscure fork() rule: in the child, if you don't end up doing exec*(), |
1102 // you call _exit() instead of exit(). This is because _exit() does not | 1108 // you call _exit() instead of exit(). This is because _exit() does not |
1103 // call any previously-registered (in the parent) exit handlers, which | 1109 // call any previously-registered (in the parent) exit handlers, which |
1104 // might do things like block waiting for threads that don't even exist | 1110 // might do things like block waiting for threads that don't even exist |
1105 // in the child. | 1111 // in the child. |
1106 int dev_null = open("/dev/null", O_WRONLY); | 1112 int dev_null = open("/dev/null", O_WRONLY); |
1107 if (dev_null < 0) | 1113 if (dev_null < 0) |
1108 _exit(127); | 1114 _exit(127); |
1109 | 1115 |
| 1116 // Stop type-profiler. |
| 1117 // The profiler should be stopped between fork and exec since it inserts |
| 1118 // locks at new/delete expressions. See http://crbug.com/36678. |
| 1119 base::type_profiler::Controller::Stop(); |
| 1120 |
1110 fd_shuffle1.push_back(InjectionArc(pipe_fd[1], STDOUT_FILENO, true)); | 1121 fd_shuffle1.push_back(InjectionArc(pipe_fd[1], STDOUT_FILENO, true)); |
1111 fd_shuffle1.push_back(InjectionArc(dev_null, STDERR_FILENO, true)); | 1122 fd_shuffle1.push_back(InjectionArc(dev_null, STDERR_FILENO, true)); |
1112 fd_shuffle1.push_back(InjectionArc(dev_null, STDIN_FILENO, true)); | 1123 fd_shuffle1.push_back(InjectionArc(dev_null, STDIN_FILENO, true)); |
1113 // Adding another element here? Remeber to increase the argument to | 1124 // Adding another element here? Remeber to increase the argument to |
1114 // reserve(), above. | 1125 // reserve(), above. |
1115 | 1126 |
1116 std::copy(fd_shuffle1.begin(), fd_shuffle1.end(), | 1127 std::copy(fd_shuffle1.begin(), fd_shuffle1.end(), |
1117 std::back_inserter(fd_shuffle2)); | 1128 std::back_inserter(fd_shuffle2)); |
1118 | 1129 |
1119 if (!ShuffleFileDescriptors(&fd_shuffle1)) | 1130 if (!ShuffleFileDescriptors(&fd_shuffle1)) |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1327 if (IsChildDead(process)) | 1338 if (IsChildDead(process)) |
1328 return; | 1339 return; |
1329 | 1340 |
1330 BackgroundReaper* reaper = new BackgroundReaper(process, 0); | 1341 BackgroundReaper* reaper = new BackgroundReaper(process, 0); |
1331 PlatformThread::CreateNonJoinable(0, reaper); | 1342 PlatformThread::CreateNonJoinable(0, reaper); |
1332 } | 1343 } |
1333 | 1344 |
1334 #endif // !defined(OS_MACOSX) | 1345 #endif // !defined(OS_MACOSX) |
1335 | 1346 |
1336 } // namespace base | 1347 } // namespace base |
OLD | NEW |