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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 // likely does not go anywhere. | 135 // likely does not go anywhere. |
136 // | 136 // |
137 // We don't use GetStdHandle() to check stdout/stderr here because | 137 // We don't use GetStdHandle() to check stdout/stderr here because |
138 // it can return dangling IDs of handles that were never inherited | 138 // it can return dangling IDs of handles that were never inherited |
139 // by this process. These IDs could have been reused by the time | 139 // by this process. These IDs could have been reused by the time |
140 // this function is called. The CRT checks the validity of | 140 // this function is called. The CRT checks the validity of |
141 // stdout/stderr on startup (before the handle IDs can be reused). | 141 // stdout/stderr on startup (before the handle IDs can be reused). |
142 // _fileno(stdout) will return -2 (_NO_CONSOLE_FILENO) if stdout was | 142 // _fileno(stdout) will return -2 (_NO_CONSOLE_FILENO) if stdout was |
143 // invalid. | 143 // invalid. |
144 if (_fileno(stdout) >= 0 || _fileno(stderr) >= 0) { | 144 if (_fileno(stdout) >= 0 || _fileno(stderr) >= 0) { |
145 return; | 145 // _fileno was broken for SUBSYSTEM:WINDOWS from VS2010 to VS2012/2013. |
| 146 // http://crbug.com/358267. Confirm that the underlying HANDLE is valid |
| 147 // before aborting. |
| 148 |
| 149 intptr_t stdout_handle = _get_osfhandle(_fileno(stdout)); |
| 150 intptr_t stderr_handle = _get_osfhandle(_fileno(stderr)); |
| 151 if (stdout_handle >= 0 || stderr_handle >= 0) |
| 152 return; |
146 } | 153 } |
147 | 154 |
148 if (!AttachConsole(ATTACH_PARENT_PROCESS)) { | 155 if (!AttachConsole(ATTACH_PARENT_PROCESS)) { |
149 unsigned int result = GetLastError(); | 156 unsigned int result = GetLastError(); |
150 // Was probably already attached. | 157 // Was probably already attached. |
151 if (result == ERROR_ACCESS_DENIED) | 158 if (result == ERROR_ACCESS_DENIED) |
152 return; | 159 return; |
153 // Don't bother creating a new console for each child process if the | 160 // Don't bother creating a new console for each child process if the |
154 // parent process is invalid (eg: crashed). | 161 // parent process is invalid (eg: crashed). |
155 if (result == ERROR_GEN_FAILURE) | 162 if (result == ERROR_GEN_FAILURE) |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 | 374 |
368 bool GetAppOutput(const StringPiece16& cl, std::string* output) { | 375 bool GetAppOutput(const StringPiece16& cl, std::string* output) { |
369 return GetAppOutputInternal(cl, false, output); | 376 return GetAppOutputInternal(cl, false, output); |
370 } | 377 } |
371 | 378 |
372 void RaiseProcessToHighPriority() { | 379 void RaiseProcessToHighPriority() { |
373 SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS); | 380 SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS); |
374 } | 381 } |
375 | 382 |
376 } // namespace base | 383 } // namespace base |
OLD | NEW |