Merge pull request #2353 from brauner/2018-05-25/fix_lxc_create

tools: fix lxc-create with global config value II
This commit is contained in:
Stéphane Graber 2018-05-25 23:48:10 -04:00 committed by GitHub
commit 85f839ccb1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 25 deletions

View File

@ -1284,7 +1284,6 @@ static inline bool cgfsng_create(struct cgroup_ops *ops,
char *container_cgroup, *offset, *tmp; char *container_cgroup, *offset, *tmp;
int idx = 0; int idx = 0;
struct lxc_conf *conf = handler->conf; struct lxc_conf *conf = handler->conf;
const char *join_args[] = {conf->cgroup_meta.dir, handler->name, NULL};
if (ops->container_cgroup) { if (ops->container_cgroup) {
WARN("cgfsng_create called a second time: %s", ops->container_cgroup); WARN("cgfsng_create called a second time: %s", ops->container_cgroup);
@ -1295,7 +1294,7 @@ static inline bool cgfsng_create(struct cgroup_ops *ops,
return false; return false;
if (conf->cgroup_meta.dir) if (conf->cgroup_meta.dir)
tmp = lxc_string_join("/", join_args, false); tmp = lxc_string_join("/", (const char *[]){conf->cgroup_meta.dir, handler->name, NULL}, false);
else else
tmp = lxc_string_replace("%n", handler->name, ops->cgroup_pattern); tmp = lxc_string_replace("%n", handler->name, ops->cgroup_pattern);
if (!tmp) { if (!tmp) {

View File

@ -1971,11 +1971,8 @@ static bool do_lxcapi_reboot2(struct lxc_container *c, int timeout)
} }
TRACE("Sent signal %d to pid %d", rebootsignal, pid); TRACE("Sent signal %d to pid %d", rebootsignal, pid);
if (timeout == 0) { if (timeout == 0)
if (state_client_fd >= 0)
close(state_client_fd);
return true; return true;
}
ret = lxc_cmd_sock_rcv_state(state_client_fd, timeout); ret = lxc_cmd_sock_rcv_state(state_client_fd, timeout);
close(state_client_fd); close(state_client_fd);
@ -2044,11 +2041,8 @@ static bool do_lxcapi_shutdown(struct lxc_container *c, int timeout)
} }
TRACE("Sent signal %d to pid %d", haltsignal, pid); TRACE("Sent signal %d to pid %d", haltsignal, pid);
if (timeout == 0) { if (timeout == 0)
if (state_client_fd >= 0)
close(state_client_fd);
return true; return true;
}
ret = lxc_cmd_sock_rcv_state(state_client_fd, timeout); ret = lxc_cmd_sock_rcv_state(state_client_fd, timeout);
close(state_client_fd); close(state_client_fd);

View File

@ -861,11 +861,11 @@ int lxc_init(const char *name, struct lxc_handler *handler)
return 0; return 0;
out_restore_sigmask: out_restore_sigmask:
pthread_sigmask(SIG_SETMASK, &handler->oldmask, NULL); (void)pthread_sigmask(SIG_SETMASK, &handler->oldmask, NULL);
out_delete_tty: out_delete_tty:
lxc_delete_tty(&conf->ttys); lxc_delete_tty(&conf->ttys);
out_aborting: out_aborting:
lxc_set_state(name, handler, ABORTING); (void)lxc_set_state(name, handler, ABORTING);
out_close_maincmd_fd: out_close_maincmd_fd:
close(conf->maincmd_fd); close(conf->maincmd_fd);
conf->maincmd_fd = -1; conf->maincmd_fd = -1;

View File

@ -267,24 +267,19 @@ int main(int argc, char *argv[])
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if (geteuid()) {
if (!my_args.lxcpath[0])
my_args.lxcpath[0] = lxc_get_global_config_item("lxc.lxcpath");
if (mkdir_p(my_args.lxcpath[0], 0755)) if (!my_args.lxcpath[0])
exit(EXIT_FAILURE); my_args.lxcpath[0] = lxc_get_global_config_item("lxc.lxcpath");
if (mkdir_p(my_args.lxcpath[0], 0755))
exit(EXIT_FAILURE);
if (geteuid())
if (access(my_args.lxcpath[0], O_RDONLY) < 0) { if (access(my_args.lxcpath[0], O_RDONLY) < 0) {
fprintf(stderr, "You lack access to %s\n", my_args.lxcpath[0]); fprintf(stderr, "You lack access to %s\n",
my_args.lxcpath[0]);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if (strcmp(my_args.bdevtype, "dir") && strcmp(my_args.bdevtype, "_unset") &&
strcmp(my_args.bdevtype, "btrfs")) {
fprintf(stderr, "Unprivileged users cannot create %s containers.\n", my_args.bdevtype);
exit(EXIT_FAILURE);
}
}
c = lxc_container_new(my_args.name, my_args.lxcpath[0]); c = lxc_container_new(my_args.name, my_args.lxcpath[0]);
if (!c) { if (!c) {