Escape special/non-printing characters in debug output (RHBZ#731744).
The default event handler in libguestfs was simply writing all debug
output directly to stderr. However if the output contains
non-printable characters such as terminal control codes then these
would also be sent directly.
With newer SeaBIOS there is a lame attempt to implement a splash
screen using terminal control codes, thus when libguestfs tries to
display debugging output it would cause the screen to clear and debug
output to be lost.
This commit causes all non-printing characters to be escaped.
(\n and \r characters from the appliance are treated somewhat
specially).
Furthermore, instead of using write(2), use buffered stderr calls.
(cherry picked from commit
06019bc82e107f7715ebc59e491610e06dad1e39)