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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
57 // that case, we don't want to open CONOUT$, because its output | 57 // that case, we don't want to open CONOUT$, because its output |
58 // likely does not go anywhere. | 58 // likely does not go anywhere. |
59 // | 59 // |
60 // We don't use GetStdHandle() to check stdout/stderr here because | 60 // We don't use GetStdHandle() to check stdout/stderr here because |
61 // it can return dangling IDs of handles that were never inherited | 61 // it can return dangling IDs of handles that were never inherited |
62 // by this process. These IDs could have been reused by the time | 62 // by this process. These IDs could have been reused by the time |
63 // this function is called. The CRT checks the validity of | 63 // this function is called. The CRT checks the validity of |
64 // stdout/stderr on startup (before the handle IDs can be reused). | 64 // stdout/stderr on startup (before the handle IDs can be reused). |
65 // _fileno(stdout) will return -2 (_NO_CONSOLE_FILENO) if stdout was | 65 // _fileno(stdout) will return -2 (_NO_CONSOLE_FILENO) if stdout was |
66 // invalid. | 66 // invalid. |
67 if (_fileno(stdout) >= 0 || _fileno(stderr) >= 0) | 67 if (_fileno(stdout) >= 0 || _fileno(stderr) >= 0) { |
68 return; | 68 // _fileno was broken for SUBSYSTEM:WINDOWS from VS2010 to VS2012/2013. |
69 // http://crbug.com/358267. Confirm that the underlying HANDLE is valid | |
70 // before aborting. | |
71 | |
72 // This causes NaCl tests to hang on XP for reasons unclear, perhaps due | |
scottmg
2015/08/12 02:28:14
It would be better if you can remove this early re
jam
2015/08/12 03:01:32
I didn't want to deal with debugging nacl tests on
| |
73 // to not being able to inherit handles. Since it's only for debugging, | |
74 // and redirecting still works, punt for now. | |
75 if (base::win::GetVersion() < base::win::VERSION_VISTA) | |
76 return; | |
77 | |
78 intptr_t stdout_handle = _get_osfhandle(_fileno(stdout)); | |
79 intptr_t stderr_handle = _get_osfhandle(_fileno(stderr)); | |
80 if (stdout_handle >= 0 || stderr_handle >= 0) | |
81 return; | |
82 } | |
69 | 83 |
70 if (!AttachConsole(ATTACH_PARENT_PROCESS)) { | 84 if (!AttachConsole(ATTACH_PARENT_PROCESS)) { |
71 unsigned int result = GetLastError(); | 85 unsigned int result = GetLastError(); |
72 // Was probably already attached. | 86 // Was probably already attached. |
73 if (result == ERROR_ACCESS_DENIED) | 87 if (result == ERROR_ACCESS_DENIED) |
74 return; | 88 return; |
75 // Don't bother creating a new console for each child process if the | 89 // Don't bother creating a new console for each child process if the |
76 // parent process is invalid (eg: crashed). | 90 // parent process is invalid (eg: crashed). |
77 if (result == ERROR_GEN_FAILURE) | 91 if (result == ERROR_GEN_FAILURE) |
78 return; | 92 return; |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
344 WaitForSingleObject(proc_info.process_handle(), INFINITE); | 358 WaitForSingleObject(proc_info.process_handle(), INFINITE); |
345 | 359 |
346 return true; | 360 return true; |
347 } | 361 } |
348 | 362 |
349 void RaiseProcessToHighPriority() { | 363 void RaiseProcessToHighPriority() { |
350 SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS); | 364 SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS); |
351 } | 365 } |
352 | 366 |
353 } // namespace base | 367 } // namespace base |
OLD | NEW |