[libvirt] Environmental Variables inside a container

Devendra K. Modium dmodium at isi.edu
Wed Jul 27 19:36:25 UTC 2011


Hi Eric

Thanks for the reply.
I am trying to run standard Ubuntu lxc file System(lxc-ubuntu) and
/sbin/init of Ubuntu is the root process of lxc process tree.

I believe most of the lxc containers start with /sbin/init
as first process.

Since I didn't exactly find the code of /sbin/init, I assumed 
since libvirt_lxc is currently sending environmental flags
to first process(I believe mostly it is /sbin/init) of LXC container
and hence this would be visible inside the container and assumed 
that /sbin/init in general should pass on this environment flags to
child process.

Though I know its not an libvirt issue, if its not passing on environment,
just wanted to know if you have some knowledge about what might going on.

Thanks in advance

Regards
Devendra





----- Original Message -----
From: "Eric Blake" <eblake at redhat.com>
To: "Devendra K. Modium" <dmodium at isi.edu>
Cc: libvir-list at redhat.com
Sent: Wednesday, July 27, 2011 3:13:51 PM
Subject: Re: [libvirt] Environmental Variables inside a container

On 07/27/2011 12:44 PM, Devendra K. Modium wrote:
> Hi All
>
> I am trying to pass an environmental flag to the
> LXC container when it is started.I found libvirt_lxc is
> already doing it  in lxc_container.c as shown below
>
>
> static virCommandPtr lxcContainerBuildInitCmd(virDomainDefPtr vmDef)
> {
>      char uuidstr[VIR_UUID_STRING_BUFLEN];
>      virCommandPtr cmd;
>
>      virUUIDFormat(vmDef->uuid, uuidstr);
>
>      cmd = virCommandNew(vmDef->os.init);
>
>      virCommandAddEnvString(cmd, "PATH=/bin:/sbin");
>      virCommandAddEnvString(cmd, "TERM=linux-deva");
>      virCommandAddEnvPair(cmd, "LIBVIRT_LXC_UUID", uuidstr);
>      virCommandAddEnvPair(cmd, "LIBVIRT_LXC_NAME", vmDef->name);

Yes, this list is hard-coded, and only guarantees to affect the 
environment of the process at the root of the lxc process tree.

> But only
> TERM flag is getting visible inside the container not remaining.
>
> Does it depends on how /sbin/init is receiving them? Is /sbin/init
> only recognizing TERM flag.

Probably something in your lxc process hierarchy is scrubbing 
environment variables prior to starting additional processes, but that's 
out of libvirt's control - libvirt can only affect the environment of 
the parent process.

> If so what is intention of sending remaining flags in current libvirt.
>
> Please let me know if there is any elegant way to send environmental
> variable to container.

Sounds like it might be an interesting feature to enhance the xml for 
lxc domains to allow the specification of additional environment 
variables that should be inherited into the lxc process tree, beyond the 
few variables already hard-coded by libvirt.

-- 
Eric Blake   eblake at redhat.com    +1-801-349-2682
Libvirt virtualization library http://libvirt.org




More information about the libvir-list mailing list