Commit f711df22 authored by Daniel P. Berrange's avatar Daniel P. Berrange

Refactor way file cleanup is performed

Remove the separate GVirSandboxCleaner class and instead introduce
some cleanup virtual methods on GVirSandboxBuilder. This avoids
needing to maintain state in memory for cleanup. This in turn
allows the process doing cleanup to be different from the one
that launches the sandbox
Signed-off-by: 's avatarDaniel P. Berrange <berrange@redhat.com>
parent 55c27104
......@@ -46,7 +46,7 @@ LIBVIRT_SANDBOX_VERSION=$LIBVIRT_SANDBOX_MAJOR_VERSION.$LIBVIRT_SANDBOX_MINOR_VE
# in the so version'd symlinks, and this is based on AGE.REVISION
#
# Until we declare ABI stability, this can be toggled upon release
LIBVIRT_SANDBOX_SONUM=2
LIBVIRT_SANDBOX_SONUM=3
AGE=`expr $LIBVIRT_SANDBOX_MAJOR_VERSION '*' 1000 + $LIBVIRT_SANDBOX_MINOR_VERSION`
REVISION=$LIBVIRT_SANDBOX_MICRO_VERSION
......
......@@ -15,7 +15,6 @@
<xi:include href="xml/libvirt-sandbox-builder-container.xml"/>
<xi:include href="xml/libvirt-sandbox-builder-initrd.xml"/>
<xi:include href="xml/libvirt-sandbox-builder-machine.xml"/>
<xi:include href="xml/libvirt-sandbox-cleaner.xml"/>
<xi:include href="xml/libvirt-sandbox-config.xml"/>
<xi:include href="xml/libvirt-sandbox-config-graphical.xml"/>
<xi:include href="xml/libvirt-sandbox-config-initrd.xml"/>
......
......@@ -69,7 +69,6 @@ SANDBOX_HEADER_FILES = \
libvirt-sandbox-config-service.h \
libvirt-sandbox-config-service-systemd.h \
libvirt-sandbox-config-service-generic.h \
libvirt-sandbox-cleaner.h \
libvirt-sandbox-builder.h \
libvirt-sandbox-builder-initrd.h \
libvirt-sandbox-builder-machine.h \
......@@ -100,7 +99,6 @@ SANDBOX_SOURCE_FILES = \
libvirt-sandbox-config-service.c \
libvirt-sandbox-config-service-systemd.c \
libvirt-sandbox-config-service-generic.c \
libvirt-sandbox-cleaner.c \
libvirt-sandbox-builder.c \
libvirt-sandbox-builder-initrd.c \
libvirt-sandbox-builder-machine.c \
......
......@@ -140,15 +140,15 @@ static gchar *gvir_sandbox_builder_container_cmdline(GVirSandboxConfig *config G
static gboolean gvir_sandbox_builder_container_construct_basic(GVirSandboxBuilder *builder,
GVirSandboxConfig *config,
const gchar *tmpdir,
const gchar *configdir,
GVirSandboxCleaner *cleaner,
GVirConfigDomain *domain,
GError **error)
{
gchar **features;
if (!GVIR_SANDBOX_BUILDER_CLASS(gvir_sandbox_builder_container_parent_class)->
construct_basic(builder, config, configdir, cleaner, domain, error))
construct_basic(builder, config, tmpdir, configdir, domain, error))
return FALSE;
gvir_config_domain_set_virt_type(domain,
......@@ -165,8 +165,8 @@ static gboolean gvir_sandbox_builder_container_construct_basic(GVirSandboxBuilde
static gboolean gvir_sandbox_builder_container_construct_os(GVirSandboxBuilder *builder,
GVirSandboxConfig *config,
const gchar *tmpdir,
const gchar *configdir,
GVirSandboxCleaner *cleaner,
GVirConfigDomain *domain,
GError **error)
{
......@@ -174,7 +174,7 @@ static gboolean gvir_sandbox_builder_container_construct_os(GVirSandboxBuilder *
GVirConfigDomainOs *os;
if (!GVIR_SANDBOX_BUILDER_CLASS(gvir_sandbox_builder_container_parent_class)->
construct_os(builder, config, configdir, cleaner, domain, error))
construct_os(builder, config, tmpdir, configdir, domain, error))
return FALSE;
cmdline = gvir_sandbox_builder_container_cmdline(config);
......@@ -197,13 +197,13 @@ static gboolean gvir_sandbox_builder_container_construct_os(GVirSandboxBuilder *
static gboolean gvir_sandbox_builder_container_construct_features(GVirSandboxBuilder *builder,
GVirSandboxConfig *config,
const gchar *tmpdir,
const gchar *configdir,
GVirSandboxCleaner *cleaner,
GVirConfigDomain *domain,
GError **error)
{
if (!GVIR_SANDBOX_BUILDER_CLASS(gvir_sandbox_builder_container_parent_class)->
construct_features(builder, config, configdir, cleaner, domain, error))
construct_features(builder, config, tmpdir, configdir, domain, error))
return FALSE;
return TRUE;
......@@ -211,8 +211,8 @@ static gboolean gvir_sandbox_builder_container_construct_features(GVirSandboxBui
static gboolean gvir_sandbox_builder_container_construct_devices(GVirSandboxBuilder *builder,
GVirSandboxConfig *config,
const gchar *tmpdir,
const gchar *configdir,
GVirSandboxCleaner *cleaner,
GVirConfigDomain *domain,
GError **error)
{
......@@ -223,7 +223,7 @@ static gboolean gvir_sandbox_builder_container_construct_devices(GVirSandboxBuil
GList *tmp = NULL, *mounts = NULL, *networks = NULL;
if (!GVIR_SANDBOX_BUILDER_CLASS(gvir_sandbox_builder_container_parent_class)->
construct_devices(builder, config, configdir, cleaner, domain, error))
construct_devices(builder, config, tmpdir, configdir, domain, error))
return FALSE;
fs = gvir_config_domain_filesys_new();
......
This diff is collapsed.
......@@ -57,40 +57,51 @@ struct _GVirSandboxBuilderClass
gboolean (*construct_basic)(GVirSandboxBuilder *builder,
GVirSandboxConfig *config,
const gchar *tmpdir,
const gchar *configdir,
GVirSandboxCleaner *cleaner,
GVirConfigDomain *domain,
GError **error);
gboolean (*construct_os)(GVirSandboxBuilder *builder,
GVirSandboxConfig *config,
const gchar *tmpdir,
const gchar *configdir,
GVirSandboxCleaner *cleaner,
GVirConfigDomain *domain,
GError **error);
gboolean (*construct_features)(GVirSandboxBuilder *builder,
GVirSandboxConfig *config,
const gchar *tmpdir,
const gchar *configdir,
GVirSandboxCleaner *cleaner,
GVirConfigDomain *domain,
GError **error);
gboolean (*construct_devices)(GVirSandboxBuilder *builder,
GVirSandboxConfig *config,
const gchar *tmpdir,
const gchar *configdir,
GVirSandboxCleaner *cleaner,
GVirConfigDomain *domain,
GError **error);
gboolean (*construct_security)(GVirSandboxBuilder *builder,
GVirSandboxConfig *config,
const gchar *tmpdir,
const gchar *configdir,
GVirSandboxCleaner *cleaner,
GVirConfigDomain *domain,
GError **error);
gboolean (*construct_domain)(GVirSandboxBuilder *builder,
GVirSandboxConfig *config,
const gchar *tmpdir,
const gchar *configdir,
GVirSandboxCleaner *cleaner,
GVirConfigDomain *domain,
GError **error);
gboolean (*clean_post_start)(GVirSandboxBuilder *builder,
GVirSandboxConfig *config,
const gchar *tmpdir,
const gchar *configdir,
GError **error);
gboolean (*clean_post_stop)(GVirSandboxBuilder *builder,
GVirSandboxConfig *config,
const gchar *tmpdir,
const gchar *configdir,
GError **error);
};
GType gvir_sandbox_builder_get_type(void);
......@@ -102,10 +113,21 @@ GVirConnection *gvir_sandbox_builder_get_connection(GVirSandboxBuilder *builder)
GVirConfigDomain *gvir_sandbox_builder_construct(GVirSandboxBuilder *builder,
GVirSandboxConfig *config,
const gchar *tmpdir,
const gchar *configdir,
GVirSandboxCleaner *cleaner,
GError **error);
gboolean gvir_sandbox_builder_clean_post_start(GVirSandboxBuilder *builder,
GVirSandboxConfig *config,
const gchar *tmpdir,
const gchar *configdir,
GError **error);
gboolean gvir_sandbox_builder_clean_post_stop(GVirSandboxBuilder *builder,
GVirSandboxConfig *config,
const gchar *tmpdir,
const gchar *configdir,
GError **error);
G_END_DECLS
#endif /* __LIBVIRT_SANDBOX_BUILDER_H__ */
/*
* libvirt-sandbox-cleaner.c: libvirt sandbox cleaner
*
* Copyright (C) 2011 Red Hat, Inc.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Author: Daniel P. Berrange <berrange@redhat.com>
*/
#include <config.h>
#include "libvirt-sandbox/libvirt-sandbox.h"
/**
* SECTION: libvirt-sandbox-cleaner
* @short_description: Sandbox context cleanup tasks
* @include: libvirt-sandbox/libvirt-sandbox.h
*
* Provides an object for managing cleanup tasks associated with a sandbox
*
* The GVirSandboxCleaner object provides a framework for registering
* cleanup tasks to be performed at various stages of a sandbox's
* lifecycle. This is typically used to delete temporary files and
* other similar state.
*/
#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);
}
static gboolean gvir_sandbox_cleaner_rmdir(GVirSandboxCleaner *cleaner G_GNUC_UNUSED,
GError **error G_GNUC_UNUSED,
gpointer opaque)
{
gchar *dir = opaque;
rmdir(dir);
return TRUE;
}
static gboolean gvir_sandbox_cleaner_rmfile(GVirSandboxCleaner *cleaner G_GNUC_UNUSED,
GError **error G_GNUC_UNUSED,
gpointer opaque)
{
gchar *file = opaque;
unlink(file);
return TRUE;
}
void gvir_sandbox_cleaner_add_rmfile_post_start(GVirSandboxCleaner *cleaner,
const gchar *file)
{
gvir_sandbox_cleaner_add_action_post_start(cleaner,
gvir_sandbox_cleaner_rmfile,
g_strdup(file),
g_free);
}
void gvir_sandbox_cleaner_add_rmdir_post_start(GVirSandboxCleaner *cleaner,
const gchar *dir)
{
gvir_sandbox_cleaner_add_action_post_start(cleaner,
gvir_sandbox_cleaner_rmdir,
g_strdup(dir),
g_free);
}
void gvir_sandbox_cleaner_add_rmfile_post_stop(GVirSandboxCleaner *cleaner,
const gchar *file)
{
gvir_sandbox_cleaner_add_action_post_stop(cleaner,
gvir_sandbox_cleaner_rmfile,
g_strdup(file),
g_free);
}
void gvir_sandbox_cleaner_add_rmdir_post_stop(GVirSandboxCleaner *cleaner,
const gchar *dir)
{
gvir_sandbox_cleaner_add_action_post_stop(cleaner,
gvir_sandbox_cleaner_rmdir,
g_strdup(dir),
g_free);
}
gboolean gvir_sandbox_cleaner_run_post_start(GVirSandboxCleaner *cleaner, GError **error)
{
GVirSandboxCleanerPrivate *priv = cleaner->priv;
GList *actions = g_list_copy(priv->postStart);
GList *tmp;
gboolean ret = TRUE;
actions = g_list_reverse(actions);
tmp = actions;
while (tmp) {
GVirSandboxCleanerEntry *ent = tmp->data;
if (!ent->func(cleaner, error, ent->opaque))
ret = FALSE;
tmp = tmp->next;
}
g_list_free(actions);
return ret;
}
gboolean gvir_sandbox_cleaner_run_post_stop(GVirSandboxCleaner *cleaner, GError **error)
{
GVirSandboxCleanerPrivate *priv = cleaner->priv;
GList *actions = g_list_copy(priv->postStop);
GList *tmp;
gboolean ret = TRUE;
actions = g_list_reverse(actions);
tmp = actions;
while (tmp) {
GVirSandboxCleanerEntry *ent = tmp->data;
if (!ent->func(cleaner, error, ent->opaque))
ret = FALSE;
tmp = tmp->next;
}
g_list_free(actions);
return ret;
}
/*
* libvirt-sandbox-cleaner.h: libvirt sandbox cleaner
*
* Copyright (C) 2011 Red Hat, Inc.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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);
void gvir_sandbox_cleaner_add_rmfile_post_start(GVirSandboxCleaner *cleaner,
const gchar *file);
void gvir_sandbox_cleaner_add_rmdir_post_start(GVirSandboxCleaner *cleaner,
const gchar *dir);
void gvir_sandbox_cleaner_add_rmfile_post_stop(GVirSandboxCleaner *cleaner,
const gchar *file);
void gvir_sandbox_cleaner_add_rmdir_post_stop(GVirSandboxCleaner *cleaner,
const gchar *dir);
gboolean gvir_sandbox_cleaner_run_post_start(GVirSandboxCleaner *cleaner, GError **error);
gboolean gvir_sandbox_cleaner_run_post_stop(GVirSandboxCleaner *cleaner, GError **error);
G_END_DECLS
#endif /* __LIBVIRT_SANDBOX_CLEANER_H__ */
......@@ -23,6 +23,7 @@
#include <config.h>
#include <string.h>
#include <errno.h>
#include <glib/gi18n.h>
......@@ -54,7 +55,6 @@ struct _GVirSandboxContextPrivate
gboolean active;
GVirSandboxBuilder *builder;
GVirSandboxCleaner *cleaner;
};
G_DEFINE_ABSTRACT_TYPE(GVirSandboxContext, gvir_sandbox_context, G_TYPE_OBJECT);
......@@ -160,8 +160,6 @@ 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);
}
......@@ -218,10 +216,7 @@ static void gvir_sandbox_context_class_init(GVirSandboxContextClass *klass)
static void gvir_sandbox_context_init(GVirSandboxContext *ctxt)
{
GVirSandboxContextPrivate *priv = ctxt->priv;
priv = ctxt->priv = GVIR_SANDBOX_CONTEXT_GET_PRIVATE(ctxt);
priv->cleaner = gvir_sandbox_cleaner_new();
ctxt->priv = GVIR_SANDBOX_CONTEXT_GET_PRIVATE(ctxt);
}
......@@ -241,22 +236,6 @@ 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
......@@ -312,12 +291,7 @@ static gboolean gvir_sandbox_context_prestart(GVirSandboxContext *ctxt,
if (!gvir_sandbox_config_save_to_path(priv->config, configfile, error))
goto cleanup;
gvir_sandbox_cleaner_add_rmfile_post_stop(priv->cleaner,
configfile);
g_mkdir_with_parents(emptydir, 0755);
gvir_sandbox_cleaner_add_rmdir_post_stop(priv->cleaner,
emptydir);
ret = TRUE;
cleanup:
......@@ -327,6 +301,84 @@ cleanup:
}
static gboolean gvir_sandbox_context_clean_post_start(GVirSandboxContext *ctxt,
GError **error)
{
GVirSandboxContextPrivate *priv = ctxt->priv;
const gchar *cachedir;
gchar *tmpdir;
gchar *configdir;
gboolean ret = TRUE;
cachedir = (getuid() ? g_get_user_cache_dir() : RUNDIR);
tmpdir = g_build_filename(cachedir, "libvirt-sandbox",
gvir_sandbox_config_get_name(priv->config),
NULL);
configdir = g_build_filename(tmpdir, "config", NULL);
if (!gvir_sandbox_builder_clean_post_start(priv->builder,
priv->config,
tmpdir,
configdir,
error))
ret = FALSE;
g_free(tmpdir);
g_free(configdir);
return ret;
}
static gboolean gvir_sandbox_context_clean_post_stop(GVirSandboxContext *ctxt,
GError **error)
{
GVirSandboxContextPrivate *priv = ctxt->priv;
const gchar *cachedir;
gchar *tmpdir;
gchar *configdir;
gchar *configfile;
gchar *emptydir;
gboolean ret = TRUE;
cachedir = (getuid() ? g_get_user_cache_dir() : RUNDIR);
tmpdir = g_build_filename(cachedir, "libvirt-sandbox",
gvir_sandbox_config_get_name(priv->config),
NULL);
configdir = g_build_filename(tmpdir, "config", NULL);
configfile = g_build_filename(configdir, "sandbox.cfg", NULL);
emptydir = g_build_filename(configdir, "empty", NULL);
if (unlink(configfile) < 0 &&
errno != ENOENT)
ret = FALSE;
if (rmdir(emptydir) < 0 &&
errno != ENOENT)
ret = FALSE;
if (rmdir(configdir) < 0 &&
errno != ENOENT)
ret = FALSE;
if (rmdir(tmpdir) < 0 &&
errno != ENOENT)
ret = FALSE;