From: "Richard W.M. Jones" <rjones(a)redhat.com>
Previously described as a "gross hack and massive layering violation".
---
src/conn-socket.c | 27 ++-------------------------
src/guestfs-internal.h | 1 +
src/launch.c | 2 +-
src/proto.c | 26 ++++++++++++++++++++++++++
4 files changed, 30 insertions(+), 26 deletions(-)
diff --git a/src/conn-socket.c b/src/conn-socket.c
index c1ad31c..d268518 100644
--- a/src/conn-socket.c
+++ b/src/conn-socket.c
@@ -318,31 +318,8 @@ handle_log_message (guestfs_h *g,
return -1;
}
- /* It's an actual log message, send it upwards if anyone is listening. */
- guestfs___call_callbacks_message (g, GUESTFS_EVENT_APPLIANCE, buf, n);
-
- /* XXX This is a gross hack and massive layering violation. See the
- * comment above guestfs___launch_send_progress.
- *
- * Fix this gross hack by:
- * (1) Have a guestfs___proto_log_message() function in proto.c.
- * (2) Replace above guestfs___call_callbacks_message with (1).
- * (3) Add the code below to guestfs___proto_log_message.
- */
- if (g->state == LAUNCHING) {
- const char *sentinel;
- size_t len;
-
- sentinel = "Linux version"; /* kernel up */
- len = strlen (sentinel);
- if (memmem (buf, n, sentinel, len) != NULL)
- guestfs___launch_send_progress (g, 6);
-
- sentinel = "Starting /init script"; /* /init running */
- len = strlen (sentinel);
- if (memmem (buf, n, sentinel, len) != NULL)
- guestfs___launch_send_progress (g, 9);
- }
+ /* It's an actual log message, send it upwards. */
+ guestfs___log_message_callback (g, buf, n);
return 1;
}
diff --git a/src/guestfs-internal.h b/src/guestfs-internal.h
index a6df003..d4d15f3 100644
--- a/src/guestfs-internal.h
+++ b/src/guestfs-internal.h
@@ -528,6 +528,7 @@ extern int guestfs___send_file (guestfs_h *g, const char *filename);
extern int guestfs___recv_file (guestfs_h *g, const char *filename);
extern int guestfs___recv_from_daemon (guestfs_h *g, uint32_t *size_rtn, void
**buf_rtn);
extern void guestfs___progress_message_callback (guestfs_h *g, const struct
guestfs_progress *message);
+extern void guestfs___log_message_callback (guestfs_h *g, const char *buf, size_t len);
/* conn-socket.c */
extern struct connection *guestfs___new_conn_socket_listening (guestfs_h *g, int
daemon_accept_sock, int console_sock);
diff --git a/src/launch.c b/src/launch.c
index 0090b28..0565a5a 100644
--- a/src/launch.c
+++ b/src/launch.c
@@ -631,7 +631,7 @@ guestfs__launch (guestfs_h *g)
* or removed in future.
* (2) Messages are only sent if more than 5 seconds has elapsed
* since the launch clock started.
- * (3) There is a gross hack in proto.c to make this work.
+ * (3) There is a hack in proto.c to make this work.
*/
void
guestfs___launch_send_progress (guestfs_h *g, int perdozen)
diff --git a/src/proto.c b/src/proto.c
index 7d0a0d3..e6deb66 100644
--- a/src/proto.c
+++ b/src/proto.c
@@ -122,6 +122,32 @@ guestfs___progress_message_callback (guestfs_h *g,
array, sizeof array / sizeof array[0]);
}
+/* Connection modules call us back here when they get a log message. */
+void
+guestfs___log_message_callback (guestfs_h *g, const char *buf, size_t len)
+{
+ /* Send the log message upwards to anyone who is listening. */
+ guestfs___call_callbacks_message (g, GUESTFS_EVENT_APPLIANCE, buf, len);
+
+ /* This is used to generate launch progress messages. See comment
+ * above guestfs___launch_send_progress.
+ */
+ if (g->state == LAUNCHING) {
+ const char *sentinel;
+ size_t slen;
+
+ sentinel = "Linux version"; /* kernel up */
+ slen = strlen (sentinel);
+ if (memmem (buf, len, sentinel, slen) != NULL)
+ guestfs___launch_send_progress (g, 6);
+
+ sentinel = "Starting /init script"; /* /init running */
+ slen = strlen (sentinel);
+ if (memmem (buf, len, sentinel, slen) != NULL)
+ guestfs___launch_send_progress (g, 9);
+ }
+}
+
/* Before writing to the daemon socket, check the read side of the
* daemon socket for any of these conditions:
*
--
1.8.1.4