From c154af98c17b3584ccafb88b10c8f861eed91093 Mon Sep 17 00:00:00 2001 From: =?utf8?q?St=C3=A9phane=20Graber?= Date: Thu, 3 Dec 2015 00:52:58 -0500 Subject: [PATCH] Export LXC_TARGET env variable in stop hook MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Stéphane Graber Acked-by: Serge E. Hallyn --- 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 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++) { -- 2.47.2