Unverified Commit c7d64498 by Stéphane Graber Committed by GitHub

Merge pull request #3645 from brauner/2021-02-01/fixes_4

attach: bugfixes
parents 32947602 4ac35afb
...@@ -1190,8 +1190,6 @@ __noreturn static void do_attach(struct attach_payload *ap) ...@@ -1190,8 +1190,6 @@ __noreturn static void do_attach(struct attach_payload *ap)
TRACE("Prepared terminal file descriptor %d", ap->terminal_pts_fd); TRACE("Prepared terminal file descriptor %d", ap->terminal_pts_fd);
} }
put_attach_payload(ap);
/* Avoid unnecessary syscalls. */ /* Avoid unnecessary syscalls. */
if (ctx->setup_ns_uid == ctx->target_ns_uid) if (ctx->setup_ns_uid == ctx->target_ns_uid)
ctx->target_ns_uid = LXC_INVALID_UID; ctx->target_ns_uid = LXC_INVALID_UID;
...@@ -1210,11 +1208,14 @@ __noreturn static void do_attach(struct attach_payload *ap) ...@@ -1210,11 +1208,14 @@ __noreturn static void do_attach(struct attach_payload *ap)
if (!lxc_switch_uid_gid(ctx->target_ns_uid, ctx->target_ns_gid)) if (!lxc_switch_uid_gid(ctx->target_ns_uid, ctx->target_ns_gid))
goto on_error; goto on_error;
put_attach_payload(ap);
/* We're done, so we can now do whatever the user intended us to do. */ /* We're done, so we can now do whatever the user intended us to do. */
_exit(attach_function(attach_function_args)); _exit(attach_function(attach_function_args));
on_error: on_error:
ERROR("Failed to attach to container"); ERROR("Failed to attach to container");
put_attach_payload(ap);
_exit(EXIT_FAILURE); _exit(EXIT_FAILURE);
} }
...@@ -1320,7 +1321,7 @@ int lxc_attach(struct lxc_container *container, lxc_attach_exec_t exec_function, ...@@ -1320,7 +1321,7 @@ int lxc_attach(struct lxc_container *container, lxc_attach_exec_t exec_function,
ret = get_attach_context_nsfds(ctx, options); ret = get_attach_context_nsfds(ctx, options);
if (ret) { if (ret) {
lxc_container_put(container); put_attach_context(ctx);
return log_error(-1, "Failed to get namespace file descriptors"); return log_error(-1, "Failed to get namespace file descriptors");
} }
......
...@@ -166,7 +166,7 @@ int lxc_add_state_client(int state_client_fd, struct lxc_handler *handler, ...@@ -166,7 +166,7 @@ int lxc_add_state_client(int state_client_fd, struct lxc_handler *handler,
__do_free struct lxc_list *tmplist = NULL; __do_free struct lxc_list *tmplist = NULL;
int state; int state;
newclient = malloc(sizeof(*newclient)); newclient = zalloc(sizeof(*newclient));
if (!newclient) if (!newclient)
return -ENOMEM; return -ENOMEM;
...@@ -174,20 +174,19 @@ int lxc_add_state_client(int state_client_fd, struct lxc_handler *handler, ...@@ -174,20 +174,19 @@ int lxc_add_state_client(int state_client_fd, struct lxc_handler *handler,
memcpy(newclient->states, states, sizeof(newclient->states)); memcpy(newclient->states, states, sizeof(newclient->states));
newclient->clientfd = state_client_fd; newclient->clientfd = state_client_fd;
tmplist = malloc(sizeof(*tmplist)); tmplist = zalloc(sizeof(*tmplist));
if (!tmplist) if (!tmplist)
return -ENOMEM; return -ENOMEM;
state = handler->state; state = handler->state;
if (states[state] != 1) { if (states[state] != 1) {
lxc_list_add_elem(tmplist, newclient); lxc_list_add_elem(tmplist, move_ptr(newclient));
lxc_list_add_tail(&handler->conf->state_clients, tmplist); lxc_list_add_tail(&handler->conf->state_clients, move_ptr(tmplist));
} else { } else {
TRACE("Container already in requested state");
return state; return state;
} }
move_ptr(newclient);
move_ptr(tmplist);
TRACE("Added state client fd %d to state client list", state_client_fd); TRACE("Added state client fd %d to state client list", state_client_fd);
return MAX_STATE; return MAX_STATE;
} }
...@@ -4112,8 +4112,7 @@ int userns_exec_1(const struct lxc_conf *conf, int (*fn)(void *), void *data, ...@@ -4112,8 +4112,7 @@ int userns_exec_1(const struct lxc_conf *conf, int (*fn)(void *), void *data,
close_prot_errno_disarm(pipe_fds[0]); close_prot_errno_disarm(pipe_fds[0]);
if (lxc_log_get_level() == LXC_LOG_LEVEL_TRACE || if (lxc_log_trace()) {
conf->loglevel == LXC_LOG_LEVEL_TRACE) {
struct id_map *map; struct id_map *map;
struct lxc_list *it; struct lxc_list *it;
...@@ -4227,8 +4226,7 @@ int userns_exec_minimal(const struct lxc_conf *conf, ...@@ -4227,8 +4226,7 @@ int userns_exec_minimal(const struct lxc_conf *conf,
close_prot_errno_disarm(sock_fds[0]); close_prot_errno_disarm(sock_fds[0]);
if (lxc_log_get_level() == LXC_LOG_LEVEL_TRACE || if (lxc_log_trace()) {
conf->loglevel == LXC_LOG_LEVEL_TRACE) {
struct id_map *map; struct id_map *map;
struct lxc_list *it; struct lxc_list *it;
...@@ -4412,8 +4410,7 @@ int userns_exec_full(struct lxc_conf *conf, int (*fn)(void *), void *data, ...@@ -4412,8 +4410,7 @@ int userns_exec_full(struct lxc_conf *conf, int (*fn)(void *), void *data,
/* idmap will now keep track of that memory. */ /* idmap will now keep track of that memory. */
host_gid_map = NULL; host_gid_map = NULL;
if (lxc_log_get_level() == LXC_LOG_LEVEL_TRACE || if (lxc_log_trace()) {
conf->loglevel == LXC_LOG_LEVEL_TRACE) {
lxc_list_for_each (cur, idmap) { lxc_list_for_each (cur, idmap) {
map = cur->elem; map = cur->elem;
TRACE("establishing %cid mapping for \"%d\" in new " TRACE("establishing %cid mapping for \"%d\" in new "
...@@ -4634,8 +4631,7 @@ int userns_exec_mapped_root(const char *path, int path_fd, ...@@ -4634,8 +4631,7 @@ int userns_exec_mapped_root(const char *path, int path_fd,
close_prot_errno_disarm(sock_fds[0]); close_prot_errno_disarm(sock_fds[0]);
if (lxc_log_get_level() == LXC_LOG_LEVEL_TRACE || if (lxc_log_trace()) {
conf->loglevel == LXC_LOG_LEVEL_TRACE) {
struct id_map *map; struct id_map *map;
struct lxc_list *it; struct lxc_list *it;
......
...@@ -225,8 +225,7 @@ void lxc_log_configured_netdevs(const struct lxc_conf *conf) ...@@ -225,8 +225,7 @@ void lxc_log_configured_netdevs(const struct lxc_conf *conf)
struct lxc_netdev *netdev; struct lxc_netdev *netdev;
struct lxc_list *it = (struct lxc_list *)&conf->network;; struct lxc_list *it = (struct lxc_list *)&conf->network;;
if ((conf->loglevel != LXC_LOG_LEVEL_TRACE) && if (!lxc_log_trace())
(lxc_log_get_level() != LXC_LOG_LEVEL_TRACE))
return; return;
if (lxc_list_empty(it)) { if (lxc_list_empty(it)) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment