From: Serge Hallyn Date: Fri, 10 May 2013 19:35:26 +0000 (-0700) Subject: A few changes for unprivileged lxc-start X-Git-Tag: lxc-1.0.0.alpha1~1^2~111 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b60ed720848c8276e4e770d380ec6014768d9923;p=thirdparty%2Flxc.git A few changes for unprivileged lxc-start When doing reboot test, must add clone_newuser to clone flags, else we can't clone(CLONE_NEWPID). If we don't have caps at lxc-start, don't refuse to start. Drop the lxc_caps_check() function altogether as it is unused now. Signed-off-by: Serge Hallyn Acked-by: Stéphane Graber --- diff --git a/src/lxc/caps.c b/src/lxc/caps.c index 05444514d..56f02411a 100644 --- a/src/lxc/caps.c +++ b/src/lxc/caps.c @@ -227,42 +227,4 @@ int lxc_caps_last_cap(void) return last_cap; } -/* - * check if we have the caps needed to start a container. returns 1 on - * success, 0 on error. (I'd prefer this be a bool, but am afraid that - * might fail to build on some distros). - */ -int lxc_caps_check(void) -{ - uid_t uid = getuid(); - cap_t caps; - cap_flag_value_t value; - int i, ret; - - cap_value_t needed_caps[] = { CAP_SYS_ADMIN, CAP_NET_ADMIN, CAP_SETUID, CAP_SETGID }; - -#define NUMCAPS ((int) (sizeof(needed_caps) / sizeof(cap_t))) - - if (!uid) - return 1; - - caps = cap_get_proc(); - if (!caps) { - ERROR("failed to cap_get_proc: %m"); - return 0; - } - - for (i=0; iid_map)) + flags |= CLONE_NEWUSER; + #ifdef __ia64__ - pid = __clone2(container_reboot_supported, stack, stack_size, CLONE_NEWPID | SIGCHLD, &cmd); + pid = __clone2(container_reboot_supported, stack, stack_size, flags, &cmd); #else stack += stack_size; - pid = clone(container_reboot_supported, stack, CLONE_NEWPID | SIGCHLD, &cmd); + pid = clone(container_reboot_supported, stack, flags, &cmd); #endif if (pid < 0) { SYSERROR("failed to clone\n"); @@ -668,6 +665,9 @@ int lxc_spawn(struct lxc_handler *handler) curcgroup = alloca(len); if (lxc_curcgroup(curcgroup, len) <= 1) curcgroup = NULL; + FILE *f = fopen("/tmp/a", "a"); + fprintf(f, "curcgroup is %s\n", curcgroup); + fclose(f); } if ((handler->cgroup = lxc_cgroup_path_create(curcgroup, name)) == NULL) goto out_delete_net; @@ -776,7 +776,7 @@ int __lxc_start(const char *name, struct lxc_conf *conf, handler->ops = ops; handler->data = data; - if (must_drop_cap_sys_boot()) { + if (must_drop_cap_sys_boot(handler->conf)) { #if HAVE_SYS_CAPABILITY_H DEBUG("Dropping cap_sys_boot\n"); #else