OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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 <string> | 10 #include <string> |
(...skipping 19 matching lines...) Expand all Loading... |
30 | 30 |
31 #if defined(OS_WIN) | 31 #if defined(OS_WIN) |
32 typedef std::vector<HANDLE> HandlesToInheritVector; | 32 typedef std::vector<HANDLE> HandlesToInheritVector; |
33 #endif | 33 #endif |
34 // TODO(viettrungluu): Only define this on POSIX? | 34 // TODO(viettrungluu): Only define this on POSIX? |
35 typedef std::vector<std::pair<int, int> > FileHandleMappingVector; | 35 typedef std::vector<std::pair<int, int> > FileHandleMappingVector; |
36 | 36 |
37 // Options for launching a subprocess that are passed to LaunchProcess(). | 37 // Options for launching a subprocess that are passed to LaunchProcess(). |
38 // The default constructor constructs the object with default options. | 38 // The default constructor constructs the object with default options. |
39 struct BASE_EXPORT LaunchOptions { | 39 struct BASE_EXPORT LaunchOptions { |
| 40 #if defined(OS_POSIX) |
| 41 // Delegate to be run in between fork and exec in the subprocess (see |
| 42 // pre_exec_delegate below) |
| 43 class BASE_EXPORT PreExecDelegate { |
| 44 public: |
| 45 PreExecDelegate() {} |
| 46 virtual ~PreExecDelegate() {} |
| 47 |
| 48 // Since this is to be run between fork and exec, and fork may have happened |
| 49 // while multiple threads were running, this function needs to be async |
| 50 // safe. |
| 51 virtual void RunAsyncSafe() = 0; |
| 52 |
| 53 private: |
| 54 DISALLOW_COPY_AND_ASSIGN(PreExecDelegate); |
| 55 }; |
| 56 #endif // defined(OS_POSIX) |
| 57 |
40 LaunchOptions(); | 58 LaunchOptions(); |
41 ~LaunchOptions(); | 59 ~LaunchOptions(); |
42 | 60 |
43 // If true, wait for the process to complete. | 61 // If true, wait for the process to complete. |
44 bool wait; | 62 bool wait; |
45 | 63 |
46 #if defined(OS_WIN) | 64 #if defined(OS_WIN) |
47 bool start_hidden; | 65 bool start_hidden; |
48 | 66 |
49 // If non-null, inherit exactly the list of handles in this vector (these | 67 // If non-null, inherit exactly the list of handles in this vector (these |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 | 133 |
116 #if defined(OS_LINUX) | 134 #if defined(OS_LINUX) |
117 // If non-zero, start the process using clone(), using flags as provided. | 135 // If non-zero, start the process using clone(), using flags as provided. |
118 int clone_flags; | 136 int clone_flags; |
119 | 137 |
120 // By default, child processes will have the PR_SET_NO_NEW_PRIVS bit set. If | 138 // By default, child processes will have the PR_SET_NO_NEW_PRIVS bit set. If |
121 // true, then this bit will not be set in the new child process. | 139 // true, then this bit will not be set in the new child process. |
122 bool allow_new_privs; | 140 bool allow_new_privs; |
123 #endif // defined(OS_LINUX) | 141 #endif // defined(OS_LINUX) |
124 | 142 |
| 143 #if defined(OS_POSIX) |
| 144 // If non-null, a delegate to be run immediately prior to executing the new |
| 145 // program in the child process. |
| 146 // |
| 147 // WARNING: If LaunchProcess is called in the presence of multiple threads, |
| 148 // code running in this delegate essentially needs to be async-signal safe |
| 149 // (see man 7 signal for a list of allowed functions). |
| 150 PreExecDelegate* pre_exec_delegate; |
| 151 #endif // defined(OS_POSIX) |
| 152 |
125 #if defined(OS_CHROMEOS) | 153 #if defined(OS_CHROMEOS) |
126 // If non-negative, the specified file descriptor will be set as the launched | 154 // If non-negative, the specified file descriptor will be set as the launched |
127 // process' controlling terminal. | 155 // process' controlling terminal. |
128 int ctrl_terminal_fd; | 156 int ctrl_terminal_fd; |
129 #endif // defined(OS_CHROMEOS) | 157 #endif // defined(OS_CHROMEOS) |
130 | 158 |
131 #if defined(OS_MACOSX) | 159 #if defined(OS_MACOSX) |
132 // If this name is non-empty, the new child, after fork() but before exec(), | 160 // If this name is non-empty, the new child, after fork() but before exec(), |
133 // will look up this server name in the bootstrap namespace. The resulting | 161 // will look up this server name in the bootstrap namespace. The resulting |
134 // service port will be replaced as the bootstrap port in the child. Because | 162 // service port will be replaced as the bootstrap port in the child. Because |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 void ReplaceBootstrapPort(const std::string& replacement_bootstrap_name); | 296 void ReplaceBootstrapPort(const std::string& replacement_bootstrap_name); |
269 #endif // defined(OS_MACOSX) | 297 #endif // defined(OS_MACOSX) |
270 | 298 |
271 // Creates a LaunchOptions object suitable for launching processes in a test | 299 // Creates a LaunchOptions object suitable for launching processes in a test |
272 // binary. This should not be called in production/released code. | 300 // binary. This should not be called in production/released code. |
273 BASE_EXPORT LaunchOptions LaunchOptionsForTest(); | 301 BASE_EXPORT LaunchOptions LaunchOptionsForTest(); |
274 | 302 |
275 } // namespace base | 303 } // namespace base |
276 | 304 |
277 #endif // BASE_PROCESS_LAUNCH_H_ | 305 #endif // BASE_PROCESS_LAUNCH_H_ |
OLD | NEW |