]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
Export LXC_TARGET env variable in stop hook
authorStéphane Graber <stgraber@ubuntu.com>
Thu, 3 Dec 2015 05:52:58 +0000 (00:52 -0500)
committerStéphane Graber <stgraber@ubuntu.com>
Thu, 3 Dec 2015 06:10:30 +0000 (01:10 -0500)
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
doc/lxc.container.conf.sgml.in
src/lxc/start.c

index 90ffefa3c3d9f7262324d4baaf89525567cfa700..7a8c6e056764e7d5c084e078e7ffc1c76476d90c 100644 (file)
@@ -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>
index fa64b6dcf94c859de472161111feb2f3ae787dbc..2606dd1d67e4dd8a3a2660dffd6aa4642f88145e 100644 (file)
@@ -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++) {