]> git.proxmox.com Git - mirror_lxc.git/blobdiff - src/lxc/start.c
start: pass namespaces as environment variables
[mirror_lxc.git] / src / lxc / start.c
index d6cd543224272dfedce19836d0fcfaa6ce58bafc..b29540603be134abc227c2f6b756570b56400d24 100644 (file)
@@ -716,8 +716,8 @@ out_close_maincmd_fd:
 void lxc_fini(const char *name, struct lxc_handler *handler)
 {
        int i, rc;
+       pid_t self;
        struct lxc_list *cur, *next;
-       pid_t self = getpid();
        char *namespaces[LXC_NS_MAX + 1];
        size_t namespace_count = 0;
 
@@ -726,16 +726,37 @@ void lxc_fini(const char *name, struct lxc_handler *handler)
         */
        lxc_set_state(name, handler, STOPPING);
 
+       self = getpid();
        for (i = 0; i < LXC_NS_MAX; i++) {
-               if (handler->nsfd[i] != -1) {
-                       rc = asprintf(&namespaces[namespace_count], "%s:/proc/%d/fd/%d",
-                                     ns_info[i].proc_name, self, handler->nsfd[i]);
-                       if (rc == -1) {
-                               SYSERROR("Failed to allocate memory.");
-                               break;
-                       }
-                       ++namespace_count;
+               if (handler->nsfd[i] < 0)
+                       continue;
+
+               if (handler->conf->hooks_version == 0)
+                       rc = asprintf(&namespaces[namespace_count],
+                                     "%s:/proc/%d/fd/%d", ns_info[i].proc_name,
+                                     self, handler->nsfd[i]);
+               else
+                       rc = asprintf(&namespaces[namespace_count],
+                                     "/proc/%d/fd/%d", self, handler->nsfd[i]);
+               if (rc == -1) {
+                       SYSERROR("Failed to allocate memory.");
+                       break;
                }
+
+               if (handler->conf->hooks_version == 0) {
+                       namespace_count++;
+                       continue;
+               }
+
+               rc = setenv(ns_info[i].env_name, namespaces[namespace_count], 1);
+               if (rc < 0)
+                       SYSERROR("Failed to set environment variable %s=%s",
+                                ns_info[i].env_name, namespaces[namespace_count]);
+               else
+                       TRACE("Set environment variable %s=%s",
+                             ns_info[i].env_name, namespaces[namespace_count]);
+
+               namespace_count++;
        }
        namespaces[namespace_count] = NULL;
 
@@ -745,8 +766,10 @@ void lxc_fini(const char *name, struct lxc_handler *handler)
        if (!handler->conf->reboot && setenv("LXC_TARGET", "stop", 1))
                SYSERROR("Failed to set environment variable: LXC_TARGET=stop.");
 
-       if (run_lxc_hooks(name, "stop", handler->conf, handler->lxcpath, namespaces))
-               ERROR("Failed to run lxc.hook.stop for container \"%s\".", name);
+       if (handler->conf->hooks_version == 0)
+               rc = run_lxc_hooks(name, "stop", handler->conf, handler->lxcpath, namespaces);
+       else
+               rc = run_lxc_hooks(name, "stop", handler->conf, handler->lxcpath, NULL);
 
        while (namespace_count--)
                free(namespaces[namespace_count]);