]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
confile: expand lxc.environment 2247/head
authorChristian Brauner <christian.brauner@ubuntu.com>
Sat, 31 Mar 2018 00:39:28 +0000 (02:39 +0200)
committerChristian Brauner <christian.brauner@ubuntu.com>
Sat, 31 Mar 2018 15:57:00 +0000 (17:57 +0200)
When a bare environment variable is specified then retrieve the value from the
current environment. For example, setting

lxc.environment = PATH

will cause LXC to inherit the value of PATH from the current environment.

Suggested-by: Jonathan Calmels <jcalmels@nvidia.com>
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
doc/lxc.container.conf.sgml.in
src/lxc/confile.c

index bd4195d9dfc7bd4c29317d9cc9b95d6c82002413..e9a013b8cf771e74f90441049a945c56e8c9b1e5 100644 (file)
@@ -2445,6 +2445,13 @@ dev/null proc/kcore none bind,relative 0 0
               lxc.environment = APP_ENV=production
               lxc.environment = SYSLOG_SERVER=192.0.2.42
             </programlisting>
+            <para>
+            It is possible to inherit host environment variables by setting the
+            name of the variable without a "=" sign. For example:
+            </para>
+            <programlisting>
+              lxc.environment = PATH
+            </programlisting>
           </listitem>
         </varlistentry>
       </variablelist>
index c1b4638d9b113f8d4abd9d6cb3ba841d5b2a1c6c..9704bbbecb4d836baa76c7f7c948858a4f1f5deb 100644 (file)
@@ -1096,7 +1096,21 @@ static int set_config_environment(const char *key, const char *value,
        if (!list_item)
                goto on_error;
 
-       list_item->elem = strdup(value);
+       if (!strchr(value, '=')) {
+               const char *env_val;
+               const char *env_key = value;
+               const char *env_var[3] = {0};
+
+               env_val = getenv(env_key);
+               if (!env_val)
+                       goto on_error;
+
+               env_var[0] = env_key;
+               env_var[1] = env_val;
+               list_item->elem = lxc_string_join("=", env_var, false);
+       } else {
+               list_item->elem = strdup(value);
+       }
 
        if (!list_item->elem)
                goto on_error;