Add new export to hostpolicy and hostfxr to redirect error output (dotnet/core-setup...
authorVitek Karas <vitek.karas@microsoft.com>
Tue, 4 Dec 2018 23:26:52 +0000 (15:26 -0800)
committerGitHub <noreply@github.com>
Tue, 4 Dec 2018 23:26:52 +0000 (15:26 -0800)
commite7b4696856650aa051e2e882dfc22d1e83d02657
tree912f8562640896ac6ad89f21b94a95a4c07a5523
parent9682c5a62d79c639471427649586ea9cbdb6b8af
Add new export to hostpolicy and hostfxr to redirect error output (dotnet/core-setup#4816)

* Add new export to hostpolicy and hostfxr to redirect error output to a callback

This introduces corehost_set_error_writer and hostfxr_set_error_writer exports.
If set, all errors will be written to the error writer instead of the default stderr.
Tracing is unaffected by this change.
The error writer is set per-thread (thread local).
Only one error writer can be set on a given thread. Subsequent calls to set error
writer will overwrite the previous writer.

hostfxr propagates the custom error writer (if any) to the hostpolicy
for the duration of the calls it makes to hostpolicy.

Added tests to validate the new behavior.

* Remove TODOs which are now resolved with this change

* Fix buffer allocation to work with any string (arbitrary large).
Remove locks on error writer since it's thread local.

* Fix the error formating on Linux

* Fix error formatting on Linux

va_list is not reusable, by definition. On Windows this works since the implementation makes it reusable. but on Linux it's not. So make a copy before calling the printf with it.

Simplify the code, since vsnprintf and _vsnwprintf do in fact behave the same if passed NULL buffer and zero length (calculates the necessary buffer size). So no need for two functions even on Windows.

Commit migrated from https://github.com/dotnet/core-setup/commit/bfb18700ea2fb0e600a034ac7f719aee2618a87e
docs/installer/design-docs/host-component-dependencies-resolution.md
src/installer/corehost/cli/fxr/hostfxr.cpp
src/installer/corehost/cli/hostpolicy.cpp
src/installer/corehost/common/pal.h
src/installer/corehost/common/trace.cpp
src/installer/corehost/common/trace.h
src/installer/test/Assets/TestProjects/HostApiInvokerApp/HostFXR.cs
src/installer/test/Assets/TestProjects/HostApiInvokerApp/HostPolicy.cs
src/installer/test/HostActivationTests/GivenThatICareAboutComponentDependencyResolution.cs
src/installer/test/HostActivationTests/GivenThatICareAboutNativeHostApis.cs