| 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 <signal.h> | 10 #include <signal.h> |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 fd_shuffle_size = options.fds_to_remap->size(); | 285 fd_shuffle_size = options.fds_to_remap->size(); |
| 286 } | 286 } |
| 287 | 287 |
| 288 InjectiveMultimap fd_shuffle1; | 288 InjectiveMultimap fd_shuffle1; |
| 289 InjectiveMultimap fd_shuffle2; | 289 InjectiveMultimap fd_shuffle2; |
| 290 fd_shuffle1.reserve(fd_shuffle_size); | 290 fd_shuffle1.reserve(fd_shuffle_size); |
| 291 fd_shuffle2.reserve(fd_shuffle_size); | 291 fd_shuffle2.reserve(fd_shuffle_size); |
| 292 | 292 |
| 293 scoped_ptr<char*[]> argv_cstr(new char*[argv.size() + 1]); | 293 scoped_ptr<char*[]> argv_cstr(new char*[argv.size() + 1]); |
| 294 scoped_ptr<char*[]> new_environ; | 294 scoped_ptr<char*[]> new_environ; |
| 295 char* const empty_environ = NULL; |
| 296 char* const* old_environ = GetEnvironment(); |
| 297 if (options.clear_environ) |
| 298 old_environ = &empty_environ; |
| 295 if (!options.environ.empty()) | 299 if (!options.environ.empty()) |
| 296 new_environ = AlterEnvironment(GetEnvironment(), options.environ); | 300 new_environ = AlterEnvironment(old_environ, options.environ); |
| 297 | 301 |
| 298 sigset_t full_sigset; | 302 sigset_t full_sigset; |
| 299 sigfillset(&full_sigset); | 303 sigfillset(&full_sigset); |
| 300 const sigset_t orig_sigmask = SetSignalMask(full_sigset); | 304 const sigset_t orig_sigmask = SetSignalMask(full_sigset); |
| 301 | 305 |
| 302 pid_t pid; | 306 pid_t pid; |
| 303 #if defined(OS_LINUX) | 307 #if defined(OS_LINUX) |
| 304 if (options.clone_flags) { | 308 if (options.clone_flags) { |
| 305 // Signal handling in this function assumes the creation of a new | 309 // Signal handling in this function assumes the creation of a new |
| 306 // process, so we check that a thread is not being created by mistake | 310 // process, so we check that a thread is not being created by mistake |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 412 if (options.fds_to_remap) { | 416 if (options.fds_to_remap) { |
| 413 // Cannot use STL iterators here, since debug iterators use locks. | 417 // Cannot use STL iterators here, since debug iterators use locks. |
| 414 for (size_t i = 0; i < options.fds_to_remap->size(); ++i) { | 418 for (size_t i = 0; i < options.fds_to_remap->size(); ++i) { |
| 415 const FileHandleMappingVector::value_type& value = | 419 const FileHandleMappingVector::value_type& value = |
| 416 (*options.fds_to_remap)[i]; | 420 (*options.fds_to_remap)[i]; |
| 417 fd_shuffle1.push_back(InjectionArc(value.first, value.second, false)); | 421 fd_shuffle1.push_back(InjectionArc(value.first, value.second, false)); |
| 418 fd_shuffle2.push_back(InjectionArc(value.first, value.second, false)); | 422 fd_shuffle2.push_back(InjectionArc(value.first, value.second, false)); |
| 419 } | 423 } |
| 420 } | 424 } |
| 421 | 425 |
| 422 if (!options.environ.empty()) | 426 if (!options.environ.empty() || options.clear_environ) |
| 423 SetEnvironment(new_environ.get()); | 427 SetEnvironment(new_environ.get()); |
| 424 | 428 |
| 425 // fd_shuffle1 is mutated by this call because it cannot malloc. | 429 // fd_shuffle1 is mutated by this call because it cannot malloc. |
| 426 if (!ShuffleFileDescriptors(&fd_shuffle1)) | 430 if (!ShuffleFileDescriptors(&fd_shuffle1)) |
| 427 _exit(127); | 431 _exit(127); |
| 428 | 432 |
| 429 CloseSuperfluousFds(fd_shuffle2); | 433 CloseSuperfluousFds(fd_shuffle2); |
| 430 | 434 |
| 431 // Set NO_NEW_PRIVS by default. Since NO_NEW_PRIVS only exists in kernel | 435 // Set NO_NEW_PRIVS by default. Since NO_NEW_PRIVS only exists in kernel |
| 432 // 3.5+, do not check the return value of prctl here. | 436 // 3.5+, do not check the return value of prctl here. |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 649 std::string* output, | 653 std::string* output, |
| 650 int* exit_code) { | 654 int* exit_code) { |
| 651 // Run |execve()| with the current environment and store "unlimited" data. | 655 // Run |execve()| with the current environment and store "unlimited" data. |
| 652 GetAppOutputInternalResult result = GetAppOutputInternal( | 656 GetAppOutputInternalResult result = GetAppOutputInternal( |
| 653 cl.argv(), NULL, output, std::numeric_limits<std::size_t>::max(), true, | 657 cl.argv(), NULL, output, std::numeric_limits<std::size_t>::max(), true, |
| 654 exit_code); | 658 exit_code); |
| 655 return result == EXECUTE_SUCCESS; | 659 return result == EXECUTE_SUCCESS; |
| 656 } | 660 } |
| 657 | 661 |
| 658 } // namespace base | 662 } // namespace base |
| OLD | NEW |