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 "base/process/launch.h" | 5 #include "base/process/launch.h" |
6 | 6 |
7 #include <dirent.h> | 7 #include <dirent.h> |
8 #include <errno.h> | 8 #include <errno.h> |
9 #include <fcntl.h> | 9 #include <fcntl.h> |
10 #include <sched.h> | 10 #include <sched.h> |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 const LaunchOptions& options) { | 300 const LaunchOptions& options) { |
301 #if defined(OS_MACOSX) | 301 #if defined(OS_MACOSX) |
302 if (FeatureList::IsEnabled(kMacLaunchProcessPosixSpawn)) { | 302 if (FeatureList::IsEnabled(kMacLaunchProcessPosixSpawn)) { |
303 // TODO(rsesek): Do this unconditionally. There is one user for each of | 303 // TODO(rsesek): Do this unconditionally. There is one user for each of |
304 // these two options. https://crbug.com/179923. | 304 // these two options. https://crbug.com/179923. |
305 if (!options.pre_exec_delegate && options.current_directory.empty()) | 305 if (!options.pre_exec_delegate && options.current_directory.empty()) |
306 return LaunchProcessPosixSpawn(argv, options); | 306 return LaunchProcessPosixSpawn(argv, options); |
307 } | 307 } |
308 #endif | 308 #endif |
309 | 309 |
310 size_t fd_shuffle_size = 0; | |
311 if (options.fds_to_remap) { | |
312 fd_shuffle_size = options.fds_to_remap->size(); | |
313 } | |
314 | |
315 InjectiveMultimap fd_shuffle1; | 310 InjectiveMultimap fd_shuffle1; |
316 InjectiveMultimap fd_shuffle2; | 311 InjectiveMultimap fd_shuffle2; |
317 fd_shuffle1.reserve(fd_shuffle_size); | 312 fd_shuffle1.reserve(options.fds_to_remap.size()); |
318 fd_shuffle2.reserve(fd_shuffle_size); | 313 fd_shuffle2.reserve(options.fds_to_remap.size()); |
319 | 314 |
320 std::vector<char*> argv_cstr; | 315 std::vector<char*> argv_cstr; |
321 argv_cstr.reserve(argv.size() + 1); | 316 argv_cstr.reserve(argv.size() + 1); |
322 for (const auto& arg : argv) | 317 for (const auto& arg : argv) |
323 argv_cstr.push_back(const_cast<char*>(arg.c_str())); | 318 argv_cstr.push_back(const_cast<char*>(arg.c_str())); |
324 argv_cstr.push_back(nullptr); | 319 argv_cstr.push_back(nullptr); |
325 | 320 |
326 std::unique_ptr<char* []> new_environ; | 321 std::unique_ptr<char* []> new_environ; |
327 char* const empty_environ = nullptr; | 322 char* const empty_environ = nullptr; |
328 char* const* old_environ = GetEnvironment(); | 323 char* const* old_environ = GetEnvironment(); |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
448 if (HANDLE_EINTR( | 443 if (HANDLE_EINTR( |
449 ioctl(options.ctrl_terminal_fd, TIOCSCTTY, nullptr)) == -1) { | 444 ioctl(options.ctrl_terminal_fd, TIOCSCTTY, nullptr)) == -1) { |
450 RAW_LOG(WARNING, "ioctl(TIOCSCTTY), ctrl terminal not set"); | 445 RAW_LOG(WARNING, "ioctl(TIOCSCTTY), ctrl terminal not set"); |
451 } | 446 } |
452 } else { | 447 } else { |
453 RAW_LOG(WARNING, "setsid failed, ctrl terminal not set"); | 448 RAW_LOG(WARNING, "setsid failed, ctrl terminal not set"); |
454 } | 449 } |
455 } | 450 } |
456 #endif // defined(OS_CHROMEOS) | 451 #endif // defined(OS_CHROMEOS) |
457 | 452 |
458 if (options.fds_to_remap) { | 453 // Cannot use STL iterators here, since debug iterators use locks. |
459 // Cannot use STL iterators here, since debug iterators use locks. | 454 for (size_t i = 0; i < options.fds_to_remap.size(); ++i) { |
460 for (size_t i = 0; i < options.fds_to_remap->size(); ++i) { | 455 const FileHandleMappingVector::value_type& value = |
461 const FileHandleMappingVector::value_type& value = | 456 options.fds_to_remap[i]; |
462 (*options.fds_to_remap)[i]; | 457 fd_shuffle1.push_back(InjectionArc(value.first, value.second, false)); |
463 fd_shuffle1.push_back(InjectionArc(value.first, value.second, false)); | 458 fd_shuffle2.push_back(InjectionArc(value.first, value.second, false)); |
464 fd_shuffle2.push_back(InjectionArc(value.first, value.second, false)); | |
465 } | |
466 } | 459 } |
467 | 460 |
468 if (!options.environ.empty() || options.clear_environ) | 461 if (!options.environ.empty() || options.clear_environ) |
469 SetEnvironment(new_environ.get()); | 462 SetEnvironment(new_environ.get()); |
470 | 463 |
471 // fd_shuffle1 is mutated by this call because it cannot malloc. | 464 // fd_shuffle1 is mutated by this call because it cannot malloc. |
472 if (!ShuffleFileDescriptors(&fd_shuffle1)) | 465 if (!ShuffleFileDescriptors(&fd_shuffle1)) |
473 _exit(127); | 466 _exit(127); |
474 | 467 |
475 CloseSuperfluousFds(fd_shuffle2); | 468 CloseSuperfluousFds(fd_shuffle2); |
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
773 jmp_buf env; | 766 jmp_buf env; |
774 if (setjmp(env) == 0) { | 767 if (setjmp(env) == 0) { |
775 return CloneAndLongjmpInChild(flags, ptid, ctid, &env); | 768 return CloneAndLongjmpInChild(flags, ptid, ctid, &env); |
776 } | 769 } |
777 | 770 |
778 return 0; | 771 return 0; |
779 } | 772 } |
780 #endif // defined(OS_LINUX) || defined(OS_NACL_NONSFI) | 773 #endif // defined(OS_LINUX) || defined(OS_NACL_NONSFI) |
781 | 774 |
782 } // namespace base | 775 } // namespace base |
OLD | NEW |