[lxc-devel] [PATCH] Export LXC_TARGET env variable in stop hook

Serge Hallyn serge.hallyn at ubuntu.com
Thu Dec 3 06:08:49 UTC 2015


Quoting Stéphane Graber (stgraber at ubuntu.com):
> Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>

Acked-by: Serge E. Hallyn <serge.hallyn at ubuntu.com>

> ---
>  doc/lxc.container.conf.sgml.in | 14 +++++++++++++-
>  src/lxc/start.c                |  9 +++++++++
>  2 files changed, 22 insertions(+), 1 deletion(-)
> 
> diff --git a/doc/lxc.container.conf.sgml.in b/doc/lxc.container.conf.sgml.in
> index 90ffefa..7a8c6e0 100644
> --- a/doc/lxc.container.conf.sgml.in
> +++ b/doc/lxc.container.conf.sgml.in
> @@ -1566,7 +1566,19 @@ mknod errno 0
>            </listitem>
>          </varlistentry>
>        </variablelist>
> -
> +      <variablelist>
> +        <varlistentry>
> +          <term>
> +            <option>LXC_TARGET</option>
> +          </term>
> +          <listitem>
> +            <para>
> +              Only for the stop hook. Is set to "stop" for a container
> +              shutdown or "reboot" for a container reboot.
> +            </para>
> +          </listitem>
> +        </varlistentry>
> +      </variablelist>
>      </refsect2>
>      <refsect2>
>      <title>Logging</title>
> diff --git a/src/lxc/start.c b/src/lxc/start.c
> index fa64b6d..2606dd1 100644
> --- a/src/lxc/start.c
> +++ b/src/lxc/start.c
> @@ -522,8 +522,17 @@ void lxc_fini(const char *name, struct lxc_handler *handler)
>  		}
>  	}
>  	namespaces[namespace_count] = NULL;
> +
> +	if (handler->conf->reboot && setenv("LXC_TARGET", "reboot", 1)) {
> +		SYSERROR("failed to set environment variable for stop target");
> +	}
> +	if (!handler->conf->reboot && setenv("LXC_TARGET", "stop", 1)) {
> +		SYSERROR("failed to set environment variable for stop target");
> +	}
> +
>  	if (run_lxc_hooks(name, "stop", handler->conf, handler->lxcpath, namespaces))
>  		ERROR("failed to run stop hooks for container '%s'.", name);
> +
>  	while (namespace_count--)
>  		free(namespaces[namespace_count]);
>  	for (i = 0; i < LXC_NS_MAX; i++) {
> -- 
> 1.9.1
> 
> _______________________________________________
> lxc-devel mailing list
> lxc-devel at lists.linuxcontainers.org
> http://lists.linuxcontainers.org/listinfo/lxc-devel


More information about the lxc-devel mailing list