[sandbox PATCH v3 19/22] Add environment parameter to virt-sandbox

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Allow users to add custom environment variables to their sandbox.
---
 bin/virt-sandbox.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/bin/virt-sandbox.c b/bin/virt-sandbox.c
index 195515f..e90b698 100644
--- a/bin/virt-sandbox.c
+++ b/bin/virt-sandbox.c
@@ -64,6 +64,7 @@ int main(int argc, char **argv) {
     GError *error = NULL;
     gchar *name = NULL;
     gchar **disks = NULL;
+    gchar **envs = NULL;
     gchar **mounts = NULL;
     gchar **includes = NULL;
     gchar *includefile = NULL;
@@ -95,6 +96,8 @@ int main(int argc, char **argv) {
           N_("root directory of the sandbox"), "DIR" },
         { "disk", ' ', 0, G_OPTION_ARG_STRING_ARRAY, &disks,
           N_("add a disk in the guest"), "TYPE:TAGNAME=SOURCE,format=FORMAT" },
+        { "env", 'e', 0, G_OPTION_ARG_STRING_ARRAY, &envs,
+          N_("add a environment variable for the sandbox"), "KEY=VALUE" },
         { "mount", 'm', 0, G_OPTION_ARG_STRING_ARRAY, &mounts,
           N_("mount a filesystem in the guest"), "TYPE:TARGET=SOURCE" },
         { "include", 'i', 0, G_OPTION_ARG_STRING_ARRAY, &includes,
@@ -185,6 +188,13 @@ int main(int argc, char **argv) {
         gvir_sandbox_config_set_username(cfg, "root");
     }
 
+    if (envs &&
+        !gvir_sandbox_config_add_env_strv(cfg, envs, &error)) {
+        g_printerr(_("Unable to parse custom environment variables: %s\n"),
+                   error && error->message ? error->message : _("Unknown failure"));
+        goto cleanup;
+    }
+
     if (disks &&
         !gvir_sandbox_config_add_disk_strv(cfg, disks, &error)) {
         g_printerr(_("Unable to parse disks: %s\n"),
@@ -329,6 +339,10 @@ inheriting the host's root filesystem.
 NB. C<DIR> must contain a matching install of the libvirt-sandbox
 package. This restriction may be lifted in a future version.
 
+=item B<--env key=value>
+
+Sets up a custom environment variable on a running sandbox.
+
 =item B<--disk TYPE:TAGNAME=SOURCE,format=FORMAT>
 
 Sets up a disk inside the sandbox by using B<SOURCE> with a symlink named as B<TAGNAME>
-- 
2.1.0

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]