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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 // Unlike in clone, clone_flags may not contain a custom termination signal | 136 // Unlike in clone, clone_flags may not contain a custom termination signal |
119 // that is sent to the parent when the child dies. The termination signal will | 137 // that is sent to the parent when the child dies. The termination signal will |
120 // always be set to SIGCHLD. | 138 // always be set to SIGCHLD. |
121 int clone_flags; | 139 int clone_flags; |
122 | 140 |
123 // By default, child processes will have the PR_SET_NO_NEW_PRIVS bit set. If | 141 // By default, child processes will have the PR_SET_NO_NEW_PRIVS bit set. If |
124 // true, then this bit will not be set in the new child process. | 142 // true, then this bit will not be set in the new child process. |
125 bool allow_new_privs; | 143 bool allow_new_privs; |
126 #endif // defined(OS_LINUX) | 144 #endif // defined(OS_LINUX) |
127 | 145 |
| 146 #if defined(OS_POSIX) |
| 147 // If non-null, a delegate to be run immediately prior to executing the new |
| 148 // program in the child process. |
| 149 // |
| 150 // WARNING: If LaunchProcess is called in the presence of multiple threads, |
| 151 // code running in this delegate essentially needs to be async-signal safe |
| 152 // (see man 7 signal for a list of allowed functions). |
| 153 PreExecDelegate* pre_exec_delegate; |
| 154 #endif // defined(OS_POSIX) |
| 155 |
128 #if defined(OS_CHROMEOS) | 156 #if defined(OS_CHROMEOS) |
129 // If non-negative, the specified file descriptor will be set as the launched | 157 // If non-negative, the specified file descriptor will be set as the launched |
130 // process' controlling terminal. | 158 // process' controlling terminal. |
131 int ctrl_terminal_fd; | 159 int ctrl_terminal_fd; |
132 #endif // defined(OS_CHROMEOS) | 160 #endif // defined(OS_CHROMEOS) |
133 | 161 |
134 #if defined(OS_MACOSX) | 162 #if defined(OS_MACOSX) |
135 // If this name is non-empty, the new child, after fork() but before exec(), | 163 // If this name is non-empty, the new child, after fork() but before exec(), |
136 // will look up this server name in the bootstrap namespace. The resulting | 164 // will look up this server name in the bootstrap namespace. The resulting |
137 // service port will be replaced as the bootstrap port in the child. Because | 165 // 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... |
271 void ReplaceBootstrapPort(const std::string& replacement_bootstrap_name); | 299 void ReplaceBootstrapPort(const std::string& replacement_bootstrap_name); |
272 #endif // defined(OS_MACOSX) | 300 #endif // defined(OS_MACOSX) |
273 | 301 |
274 // Creates a LaunchOptions object suitable for launching processes in a test | 302 // Creates a LaunchOptions object suitable for launching processes in a test |
275 // binary. This should not be called in production/released code. | 303 // binary. This should not be called in production/released code. |
276 BASE_EXPORT LaunchOptions LaunchOptionsForTest(); | 304 BASE_EXPORT LaunchOptions LaunchOptionsForTest(); |
277 | 305 |
278 } // namespace base | 306 } // namespace base |
279 | 307 |
280 #endif // BASE_PROCESS_LAUNCH_H_ | 308 #endif // BASE_PROCESS_LAUNCH_H_ |
OLD | NEW |