|
|
e76f14 |
From 4f88b55bfad9d72675ef09480dd4d8ad96047842 Mon Sep 17 00:00:00 2001
|
|
|
e76f14 |
From: "Richard W.M. Jones" <rjones@redhat.com>
|
|
|
e76f14 |
Date: Sun, 20 Mar 2016 15:50:31 +0000
|
|
|
e76f14 |
Subject: [PATCH] conn: Pretend to be a serial terminal, so sgabios doesn't
|
|
|
e76f14 |
hang.
|
|
|
e76f14 |
|
|
|
e76f14 |
This tedious workaround avoids a 0.26 second pause when using sgabios
|
|
|
e76f14 |
(the Serial Graphics Adapter). It's basically a workaround for buggy
|
|
|
e76f14 |
code in sgabios, but much easier than fixing the assembler.
|
|
|
e76f14 |
|
|
|
e76f14 |
(cherry picked from commit cd578510197eb87abf996a3a050779806682e83f)
|
|
|
e76f14 |
---
|
|
|
e76f14 |
src/conn-socket.c | 34 +++++++++++++++++++++++++++++++++-
|
|
|
e76f14 |
1 file changed, 33 insertions(+), 1 deletion(-)
|
|
|
e76f14 |
|
|
|
e76f14 |
diff --git a/src/conn-socket.c b/src/conn-socket.c
|
|
|
e76f14 |
index 9db0bfd..8a4b9d0 100644
|
|
|
e76f14 |
--- a/src/conn-socket.c
|
|
|
e76f14 |
+++ b/src/conn-socket.c
|
|
|
e76f14 |
@@ -33,6 +33,8 @@
|
|
|
e76f14 |
#include <assert.h>
|
|
|
e76f14 |
#include <libintl.h>
|
|
|
e76f14 |
|
|
|
e76f14 |
+#include "ignore-value.h"
|
|
|
e76f14 |
+
|
|
|
e76f14 |
#include "guestfs.h"
|
|
|
e76f14 |
#include "guestfs-internal.h"
|
|
|
e76f14 |
|
|
|
e76f14 |
@@ -314,6 +316,9 @@ handle_log_message (guestfs_h *g,
|
|
|
e76f14 |
{
|
|
|
e76f14 |
char buf[BUFSIZ];
|
|
|
e76f14 |
ssize_t n;
|
|
|
e76f14 |
+ const char dsr_request[] = "\033[6n";
|
|
|
e76f14 |
+ const char dsr_reply[] = "\033[24;80R";
|
|
|
e76f14 |
+ const char dsr_reply_padding[] = "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b";
|
|
|
e76f14 |
|
|
|
e76f14 |
/* Carried over from ancient proto.c code. The comment there was:
|
|
|
e76f14 |
*
|
|
|
e76f14 |
@@ -341,7 +346,34 @@ handle_log_message (guestfs_h *g,
|
|
|
e76f14 |
return -1;
|
|
|
e76f14 |
}
|
|
|
e76f14 |
|
|
|
e76f14 |
- /* It's an actual log message, send it upwards. */
|
|
|
e76f14 |
+ /* It's an actual log message. */
|
|
|
e76f14 |
+
|
|
|
e76f14 |
+ /* SGABIOS tries to query the "serial console" for its size using the
|
|
|
e76f14 |
+ * ISO/IEC 6429 Device Status Report (ESC [ 6 n). If it doesn't
|
|
|
e76f14 |
+ * read anything back, then it unfortunately hangs for 0.26 seconds.
|
|
|
e76f14 |
+ * Therefore we detect this situation and send back a fake console
|
|
|
e76f14 |
+ * size.
|
|
|
e76f14 |
+ */
|
|
|
e76f14 |
+ if (memmem (buf, n, dsr_request, sizeof dsr_request - 1) != NULL) {
|
|
|
e76f14 |
+ debug (g, "responding to serial console Device Status Report");
|
|
|
e76f14 |
+
|
|
|
e76f14 |
+ /* Ignore any error from this write, as it's just an optimization.
|
|
|
e76f14 |
+ * We can't even be sure that console_sock is a socket or that
|
|
|
e76f14 |
+ * it's writable.
|
|
|
e76f14 |
+ */
|
|
|
e76f14 |
+ ignore_value (write (conn->console_sock, dsr_reply,
|
|
|
e76f14 |
+ sizeof dsr_reply - 1));
|
|
|
e76f14 |
+ /* Additionally, because of a bug in sgabios, it will still pause
|
|
|
e76f14 |
+ * unless you write at least 14 bytes, so we have to pad the
|
|
|
e76f14 |
+ * reply. We can't pad with NULs since sgabios's input routine
|
|
|
e76f14 |
+ * ignores these, so we have to use some other safe padding
|
|
|
e76f14 |
+ * characters. Backspace seems innocuous.
|
|
|
e76f14 |
+ */
|
|
|
e76f14 |
+ ignore_value (write (conn->console_sock, dsr_reply_padding,
|
|
|
e76f14 |
+ sizeof dsr_reply_padding - 1));
|
|
|
e76f14 |
+ }
|
|
|
e76f14 |
+
|
|
|
e76f14 |
+ /* Send it upwards. */
|
|
|
e76f14 |
guestfs_int_log_message_callback (g, buf, n);
|
|
|
e76f14 |
|
|
|
e76f14 |
return 1;
|
|
|
e76f14 |
--
|
|
|
e76f14 |
1.8.3.1
|
|
|
e76f14 |
|