[libvirt] [PATCH] send 'container=libvirt' in env to container init

Eric Blake eblake at redhat.com
Mon May 16 22:41:40 UTC 2011


On 05/16/2011 09:14 AM, Serge Hallyn wrote:
>>> @@ -112,6 +112,7 @@ static virCommandPtr lxcContainerBuildInitCmd(virDomainDefPtr vmDef)
>>>  
>>>      virCommandAddEnvString(cmd, "PATH=/bin:/sbin");
>>>      virCommandAddEnvString(cmd, "TERM=linux");
>>> +    virCommandAddEnvString(cmd, "container=libvirt");
>>
>> POSIX reserves lowercase env names for the user.  Is upstart really
>> using a lower case name, or should this be an upper case name?
> 
> No upstart isn't doing anything itself :)  Just blame me - the upstart
> scripts I put into lxcguest do in fact check for lower-case.
> 
> What do you mean by 'for the user'?  For the user to type into the
> boot args, or something else?

http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap08.html

Environment variable names used by the utilities in the Shell and
Utilities volume of POSIX.1-2008 consist solely of uppercase letters,
digits, and the <underscore> ( '_' ) from the characters defined in
Portable Character Set and do not begin with a digit. Other characters
may be permitted by an implementation; applications shall tolerate the
presence of such names. Uppercase and lowercase letters shall retain
their unique identities and shall not be folded together. The name space
of environment variable names containing lowercase letters is reserved
for applications. Applications can define any environment variables with
names from this name space without modifying the behavior of the
standard utilities.

That is, if your startup scripts make anything in the system, including
/bin/sh, behave differently because it is in a container, then it's
probably better to use an upper-case name, since /bin/sh should not
behave differently regardless of what lower-case names are in the
environment.

But this is a borderline case - upstart is outside the realm of POSIX,
and you can easily arrange for $container to be reset before any
standard applications are ever invoked from within the container.

>>>      virCommandAddEnvPair(cmd, "LIBVIRT_LXC_UUID", uuidstr);
>>>      virCommandAddEnvPair(cmd, "LIBVIRT_LXC_NAME", vmDef->name);
>>
>> Can upstart be taught to look for LIBIVRT_LXC_UUID instead?
> 
> That's a possibility, yes.  It just makes it less symmetric to the
> liblxc case, but if you prefer that I see no reason why it wouldn't
> work.

Do you have a pointer to the liblxc code that's inspecting its environment?

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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 619 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20110516/228d1cac/attachment-0001.sig>


More information about the libvir-list mailing list