From a2c09be066863f047b6f1f54249a547530738706 Mon Sep 17 00:00:00 2001 From: Christian Brauner Date: Mon, 11 Dec 2017 12:10:37 +0100 Subject: [PATCH] start: set LXC_HOOK_VERSION This can be used by scripts to detect what version of the hooks are used. Unblocks #2013. Unblocks #2015. Closes #1766. Signed-off-by: Christian Brauner --- doc/lxc.container.conf.sgml.in | 5 +++++ src/lxc/start.c | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/doc/lxc.container.conf.sgml.in b/doc/lxc.container.conf.sgml.in index cd49b8662..9d4b4cb36 100644 --- a/doc/lxc.container.conf.sgml.in +++ b/doc/lxc.container.conf.sgml.in @@ -1667,6 +1667,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA conditional on the value of . If it is set to 1 then LXC_HOOK_SECTION will be set. + LXC_HOOK_VERSION: the version of the hooks. This + value is identical to the value of the container's + config item. If it is set to 0 then + old-style hooks are used. If it is set to 1 then new-style hooks are + used. LXC_LOG_LEVEL: the container's log level. LXC_NAME: is the container's name. LXC_ROOTFS_MOUNT: the path to the mounted root filesystem. diff --git a/src/lxc/start.c b/src/lxc/start.c index a144d6f8f..d6cd54322 100644 --- a/src/lxc/start.c +++ b/src/lxc/start.c @@ -612,6 +612,7 @@ on_error: int lxc_init(const char *name, struct lxc_handler *handler) { + int ret; const char *loglevel; struct lxc_conf *conf = handler->conf; @@ -656,6 +657,13 @@ int lxc_init(const char *name, struct lxc_handler *handler) loglevel = lxc_log_priority_to_string(lxc_log_get_level()); if (setenv("LXC_LOG_LEVEL", loglevel, 1)) SYSERROR("Failed to set environment variable LXC_LOG_LEVEL=%s", loglevel); + + if (conf->hooks_version == 0) + ret = setenv("LXC_HOOK_VERSION", "0", 1); + else + ret = setenv("LXC_HOOK_VERSION", "1", 1); + if (ret < 0) + SYSERROR("Failed to set environment variable LXC_HOOK_VERSION=%u", conf->hooks_version); /* End of environment variable setup for hooks. */ TRACE("set environment variables"); -- 2.47.2