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 <fcntl.h> | 7 #include <fcntl.h> |
8 #include <io.h> | 8 #include <io.h> |
9 #include <shellapi.h> | 9 #include <shellapi.h> |
10 #include <windows.h> | 10 #include <windows.h> |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 Process LaunchProcess(const CommandLine& cmdline, | 205 Process LaunchProcess(const CommandLine& cmdline, |
206 const LaunchOptions& options) { | 206 const LaunchOptions& options) { |
207 return LaunchProcess(cmdline.GetCommandLineString(), options); | 207 return LaunchProcess(cmdline.GetCommandLineString(), options); |
208 } | 208 } |
209 | 209 |
210 Process LaunchProcess(const string16& cmdline, | 210 Process LaunchProcess(const string16& cmdline, |
211 const LaunchOptions& options) { | 211 const LaunchOptions& options) { |
212 win::StartupInformation startup_info_wrapper; | 212 win::StartupInformation startup_info_wrapper; |
213 STARTUPINFO* startup_info = startup_info_wrapper.startup_info(); | 213 STARTUPINFO* startup_info = startup_info_wrapper.startup_info(); |
214 | 214 |
215 bool inherit_handles = options.inherit_handles; | 215 bool inherit_handles = options.inherit_mode == LaunchOptions::Inherit::kAll; |
216 DWORD flags = 0; | 216 DWORD flags = 0; |
217 if (options.handles_to_inherit) { | 217 if (!options.handles_to_inherit.empty()) { |
218 if (options.handles_to_inherit->empty()) { | 218 DCHECK_EQ(options.inherit_mode, LaunchOptions::Inherit::kSpecific); |
219 inherit_handles = false; | |
220 } else { | |
221 if (options.handles_to_inherit->size() > | |
222 std::numeric_limits<DWORD>::max() / sizeof(HANDLE)) { | |
223 DLOG(ERROR) << "Too many handles to inherit."; | |
224 return Process(); | |
225 } | |
226 | 219 |
227 // Ensure the handles can be inherited. | 220 if (options.handles_to_inherit.size() > |
228 for (HANDLE handle : *options.handles_to_inherit) { | 221 std::numeric_limits<DWORD>::max() / sizeof(HANDLE)) { |
229 BOOL result = SetHandleInformation(handle, HANDLE_FLAG_INHERIT, | 222 DLOG(ERROR) << "Too many handles to inherit."; |
230 HANDLE_FLAG_INHERIT); | 223 return Process(); |
231 PCHECK(result); | 224 } |
232 } | |
233 | 225 |
234 if (!startup_info_wrapper.InitializeProcThreadAttributeList(1)) { | 226 // Ensure the handles can be inherited. |
235 DPLOG(ERROR); | 227 for (HANDLE handle : options.handles_to_inherit) { |
236 return Process(); | 228 BOOL result = SetHandleInformation(handle, HANDLE_FLAG_INHERIT, |
237 } | 229 HANDLE_FLAG_INHERIT); |
| 230 PCHECK(result); |
| 231 } |
238 | 232 |
239 if (!startup_info_wrapper.UpdateProcThreadAttribute( | 233 if (!startup_info_wrapper.InitializeProcThreadAttributeList(1)) { |
240 PROC_THREAD_ATTRIBUTE_HANDLE_LIST, | 234 DPLOG(ERROR); |
241 const_cast<HANDLE*>(&options.handles_to_inherit->at(0)), | 235 return Process(); |
242 static_cast<DWORD>(options.handles_to_inherit->size() * | 236 } |
243 sizeof(HANDLE)))) { | |
244 DPLOG(ERROR); | |
245 return Process(); | |
246 } | |
247 | 237 |
248 inherit_handles = true; | 238 if (!startup_info_wrapper.UpdateProcThreadAttribute( |
249 flags |= EXTENDED_STARTUPINFO_PRESENT; | 239 PROC_THREAD_ATTRIBUTE_HANDLE_LIST, |
| 240 const_cast<HANDLE*>(&options.handles_to_inherit[0]), |
| 241 static_cast<DWORD>(options.handles_to_inherit.size() * |
| 242 sizeof(HANDLE)))) { |
| 243 DPLOG(ERROR); |
| 244 return Process(); |
250 } | 245 } |
| 246 |
| 247 inherit_handles = true; |
| 248 flags |= EXTENDED_STARTUPINFO_PRESENT; |
251 } | 249 } |
252 | 250 |
253 if (options.empty_desktop_name) | 251 if (options.empty_desktop_name) |
254 startup_info->lpDesktop = const_cast<wchar_t*>(L""); | 252 startup_info->lpDesktop = const_cast<wchar_t*>(L""); |
255 startup_info->dwFlags = STARTF_USESHOWWINDOW; | 253 startup_info->dwFlags = STARTF_USESHOWWINDOW; |
256 startup_info->wShowWindow = options.start_hidden ? SW_HIDE : SW_SHOWNORMAL; | 254 startup_info->wShowWindow = options.start_hidden ? SW_HIDE : SW_SHOWNORMAL; |
257 | 255 |
258 if (options.stdin_handle || options.stdout_handle || options.stderr_handle) { | 256 if (options.stdin_handle || options.stdout_handle || options.stderr_handle) { |
259 DCHECK(inherit_handles); | 257 DCHECK(inherit_handles); |
260 DCHECK(options.stdin_handle); | 258 DCHECK(options.stdin_handle); |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 | 384 |
387 bool GetAppOutput(const StringPiece16& cl, std::string* output) { | 385 bool GetAppOutput(const StringPiece16& cl, std::string* output) { |
388 return GetAppOutputInternal(cl, false, output); | 386 return GetAppOutputInternal(cl, false, output); |
389 } | 387 } |
390 | 388 |
391 void RaiseProcessToHighPriority() { | 389 void RaiseProcessToHighPriority() { |
392 SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS); | 390 SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS); |
393 } | 391 } |
394 | 392 |
395 } // namespace base | 393 } // namespace base |
OLD | NEW |