| 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 #include "base/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/file_util.h" | 6 #include "base/file_util.h" |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/process/kill.h" | 8 #include "base/process/kill.h" |
| 9 #include "base/process/launch.h" | 9 #include "base/process/launch.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 NOTREACHED() << "Failed to disabled pipe inheritance"; | 78 NOTREACHED() << "Failed to disabled pipe inheritance"; |
| 79 return false; | 79 return false; |
| 80 } | 80 } |
| 81 if (!SetHandleInformation(err_read, HANDLE_FLAG_INHERIT, 0)) { | 81 if (!SetHandleInformation(err_read, HANDLE_FLAG_INHERIT, 0)) { |
| 82 NOTREACHED() << "Failed to disabled pipe inheritance"; | 82 NOTREACHED() << "Failed to disabled pipe inheritance"; |
| 83 return false; | 83 return false; |
| 84 } | 84 } |
| 85 | 85 |
| 86 base::FilePath::StringType cmdline_str(cmdline.GetCommandLineString()); | 86 base::FilePath::StringType cmdline_str(cmdline.GetCommandLineString()); |
| 87 | 87 |
| 88 STARTUPINFO start_info = {}; | 88 base::win::ScopedProcessInformation proc_info; |
| 89 STARTUPINFO start_info = { 0 }; |
| 89 | 90 |
| 90 start_info.cb = sizeof(STARTUPINFO); | 91 start_info.cb = sizeof(STARTUPINFO); |
| 91 start_info.hStdOutput = out_write; | 92 start_info.hStdOutput = out_write; |
| 92 // Keep the normal stdin. | 93 // Keep the normal stdin. |
| 93 start_info.hStdInput = GetStdHandle(STD_INPUT_HANDLE); | 94 start_info.hStdInput = GetStdHandle(STD_INPUT_HANDLE); |
| 94 // FIXME(brettw) set stderr here when we actually read it below. | 95 // FIXME(brettw) set stderr here when we actually read it below. |
| 95 //start_info.hStdError = err_write; | 96 //start_info.hStdError = err_write; |
| 96 start_info.hStdError = GetStdHandle(STD_ERROR_HANDLE); | 97 start_info.hStdError = GetStdHandle(STD_ERROR_HANDLE); |
| 97 start_info.dwFlags |= STARTF_USESTDHANDLES; | 98 start_info.dwFlags |= STARTF_USESTDHANDLES; |
| 98 | 99 |
| 99 // Create the child process. | 100 // Create the child process. |
| 100 PROCESS_INFORMATION temp_process_info = {}; | |
| 101 if (!CreateProcess(NULL, | 101 if (!CreateProcess(NULL, |
| 102 &cmdline_str[0], | 102 &cmdline_str[0], |
| 103 NULL, NULL, | 103 NULL, NULL, |
| 104 TRUE, // Handles are inherited. | 104 TRUE, // Handles are inherited. |
| 105 0, NULL, | 105 0, NULL, |
| 106 startup_dir.value().c_str(), | 106 startup_dir.value().c_str(), |
| 107 &start_info, &temp_process_info)) { | 107 &start_info, proc_info.Receive())) { |
| 108 return false; | 108 return false; |
| 109 } | 109 } |
| 110 base::win::ScopedProcessInformation proc_info(temp_process_info); | |
| 111 | 110 |
| 112 // Close our writing end of pipes now. Otherwise later read would not be able | 111 // Close our writing end of pipes now. Otherwise later read would not be able |
| 113 // to detect end of child's output. | 112 // to detect end of child's output. |
| 114 scoped_out_write.Close(); | 113 scoped_out_write.Close(); |
| 115 scoped_err_write.Close(); | 114 scoped_err_write.Close(); |
| 116 | 115 |
| 117 // Read output from the child process's pipe for STDOUT | 116 // Read output from the child process's pipe for STDOUT |
| 118 const int kBufferSize = 1024; | 117 const int kBufferSize = 1024; |
| 119 char buffer[kBufferSize]; | 118 char buffer[kBufferSize]; |
| 120 | 119 |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 msg += "."; | 388 msg += "."; |
| 390 *err = Err(function->function(), "Script returned non-zero exit code.", | 389 *err = Err(function->function(), "Script returned non-zero exit code.", |
| 391 msg); | 390 msg); |
| 392 return Value(); | 391 return Value(); |
| 393 } | 392 } |
| 394 | 393 |
| 395 return ConvertInputToValue(output, function, args[2], err); | 394 return ConvertInputToValue(output, function, args[2], err); |
| 396 } | 395 } |
| 397 | 396 |
| 398 } // namespace functions | 397 } // namespace functions |
| OLD | NEW |