Skip to content

Commit

Permalink
Merge pull request lxc#2247 from brauner/2018-03-31/expand_lxc_enviro…
Browse files Browse the repository at this point in the history
…nment

confile: expand lxc.environment
  • Loading branch information
stgraber authored Apr 2, 2018
2 parents dae2930 + 5eab47b commit 0474e8a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
7 changes: 7 additions & 0 deletions doc/lxc.container.conf.sgml.in
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
16 changes: 15 additions & 1 deletion src/lxc/confile.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 0474e8a

Please sign in to comment.