| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 // This file contains functions for launching subprocesses. | 5 // This file contains functions for launching subprocesses. |
| 6 | 6 |
| 7 #ifndef BASE_PROCESS_LAUNCH_H_ | 7 #ifndef BASE_PROCESS_LAUNCH_H_ |
| 8 #define BASE_PROCESS_LAUNCH_H_ | 8 #define BASE_PROCESS_LAUNCH_H_ |
| 9 | 9 |
| 10 #include <set> | 10 #include <set> |
| 11 #include <string> | 11 #include <string> |
| 12 #include <utility> | 12 #include <utility> |
| 13 #include <vector> | 13 #include <vector> |
| 14 | 14 |
| 15 #include "base/base_export.h" | 15 #include "base/base_export.h" |
| 16 #include "base/basictypes.h" | 16 #include "base/basictypes.h" |
| 17 #include "base/environment.h" |
| 17 #include "base/process/process_handle.h" | 18 #include "base/process/process_handle.h" |
| 18 | 19 |
| 19 #if defined(OS_POSIX) | 20 #if defined(OS_POSIX) |
| 20 #include "base/posix/file_descriptor_shuffle.h" | 21 #include "base/posix/file_descriptor_shuffle.h" |
| 21 #elif defined(OS_WIN) | 22 #elif defined(OS_WIN) |
| 22 #include <windows.h> | 23 #include <windows.h> |
| 23 #endif | 24 #endif |
| 24 | 25 |
| 25 class CommandLine; | 26 class CommandLine; |
| 26 | 27 |
| 27 namespace base { | 28 namespace base { |
| 28 | 29 |
| 29 typedef std::vector<std::pair<std::string, std::string> > EnvironmentVector; | |
| 30 typedef std::vector<std::pair<int, int> > FileHandleMappingVector; | 30 typedef std::vector<std::pair<int, int> > FileHandleMappingVector; |
| 31 | 31 |
| 32 // Options for launching a subprocess that are passed to LaunchProcess(). | 32 // Options for launching a subprocess that are passed to LaunchProcess(). |
| 33 // The default constructor constructs the object with default options. | 33 // The default constructor constructs the object with default options. |
| 34 struct LaunchOptions { | 34 struct BASE_EXPORT LaunchOptions { |
| 35 LaunchOptions() | 35 LaunchOptions(); |
| 36 : wait(false), | 36 ~LaunchOptions(); |
| 37 #if defined(OS_WIN) | |
| 38 start_hidden(false), | |
| 39 inherit_handles(false), | |
| 40 as_user(NULL), | |
| 41 empty_desktop_name(false), | |
| 42 job_handle(NULL), | |
| 43 stdin_handle(NULL), | |
| 44 stdout_handle(NULL), | |
| 45 stderr_handle(NULL), | |
| 46 force_breakaway_from_job_(false) | |
| 47 #else | |
| 48 environ(NULL), | |
| 49 fds_to_remap(NULL), | |
| 50 maximize_rlimits(NULL), | |
| 51 new_process_group(false) | |
| 52 #if defined(OS_LINUX) | |
| 53 , clone_flags(0) | |
| 54 #endif // OS_LINUX | |
| 55 #if defined(OS_CHROMEOS) | |
| 56 , ctrl_terminal_fd(-1) | |
| 57 #endif // OS_CHROMEOS | |
| 58 #endif // !defined(OS_WIN) | |
| 59 {} | |
| 60 | 37 |
| 61 // If true, wait for the process to complete. | 38 // If true, wait for the process to complete. |
| 62 bool wait; | 39 bool wait; |
| 63 | 40 |
| 64 #if defined(OS_WIN) | 41 #if defined(OS_WIN) |
| 65 bool start_hidden; | 42 bool start_hidden; |
| 66 | 43 |
| 67 // If true, the new process inherits handles from the parent. In production | 44 // If true, the new process inherits handles from the parent. In production |
| 68 // code this flag should be used only when running short-lived, trusted | 45 // code this flag should be used only when running short-lived, trusted |
| 69 // binaries, because open handles from other libraries and subsystems will | 46 // binaries, because open handles from other libraries and subsystems will |
| (...skipping 23 matching lines...) Expand all Loading... |
| 93 // |inherit_handles| flag must be set to true when redirecting stdio stream. | 70 // |inherit_handles| flag must be set to true when redirecting stdio stream. |
| 94 HANDLE stdin_handle; | 71 HANDLE stdin_handle; |
| 95 HANDLE stdout_handle; | 72 HANDLE stdout_handle; |
| 96 HANDLE stderr_handle; | 73 HANDLE stderr_handle; |
| 97 | 74 |
| 98 // If set to true, ensures that the child process is launched with the | 75 // If set to true, ensures that the child process is launched with the |
| 99 // CREATE_BREAKAWAY_FROM_JOB flag which allows it to breakout of the parent | 76 // CREATE_BREAKAWAY_FROM_JOB flag which allows it to breakout of the parent |
| 100 // job if any. | 77 // job if any. |
| 101 bool force_breakaway_from_job_; | 78 bool force_breakaway_from_job_; |
| 102 #else | 79 #else |
| 103 // If non-NULL, set/unset environment variables. | 80 // Set/unset environment variables. Empty (the default) means to inherit |
| 104 // See documentation of AlterEnvironment(). | 81 // the same environment. See AlterEnvironment(). |
| 105 // This pointer is owned by the caller and must live through the | 82 EnvironmentMap environ; |
| 106 // call to LaunchProcess(). | |
| 107 const EnvironmentVector* environ; | |
| 108 | 83 |
| 109 // If non-NULL, remap file descriptors according to the mapping of | 84 // If non-NULL, remap file descriptors according to the mapping of |
| 110 // src fd->dest fd to propagate FDs into the child process. | 85 // src fd->dest fd to propagate FDs into the child process. |
| 111 // This pointer is owned by the caller and must live through the | 86 // This pointer is owned by the caller and must live through the |
| 112 // call to LaunchProcess(). | 87 // call to LaunchProcess(). |
| 113 const FileHandleMappingVector* fds_to_remap; | 88 const FileHandleMappingVector* fds_to_remap; |
| 114 | 89 |
| 115 // Each element is an RLIMIT_* constant that should be raised to its | 90 // Each element is an RLIMIT_* constant that should be raised to its |
| 116 // rlim_max. This pointer is owned by the caller and must live through | 91 // rlim_max. This pointer is owned by the caller and must live through |
| 117 // the call to LaunchProcess(). | 92 // the call to LaunchProcess(). |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 | 150 |
| 176 #elif defined(OS_POSIX) | 151 #elif defined(OS_POSIX) |
| 177 // A POSIX-specific version of LaunchProcess that takes an argv array | 152 // A POSIX-specific version of LaunchProcess that takes an argv array |
| 178 // instead of a CommandLine. Useful for situations where you need to | 153 // instead of a CommandLine. Useful for situations where you need to |
| 179 // control the command line arguments directly, but prefer the | 154 // control the command line arguments directly, but prefer the |
| 180 // CommandLine version if launching Chrome itself. | 155 // CommandLine version if launching Chrome itself. |
| 181 BASE_EXPORT bool LaunchProcess(const std::vector<std::string>& argv, | 156 BASE_EXPORT bool LaunchProcess(const std::vector<std::string>& argv, |
| 182 const LaunchOptions& options, | 157 const LaunchOptions& options, |
| 183 ProcessHandle* process_handle); | 158 ProcessHandle* process_handle); |
| 184 | 159 |
| 185 // AlterEnvironment returns a modified environment vector, constructed from the | |
| 186 // given environment and the list of changes given in |changes|. Each key in | |
| 187 // the environment is matched against the first element of the pairs. In the | |
| 188 // event of a match, the value is replaced by the second of the pair, unless | |
| 189 // the second is empty, in which case the key-value is removed. | |
| 190 // | |
| 191 // The returned array is allocated using new[] and must be freed by the caller. | |
| 192 BASE_EXPORT char** AlterEnvironment(const EnvironmentVector& changes, | |
| 193 const char* const* const env); | |
| 194 | |
| 195 // Close all file descriptors, except those which are a destination in the | 160 // Close all file descriptors, except those which are a destination in the |
| 196 // given multimap. Only call this function in a child process where you know | 161 // given multimap. Only call this function in a child process where you know |
| 197 // that there aren't any other threads. | 162 // that there aren't any other threads. |
| 198 BASE_EXPORT void CloseSuperfluousFds(const InjectiveMultimap& saved_map); | 163 BASE_EXPORT void CloseSuperfluousFds(const InjectiveMultimap& saved_map); |
| 199 #endif // defined(OS_POSIX) | 164 #endif // defined(OS_POSIX) |
| 200 | 165 |
| 201 #if defined(OS_WIN) | 166 #if defined(OS_WIN) |
| 202 // Set JOBOBJECT_EXTENDED_LIMIT_INFORMATION to JobObject |job_object|. | 167 // Set JOBOBJECT_EXTENDED_LIMIT_INFORMATION to JobObject |job_object|. |
| 203 // As its limit_info.BasicLimitInformation.LimitFlags has | 168 // As its limit_info.BasicLimitInformation.LimitFlags has |
| 204 // JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE. | 169 // JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE. |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 // instance running inside the parent. The parent's Breakpad instance should | 214 // instance running inside the parent. The parent's Breakpad instance should |
| 250 // not handle the child's exceptions. Calling RestoreDefaultExceptionHandler | 215 // not handle the child's exceptions. Calling RestoreDefaultExceptionHandler |
| 251 // in the child after forking will restore the standard exception handler. | 216 // in the child after forking will restore the standard exception handler. |
| 252 // See http://crbug.com/20371/ for more details. | 217 // See http://crbug.com/20371/ for more details. |
| 253 void RestoreDefaultExceptionHandler(); | 218 void RestoreDefaultExceptionHandler(); |
| 254 #endif // defined(OS_MACOSX) | 219 #endif // defined(OS_MACOSX) |
| 255 | 220 |
| 256 } // namespace base | 221 } // namespace base |
| 257 | 222 |
| 258 #endif // BASE_PROCESS_LAUNCH_H_ | 223 #endif // BASE_PROCESS_LAUNCH_H_ |
| OLD | NEW |