| 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 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 // likely does not go anywhere. | 143 // likely does not go anywhere. |
| 144 // | 144 // |
| 145 // We don't use GetStdHandle() to check stdout/stderr here because | 145 // We don't use GetStdHandle() to check stdout/stderr here because |
| 146 // it can return dangling IDs of handles that were never inherited | 146 // it can return dangling IDs of handles that were never inherited |
| 147 // by this process. These IDs could have been reused by the time | 147 // by this process. These IDs could have been reused by the time |
| 148 // this function is called. The CRT checks the validity of | 148 // this function is called. The CRT checks the validity of |
| 149 // stdout/stderr on startup (before the handle IDs can be reused). | 149 // stdout/stderr on startup (before the handle IDs can be reused). |
| 150 // _fileno(stdout) will return -2 (_NO_CONSOLE_FILENO) if stdout was | 150 // _fileno(stdout) will return -2 (_NO_CONSOLE_FILENO) if stdout was |
| 151 // invalid. | 151 // invalid. |
| 152 if (_fileno(stdout) >= 0 || _fileno(stderr) >= 0) { | 152 if (_fileno(stdout) >= 0 || _fileno(stderr) >= 0) { |
| 153 return; | 153 // _fileno was broken for SUBSYSTEM:WINDOWS from VS2010 to VS2012/2013. |
| 154 // http://crbug.com/358267. Confirm that the underlying HANDLE is valid |
| 155 // before aborting. |
| 156 |
| 157 intptr_t stdout_handle = _get_osfhandle(_fileno(stdout)); |
| 158 intptr_t stderr_handle = _get_osfhandle(_fileno(stderr)); |
| 159 if (stdout_handle >= 0 || stderr_handle >= 0) |
| 160 return; |
| 154 } | 161 } |
| 155 | 162 |
| 156 if (!AttachConsole(ATTACH_PARENT_PROCESS)) { | 163 if (!AttachConsole(ATTACH_PARENT_PROCESS)) { |
| 157 unsigned int result = GetLastError(); | 164 unsigned int result = GetLastError(); |
| 158 // Was probably already attached. | 165 // Was probably already attached. |
| 159 if (result == ERROR_ACCESS_DENIED) | 166 if (result == ERROR_ACCESS_DENIED) |
| 160 return; | 167 return; |
| 161 // Don't bother creating a new console for each child process if the | 168 // Don't bother creating a new console for each child process if the |
| 162 // parent process is invalid (eg: crashed). | 169 // parent process is invalid (eg: crashed). |
| 163 if (result == ERROR_GEN_FAILURE) | 170 if (result == ERROR_GEN_FAILURE) |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 379 | 386 |
| 380 bool GetAppOutput(const StringPiece16& cl, std::string* output) { | 387 bool GetAppOutput(const StringPiece16& cl, std::string* output) { |
| 381 return GetAppOutputInternal(cl, false, output); | 388 return GetAppOutputInternal(cl, false, output); |
| 382 } | 389 } |
| 383 | 390 |
| 384 void RaiseProcessToHighPriority() { | 391 void RaiseProcessToHighPriority() { |
| 385 SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS); | 392 SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS); |
| 386 } | 393 } |
| 387 | 394 |
| 388 } // namespace base | 395 } // namespace base |
| OLD | NEW |