Hello,

I wanted to get some feedback on how Jailhouse is implementing newlines for 
console printing.

Here's the code:

https://github.com/siemens/jailhouse/blob/92db71f257fabd3c08fa4b99498fa61a41ea831d/inmates/lib/printk.c#L60-L63

https://github.com/siemens/jailhouse/blob/92db71f257fabd3c08fa4b99498fa61a41ea831d/hypervisor/uart.c#L25-L28

You can see that the code is doing this:

if (c == '\n')

c = '\r';

else

c = *msg++;

So if the last character printed was '\n' (the Line Feed character), this 
code injects an '\r' (the Carriage Return character). I’m assuming the 
reason for this is just in case the console output is on Windows. Looking 
through the git history, it looks like this pattern has been in Jailhouse 
since the very beginning.

This seems incorrect to me. The thing is, Windows newlines are CR + LF, in 
that order, while Jailhouse is printing LF + CR, which doesn’t match Unix 
_or_ Windows. See https://en.wikipedia.org/wiki/Newline#Representation. 
However, maybe there is a good reason for this that I don’t see yet.

I’m consuming the Jailhouse console output in Linux, not Windows, but this 
still causes trouble because the extra CR after the LF can mess up awk (and 
possibly other line-based parsing tools). For more details, see 
https://stackoverflow.com/questions/60203007/awk-is-only-matching-the-first-line-when-matching-against-first-column
.

One solution is to reverse the order: inject CR _before_ printing LF. 
Another solution is to not inject CR at all, and leave it to the users of 
printk() to manually insert CR when needed.

Let me know what you all think.

Thanks,

-Michael

-- 
You received this message because you are subscribed to the Google Groups 
"Jailhouse" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jailhouse-dev/0d86ac87-9d3c-42c4-b499-af40aa76d302%40googlegroups.com.

Reply via email to