]> git.proxmox.com Git - mirror_lxc.git/blobdiff - src/lxc/start.c
start: remove stack allocations
[mirror_lxc.git] / src / lxc / start.c
index dae3bcfe534704514589afec5f0e24b69edf9459..b4bb6ef9a0db53acce19e1de966d2b87f9b749f5 100644 (file)
@@ -26,7 +26,6 @@
 #ifndef _GNU_SOURCE
 #define _GNU_SOURCE 1
 #endif
-#include <alloca.h>
 #include <dirent.h>
 #include <errno.h>
 #include <fcntl.h>
@@ -67,6 +66,7 @@
 #include "lxcseccomp.h"
 #include "macro.h"
 #include "mainloop.h"
+#include "memory_utils.h"
 #include "monitor.h"
 #include "namespace.h"
 #include "network.h"
@@ -97,16 +97,13 @@ static void lxc_destroy_container_on_signal(struct lxc_handler *handler,
 
 static void print_top_failing_dir(const char *path)
 {
+       __do_free char *copy;
        int ret;
-       size_t len;
-       char *copy, *e, *p, saved;
-
-       len = strlen(path);
-       copy = alloca(len + 1);
-       (void)strlcpy(copy, path, len + 1);
+       char *e, *p, saved;
 
+       copy = must_copy_string(path);
        p = copy;
-       e = copy + len;
+       e = copy + strlen(path);
 
        while (p < e) {
                while (p < e && *p == '/')
@@ -1252,10 +1249,16 @@ static int do_start(void *data)
        if (handler->ns_clone_flags & CLONE_NEWCGROUP) {
                ret = unshare(CLONE_NEWCGROUP);
                if (ret < 0) {
-                       INFO("Failed to unshare CLONE_NEWCGROUP");
-                       goto out_warn_father;
+                       if (errno != EINVAL) {
+                               SYSERROR("Failed to unshare CLONE_NEWCGROUP");
+                               goto out_warn_father;
+                       }
+
+                       handler->ns_clone_flags &= ~CLONE_NEWCGROUP;
+                       SYSINFO("Kernel does not support CLONE_NEWCGROUP");
+               } else {
+                       INFO("Unshared CLONE_NEWCGROUP");
                }
-               INFO("Unshared CLONE_NEWCGROUP");
        }
 
        /* Add the requested environment variables to the current environment to
@@ -1934,16 +1937,19 @@ int __lxc_start(const char *name, struct lxc_handler *handler,
 
        if (!attach_block_device(handler->conf)) {
                ERROR("Failed to attach block device");
+               ret = -1;
                goto out_fini_nonet;
        }
 
        if (!cgroup_ops->monitor_create(cgroup_ops, handler)) {
                ERROR("Failed to create monitor cgroup");
+               ret = -1;
                goto out_fini_nonet;
        }
 
        if (!cgroup_ops->monitor_enter(cgroup_ops, handler->monitor_pid)) {
                ERROR("Failed to enter monitor cgroup");
+               ret = -1;
                goto out_fini_nonet;
        }
 
@@ -1988,6 +1994,7 @@ int __lxc_start(const char *name, struct lxc_handler *handler,
 
        if (!handler->init_died && handler->pid > 0) {
                ERROR("Child process is not killed");
+               ret = -1;
                goto out_abort;
        }