зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1680402. Use stderr in printf_stderr instead of reopening fd 2. r=glandium
Currently, printf_stderr doesn't show up when running with ./mach run. This is because we run with -attach-console and that redirects stderr to a different file descriptor using freopen in UseParentConsole. The change from just using stderr directly happened in bug 340443 and was done to avoid some linking issues. That problem doesn't seem to apply anymore so you'd expect we'd be able to go back to the straightforward implemention that works even if stderr has been redirected. Unfortunately, Windows takes not buffering stderr very seriously and fprintf will write out the results character by character. This can cause log output lines to be intermixed which breaks log parsing in CI. We keep using fdopen to create a new FILE* that's buffered but instead of hard coding fd 2, we get the actual fd that corresponds to stderr using fileno. The mozglue implementation was cargo culted from xpcom, so we update it as well. Differential Revision: https://phabricator.services.mozilla.com/D98550
This commit is contained in:
Родитель
41ce60db53
Коммит
702bd6eeec
|
@ -45,7 +45,12 @@ inline void printf_stderr(const char* fmt, ...) MOZ_FORMAT_PRINTF(1, 2) {
|
|||
}
|
||||
#endif // defined(XP_WIN)
|
||||
|
||||
FILE* fp = _fdopen(_dup(2), "a");
|
||||
// stderr is unbuffered by default so we open a new FILE (which is buffered)
|
||||
// so that calls to printf_stderr are not as likely to get mixed together.
|
||||
int fd = _fileno(stderr);
|
||||
if (fd == -2) return;
|
||||
|
||||
FILE* fp = _fdopen(_dup(fd), "a");
|
||||
if (!fp) return;
|
||||
|
||||
va_list args;
|
||||
|
|
|
@ -253,7 +253,14 @@ void vprintf_stderr(const char* aFmt, va_list aArgs) {
|
|||
}
|
||||
}
|
||||
|
||||
FILE* fp = _fdopen(_dup(2), "a");
|
||||
// stderr is unbuffered by default so we open a new FILE (which is buffered)
|
||||
// so that calls to printf_stderr are not as likely to get mixed together.
|
||||
int fd = _fileno(stderr);
|
||||
if (fd == -2) {
|
||||
return;
|
||||
}
|
||||
|
||||
FILE* fp = _fdopen(_dup(fd), "a");
|
||||
if (!fp) {
|
||||
return;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче