On 08/11/18 17:31, Andrew Cooper wrote:
> On 08/11/18 17:28, Ian Jackson wrote:
>> Andrew Cooper writes ("Re: [Xen-devel] [PATCH v2 01/11] tools/libs/toollog:
>> Provide a default logger"):
>>> You want something like:
>>>
>>> static xentoollog_logger_stdiostream stdio_logger = {
>>> .vtable = {
>>> .vmessage = stdiostream_vmessage,
>>> .progress = stdiostream_progress,
>>> .destroy = 0, /* no-one should destroy this */
>>> },
>>> .min_level = XTL_PROGRESS,
>>> /* for other fields except .f, 0 is good */
>>> };
>>>
>>> static void __attribute__((__constructor__)) init_stdio_logger(void)
>>> {
>>> stdio_logger.f = stderr;
>>> }
>> Blimey. Is that portable enough ?
> Should be. Its how C++ globals work, and it appears that we already use
> it in xc_dom.h for the dombuilder register_{loader,arch_hooks}()
> infrastructure.
Although actually, you can't capture stderr in a variable like this at
all. freopen() at a later point will close the current FILE object and
create a new one, after which this logger will use-after-free.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel