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;
*/
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;
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]);