}
# endif /* !HAVE_CFMAKERAW */
+static void
+virConsoleShutdown(virConsolePtr con)
+{
+ con->quit = true;
+ virStreamEventRemoveCallback(con->st);
+ if (con->stdinWatch != -1)
+ virEventRemoveHandleImpl(con->stdinWatch);
+ if (con->stdinWatch != -1)
+ virEventRemoveHandleImpl(con->stdoutWatch);
+ con->stdinWatch = -1;
+ con->stdoutWatch = -1;
+}
+
static void
virConsoleEventOnStream(virStreamPtr st,
int events, void *opaque)
if (VIR_REALLOC_N(con->streamToTerminal.data,
con->streamToTerminal.length + 1024) < 0) {
virReportOOMError();
- con->quit = true;
+ virConsoleShutdown(con);
return;
}
con->streamToTerminal.length += 1024;
if (got == -2)
return; /* blocking */
if (got <= 0) {
- con->quit = true;
+ virConsoleShutdown(con);
return;
}
con->streamToTerminal.offset += got;
if (done == -2)
return; /* blocking */
if (done < 0) {
- con->quit = true;
+ virConsoleShutdown(con);
return;
}
memmove(con->terminalToStream.data,
if (events & VIR_STREAM_EVENT_ERROR ||
events & VIR_STREAM_EVENT_HANGUP) {
- con->quit = true;
+ virConsoleShutdown(con);
}
}
if (VIR_REALLOC_N(con->terminalToStream.data,
con->terminalToStream.length + 1024) < 0) {
virReportOOMError();
- con->quit = true;
+ virConsoleShutdown(con);
return;
}
con->terminalToStream.length += 1024;
avail);
if (got < 0) {
if (errno != EAGAIN) {
- con->quit = true;
+ virConsoleShutdown(con);
}
return;
}
if (got == 0) {
- con->quit = true;
+ virConsoleShutdown(con);
return;
}
if (con->terminalToStream.data[con->terminalToStream.offset] == CTRL_CLOSE_BRACKET) {
- con->quit = true;
+ virConsoleShutdown(con);
return;
}
if (events & VIR_EVENT_HANDLE_ERROR ||
events & VIR_EVENT_HANDLE_HANGUP) {
- con->quit = true;
+ virConsoleShutdown(con);
}
}
con->streamToTerminal.offset);
if (done < 0) {
if (errno != EAGAIN) {
- con->quit = true;
+ virConsoleShutdown(con);
}
return;
}
if (events & VIR_EVENT_HANDLE_ERROR ||
events & VIR_EVENT_HANDLE_HANGUP) {
- con->quit = true;
+ virConsoleShutdown(con);
}
}
break;
}
- virStreamEventRemoveCallback(con->st);
- virEventRemoveHandleImpl(con->stdinWatch);
- virEventRemoveHandleImpl(con->stdoutWatch);
-
ret = 0;
cleanup:
char *name;
if (ctl->conn) {
- if (virConnectClose(ctl->conn) != 0) {
- vshError(ctl, "%s", _("Failed to disconnect from the hypervisor"));
+ int ret;
+ if ((ret = virConnectClose(ctl->conn)) != 0) {
+ vshError(ctl, _("Failed to disconnect from the hypervisor, %d leaked reference(s)"), ret);
return FALSE;
}
ctl->conn = NULL;
vshCloseLogFile(ctl);
VIR_FREE(ctl->name);
if (ctl->conn) {
- if (virConnectClose(ctl->conn) != 0) {
- vshError(ctl, "%s", _("failed to disconnect from the hypervisor"));
+ int ret;
+ if ((ret = virConnectClose(ctl->conn)) != 0) {
+ vshError(ctl, _("Failed to disconnect from the hypervisor, %d leaked reference(s)"), ret);
}
}
virResetLastError();