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
This commit is contained in:
Daniel P. Berrange 2011-02-22 13:09:19 +00:00
parent 449b4c87b5
commit 6704e3fdb3

View File

@ -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,
};