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 we
should be able to go back to the straightforward implemention that works even
if stderr has been redirected. The mozglue implementation was cargo culted from
xpcom, and there wasn't a reason other than that for the fdopen(dup()) there.

Differential Revision: https://phabricator.services.mozilla.com/D98550
This commit is contained in:
Jeff Muizelaar 2020-12-04 02:46:57 +00:00
parent f5c9716fcb
commit 62e7969d1a
2 changed files with 2 additions and 15 deletions

View File

@ -45,15 +45,10 @@ inline void printf_stderr(const char* fmt, ...) MOZ_FORMAT_PRINTF(1, 2) {
}
#endif // defined(XP_WIN)
FILE* fp = _fdopen(_dup(2), "a");
if (!fp) return;
va_list args;
va_start(args, fmt);
vfprintf(fp, fmt, args);
vfprintf(stderr, fmt, args);
va_end(args);
fclose(fp);
}
#ifdef __cplusplus

View File

@ -253,15 +253,7 @@ void vprintf_stderr(const char* aFmt, va_list aArgs) {
}
}
FILE* fp = _fdopen(_dup(2), "a");
if (!fp) {
return;
}
vfprintf(fp, aFmt, aArgs);
AutoSuspendLateWriteChecks suspend;
fclose(fp);
vfprintf(stderr, aFmt, aArgs);
}
#elif defined(ANDROID)