Commit 1209210e authored by Daniel P. Berrange's avatar Daniel P. Berrange

Introduce concept of a "cleaner" class

parent 00500fe4
......@@ -9,6 +9,7 @@ SANDBOX_HEADER_FILES = \
libvirt-sandbox-config.h \
libvirt-sandbox-config-graphical.h \
libvirt-sandbox-config-mount.h \
libvirt-sandbox-cleaner.h \
libvirt-sandbox-builder.h \
libvirt-sandbox-builder-machine.h \
libvirt-sandbox-builder-container.h \
......@@ -18,6 +19,7 @@ SANDBOX_SOURCE_FILES = \
libvirt-sandbox-config.c \
libvirt-sandbox-config-graphical.c \
libvirt-sandbox-config-mount.c \
libvirt-sandbox-cleaner.c \
libvirt-sandbox-builder.c \
libvirt-sandbox-builder-machine.c \
libvirt-sandbox-builder-container.c \
......
......@@ -103,9 +103,10 @@ static void gvir_sandbox_builder_container_finalize(GObject *object)
static GVirConfigDomain *gvir_sandbox_builder_container_construct(GVirSandboxBuilder *builder G_GNUC_UNUSED,
GVirSandboxConfig *config,
GVirSandboxCleaner *cleaner G_GNUC_UNUSED,
GError **error G_GNUC_UNUSED)
{
GVirSandboxConfig *config = gvir_sandbox_builder_get_config(builder);
GString *str = g_string_new("<domain type='lxc'>\n");
GVirConfigDomain *dom;
const gchar *cmdline = "";
......@@ -208,17 +209,14 @@ static void gvir_sandbox_builder_container_init(GVirSandboxBuilderContainer *bui
/**
* gvir_sandbox_builder_container_new:
* @connection: (transfer none): the connection
* @config: (transfer none): the sandbox configuration
*
* Create a new graphical application sandbox builderuration
*
* Returns: (transfer full): a new graphical sandbox builder object
*/
GVirSandboxBuilderContainer *gvir_sandbox_builder_container_new(GVirConnection *connection,
GVirSandboxConfig *config)
GVirSandboxBuilderContainer *gvir_sandbox_builder_container_new(GVirConnection *connection)
{
return GVIR_SANDBOX_BUILDER_CONTAINER(g_object_new(GVIR_SANDBOX_TYPE_BUILDER_CONTAINER,
"connection", connection,
"config", config,
NULL));
}
......@@ -57,8 +57,7 @@ struct _GVirSandboxBuilderContainerClass
GType gvir_sandbox_builder_container_get_type(void);
GVirSandboxBuilderContainer *gvir_sandbox_builder_container_new(GVirConnection *connection,
GVirSandboxConfig *config);
GVirSandboxBuilderContainer *gvir_sandbox_builder_container_new(GVirConnection *connection);
G_END_DECLS
......
......@@ -102,10 +102,11 @@ static void gvir_sandbox_builder_machine_finalize(GObject *object)
}
static GVirConfigDomain *gvir_sandbox_builder_machine_construct(GVirSandboxBuilder *builder,
static GVirConfigDomain *gvir_sandbox_builder_machine_construct(GVirSandboxBuilder *builder G_GNUC_UNUSED,
GVirSandboxConfig *config,
GVirSandboxCleaner *cleaner G_GNUC_UNUSED,
GError **error)
{
GVirSandboxConfig *config = gvir_sandbox_builder_get_config(builder);
GString *str = g_string_new("<domain type='kvm'>\n");
GVirConfigDomain *dom;
const gchar *kernel = "";
......@@ -235,17 +236,14 @@ static void gvir_sandbox_builder_machine_init(GVirSandboxBuilderMachine *builder
/**
* gvir_sandbox_builder_machine_new:
* @connection: (transfer none): the connection
* @config: (transfer none): the sandbox configuration
*
* Create a new graphical application sandbox builderuration
*
* Returns: (transfer full): a new graphical sandbox builder object
*/
GVirSandboxBuilderMachine *gvir_sandbox_builder_machine_new(GVirConnection *connection,
GVirSandboxConfig *config)
GVirSandboxBuilderMachine *gvir_sandbox_builder_machine_new(GVirConnection *connection)
{
return GVIR_SANDBOX_BUILDER_MACHINE(g_object_new(GVIR_SANDBOX_TYPE_BUILDER_MACHINE,
"connection", connection,
"config", config,
NULL));
}
......@@ -57,8 +57,7 @@ struct _GVirSandboxBuilderMachineClass
GType gvir_sandbox_builder_machine_get_type(void);
GVirSandboxBuilderMachine *gvir_sandbox_builder_machine_new(GVirConnection *connection,
GVirSandboxConfig *config);
GVirSandboxBuilderMachine *gvir_sandbox_builder_machine_new(GVirConnection *connection);
G_END_DECLS
......
......@@ -31,7 +31,6 @@
struct _GVirSandboxBuilderPrivate
{
GVirConnection *connection;
GVirSandboxConfig *config;
};
G_DEFINE_ABSTRACT_TYPE(GVirSandboxBuilder, gvir_sandbox_builder, G_TYPE_OBJECT);
......@@ -40,7 +39,6 @@ G_DEFINE_ABSTRACT_TYPE(GVirSandboxBuilder, gvir_sandbox_builder, G_TYPE_OBJECT);
enum {
PROP_0,
PROP_CONFIG,
PROP_CONNECTION,
};
......@@ -67,10 +65,6 @@ static void gvir_sandbox_builder_get_property(GObject *object,
GVirSandboxBuilderPrivate *priv = ctxt->priv;
switch (prop_id) {
case PROP_CONFIG:
g_value_set_object(value, priv->config);
break;
case PROP_CONNECTION:
g_value_set_object(value, priv->connection);
break;
......@@ -90,12 +84,6 @@ static void gvir_sandbox_builder_set_property(GObject *object,
GVirSandboxBuilderPrivate *priv = ctxt->priv;
switch (prop_id) {
case PROP_CONFIG:
if (priv->config)
g_object_unref(priv->config);
priv->config = g_value_dup_object(value);
break;
case PROP_CONNECTION:
if (priv->connection)
g_object_unref(priv->connection);
......@@ -113,8 +101,6 @@ static void gvir_sandbox_builder_finalize(GObject *object)
GVirSandboxBuilder *ctxt = GVIR_SANDBOX_BUILDER(object);
GVirSandboxBuilderPrivate *priv = ctxt->priv;
if (priv->config)
g_object_unref(priv->config);
if (priv->connection)
g_object_unref(priv->connection);
......@@ -130,18 +116,6 @@ static void gvir_sandbox_builder_class_init(GVirSandboxBuilderClass *klass)
object_class->get_property = gvir_sandbox_builder_get_property;
object_class->set_property = gvir_sandbox_builder_set_property;
g_object_class_install_property(object_class,
PROP_CONFIG,
g_param_spec_object("config",
"Config",
"The sandbox configuration",
GVIR_SANDBOX_TYPE_CONFIG,
G_PARAM_READABLE |
G_PARAM_WRITABLE |
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_NAME |
G_PARAM_STATIC_NICK |
G_PARAM_STATIC_BLURB));
g_object_class_install_property(object_class,
PROP_CONNECTION,
g_param_spec_object("connection",
......@@ -168,7 +142,6 @@ static void gvir_sandbox_builder_init(GVirSandboxBuilder *ctxt)
/**
* gvir_sandbox_builder_for_connection:
* @connection: (transfer none): the connection to host the sandbox
* @config: (transfer none): the sandbox configuration
* @error: (out): the error
*
* Find and instantiate a suitable builder for sandboxes to be hosted
......@@ -177,17 +150,16 @@ static void gvir_sandbox_builder_init(GVirSandboxBuilder *ctxt)
* Returns: (transfer full): a new builder or NULL
*/
GVirSandboxBuilder *gvir_sandbox_builder_for_connection(GVirConnection *connection,
GVirSandboxConfig *config,
GError **error)
{
const gchar *uri = gvir_connection_get_uri(connection);
GVirSandboxBuilder *builder = NULL;
if (strcmp(uri, "lxc:///") == 0) {
builder = GVIR_SANDBOX_BUILDER(gvir_sandbox_builder_container_new(connection, config));
builder = GVIR_SANDBOX_BUILDER(gvir_sandbox_builder_container_new(connection));
} else if (strcmp(uri, "qemu:///session") == 0 ||
strcmp(uri, "qemu:///system") == 0) {
builder = GVIR_SANDBOX_BUILDER(gvir_sandbox_builder_machine_new(connection, config));
builder = GVIR_SANDBOX_BUILDER(gvir_sandbox_builder_machine_new(connection));
}
if (!builder)
......@@ -198,22 +170,6 @@ GVirSandboxBuilder *gvir_sandbox_builder_for_connection(GVirConnection *connecti
}
/**
* gvir_sandbox_builder_get_config:
* @builder: (transfer none): the sandbox builder
*
* Retrieves the sandbox configuration
*
* Returns: (transfer full): the current configuration
*/
GVirSandboxConfig *gvir_sandbox_builder_get_config(GVirSandboxBuilder *builder)
{
GVirSandboxBuilderPrivate *priv = builder->priv;
g_object_ref(priv->config);
return priv->config;
}
/**
* gvir_sandbox_builder_get_connection:
* @builder: (transfer none): the sandbox builder
......@@ -232,6 +188,8 @@ GVirConnection *gvir_sandbox_builder_get_connection(GVirSandboxBuilder *builder)
/**
* gvir_sandbox_builder_construct:
* @builder: (transfer none): the sandbox builder
* @config: (transfer none): the sandbox configuration
* @cleaner: (transfer none): the sandbox cleaner
* @error: (out): the error location
*
* Create a domain configuration from the sandbox configuration
......@@ -239,40 +197,9 @@ GVirConnection *gvir_sandbox_builder_get_connection(GVirSandboxBuilder *builder)
* Returns: (transfer full): the newly built domain configuration
*/
GVirConfigDomain *gvir_sandbox_builder_construct(GVirSandboxBuilder *builder,
GVirSandboxConfig *config,
GVirSandboxCleaner *cleaner,
GError **error)
{
return GVIR_SANDBOX_BUILDER_GET_CLASS(builder)->construct(builder, error);
}
/**
* gvir_sandbox_builder_cleanup_post_start:
* @builder: (transfer none): the sandbox builder
* @error: (out): the error location
*
* Remove any temporary files no longer required after the sandbox
* has started
*
* Returns: (transfer full): the newly built domain configuration
*/
gboolean gvir_sandbox_builder_cleanup_post_start(GVirSandboxBuilder *builder G_GNUC_UNUSED,
GError **error G_GNUC_UNUSED)
{
return TRUE;
}
/**
* gvir_sandbox_builder_cleanup_post_start:
* @builder: (transfer none): the sandbox builder
* @error: (out): the error location
*
* Remove any temporary files no longer required after the sandbox
* has stopped
*
* Returns: (transfer full): the newly built domain configuration
*/
gboolean gvir_sandbox_builder_cleanup_post_stop(GVirSandboxBuilder *builder G_GNUC_UNUSED,
GError **error G_GNUC_UNUSED)
{
return TRUE;
return GVIR_SANDBOX_BUILDER_GET_CLASS(builder)->construct(builder, config, cleaner, error);
}
......@@ -56,28 +56,23 @@ struct _GVirSandboxBuilderClass
GObjectClass parent_class;
GVirConfigDomain *(*construct)(GVirSandboxBuilder *builder,
GVirSandboxConfig *config,
GVirSandboxCleaner *cleaner,
GError **error);
};
GType gvir_sandbox_builder_get_type(void);
GVirSandboxBuilder *gvir_sandbox_builder_for_connection(GVirConnection *connection,
GVirSandboxConfig *config,
GError **error);
GVirSandboxConfig *gvir_sandbox_builder_get_config(GVirSandboxBuilder *builder);
GVirConnection *gvir_sandbox_builder_get_connection(GVirSandboxBuilder *builder);
GVirConfigDomain *gvir_sandbox_builder_construct(GVirSandboxBuilder *builder,
GVirSandboxConfig *config,
GVirSandboxCleaner *cleaner,
GError **error);
gboolean gvir_sandbox_builder_cleanup_post_start(GVirSandboxBuilder *builder,
GError **error);
gboolean gvir_sandbox_builder_cleanup_post_stop(GVirSandboxBuilder *builder,
GError **error);
G_END_DECLS
#endif /* __LIBVIRT_SANDBOX_BUILDER_H__ */
/*
* libvirt-sandbox-cleaner.c: libvirt sandbox cleaner
*
* Copyright (C) 2011 Red Hat
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Author: Daniel P. Berrange <berrange@redhat.com>
*/
#include <config.h>
#include "libvirt-sandbox/libvirt-sandbox.h"
#define GVIR_SANDBOX_CLEANER_GET_PRIVATE(obj) \
(G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_SANDBOX_TYPE_CLEANER, GVirSandboxCleanerPrivate))
struct _GVirSandboxCleanerPrivate
{
GList *postStart;
GList *postStop;
};
typedef struct _GVirSandboxCleanerEntry GVirSandboxCleanerEntry;
struct _GVirSandboxCleanerEntry
{
GVirSandboxCleanerFunc func;
gpointer opaque;
GDestroyNotify ff;
};
G_DEFINE_TYPE(GVirSandboxCleaner, gvir_sandbox_cleaner, G_TYPE_OBJECT);
enum {
PROP_0,
};
enum {
LAST_SIGNAL
};
//static gint signals[LAST_SIGNAL];
static void gvir_sandbox_cleaner_get_property(GObject *object,
guint prop_id,
GValue *value G_GNUC_UNUSED,
GParamSpec *pspec)
{
#if 0
GVirSandboxCleaner *cleaner = GVIR_SANDBOX_CLEANER(object);
GVirSandboxCleanerPrivate *priv = cleaner->priv;
#endif
switch (prop_id) {
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
}
}
static void gvir_sandbox_cleaner_set_property(GObject *object,
guint prop_id,
const GValue *value G_GNUC_UNUSED,
GParamSpec *pspec)
{
#if 0
GVirSandboxCleaner *cleaner = GVIR_SANDBOX_CLEANER(object);
GVirSandboxCleanerPrivate *priv = cleaner->priv;
#endif
switch (prop_id) {
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
}
}
static void gvir_sandbox_cleaner_finalize(GObject *object)
{
GVirSandboxCleaner *cleaner = GVIR_SANDBOX_CLEANER(object);
GVirSandboxCleanerPrivate *priv = cleaner->priv;
GList *tmp;
tmp = priv->postStart;
while (tmp) {
GVirSandboxCleanerEntry *ent = tmp->data;
ent->ff(ent->opaque);
g_free(ent);
tmp = tmp->next;
}
g_list_free(priv->postStart);
tmp = priv->postStop;
while (tmp) {
GVirSandboxCleanerEntry *ent = tmp->data;
ent->ff(ent->opaque);
g_free(ent);
tmp = tmp->next;
}
g_list_free(priv->postStop);
G_OBJECT_CLASS(gvir_sandbox_cleaner_parent_class)->finalize(object);
}
static void gvir_sandbox_cleaner_class_init(GVirSandboxCleanerClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS(klass);
object_class->finalize = gvir_sandbox_cleaner_finalize;
object_class->get_property = gvir_sandbox_cleaner_get_property;
object_class->set_property = gvir_sandbox_cleaner_set_property;
g_type_class_add_private(klass, sizeof(GVirSandboxCleanerPrivate));
}
static void gvir_sandbox_cleaner_init(GVirSandboxCleaner *cleaner)
{
cleaner->priv = GVIR_SANDBOX_CLEANER_GET_PRIVATE(cleaner);
}
/**
* gvir_sandbox_cleaner_new:
*
* Create a new sandbox cleaner
*
* Returns: (transfer full): a new sandbox cleaner object
*/
GVirSandboxCleaner *gvir_sandbox_cleaner_new(void)
{
return GVIR_SANDBOX_CLEANER(g_object_new(GVIR_SANDBOX_TYPE_CLEANER,
NULL));
}
void gvir_sandbox_cleaner_add_action_post_start(GVirSandboxCleaner *cleaner,
GVirSandboxCleanerFunc func,
gpointer opaque,
GDestroyNotify ff)
{
GVirSandboxCleanerPrivate *priv = cleaner->priv;
GVirSandboxCleanerEntry *ent = g_new0(GVirSandboxCleanerEntry, 1);
ent->func = func;
ent->opaque = opaque;
ent->ff = ff;
priv->postStart = g_list_append(priv->postStart, ent);
}
void gvir_sandbox_cleaner_add_action_post_stop(GVirSandboxCleaner *cleaner,
GVirSandboxCleanerFunc func,
gpointer opaque,
GDestroyNotify ff)
{
GVirSandboxCleanerPrivate *priv = cleaner->priv;
GVirSandboxCleanerEntry *ent = g_new0(GVirSandboxCleanerEntry, 1);
ent->func = func;
ent->opaque = opaque;
ent->ff = ff;
priv->postStop = g_list_append(priv->postStop, ent);
}
gboolean gvir_sandbox_cleaner_run_post_start(GVirSandboxCleaner *cleaner, GError **error)
{
GVirSandboxCleanerPrivate *priv = cleaner->priv;
GList *tmp = priv->postStart;
gboolean ret = TRUE;
while (tmp) {
GVirSandboxCleanerEntry *ent = tmp->data;
if (!ent->func(cleaner, error, ent->opaque))
ret = FALSE;
tmp = tmp->next;
}
return ret;
}
gboolean gvir_sandbox_cleaner_run_post_stop(GVirSandboxCleaner *cleaner, GError **error)
{
GVirSandboxCleanerPrivate *priv = cleaner->priv;
GList *tmp = priv->postStop;
gboolean ret = TRUE;
while (tmp) {
GVirSandboxCleanerEntry *ent = tmp->data;
if (!ent->func(cleaner, error, ent->opaque))
ret = FALSE;
tmp = tmp->next;
}
return ret;
}
/*
* libvirt-sandbox-cleaner.h: libvirt sandbox cleaner
*
* Copyright (C) 2011 Red Hat
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Author: Daniel P. Berrange <berrange@redhat.com>
*/
#if !defined(__LIBVIRT_SANDBOX_H__) && !defined(LIBVIRT_SANDBOX_BUILD)
#error "Only <libvirt-sandbox/libvirt-sandbox.h> can be included directly."
#endif
#ifndef __LIBVIRT_SANDBOX_CLEANER_H__
#define __LIBVIRT_SANDBOX_CLEANER_H__
G_BEGIN_DECLS
#define GVIR_SANDBOX_TYPE_CLEANER (gvir_sandbox_cleaner_get_type ())
#define GVIR_SANDBOX_CLEANER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_SANDBOX_TYPE_CLEANER, GVirSandboxCleaner))
#define GVIR_SANDBOX_CLEANER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_SANDBOX_TYPE_CLEANER, GVirSandboxCleanerClass))
#define GVIR_SANDBOX_IS_CLEANER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_SANDBOX_TYPE_CLEANER))
#define GVIR_SANDBOX_IS_CLEANER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_SANDBOX_TYPE_CLEANER))
#define GVIR_SANDBOX_CLEANER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_SANDBOX_TYPE_CLEANER, GVirSandboxCleanerClass))
#define GVIR_SANDBOX_TYPE_CLEANER_HANDLE (gvir_sandbox_cleaner_handle_get_type ())
typedef struct _GVirSandboxCleaner GVirSandboxCleaner;
typedef struct _GVirSandboxCleanerPrivate GVirSandboxCleanerPrivate;
typedef struct _GVirSandboxCleanerClass GVirSandboxCleanerClass;
struct _GVirSandboxCleaner
{
GObject parent;
GVirSandboxCleanerPrivate *priv;
/* Do not add fields to this struct */
};
struct _GVirSandboxCleanerClass
{
GObjectClass parent_class;
};
GType gvir_sandbox_cleaner_get_type(void);
GVirSandboxCleaner *gvir_sandbox_cleaner_new(void);
typedef gboolean (*GVirSandboxCleanerFunc)(GVirSandboxCleaner *ctxt,
GError **error,
gpointer opaque);
void gvir_sandbox_cleaner_add_action_post_start(GVirSandboxCleaner *ctxt,
GVirSandboxCleanerFunc func,
gpointer opaque,
GDestroyNotify ff);
void gvir_sandbox_cleaner_add_action_post_stop(GVirSandboxCleaner *ctxt,
GVirSandboxCleanerFunc func,
gpointer opaque,
GDestroyNotify ff);
gboolean gvir_sandbox_cleaner_run_post_start(GVirSandboxCleaner *ctxt, GError **error);
gboolean gvir_sandbox_cleaner_run_post_stop(GVirSandboxCleaner *ctxt, GError **error);
G_END_DECLS
#endif /* __LIBVIRT_SANDBOX_CLEANER_H__ */
......@@ -34,6 +34,7 @@ struct _GVirSandboxContextPrivate
GVirSandboxConfig *config;
GVirSandboxBuilder *builder;
GVirSandboxCleaner *cleaner;
};
G_DEFINE_TYPE(GVirSandboxContext, gvir_sandbox_context, G_TYPE_OBJECT);
......@@ -132,6 +133,8 @@ static void gvir_sandbox_context_finalize(GObject *object)
g_object_unref(priv->connection);
if (priv->config)
g_object_unref(priv->config);
if (priv->cleaner)
g_object_unref(priv->cleaner);
G_OBJECT_CLASS(gvir_sandbox_context_parent_class)->finalize(object);
}
......@@ -186,7 +189,10 @@ static void gvir_sandbox_context_class_init(GVirSandboxContextClass *klass)
static void gvir_sandbox_context_init(GVirSandboxContext *ctxt)
{
GVirSandboxContextPrivate *priv = ctxt->priv;
ctxt->priv = GVIR_SANDBOX_CONTEXT_GET_PRIVATE(ctxt);
priv->cleaner = gvir_sandbox_cleaner_new();
}
......@@ -224,6 +230,22 @@ GVirSandboxConfig *gvir_sandbox_context_get_config(GVirSandboxContext *ctxt)
}
/**
* gvir_sandbox_context_get_cleaner:
* @ctxt: (transfer none): the sandbox context
*
* Retrieves the sandbox cleaner
*
* Returns: (transfer full): the current cleaner
*/
GVirSandboxCleaner *gvir_sandbox_context_get_cleaner(GVirSandboxContext *ctxt)
{
GVirSandboxContextPrivate *priv = ctxt->priv;
g_object_ref(priv->cleaner);
return priv->cleaner;
}
/**
* gvir_sandbox_context_get_domain:
* @ctxt: (transfer none): the sandbox context
......@@ -269,11 +291,12 @@ gboolean gvir_sandbox_context_start(GVirSandboxContext *ctxt, GError **error)
}
if (!(priv->builder = gvir_sandbox_builder_for_connection(priv->connection,
priv->config,
error)))
return FALSE;
if (!(config = gvir_sandbox_builder_construct(priv->builder,
priv->config,
priv->cleaner,
error))) {
goto error;
}
......@@ -286,8 +309,7 @@ gboolean gvir_sandbox_context_start(GVirSandboxContext *ctxt, GError **error)
if (!gvir_domain_start(priv->domain, 0, error))
goto error;
if (!gvir_sandbox_builder_cleanup_post_start(priv->builder,
error))
if (!(gvir_sandbox_cleaner_run_post_start(priv->cleaner, NULL)))
goto error;
g_object_unref(config);
......@@ -301,10 +323,14 @@ error:
}
if (priv->domain) {
gvir_domain_stop(priv->domain, 0, NULL);
gvir_sandbox_cleaner_run_post_stop(priv->cleaner, NULL);
gvir_domain_delete(priv->domain, 0, NULL);
g_object_unref(priv->domain);
priv->domain = NULL;
}
g_object_unref(priv->cleaner);
priv->cleaner = gvir_sandbox_cleaner_new();
return FALSE;
}
......@@ -312,23 +338,25 @@ error:
gboolean gvir_sandbox_context_stop(GVirSandboxContext *ctxt, GError **error)
{
GVirSandboxContextPrivate *priv = ctxt->priv;
gboolean ret = TRUE;
if (!gvir_domain_stop(priv->domain, 0, error))
return FALSE;
ret = FALSE;
gvir_domain_delete(priv->domain, 0, NULL);
if (!gvir_domain_delete(priv->domain, 0, error))
ret = FALSE;
g_object_unref(priv->domain);
priv->domain = NULL;
if (!gvir_sandbox_builder_cleanup_post_stop(priv->builder, error)) {
g_object_unref(priv->builder);
priv->builder = NULL;
return FALSE;
}
if (!gvir_sandbox_cleaner_run_post_stop(priv->cleaner, error))
ret = FALSE;
g_object_unref(priv->builder);
priv->builder = NULL;
return TRUE;
g_object_unref(priv->cleaner);
priv->cleaner = gvir_sandbox_cleaner_new();
return ret;