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 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
341 if (options.fds_to_remap) { | 341 if (options.fds_to_remap) { |
342 fd_shuffle_size = options.fds_to_remap->size(); | 342 fd_shuffle_size = options.fds_to_remap->size(); |
343 } | 343 } |
344 | 344 |
345 InjectiveMultimap fd_shuffle1; | 345 InjectiveMultimap fd_shuffle1; |
346 InjectiveMultimap fd_shuffle2; | 346 InjectiveMultimap fd_shuffle2; |
347 fd_shuffle1.reserve(fd_shuffle_size); | 347 fd_shuffle1.reserve(fd_shuffle_size); |
348 fd_shuffle2.reserve(fd_shuffle_size); | 348 fd_shuffle2.reserve(fd_shuffle_size); |
349 | 349 |
350 scoped_ptr<char*[]> argv_cstr(new char*[argv.size() + 1]); | 350 scoped_ptr<char*[]> argv_cstr(new char*[argv.size() + 1]); |
351 for (size_t i = 0; i < argv.size(); i++) | |
jln (very slow on Chromium)
2015/02/03 02:37:26
Wrong indent.
Nit: I also prefer {}, but your cho
rickyz (no longer on Chrome)
2015/02/03 02:44:44
Oops, fixed - I prefer {} too.
| |
352 argv_cstr[i] = const_cast<char*>(argv[i].c_str()); | |
353 argv_cstr[argv.size()] = NULL; | |
354 | |
351 scoped_ptr<char*[]> new_environ; | 355 scoped_ptr<char*[]> new_environ; |
352 char* const empty_environ = NULL; | 356 char* const empty_environ = NULL; |
353 char* const* old_environ = GetEnvironment(); | 357 char* const* old_environ = GetEnvironment(); |
354 if (options.clear_environ) | 358 if (options.clear_environ) |
355 old_environ = &empty_environ; | 359 old_environ = &empty_environ; |
356 if (!options.environ.empty()) | 360 if (!options.environ.empty()) |
357 new_environ = AlterEnvironment(old_environ, options.environ); | 361 new_environ = AlterEnvironment(old_environ, options.environ); |
358 | 362 |
359 sigset_t full_sigset; | 363 sigset_t full_sigset; |
360 sigfillset(&full_sigset); | 364 sigfillset(&full_sigset); |
361 const sigset_t orig_sigmask = SetSignalMask(full_sigset); | 365 const sigset_t orig_sigmask = SetSignalMask(full_sigset); |
362 | 366 |
367 const char* current_directory = nullptr; | |
368 if (!options.current_directory.empty()) { | |
369 current_directory = options.current_directory.value().c_str(); | |
370 } | |
371 | |
363 pid_t pid; | 372 pid_t pid; |
364 #if defined(OS_LINUX) | 373 #if defined(OS_LINUX) |
365 if (options.clone_flags) { | 374 if (options.clone_flags) { |
366 // Signal handling in this function assumes the creation of a new | 375 // Signal handling in this function assumes the creation of a new |
367 // process, so we check that a thread is not being created by mistake | 376 // process, so we check that a thread is not being created by mistake |
368 // and that signal handling follows the process-creation rules. | 377 // and that signal handling follows the process-creation rules. |
369 RAW_CHECK( | 378 RAW_CHECK( |
370 !(options.clone_flags & (CLONE_SIGHAND | CLONE_THREAD | CLONE_VM))); | 379 !(options.clone_flags & (CLONE_SIGHAND | CLONE_THREAD | CLONE_VM))); |
371 | 380 |
372 // We specify a null ptid and ctid. | 381 // We specify a null ptid and ctid. |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
509 #endif | 518 #endif |
510 if (!options.allow_new_privs) { | 519 if (!options.allow_new_privs) { |
511 if (prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0) && errno != EINVAL) { | 520 if (prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0) && errno != EINVAL) { |
512 // Only log if the error is not EINVAL (i.e. not supported). | 521 // Only log if the error is not EINVAL (i.e. not supported). |
513 RAW_LOG(FATAL, "prctl(PR_SET_NO_NEW_PRIVS) failed"); | 522 RAW_LOG(FATAL, "prctl(PR_SET_NO_NEW_PRIVS) failed"); |
514 } | 523 } |
515 } | 524 } |
516 #endif | 525 #endif |
517 | 526 |
518 #if defined(OS_POSIX) | 527 #if defined(OS_POSIX) |
528 if (current_directory != nullptr) { | |
529 RAW_CHECK(chdir(current_directory) == 0); | |
530 } | |
531 | |
519 if (options.pre_exec_delegate != nullptr) { | 532 if (options.pre_exec_delegate != nullptr) { |
520 options.pre_exec_delegate->RunAsyncSafe(); | 533 options.pre_exec_delegate->RunAsyncSafe(); |
521 } | 534 } |
522 #endif | 535 #endif |
523 | 536 |
524 for (size_t i = 0; i < argv.size(); i++) | |
525 argv_cstr[i] = const_cast<char*>(argv[i].c_str()); | |
526 argv_cstr[argv.size()] = NULL; | |
527 execvp(argv_cstr[0], argv_cstr.get()); | 537 execvp(argv_cstr[0], argv_cstr.get()); |
528 | 538 |
529 RAW_LOG(ERROR, "LaunchProcess: failed to execvp:"); | 539 RAW_LOG(ERROR, "LaunchProcess: failed to execvp:"); |
530 RAW_LOG(ERROR, argv_cstr[0]); | 540 RAW_LOG(ERROR, argv_cstr[0]); |
531 _exit(127); | 541 _exit(127); |
532 } else { | 542 } else { |
533 // Parent process | 543 // Parent process |
534 if (options.wait) { | 544 if (options.wait) { |
535 // While this isn't strictly disk IO, waiting for another process to | 545 // While this isn't strictly disk IO, waiting for another process to |
536 // finish is the sort of thing ThreadRestrictions is trying to prevent. | 546 // finish is the sort of thing ThreadRestrictions is trying to prevent. |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
759 jmp_buf env; | 769 jmp_buf env; |
760 if (setjmp(env) == 0) { | 770 if (setjmp(env) == 0) { |
761 return CloneAndLongjmpInChild(flags, ptid, ctid, &env); | 771 return CloneAndLongjmpInChild(flags, ptid, ctid, &env); |
762 } | 772 } |
763 | 773 |
764 return 0; | 774 return 0; |
765 } | 775 } |
766 #endif // defined(OS_LINUX) | 776 #endif // defined(OS_LINUX) |
767 | 777 |
768 } // namespace base | 778 } // namespace base |
OLD | NEW |