2
0
mirror of git://github.com/lxc/lxc synced 2025-09-04 04:59:35 +00:00

Merge pull request #3009 from brauner/2019-05-16/rework_attach

attach: do not reload container
This commit is contained in:
Stéphane Graber
2019-05-16 19:33:41 +02:00
committed by GitHub
3 changed files with 20 additions and 12 deletions

View File

@@ -1008,9 +1008,9 @@ static inline void lxc_attach_terminal_close_log(struct lxc_terminal *terminal)
close_prot_errno_disarm(terminal->log_fd); close_prot_errno_disarm(terminal->log_fd);
} }
int lxc_attach(const char *name, const char *lxcpath, int lxc_attach(struct lxc_container *container, lxc_attach_exec_t exec_function,
lxc_attach_exec_t exec_function, void *exec_payload, void *exec_payload, lxc_attach_options_t *options,
lxc_attach_options_t *options, pid_t *attached_process) pid_t *attached_process)
{ {
int i, ret, status; int i, ret, status;
int ipc_sockets[2]; int ipc_sockets[2];
@@ -1020,6 +1020,7 @@ int lxc_attach(const char *name, const char *lxcpath,
struct lxc_proc_context_info *init_ctx; struct lxc_proc_context_info *init_ctx;
struct lxc_terminal terminal; struct lxc_terminal terminal;
struct lxc_conf *conf; struct lxc_conf *conf;
char *name, *lxcpath;
struct attach_clone_payload payload = {0}; struct attach_clone_payload payload = {0};
ret = access("/proc/self/ns", X_OK); ret = access("/proc/self/ns", X_OK);
@@ -1028,21 +1029,34 @@ int lxc_attach(const char *name, const char *lxcpath,
return -1; return -1;
} }
if (!container)
return minus_one_set_errno(EINVAL);
if (!lxc_container_get(container))
return minus_one_set_errno(EINVAL);
name = container->name;
lxcpath = container->config_path;
if (!options) if (!options)
options = &attach_static_default_options; options = &attach_static_default_options;
init_pid = lxc_cmd_get_init_pid(name, lxcpath); init_pid = lxc_cmd_get_init_pid(name, lxcpath);
if (init_pid < 0) { if (init_pid < 0) {
ERROR("Failed to get init pid"); ERROR("Failed to get init pid");
lxc_container_put(container);
return -1; return -1;
} }
init_ctx = lxc_proc_get_context_info(init_pid); init_ctx = lxc_proc_get_context_info(init_pid);
if (!init_ctx) { if (!init_ctx) {
ERROR("Failed to get context of init process: %ld", (long)init_pid); ERROR("Failed to get context of init process: %ld", (long)init_pid);
lxc_container_put(container);
return -1; return -1;
} }
init_ctx->container = container;
personality = get_personality(name, lxcpath); personality = get_personality(name, lxcpath);
if (init_ctx->personality < 0) { if (init_ctx->personality < 0) {
ERROR("Failed to get personality of the container"); ERROR("Failed to get personality of the container");
@@ -1051,12 +1065,6 @@ int lxc_attach(const char *name, const char *lxcpath,
} }
init_ctx->personality = personality; init_ctx->personality = personality;
init_ctx->container = lxc_container_new(name, lxcpath);
if (!init_ctx->container) {
lxc_proc_put_context_info(init_ctx);
return -1;
}
if (!init_ctx->container->lxc_conf) { if (!init_ctx->container->lxc_conf) {
init_ctx->container->lxc_conf = lxc_conf_init(); init_ctx->container->lxc_conf = lxc_conf_init();
if (!init_ctx->container->lxc_conf) { if (!init_ctx->container->lxc_conf) {

View File

@@ -41,7 +41,7 @@ struct lxc_proc_context_info {
int ns_fd[LXC_NS_MAX]; int ns_fd[LXC_NS_MAX];
}; };
extern int lxc_attach(const char *name, const char *lxcpath, extern int lxc_attach(struct lxc_container *container,
lxc_attach_exec_t exec_function, void *exec_payload, lxc_attach_exec_t exec_function, void *exec_payload,
lxc_attach_options_t *options, pid_t *attached_process); lxc_attach_options_t *options, pid_t *attached_process);

View File

@@ -4064,7 +4064,7 @@ static int lxcapi_attach(struct lxc_container *c, lxc_attach_exec_t exec_functio
current_config = c->lxc_conf; current_config = c->lxc_conf;
ret = lxc_attach(c->name, c->config_path, exec_function, exec_payload, options, attached_process); ret = lxc_attach(c, exec_function, exec_payload, options, attached_process);
current_config = NULL; current_config = NULL;
return ret; return ret;
} }
@@ -4081,7 +4081,7 @@ static int do_lxcapi_attach_run_wait(struct lxc_container *c, lxc_attach_options
command.program = (char*)program; command.program = (char*)program;
command.argv = (char**)argv; command.argv = (char**)argv;
r = lxc_attach(c->name, c->config_path, lxc_attach_run_command, &command, options, &pid); r = lxc_attach(c, lxc_attach_run_command, &command, options, &pid);
if (r < 0) { if (r < 0) {
ERROR("ups"); ERROR("ups");
return r; return r;