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> |
11 #include <setjmp.h> | 11 #include <setjmp.h> |
12 #include <signal.h> | 12 #include <signal.h> |
13 #include <stddef.h> | 13 #include <stddef.h> |
14 #include <stdint.h> | 14 #include <stdint.h> |
15 #include <stdlib.h> | 15 #include <stdlib.h> |
16 #include <sys/resource.h> | 16 #include <sys/resource.h> |
17 #include <sys/syscall.h> | 17 #include <sys/syscall.h> |
18 #include <sys/time.h> | 18 #include <sys/time.h> |
19 #include <sys/types.h> | 19 #include <sys/types.h> |
20 #include <sys/wait.h> | 20 #include <sys/wait.h> |
21 #include <unistd.h> | 21 #include <unistd.h> |
22 | 22 |
23 #include <iterator> | 23 #include <iterator> |
24 #include <limits> | 24 #include <limits> |
| 25 #include <memory> |
25 #include <set> | 26 #include <set> |
26 | 27 |
27 #include "base/command_line.h" | 28 #include "base/command_line.h" |
28 #include "base/compiler_specific.h" | 29 #include "base/compiler_specific.h" |
29 #include "base/debug/debugger.h" | 30 #include "base/debug/debugger.h" |
30 #include "base/debug/stack_trace.h" | 31 #include "base/debug/stack_trace.h" |
31 #include "base/files/dir_reader_posix.h" | 32 #include "base/files/dir_reader_posix.h" |
32 #include "base/files/file_util.h" | 33 #include "base/files/file_util.h" |
33 #include "base/files/scoped_file.h" | 34 #include "base/files/scoped_file.h" |
34 #include "base/logging.h" | 35 #include "base/logging.h" |
35 #include "base/memory/scoped_ptr.h" | |
36 #include "base/posix/eintr_wrapper.h" | 36 #include "base/posix/eintr_wrapper.h" |
37 #include "base/process/process.h" | 37 #include "base/process/process.h" |
38 #include "base/process/process_metrics.h" | 38 #include "base/process/process_metrics.h" |
39 #include "base/strings/stringprintf.h" | 39 #include "base/strings/stringprintf.h" |
40 #include "base/synchronization/waitable_event.h" | 40 #include "base/synchronization/waitable_event.h" |
41 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" | 41 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" |
42 #include "base/third_party/valgrind/valgrind.h" | 42 #include "base/third_party/valgrind/valgrind.h" |
43 #include "base/threading/platform_thread.h" | 43 #include "base/threading/platform_thread.h" |
44 #include "base/threading/thread_restrictions.h" | 44 #include "base/threading/thread_restrictions.h" |
45 #include "build/build_config.h" | 45 #include "build/build_config.h" |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 | 195 |
196 // Functor for |ScopedDIR| (below). | 196 // Functor for |ScopedDIR| (below). |
197 struct ScopedDIRClose { | 197 struct ScopedDIRClose { |
198 inline void operator()(DIR* x) const { | 198 inline void operator()(DIR* x) const { |
199 if (x) | 199 if (x) |
200 closedir(x); | 200 closedir(x); |
201 } | 201 } |
202 }; | 202 }; |
203 | 203 |
204 // Automatically closes |DIR*|s. | 204 // Automatically closes |DIR*|s. |
205 typedef scoped_ptr<DIR, ScopedDIRClose> ScopedDIR; | 205 typedef std::unique_ptr<DIR, ScopedDIRClose> ScopedDIR; |
206 | 206 |
207 #if defined(OS_LINUX) | 207 #if defined(OS_LINUX) |
208 static const char kFDDir[] = "/proc/self/fd"; | 208 static const char kFDDir[] = "/proc/self/fd"; |
209 #elif defined(OS_MACOSX) | 209 #elif defined(OS_MACOSX) |
210 static const char kFDDir[] = "/dev/fd"; | 210 static const char kFDDir[] = "/dev/fd"; |
211 #elif defined(OS_SOLARIS) | 211 #elif defined(OS_SOLARIS) |
212 static const char kFDDir[] = "/dev/fd"; | 212 static const char kFDDir[] = "/dev/fd"; |
213 #elif defined(OS_FREEBSD) | 213 #elif defined(OS_FREEBSD) |
214 static const char kFDDir[] = "/dev/fd"; | 214 static const char kFDDir[] = "/dev/fd"; |
215 #elif defined(OS_OPENBSD) | 215 #elif defined(OS_OPENBSD) |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 size_t fd_shuffle_size = 0; | 294 size_t fd_shuffle_size = 0; |
295 if (options.fds_to_remap) { | 295 if (options.fds_to_remap) { |
296 fd_shuffle_size = options.fds_to_remap->size(); | 296 fd_shuffle_size = options.fds_to_remap->size(); |
297 } | 297 } |
298 | 298 |
299 InjectiveMultimap fd_shuffle1; | 299 InjectiveMultimap fd_shuffle1; |
300 InjectiveMultimap fd_shuffle2; | 300 InjectiveMultimap fd_shuffle2; |
301 fd_shuffle1.reserve(fd_shuffle_size); | 301 fd_shuffle1.reserve(fd_shuffle_size); |
302 fd_shuffle2.reserve(fd_shuffle_size); | 302 fd_shuffle2.reserve(fd_shuffle_size); |
303 | 303 |
304 scoped_ptr<char* []> argv_cstr(new char* [argv.size() + 1]); | 304 std::unique_ptr<char* []> argv_cstr(new char*[argv.size() + 1]); |
305 for (size_t i = 0; i < argv.size(); i++) { | 305 for (size_t i = 0; i < argv.size(); i++) { |
306 argv_cstr[i] = const_cast<char*>(argv[i].c_str()); | 306 argv_cstr[i] = const_cast<char*>(argv[i].c_str()); |
307 } | 307 } |
308 argv_cstr[argv.size()] = NULL; | 308 argv_cstr[argv.size()] = NULL; |
309 | 309 |
310 scoped_ptr<char*[]> new_environ; | 310 std::unique_ptr<char* []> new_environ; |
311 char* const empty_environ = NULL; | 311 char* const empty_environ = NULL; |
312 char* const* old_environ = GetEnvironment(); | 312 char* const* old_environ = GetEnvironment(); |
313 if (options.clear_environ) | 313 if (options.clear_environ) |
314 old_environ = &empty_environ; | 314 old_environ = &empty_environ; |
315 if (!options.environ.empty()) | 315 if (!options.environ.empty()) |
316 new_environ = AlterEnvironment(old_environ, options.environ); | 316 new_environ = AlterEnvironment(old_environ, options.environ); |
317 | 317 |
318 sigset_t full_sigset; | 318 sigset_t full_sigset; |
319 sigfillset(&full_sigset); | 319 sigfillset(&full_sigset); |
320 const sigset_t orig_sigmask = SetSignalMask(full_sigset); | 320 const sigset_t orig_sigmask = SetSignalMask(full_sigset); |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
545 int* exit_code) { | 545 int* exit_code) { |
546 // Doing a blocking wait for another command to finish counts as IO. | 546 // Doing a blocking wait for another command to finish counts as IO. |
547 base::ThreadRestrictions::AssertIOAllowed(); | 547 base::ThreadRestrictions::AssertIOAllowed(); |
548 // exit_code must be supplied so calling function can determine success. | 548 // exit_code must be supplied so calling function can determine success. |
549 DCHECK(exit_code); | 549 DCHECK(exit_code); |
550 *exit_code = EXIT_FAILURE; | 550 *exit_code = EXIT_FAILURE; |
551 | 551 |
552 int pipe_fd[2]; | 552 int pipe_fd[2]; |
553 pid_t pid; | 553 pid_t pid; |
554 InjectiveMultimap fd_shuffle1, fd_shuffle2; | 554 InjectiveMultimap fd_shuffle1, fd_shuffle2; |
555 scoped_ptr<char*[]> argv_cstr(new char*[argv.size() + 1]); | 555 std::unique_ptr<char* []> argv_cstr(new char*[argv.size() + 1]); |
556 | 556 |
557 fd_shuffle1.reserve(3); | 557 fd_shuffle1.reserve(3); |
558 fd_shuffle2.reserve(3); | 558 fd_shuffle2.reserve(3); |
559 | 559 |
560 // Either |do_search_path| should be false or |envp| should be null, but not | 560 // Either |do_search_path| should be false or |envp| should be null, but not |
561 // both. | 561 // both. |
562 DCHECK(!do_search_path ^ !envp); | 562 DCHECK(!do_search_path ^ !envp); |
563 | 563 |
564 if (pipe(pipe_fd) < 0) | 564 if (pipe(pipe_fd) < 0) |
565 return EXECUTE_FAILURE; | 565 return EXECUTE_FAILURE; |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
783 jmp_buf env; | 783 jmp_buf env; |
784 if (setjmp(env) == 0) { | 784 if (setjmp(env) == 0) { |
785 return CloneAndLongjmpInChild(flags, ptid, ctid, &env); | 785 return CloneAndLongjmpInChild(flags, ptid, ctid, &env); |
786 } | 786 } |
787 | 787 |
788 return 0; | 788 return 0; |
789 } | 789 } |
790 #endif // defined(OS_LINUX) || defined(OS_NACL_NONSFI) | 790 #endif // defined(OS_LINUX) || defined(OS_NACL_NONSFI) |
791 | 791 |
792 } // namespace base | 792 } // namespace base |
OLD | NEW |