提交 6704e3fd 编写于 作者: D Daniel P. Berrange

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
上级 449b4c87
......@@ -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,
};
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册