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

[libvirt] [PATCH] Expose name + UUID to LXC containers via env variables



When spawning 'init' in the container, set

  LIBVIRT_LXC_UUID=XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
  LIBVIRT_LXC_NAME=YYYYYYYYYYYY

to allow guest software to detect & identify that they
are in a container

* src/lxc/lxc_container.c: Set LIBVIRT_LXC_UUID and
  LIBVIRT_LXC_NAME env vars
---
 src/lxc/lxc_container.c |   17 +++++++++++++++++
 1 files changed, 17 insertions(+), 0 deletions(-)

diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c
index d973984..269dc97 100644
--- a/src/lxc/lxc_container.c
+++ b/src/lxc/lxc_container.c
@@ -52,6 +52,7 @@
 #include "util.h"
 #include "memory.h"
 #include "veth.h"
+#include "uuid.h"
 #include "files.h"
 
 #define VIR_FROM_THIS VIR_FROM_LXC
@@ -102,6 +103,20 @@ struct __lxc_child_argv {
  */
 static int lxcContainerExecInit(virDomainDefPtr vmDef)
 {
+    char *uuidenv, *nameenv;
+    char uuidstr[VIR_UUID_STRING_BUFLEN];
+
+    virUUIDFormat(vmDef->uuid, uuidstr);
+
+    if (virAsprintf(&uuidenv, "LIBVIRT_LXC_UUID=%s", uuidstr) < 0) {
+        virReportOOMError();
+        return -1;
+    }
+    if (virAsprintf(&nameenv, "LIBVIRT_LXC_NAME=%s", vmDef->name) < 0) {
+        virReportOOMError();
+        return -1;
+    }
+
     const char *const argv[] = {
         vmDef->os.init,
         NULL,
@@ -109,6 +124,8 @@ static int lxcContainerExecInit(virDomainDefPtr vmDef)
     const char *const envp[] = {
         "PATH=/bin:/sbin",
         "TERM=linux",
+        uuidenv,
+        nameenv,
         NULL,
     };
 
-- 
1.7.4


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