[libvirt] [sandbox 1/6] Pass debug and verbose values to init

Cédric Bosdonnat cbosdonnat at suse.com
Tue Dec 5 09:53:17 UTC 2017


libvirt-sandbox-init-common is expecting -d and -v parameters to
set it in debug or verbose mode... but those will never be passed
by the launcher program.

Writing the core.debug and core.verbose parameters in the sandbox
configuration makes those values actually usable from the init.
---
 bin/virt-sandbox.c                            |  3 ++
 libvirt-sandbox/libvirt-sandbox-config.c      | 75 +++++++++++++++++++++++++++
 libvirt-sandbox/libvirt-sandbox-config.h      |  6 +++
 libvirt-sandbox/libvirt-sandbox-init-common.c |  3 ++
 libvirt-sandbox/libvirt-sandbox.sym           |  4 ++
 5 files changed, 91 insertions(+)

diff --git a/bin/virt-sandbox.c b/bin/virt-sandbox.c
index 3058013..6032562 100644
--- a/bin/virt-sandbox.c
+++ b/bin/virt-sandbox.c
@@ -273,6 +273,9 @@ int main(int argc, char **argv) {
     if (shell)
         gvir_sandbox_config_set_shell(cfg, TRUE);
 
+    gvir_sandbox_config_set_debug(cfg, debug);
+    gvir_sandbox_config_set_verbose(cfg, verbose);
+
     if (isatty(STDIN_FILENO))
         gvir_sandbox_config_interactive_set_tty(icfg, TRUE);
 
diff --git a/libvirt-sandbox/libvirt-sandbox-config.c b/libvirt-sandbox/libvirt-sandbox-config.c
index 8709736..73a0fa4 100644
--- a/libvirt-sandbox/libvirt-sandbox-config.c
+++ b/libvirt-sandbox/libvirt-sandbox-config.c
@@ -68,6 +68,9 @@ struct _GVirSandboxConfigPrivate
 
     gchar *secLabel;
     gboolean secDynamic;
+
+    gboolean debug;
+    gboolean verbose;
 };
 
 G_DEFINE_ABSTRACT_TYPE(GVirSandboxConfig, gvir_sandbox_config, G_TYPE_OBJECT);
@@ -1926,6 +1929,59 @@ gboolean gvir_sandbox_config_set_security_opts(GVirSandboxConfig *config,
     return ret;
 }
 
+/**
+ * gvir_sandbox_config_set_debug:
+ * @config: (transfer none): the sandbox config
+ * @debug: true if the container init should print debugging messages
+ *
+ * Set whether the container init should print debugging messages.
+ */
+void gvir_sandbox_config_set_debug(GVirSandboxConfig *config, gboolean debug)
+{
+    GVirSandboxConfigPrivate *priv = config->priv;
+    priv->debug = debug;
+}
+
+/**
+ * gvir_sandbox_config_get_debug:
+ * @config: (transfer none): the sandbox config
+ *
+ * Retrieves the sandbox debug flag
+ *
+ * Returns: the debug flag
+ */
+gboolean gvir_sandbox_config_get_debug(GVirSandboxConfig *config)
+{
+    GVirSandboxConfigPrivate *priv = config->priv;
+    return priv->debug;
+}
+
+/**
+ * gvir_sandbox_config_set_verbose:
+ * @config: (transfer none): the sandbox config
+ * @verbose: true if the container init should be verbose
+ *
+ * Set whether the container init should be verbose.
+ */
+void gvir_sandbox_config_set_verbose(GVirSandboxConfig *config, gboolean verbose)
+{
+    GVirSandboxConfigPrivate *priv = config->priv;
+    priv->verbose = verbose;
+}
+
+/**
+ * gvir_sandbox_config_get_verbose:
+ * @config: (transfer none): the sandbox config
+ *
+ * Retrieves the sandbox verbose flag
+ *
+ * Returns: the verbose flag
+ */
+gboolean gvir_sandbox_config_get_verbose(GVirSandboxConfig *config)
+{
+    GVirSandboxConfigPrivate *priv = config->priv;
+    return priv->verbose;
+}
 
 static GVirSandboxConfigMount *gvir_sandbox_config_load_config_mount(GKeyFile *file,
                                                                      guint i,
@@ -2415,6 +2471,22 @@ static gboolean gvir_sandbox_config_load_config(GVirSandboxConfig *config,
         priv->secDynamic = b;
     }
 
+    b = g_key_file_get_boolean(file, "core", "debug", &e);
+    if (e) {
+        g_error_free(e);
+        e = NULL;
+    } else {
+        priv->debug = b;
+    }
+
+    b = g_key_file_get_boolean(file, "core", "verbose", &e);
+    if (e) {
+        g_error_free(e);
+        e = NULL;
+    } else {
+        priv->verbose = b;
+    }
+
     ret = TRUE;
  cleanup:
     return ret;
@@ -2677,6 +2749,9 @@ static void gvir_sandbox_config_save_config(GVirSandboxConfig *config,
     if (priv->secLabel)
         g_key_file_set_string(file, "security", "label", priv->secLabel);
     g_key_file_set_boolean(file, "security", "dynamic", priv->secDynamic);
+
+    g_key_file_set_boolean(file, "core", "debug", priv->debug);
+    g_key_file_set_boolean(file, "core", "verbose", priv->verbose);
 }
 
 
diff --git a/libvirt-sandbox/libvirt-sandbox-config.h b/libvirt-sandbox/libvirt-sandbox-config.h
index e5e53f7..8950e25 100644
--- a/libvirt-sandbox/libvirt-sandbox-config.h
+++ b/libvirt-sandbox/libvirt-sandbox-config.h
@@ -180,6 +180,12 @@ gboolean gvir_sandbox_config_set_security_opts(GVirSandboxConfig *config,
                                                const gchar *optstr,
                                                GError**error);
 
+void gvir_sandbox_config_set_debug(GVirSandboxConfig *config, gboolean debug);
+gboolean gvir_sandbox_config_get_debug(GVirSandboxConfig *config);
+
+void gvir_sandbox_config_set_verbose(GVirSandboxConfig *config, gboolean verbose);
+gboolean gvir_sandbox_config_get_verbose(GVirSandboxConfig *config);
+
 gchar **gvir_sandbox_config_get_command(GVirSandboxConfig *config);
 
 G_END_DECLS
diff --git a/libvirt-sandbox/libvirt-sandbox-init-common.c b/libvirt-sandbox/libvirt-sandbox-init-common.c
index 7ea63cf..240ca83 100644
--- a/libvirt-sandbox/libvirt-sandbox-init-common.c
+++ b/libvirt-sandbox/libvirt-sandbox-init-common.c
@@ -1442,6 +1442,9 @@ int main(int argc, char **argv) {
         goto cleanup;
     }
 
+    debug = gvir_sandbox_config_get_debug(config);
+    verbose = gvir_sandbox_config_get_verbose(config);
+
     setenv("PATH", "/bin:/usr/bin:/usr/local/bin:/sbin/:/usr/sbin", 1);
     unsetenv("LD_LIBRARY_PATH");
 
diff --git a/libvirt-sandbox/libvirt-sandbox.sym b/libvirt-sandbox/libvirt-sandbox.sym
index b7c5921..1bead3e 100644
--- a/libvirt-sandbox/libvirt-sandbox.sym
+++ b/libvirt-sandbox/libvirt-sandbox.sym
@@ -120,6 +120,8 @@ LIBVIRT_SANDBOX_0.6.0 {
 	gvir_sandbox_config_get_userid;
 	gvir_sandbox_config_get_username;
 	gvir_sandbox_config_get_uuid;
+	gvir_sandbox_config_get_debug;
+	gvir_sandbox_config_get_verbose;
 	gvir_sandbox_config_find_mount;
 	gvir_sandbox_config_has_networks;
 	gvir_sandbox_config_has_mounts;
@@ -143,6 +145,8 @@ LIBVIRT_SANDBOX_0.6.0 {
 	gvir_sandbox_config_set_security_label;
 	gvir_sandbox_config_set_security_opts;
 	gvir_sandbox_config_set_uuid;
+	gvir_sandbox_config_set_debug;
+	gvir_sandbox_config_set_verbose;
 
 	gvir_sandbox_config_initrd_add_module;
 	gvir_sandbox_config_initrd_get_init;
-- 
2.15.1




More information about the libvir-list mailing list