| 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 // _fileno was broken for SUBSYSTEM:WINDOWS from VS2010 to VS2012/2013. | 145 return; |
| 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; | |
| 153 } | 146 } |
| 154 | 147 |
| 155 if (!AttachConsole(ATTACH_PARENT_PROCESS)) { | 148 if (!AttachConsole(ATTACH_PARENT_PROCESS)) { |
| 156 unsigned int result = GetLastError(); | 149 unsigned int result = GetLastError(); |
| 157 // Was probably already attached. | 150 // Was probably already attached. |
| 158 if (result == ERROR_ACCESS_DENIED) | 151 if (result == ERROR_ACCESS_DENIED) |
| 159 return; | 152 return; |
| 160 // Don't bother creating a new console for each child process if the | 153 // Don't bother creating a new console for each child process if the |
| 161 // parent process is invalid (eg: crashed). | 154 // parent process is invalid (eg: crashed). |
| 162 if (result == ERROR_GEN_FAILURE) | 155 if (result == ERROR_GEN_FAILURE) |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 374 | 367 |
| 375 bool GetAppOutput(const StringPiece16& cl, std::string* output) { | 368 bool GetAppOutput(const StringPiece16& cl, std::string* output) { |
| 376 return GetAppOutputInternal(cl, false, output); | 369 return GetAppOutputInternal(cl, false, output); |
| 377 } | 370 } |
| 378 | 371 |
| 379 void RaiseProcessToHighPriority() { | 372 void RaiseProcessToHighPriority() { |
| 380 SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS); | 373 SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS); |
| 381 } | 374 } |
| 382 | 375 |
| 383 } // namespace base | 376 } // namespace base |
| OLD | NEW |