mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
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:
parent
449b4c87b5
commit
6704e3fdb3
@ -52,6 +52,7 @@
|
|||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
#include "veth.h"
|
#include "veth.h"
|
||||||
|
#include "uuid.h"
|
||||||
#include "files.h"
|
#include "files.h"
|
||||||
|
|
||||||
#define VIR_FROM_THIS VIR_FROM_LXC
|
#define VIR_FROM_THIS VIR_FROM_LXC
|
||||||
@ -102,6 +103,20 @@ struct __lxc_child_argv {
|
|||||||
*/
|
*/
|
||||||
static int lxcContainerExecInit(virDomainDefPtr vmDef)
|
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[] = {
|
const char *const argv[] = {
|
||||||
vmDef->os.init,
|
vmDef->os.init,
|
||||||
NULL,
|
NULL,
|
||||||
@ -109,6 +124,8 @@ static int lxcContainerExecInit(virDomainDefPtr vmDef)
|
|||||||
const char *const envp[] = {
|
const char *const envp[] = {
|
||||||
"PATH=/bin:/sbin",
|
"PATH=/bin:/sbin",
|
||||||
"TERM=linux",
|
"TERM=linux",
|
||||||
|
uuidenv,
|
||||||
|
nameenv,
|
||||||
NULL,
|
NULL,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user