mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-21 22:53:37 +00:00
protocol: Handle log messages from connection layer centrally.
Previously described as a "gross hack and massive layering violation".
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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)
|
||||
|
||||
26
src/proto.c
26
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:
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user