From: Stéphane Graber Date: Thu, 3 Dec 2015 05:52:58 +0000 (-0500) Subject: Export LXC_TARGET env variable in stop hook X-Git-Tag: lxc-2.0.0.beta1~43 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c154af98c17b3584ccafb88b10c8f861eed91093;p=thirdparty%2Flxc.git Export LXC_TARGET env variable in stop hook Signed-off-by: Stéphane Graber Acked-by: Serge E. Hallyn --- diff --git a/doc/lxc.container.conf.sgml.in b/doc/lxc.container.conf.sgml.in index 90ffefa3c..7a8c6e056 100644 --- a/doc/lxc.container.conf.sgml.in +++ b/doc/lxc.container.conf.sgml.in @@ -1566,7 +1566,19 @@ mknod errno 0 - + + + + + + + + Only for the stop hook. Is set to "stop" for a container + shutdown or "reboot" for a container reboot. + + + + Logging diff --git a/src/lxc/start.c b/src/lxc/start.c index fa64b6dcf..2606dd1d6 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++) {