| 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_util.h" | 5 #include "base/process_util.h" |
| 6 | 6 |
| 7 #include <fcntl.h> | 7 #include <fcntl.h> |
| 8 #include <io.h> | 8 #include <io.h> |
| 9 #include <windows.h> | 9 #include <windows.h> |
| 10 #include <userenv.h> | 10 #include <userenv.h> |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 // it fails quite often. This should be investigated eventually. | 115 // it fails quite often. This should be investigated eventually. |
| 116 base::KillProcess(process_, kProcessKilledExitCode, false); | 116 base::KillProcess(process_, kProcessKilledExitCode, false); |
| 117 | 117 |
| 118 // Now, just cleanup as if the process exited normally. | 118 // Now, just cleanup as if the process exited normally. |
| 119 OnObjectSignaled(process_); | 119 OnObjectSignaled(process_); |
| 120 } | 120 } |
| 121 | 121 |
| 122 } // namespace | 122 } // namespace |
| 123 | 123 |
| 124 void RouteStdioToConsole() { | 124 void RouteStdioToConsole() { |
| 125 // Don't change anything if stdout or stderr already point to a |
| 126 // valid stream. |
| 127 // |
| 128 // If we are running under Buildbot or under Cygwin's default |
| 129 // terminal (mintty), stderr and stderr will be pipe handles. In |
| 130 // that case, we don't want to open CONOUT$, because its output |
| 131 // likely does not go anywhere. |
| 132 // |
| 133 // We don't use GetStdHandle() to check stdout/stderr here because |
| 134 // it can return dangling IDs of handles that were never inherited |
| 135 // by this process. These IDs could have been reused by the time |
| 136 // this function is called. The CRT checks the validity of |
| 137 // stdout/stderr on startup (before the handle IDs can be reused). |
| 138 // _fileno(stdout) will return -2 (_NO_CONSOLE_FILENO) if stdout was |
| 139 // invalid. |
| 140 if (_fileno(stdout) >= 0 || _fileno(stderr) >= 0) |
| 141 return; |
| 142 |
| 125 if (!AttachConsole(ATTACH_PARENT_PROCESS)) { | 143 if (!AttachConsole(ATTACH_PARENT_PROCESS)) { |
| 126 unsigned int result = GetLastError(); | 144 unsigned int result = GetLastError(); |
| 127 // Was probably already attached. | 145 // Was probably already attached. |
| 128 if (result == ERROR_ACCESS_DENIED) | 146 if (result == ERROR_ACCESS_DENIED) |
| 129 return; | 147 return; |
| 130 // Don't bother creating a new console for each child process if the | 148 // Don't bother creating a new console for each child process if the |
| 131 // parent process is invalid (eg: crashed). | 149 // parent process is invalid (eg: crashed). |
| 132 if (result == ERROR_GEN_FAILURE) | 150 if (result == ERROR_GEN_FAILURE) |
| 133 return; | 151 return; |
| 134 // Make a new console if attaching to parent fails with any other error. | 152 // Make a new console if attaching to parent fails with any other error. |
| (...skipping 849 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 984 | 1002 |
| 985 PERFORMANCE_INFORMATION info; | 1003 PERFORMANCE_INFORMATION info; |
| 986 if (!InternalGetPerformanceInfo(&info, sizeof(info))) { | 1004 if (!InternalGetPerformanceInfo(&info, sizeof(info))) { |
| 987 DLOG(ERROR) << "Failed to fetch internal performance info."; | 1005 DLOG(ERROR) << "Failed to fetch internal performance info."; |
| 988 return 0; | 1006 return 0; |
| 989 } | 1007 } |
| 990 return (info.CommitTotal * system_info.dwPageSize) / 1024; | 1008 return (info.CommitTotal * system_info.dwPageSize) / 1024; |
| 991 } | 1009 } |
| 992 | 1010 |
| 993 } // namespace base | 1011 } // namespace base |
| OLD | NEW |