@@ -318,7 +318,7 @@ static gboolean guest_exec_output_watch(GIOChannel *ch,
struct GuestExecIOData *p = (struct GuestExecIOData *)p_;
gsize bytes_read = 0;
- if (cond == G_IO_HUP) {
+ if (cond == G_IO_HUP || cond == G_IO_ERR) {
g_io_channel_unref(ch);
g_atomic_int_set(&p->closed, 1);
return FALSE;
@@ -330,10 +330,18 @@ static gboolean guest_exec_output_watch(GIOChannel *ch,
t = g_try_realloc(p->data, p->size + GUEST_EXEC_IO_SIZE);
}
if (t == NULL) {
+ GIOStatus gstatus = 0;
p->truncated = true;
/* ignore truncated output */
gchar buf[GUEST_EXEC_IO_SIZE];
- g_io_channel_read_chars(ch, buf, sizeof(buf), &bytes_read, NULL);
+ gstatus = g_io_channel_read_chars(ch, buf, sizeof(buf),
+ &bytes_read, NULL);
+ if (gstatus == G_IO_STATUS_EOF || gstatus == G_IO_STATUS_ERROR) {
+ g_io_channel_unref(ch);
+ g_atomic_int_set(&p->closed, 1);
+ return false;
+ }
+
return TRUE;
}
p->size += GUEST_EXEC_IO_SIZE;
@@ -342,8 +350,14 @@ static gboolean guest_exec_output_watch(GIOChannel *ch,
/* Calling read API once.
* On next available data our callback will be called again */
- g_io_channel_read_chars(ch, (gchar *)p->data + p->length,
+ GIOStatus gstatus = 0;
+ gstatus = g_io_channel_read_chars(ch, (gchar *)p->data + p->length,
p->size - p->length, &bytes_read, NULL);
+ if (gstatus == G_IO_STATUS_EOF || gstatus == G_IO_STATUS_ERROR) {
+ g_io_channel_unref(ch);
+ g_atomic_int_set(&p->closed, 1);
+ return false;
+ }
> ---
> qga/commands.c | 175 ++++++++++++++++++++++++++++++++++++++++++++++++---