| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_util.h" | 5 #include "base/process_util.h" |
| 6 | 6 |
| 7 #include <fcntl.h> | 7 #include <fcntl.h> |
| 8 #include <io.h> | 8 #include <io.h> |
| 9 #include <windows.h> | 9 #include <windows.h> |
| 10 #include <userenv.h> | 10 #include <userenv.h> |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 *process_handle = process_info.hProcess; | 264 *process_handle = process_info.hProcess; |
| 265 } else { | 265 } else { |
| 266 CloseHandle(process_info.hProcess); | 266 CloseHandle(process_info.hProcess); |
| 267 } | 267 } |
| 268 return true; | 268 return true; |
| 269 } | 269 } |
| 270 | 270 |
| 271 bool LaunchProcess(const CommandLine& cmdline, | 271 bool LaunchProcess(const CommandLine& cmdline, |
| 272 const LaunchOptions& options, | 272 const LaunchOptions& options, |
| 273 ProcessHandle* process_handle) { | 273 ProcessHandle* process_handle) { |
| 274 return LaunchProcess(cmdline.command_line_string(), options, process_handle); | 274 return LaunchProcess(cmdline.GetCommandLineString(), options, process_handle); |
| 275 } | 275 } |
| 276 | 276 |
| 277 // Attempts to kill the process identified by the given process | 277 // Attempts to kill the process identified by the given process |
| 278 // entry structure, giving it the specified exit code. | 278 // entry structure, giving it the specified exit code. |
| 279 // Returns true if this is successful, false otherwise. | 279 // Returns true if this is successful, false otherwise. |
| 280 bool KillProcessById(ProcessId process_id, int exit_code, bool wait) { | 280 bool KillProcessById(ProcessId process_id, int exit_code, bool wait) { |
| 281 HANDLE process = OpenProcess(PROCESS_TERMINATE | SYNCHRONIZE, | 281 HANDLE process = OpenProcess(PROCESS_TERMINATE | SYNCHRONIZE, |
| 282 FALSE, // Don't inherit handle | 282 FALSE, // Don't inherit handle |
| 283 process_id); | 283 process_id); |
| 284 if (!process) { | 284 if (!process) { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 310 // Ensure we don't leak the handles. | 310 // Ensure we don't leak the handles. |
| 311 win::ScopedHandle scoped_out_read(out_read); | 311 win::ScopedHandle scoped_out_read(out_read); |
| 312 win::ScopedHandle scoped_out_write(out_write); | 312 win::ScopedHandle scoped_out_write(out_write); |
| 313 | 313 |
| 314 // Ensure the read handle to the pipe for STDOUT is not inherited. | 314 // Ensure the read handle to the pipe for STDOUT is not inherited. |
| 315 if (!SetHandleInformation(out_read, HANDLE_FLAG_INHERIT, 0)) { | 315 if (!SetHandleInformation(out_read, HANDLE_FLAG_INHERIT, 0)) { |
| 316 NOTREACHED() << "Failed to disabled pipe inheritance"; | 316 NOTREACHED() << "Failed to disabled pipe inheritance"; |
| 317 return false; | 317 return false; |
| 318 } | 318 } |
| 319 | 319 |
| 320 // Now create the child process | 320 std::wstring writable_command_line_string(cl.GetCommandLineString()); |
| 321 |
| 321 PROCESS_INFORMATION proc_info = { 0 }; | 322 PROCESS_INFORMATION proc_info = { 0 }; |
| 322 STARTUPINFO start_info = { 0 }; | 323 STARTUPINFO start_info = { 0 }; |
| 323 | 324 |
| 324 start_info.cb = sizeof(STARTUPINFO); | 325 start_info.cb = sizeof(STARTUPINFO); |
| 325 start_info.hStdOutput = out_write; | 326 start_info.hStdOutput = out_write; |
| 326 // Keep the normal stdin and stderr. | 327 // Keep the normal stdin and stderr. |
| 327 start_info.hStdInput = GetStdHandle(STD_INPUT_HANDLE); | 328 start_info.hStdInput = GetStdHandle(STD_INPUT_HANDLE); |
| 328 start_info.hStdError = GetStdHandle(STD_ERROR_HANDLE); | 329 start_info.hStdError = GetStdHandle(STD_ERROR_HANDLE); |
| 329 start_info.dwFlags |= STARTF_USESTDHANDLES; | 330 start_info.dwFlags |= STARTF_USESTDHANDLES; |
| 330 | 331 |
| 331 // Create the child process. | 332 // Create the child process. |
| 332 if (!CreateProcess(NULL, | 333 if (!CreateProcess(NULL, |
| 333 const_cast<wchar_t*>(cl.command_line_string().c_str()), | 334 &writable_command_line_string[0], |
| 334 NULL, NULL, | 335 NULL, NULL, |
| 335 TRUE, // Handles are inherited. | 336 TRUE, // Handles are inherited. |
| 336 0, NULL, NULL, &start_info, &proc_info)) { | 337 0, NULL, NULL, &start_info, &proc_info)) { |
| 337 NOTREACHED() << "Failed to start process"; | 338 NOTREACHED() << "Failed to start process"; |
| 338 return false; | 339 return false; |
| 339 } | 340 } |
| 340 | 341 |
| 341 // We don't need the thread handle, close it now. | 342 // We don't need the thread handle, close it now. |
| 342 CloseHandle(proc_info.hThread); | 343 CloseHandle(proc_info.hThread); |
| 343 | 344 |
| (...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 866 | 867 |
| 867 PERFORMANCE_INFORMATION info; | 868 PERFORMANCE_INFORMATION info; |
| 868 if (!InternalGetPerformanceInfo(&info, sizeof(info))) { | 869 if (!InternalGetPerformanceInfo(&info, sizeof(info))) { |
| 869 LOG(ERROR) << "Failed to fetch internal performance info."; | 870 LOG(ERROR) << "Failed to fetch internal performance info."; |
| 870 return 0; | 871 return 0; |
| 871 } | 872 } |
| 872 return (info.CommitTotal * system_info.dwPageSize) / 1024; | 873 return (info.CommitTotal * system_info.dwPageSize) / 1024; |
| 873 } | 874 } |
| 874 | 875 |
| 875 } // namespace base | 876 } // namespace base |
| OLD | NEW |