#include <sys/ioctl.h>
#include <sys/mount.h>
#include <sys/stat.h>
+#include <sys/mman.h>
#include <unistd.h>
#include <mntent.h>
#include <sys/reboot.h>
{
pid_t pid;
int cflags;
- int stacksize = getpagesize() * 4;
- g_autofree char *stack = NULL;
+ int stacksize = getpagesize() * 16;
+ char *stack = NULL;
char *stacktop;
+ int ret = -1;
lxc_child_argv_t args = {
.config = def,
.securityDriver = securityDriver,
};
/* allocate a stack for the container */
- stack = g_new0(char, stacksize);
+ stack = mmap(NULL, stacksize, PROT_READ | PROT_WRITE,
+ MAP_PRIVATE | MAP_ANONYMOUS | MAP_GROWSDOWN | MAP_STACK,
+ -1, 0);
+ if (stack == MAP_FAILED) {
+ virReportSystemError(errno, "%s",
+ _("Unable to allocate stack"));
+ return -1;
+ }
stacktop = stack + stacksize;
if (virProcessNamespaceAvailable(VIR_PROCESS_NAMESPACE_USER) < 0) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("Kernel doesn't support user namespace"));
- return -1;
+ goto cleanup;
}
VIR_DEBUG("Enable user namespace");
cflags |= CLONE_NEWUSER;
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("Config asks for inherit net namespace "
"as well as private network interfaces"));
- return -1;
+ goto cleanup;
}
VIR_DEBUG("Inheriting a net namespace");
}
if (pid < 0) {
virReportSystemError(errno, "%s",
_("Failed to run clone container"));
- return -1;
+ goto cleanup;
}
- return pid;
+ ret = pid;
+ cleanup:
+ if (munmap(stack, stacksize) < 0)
+ VIR_WARN("Unable to munmap() stack: %s", g_strerror(errno));
+
+ return ret;
}
int lxcContainerChown(virDomainDef *def, const char *path)