Commit 23a69bdb authored by Daniel P. Berrange's avatar Daniel P. Berrange

Don't hold open connection when showing console output

parent f0ee7658
......@@ -111,6 +111,8 @@ static int container_start(const char *uri, const char *name, GMainLoop *loop)
goto cleanup;
}
gvir_sandbox_console_set_direct(con, TRUE);
g_signal_connect(con, "closed", (GCallback)do_close, loop);
if (gvir_sandbox_console_attach_stderr(con, &err) < 0) {
......@@ -119,6 +121,17 @@ static int container_start(const char *uri, const char *name, GMainLoop *loop)
goto cleanup;
}
/* Stop holding open libvirt connection */
if (gvir_sandbox_console_isolate(con, &err) < 0) {
g_printerr(_("Unable to disconnect console from libvirt: %s\n"),
err && err->message ? err->message : _("unknown"));
goto cleanup;
}
gvir_sandbox_context_detach(ctx, NULL);
g_object_unref(ctx);
ctx = NULL;
g_main_loop_run(loop);
ret = EXIT_SUCCESS;
......@@ -153,6 +166,8 @@ static int container_attach(const char *uri, const char *name, GMainLoop *loop)
goto cleanup;
}
gvir_sandbox_console_set_direct(con, TRUE);
g_signal_connect(con, "closed", (GCallback)do_close, loop);
if (!(gvir_sandbox_console_attach_stdio(con, &err))) {
......@@ -161,6 +176,18 @@ static int container_attach(const char *uri, const char *name, GMainLoop *loop)
goto cleanup;
}
/* Stop holding open libvirt connection */
if (gvir_sandbox_console_isolate(con, &err) < 0) {
g_printerr(_("Unable to disconnect console from libvirt: %s\n"),
err && err->message ? err->message : _("unknown"));
goto cleanup;
}
gvir_sandbox_context_detach(ctx, NULL);
g_object_unref(ctx);
ctx = NULL;
g_main_loop_run(loop);
ret = EXIT_SUCCESS;
......
......@@ -520,7 +520,7 @@ gboolean gvir_sandbox_context_attach(GVirSandboxContext *ctxt, GError **error)
{
GVirSandboxContextPrivate *priv = ctxt->priv;
if (priv->domain) {
if (priv->active) {
*error = g_error_new(GVIR_SANDBOX_CONTEXT_ERROR, 0,
"%s", "A previously built sandbox still exists");
return FALSE;
......@@ -542,6 +542,30 @@ gboolean gvir_sandbox_context_attach(GVirSandboxContext *ctxt, GError **error)
error)))
return FALSE;
priv->active = TRUE;
return TRUE;
}
gboolean gvir_sandbox_context_detach(GVirSandboxContext *ctxt, GError **error)
{
GVirSandboxContextPrivate *priv = ctxt->priv;
if (!priv->active)
return TRUE;
if (priv->domain) {
g_object_unref(priv->domain);
priv->domain = NULL;
}
if (priv->builder) {
g_object_unref(priv->builder);
priv->builder = NULL;
}
priv->active = FALSE;
return TRUE;
}
......@@ -551,6 +575,9 @@ gboolean gvir_sandbox_context_stop(GVirSandboxContext *ctxt, GError **error)
GVirSandboxContextPrivate *priv = ctxt->priv;
gboolean ret = TRUE;
if (!priv->active)
return TRUE;
if (priv->domain) {
if (!gvir_domain_stop(priv->domain, 0, error))
ret = FALSE;
......
......@@ -73,6 +73,7 @@ gboolean gvir_sandbox_context_get_autodestroy(GVirSandboxContext *ctxt);
gboolean gvir_sandbox_context_start(GVirSandboxContext *ctxt, GError **error);
gboolean gvir_sandbox_context_stop(GVirSandboxContext *ctxt, GError **error);
gboolean gvir_sandbox_context_attach(GVirSandboxContext *ctxt, GError **error);
gboolean gvir_sandbox_context_detach(GVirSandboxContext *ctxt, GError **error);
GVirDomain *gvir_sandbox_context_get_domain(GVirSandboxContext *ctxt,
GError **error);
......
......@@ -153,6 +153,7 @@ LIBVIRT_SANDBOX_0.2.1 {
gvir_sandbox_console_rpc_new;
gvir_sandbox_context_attach;
gvir_sandbox_context_detach;
gvir_sandbox_context_get_type;
gvir_sandbox_context_get_config;
gvir_sandbox_context_get_domain;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment