]> xenbits.xensource.com Git - xtf.git/commit
vsnprintf: Expand \n to \r\n for console output
authorAndrew Cooper <andrew.cooper3@citrix.com>
Thu, 4 Jun 2020 12:54:54 +0000 (13:54 +0100)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Fri, 5 Jun 2020 19:33:08 +0000 (20:33 +0100)
commitbefa0352bdec39cc7bf642c5283fd470b85cc44c
treee7d83c6bd986a0880c803a4710932589b8a51018
parentfa268bcc69c3d2091dff1c40c2245aeea1eb0268
vsnprintf: Expand \n to \r\n for console output

xenconsoled doesn't automatically convert \n into \r\n, which causes test
output to appear like this in some terminals:

  [root@host ~]# xl create -c tests/selftest/test-pv64-selftest.cfg
  Parsing config from tests/selftest/test-pv64-selftest.cfg
  --- Xen Test Framework ---
                            Environment: PV 64bit (Long mode 4 levels)
                                                                      XTF Selftests

There are a number of ways to do this, but by far the most efficient way is to
have vsnprintf() expand \n's in the output buffer.

This however is non-standard behaviour for vsnprintf().  Rename it to
vsnprintf_internal() and take extra flags, and have vprintk() use the new
LF_TO_CRLF control flag.

Inside vsnprintf_internal(), rearrange the non-format and %c logic to share
the expansion logic, as well as extending the logic to fmt_string().

Extend the selftests to confirm correct behaviour in both modes, for all ways
of being able to pass newline characters into a format operation.

Reported-by: Pawel Wieczorkiewicz <wipawel@amazon.de>
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
common/console.c
common/libc/vsnprintf.c
include/xtf/libc.h
tests/selftest/main.c