Unverified Commit 19462d43 by Serge Hallyn Committed by GitHub

Merge pull request #2193 from brauner/2018-02-27/naming_tweaks

tree-wide: introduce consistent and agnostic naming for ptys, ttys, and consoles
parents 7263b97f a44ae1a9
......@@ -26,7 +26,6 @@ noinst_HEADERS = \
conf.h \
confile.h \
confile_utils.h \
console.h \
error.h \
initutils.h \
list.h \
......@@ -37,6 +36,7 @@ noinst_HEADERS = \
namespace.h \
start.h \
state.h \
terminal.h \
utils.h \
criu.h \
../tests/lxctest.h
......@@ -100,7 +100,7 @@ liblxc_la_SOURCES = \
start.c start.h \
execute.c \
monitor.c monitor.h \
console.c \
terminal.c \
freezer.c \
error.h error.c \
parse.c parse.h \
......
......@@ -61,13 +61,13 @@
#include "conf.h"
#include "config.h"
#include "confile.h"
#include "console.h"
#include "log.h"
#include "lsm/lsm.h"
#include "lxclock.h"
#include "lxcseccomp.h"
#include "mainloop.h"
#include "namespace.h"
#include "terminal.h"
#include "utils.h"
#if HAVE_SYS_PERSONALITY_H
......@@ -974,20 +974,20 @@ on_error:
rexit(EXIT_FAILURE);
}
static int lxc_attach_pty(struct lxc_conf *conf, struct lxc_console *pty)
static int lxc_attach_pty(struct lxc_conf *conf, struct lxc_terminal *pty)
{
int ret;
lxc_pty_init(pty);
lxc_terminal_init(pty);
ret = lxc_pty_create(pty);
ret = lxc_terminal_create(pty);
if (ret < 0) {
SYSERROR("Failed to create pty");
return -1;
}
/* Shift ttys to container. */
ret = lxc_pty_map_ids(conf, pty);
ret = lxc_terminal_map_ids(conf, pty);
if (ret < 0) {
ERROR("Failed to shift pty");
goto on_error;
......@@ -996,12 +996,12 @@ static int lxc_attach_pty(struct lxc_conf *conf, struct lxc_console *pty)
return 0;
on_error:
lxc_console_delete(pty);
lxc_pty_conf_free(pty);
lxc_terminal_delete(pty);
lxc_terminal_conf_free(pty);
return -1;
}
static int lxc_attach_pty_mainloop_init(struct lxc_console *pty,
static int lxc_attach_pty_mainloop_init(struct lxc_terminal *pty,
struct lxc_epoll_descr *descr)
{
int ret;
......@@ -1012,7 +1012,7 @@ static int lxc_attach_pty_mainloop_init(struct lxc_console *pty,
return -1;
}
ret = lxc_console_mainloop_add(descr, pty);
ret = lxc_terminal_mainloop_add(descr, pty);
if (ret < 0) {
ERROR("Failed to add handlers to mainloop");
lxc_mainloop_close(descr);
......@@ -1022,7 +1022,7 @@ static int lxc_attach_pty_mainloop_init(struct lxc_console *pty,
return 0;
}
static inline void lxc_attach_pty_close_master(struct lxc_console *pty)
static inline void lxc_attach_pty_close_master(struct lxc_terminal *pty)
{
if (pty->master < 0)
return;
......@@ -1031,7 +1031,7 @@ static inline void lxc_attach_pty_close_master(struct lxc_console *pty)
pty->master = -EBADF;
}
static inline void lxc_attach_pty_close_slave(struct lxc_console *pty)
static inline void lxc_attach_pty_close_slave(struct lxc_terminal *pty)
{
if (pty->slave < 0)
return;
......@@ -1040,7 +1040,7 @@ static inline void lxc_attach_pty_close_slave(struct lxc_console *pty)
pty->slave = -EBADF;
}
static inline void lxc_attach_pty_close_peer(struct lxc_console *pty)
static inline void lxc_attach_pty_close_peer(struct lxc_terminal *pty)
{
if (pty->peer < 0)
return;
......@@ -1049,7 +1049,7 @@ static inline void lxc_attach_pty_close_peer(struct lxc_console *pty)
pty->peer = -EBADF;
}
static inline void lxc_attach_pty_close_log(struct lxc_console *pty)
static inline void lxc_attach_pty_close_log(struct lxc_terminal *pty)
{
if (pty->log_fd < 0)
return;
......@@ -1068,7 +1068,7 @@ int lxc_attach(const char *name, const char *lxcpath,
signed long personality;
pid_t attached_pid, init_pid, pid;
struct lxc_proc_context_info *init_ctx;
struct lxc_console pty;
struct lxc_terminal pty;
struct lxc_conf *conf;
struct attach_clone_payload payload = {0};
......@@ -1198,7 +1198,7 @@ int lxc_attach(const char *name, const char *lxcpath,
pty.log_fd = options->log_fd;
} else {
lxc_pty_init(&pty);
lxc_terminal_init(&pty);
}
/* Create a socket pair for IPC communication; set SOCK_CLOEXEC in order
......@@ -1386,8 +1386,8 @@ int lxc_attach(const char *name, const char *lxcpath,
(void)wait_for_pid(to_cleanup_pid);
if (options->attach_flags & LXC_ATTACH_ALLOCATE_PTY) {
lxc_console_delete(&pty);
lxc_pty_conf_free(&pty);
lxc_terminal_delete(&pty);
lxc_terminal_conf_free(&pty);
}
lxc_proc_put_context_info(init_ctx);
return ret_parent;
......
......@@ -843,13 +843,11 @@ static bool all_controllers_found(void)
if (!cgroup_use)
return true;
for (p = strtok_r(cgroup_use, ",", &saveptr); p;
p = strtok_r(NULL, ",", &saveptr)) {
for (; (p = strtok_r(cgroup_use, ",", &saveptr)); cgroup_use = NULL)
if (!controller_found(hlist, p)) {
CGFSNG_DEBUG("No %s controller mountpoint found\n", p);
return false;
}
}
return true;
}
......
......@@ -42,13 +42,13 @@
#include "commands_utils.h"
#include "conf.h"
#include "confile.h"
#include "console.h"
#include "log.h"
#include "lxc.h"
#include "lxclock.h"
#include "mainloop.h"
#include "monitor.h"
#include "start.h"
#include "terminal.h"
#include "utils.h"
/*
......@@ -82,7 +82,7 @@ static const char *lxc_cmd_str(lxc_cmd_t cmd)
{
static const char *const cmdname[LXC_CMD_MAX] = {
[LXC_CMD_CONSOLE] = "console",
[LXC_CMD_CONSOLE_WINCH] = "console_winch",
[LXC_CMD_TERMINAL_WINCH] = "terminal_winch",
[LXC_CMD_STOP] = "stop",
[LXC_CMD_GET_STATE] = "get_state",
[LXC_CMD_GET_INIT_PID] = "get_init_pid",
......@@ -659,18 +659,18 @@ static int lxc_cmd_stop_callback(int fd, struct lxc_cmd_req *req,
}
/*
* lxc_cmd_console_winch: To process as if a SIGWINCH were received
* lxc_cmd_terminal_winch: To process as if a SIGWINCH were received
*
* @name : name of container to connect to
* @lxcpath : the lxcpath in which the container is running
*
* Returns 0 on success, < 0 on failure
*/
int lxc_cmd_console_winch(const char *name, const char *lxcpath)
int lxc_cmd_terminal_winch(const char *name, const char *lxcpath)
{
int ret, stopped;
struct lxc_cmd_rr cmd = {
.req = { .cmd = LXC_CMD_CONSOLE_WINCH },
.req = { .cmd = LXC_CMD_TERMINAL_WINCH },
};
ret = lxc_cmd(name, &cmd, &stopped, lxcpath, NULL);
......@@ -680,12 +680,12 @@ int lxc_cmd_console_winch(const char *name, const char *lxcpath)
return 0;
}
static int lxc_cmd_console_winch_callback(int fd, struct lxc_cmd_req *req,
struct lxc_handler *handler)
static int lxc_cmd_terminal_winch_callback(int fd, struct lxc_cmd_req *req,
struct lxc_handler *handler)
{
struct lxc_cmd_rsp rsp = { .data = 0 };
lxc_console_sigwinch(SIGWINCH);
lxc_terminal_sigwinch(SIGWINCH);
return lxc_cmd_rsp_send(fd, &rsp);
}
......@@ -748,7 +748,7 @@ static int lxc_cmd_console_callback(int fd, struct lxc_cmd_req *req,
struct lxc_cmd_rsp rsp;
int ttynum = PTR_TO_INT(req->data);
masterfd = lxc_console_allocate(handler->conf, fd, &ttynum);
masterfd = lxc_terminal_allocate(handler->conf, fd, &ttynum);
if (masterfd < 0)
goto out_close;
......@@ -757,7 +757,7 @@ static int lxc_cmd_console_callback(int fd, struct lxc_cmd_req *req,
ret = lxc_abstract_unix_send_fds(fd, &masterfd, 1, &rsp, sizeof(rsp));
if (ret < 0) {
ERROR("Failed to send tty to client");
lxc_console_free(handler->conf, fd);
lxc_terminal_free(handler->conf, fd);
goto out_close;
}
......@@ -991,8 +991,7 @@ static int lxc_cmd_console_log_callback(int fd, struct lxc_cmd_req *req,
rsp.ret = 0;
if (log->clear)
/* clear the ringbuffer */
lxc_ringbuf_clear(buf);
lxc_ringbuf_clear(buf); /* clear the ringbuffer */
else if (rsp.datalen > 0)
lxc_ringbuf_move_read_addr(buf, rsp.datalen);
......@@ -1052,7 +1051,7 @@ static int lxc_cmd_process(int fd, struct lxc_cmd_req *req,
callback cb[LXC_CMD_MAX] = {
[LXC_CMD_CONSOLE] = lxc_cmd_console_callback,
[LXC_CMD_CONSOLE_WINCH] = lxc_cmd_console_winch_callback,
[LXC_CMD_TERMINAL_WINCH] = lxc_cmd_terminal_winch_callback,
[LXC_CMD_STOP] = lxc_cmd_stop_callback,
[LXC_CMD_GET_STATE] = lxc_cmd_get_state_callback,
[LXC_CMD_GET_INIT_PID] = lxc_cmd_get_init_pid_callback,
......@@ -1080,7 +1079,7 @@ static void lxc_cmd_fd_cleanup(int fd, struct lxc_handler *handler,
struct lxc_state_client *client;
struct lxc_list *cur, *next;
lxc_console_free(handler->conf, fd);
lxc_terminal_free(handler->conf, fd);
lxc_mainloop_del_handler(descr, fd);
if (cmd != LXC_CMD_ADD_STATE_CLIENT) {
close(fd);
......
......@@ -39,7 +39,7 @@
typedef enum {
LXC_CMD_CONSOLE,
LXC_CMD_CONSOLE_WINCH,
LXC_CMD_TERMINAL_WINCH,
LXC_CMD_STOP,
LXC_CMD_GET_STATE,
LXC_CMD_GET_INIT_PID,
......@@ -84,7 +84,7 @@ struct lxc_cmd_console_log {
};
extern int lxc_cmd_console_winch(const char *name, const char *lxcpath);
extern int lxc_cmd_terminal_winch(const char *name, const char *lxcpath);
extern int lxc_cmd_console(const char *name, int *ttynum, int *fd,
const char *lxcpath);
/*
......
......@@ -73,9 +73,9 @@
#include "cgroup.h"
#include "conf.h"
#include "confile_utils.h"
#include "console.h"
#include "error.h"
#include "log.h"
#include "lsm/lsm.h"
#include "lxclock.h"
#include "lxcseccomp.h"
#include "namespace.h"
......@@ -85,8 +85,8 @@
#include "storage.h"
#include "storage/aufs.h"
#include "storage/overlay.h"
#include "terminal.h"
#include "utils.h"
#include "lsm/lsm.h"
#if HAVE_LIBCAP
#include <sys/capability.h>
......@@ -840,15 +840,15 @@ static bool append_ptyname(char **pp, char *name)
static int lxc_setup_ttys(struct lxc_conf *conf)
{
int i, ret;
const struct lxc_tty_info *tty_info = &conf->tty_info;
const struct lxc_tty_info *ttys = &conf->ttys;
char *ttydir = conf->ttydir;
char path[MAXPATHLEN], lxcpath[MAXPATHLEN];
if (!conf->rootfs.path)
return 0;
for (i = 0; i < tty_info->nbtty; i++) {
struct lxc_pty_info *pty_info = &tty_info->pty_info[i];
for (i = 0; i < ttys->nbtty; i++) {
struct lxc_terminal_info *tty = &ttys->tty[i];
ret = snprintf(path, sizeof(path), "/dev/tty%d", i + 1);
if (ret < 0 || (size_t)ret >= sizeof(path))
......@@ -875,13 +875,13 @@ static int lxc_setup_ttys(struct lxc_conf *conf)
return -1;
}
ret = mount(pty_info->name, lxcpath, "none", MS_BIND, 0);
ret = mount(tty->name, lxcpath, "none", MS_BIND, 0);
if (ret < 0) {
WARN("Failed to bind mount \"%s\" onto \"%s\"",
pty_info->name, path);
tty->name, path);
continue;
}
DEBUG("bind mounted \"%s\" onto \"%s\"", pty_info->name,
DEBUG("bind mounted \"%s\" onto \"%s\"", tty->name,
path);
ret = snprintf(lxcpath, sizeof(lxcpath), "%s/tty%d",
......@@ -910,99 +910,97 @@ static int lxc_setup_ttys(struct lxc_conf *conf)
}
}
ret = mount(pty_info->name, path, "none", MS_BIND, 0);
ret = mount(tty->name, path, "none", MS_BIND, 0);
if (ret < 0) {
SYSERROR("Failed to mount '%s'->'%s'", pty_info->name, path);
SYSERROR("Failed to mount '%s'->'%s'", tty->name, path);
continue;
}
DEBUG("Bind mounted \"%s\" onto \"%s\"", pty_info->name,
DEBUG("Bind mounted \"%s\" onto \"%s\"", tty->name,
path);
}
if (!append_ptyname(&conf->pty_names, pty_info->name)) {
if (!append_ptyname(&conf->pty_names, tty->name)) {
ERROR("Error setting up container_ttys string");
return -1;
}
}
INFO("Finished setting up %d /dev/tty<N> device(s)", tty_info->nbtty);
INFO("Finished setting up %d /dev/tty<N> device(s)", ttys->nbtty);
return 0;
}
int lxc_allocate_ttys(const char *name, struct lxc_conf *conf)
{
struct lxc_tty_info *tty_info = &conf->tty_info;
struct lxc_tty_info *ttys = &conf->ttys;
int i, ret;
/* no tty in the configuration */
if (!conf->tty)
return 0;
tty_info->pty_info = malloc(sizeof(*tty_info->pty_info) * conf->tty);
if (!tty_info->pty_info) {
SYSERROR("failed to allocate struct *pty_info");
ttys->tty = malloc(sizeof(*ttys->tty) * conf->tty);
if (!ttys->tty)
return -ENOMEM;
}
for (i = 0; i < conf->tty; i++) {
struct lxc_pty_info *pty_info = &tty_info->pty_info[i];
struct lxc_terminal_info *tty = &ttys->tty[i];
ret = openpty(&pty_info->master, &pty_info->slave,
pty_info->name, NULL, NULL);
ret = openpty(&tty->master, &tty->slave,
tty->name, NULL, NULL);
if (ret) {
SYSERROR("failed to create pty device number %d", i);
tty_info->nbtty = i;
lxc_delete_tty(tty_info);
ttys->nbtty = i;
lxc_delete_tty(ttys);
return -ENOTTY;
}
DEBUG("allocated pty \"%s\" with master fd %d and slave fd %d",
pty_info->name, pty_info->master, pty_info->slave);
tty->name, tty->master, tty->slave);
/* Prevent leaking the file descriptors to the container */
ret = fcntl(pty_info->master, F_SETFD, FD_CLOEXEC);
ret = fcntl(tty->master, F_SETFD, FD_CLOEXEC);
if (ret < 0)
WARN("failed to set FD_CLOEXEC flag on master fd %d of "
"pty device \"%s\": %s",
pty_info->master, pty_info->name, strerror(errno));
tty->master, tty->name, strerror(errno));
ret = fcntl(pty_info->slave, F_SETFD, FD_CLOEXEC);
ret = fcntl(tty->slave, F_SETFD, FD_CLOEXEC);
if (ret < 0)
WARN("failed to set FD_CLOEXEC flag on slave fd %d of "
"pty device \"%s\": %s",
pty_info->slave, pty_info->name, strerror(errno));
tty->slave, tty->name, strerror(errno));
pty_info->busy = 0;
tty->busy = 0;
}
tty_info->nbtty = conf->tty;
ttys->nbtty = conf->tty;
INFO("finished allocating %d pts devices", conf->tty);
return 0;
}
void lxc_delete_tty(struct lxc_tty_info *tty_info)
void lxc_delete_tty(struct lxc_tty_info *ttys)
{
int i;
for (i = 0; i < tty_info->nbtty; i++) {
struct lxc_pty_info *pty_info = &tty_info->pty_info[i];
for (i = 0; i < ttys->nbtty; i++) {
struct lxc_terminal_info *tty = &ttys->tty[i];
close(pty_info->master);
close(pty_info->slave);
close(tty->master);
close(tty->slave);
}
free(tty_info->pty_info);
tty_info->pty_info = NULL;
tty_info->nbtty = 0;
free(ttys->tty);
ttys->tty = NULL;
ttys->nbtty = 0;
}
static int lxc_send_ttys_to_parent(struct lxc_handler *handler)
{
int i;
struct lxc_conf *conf = handler->conf;
struct lxc_tty_info *tty_info = &conf->tty_info;
struct lxc_tty_info *ttys = &conf->ttys;
int sock = handler->data_sock[0];
int ret = -1;
......@@ -1011,17 +1009,17 @@ static int lxc_send_ttys_to_parent(struct lxc_handler *handler)
for (i = 0; i < conf->tty; i++) {
int ttyfds[2];
struct lxc_pty_info *pty_info = &tty_info->pty_info[i];
struct lxc_terminal_info *tty = &ttys->tty[i];
ttyfds[0] = pty_info->master;
ttyfds[1] = pty_info->slave;
ttyfds[0] = tty->master;
ttyfds[1] = tty->slave;
ret = lxc_abstract_unix_send_fds(sock, ttyfds, 2, NULL, 0);
if (ret < 0)
break;
TRACE("Send pty \"%s\" with master fd %d and slave fd %d to "
"parent", pty_info->name, pty_info->master, pty_info->slave);
"parent", tty->name, tty->master, tty->slave);
}
if (ret < 0)
......@@ -1067,7 +1065,7 @@ static int lxc_create_ttys(struct lxc_handler *handler)
ret = 0;
on_error:
lxc_delete_tty(&conf->tty_info);
lxc_delete_tty(&conf->ttys);
return ret;
}
......@@ -1578,7 +1576,7 @@ static int setup_personality(int persona)
}
static int lxc_setup_dev_console(const struct lxc_rootfs *rootfs,
const struct lxc_console *console)
const struct lxc_terminal *console)
{
char path[MAXPATHLEN];
int ret, fd;
......@@ -1634,7 +1632,7 @@ static int lxc_setup_dev_console(const struct lxc_rootfs *rootfs,
}
static int lxc_setup_ttydir_console(const struct lxc_rootfs *rootfs,
const struct lxc_console *console,
const struct lxc_terminal *console,
char *ttydir)
{
int ret, fd;
......@@ -1720,7 +1718,7 @@ static int lxc_setup_ttydir_console(const struct lxc_rootfs *rootfs,
}
static int lxc_setup_console(const struct lxc_rootfs *rootfs,
const struct lxc_console *console, char *ttydir)
const struct lxc_terminal *console, char *ttydir)
{
if (!ttydir)
......@@ -2615,9 +2613,9 @@ struct lxc_conf *lxc_conf_init(void)
new->console.log_size = 0;
new->console.path = NULL;
new->console.peer = -1;
new->console.peerpty.busy = -1;
new->console.peerpty.master = -1;
new->console.peerpty.slave = -1;
new->console.proxy.busy = -1;
new->console.proxy.master = -1;
new->console.proxy.slave = -1;
new->console.master = -1;
new->console.slave = -1;
new->console.name[0] = '\0';
......@@ -3786,7 +3784,7 @@ void lxc_conf_free(struct lxc_conf *conf)
return;
if (current_config == conf)
current_config = NULL;
lxc_pty_conf_free(&conf->console);
lxc_terminal_conf_free(&conf->console);
free(conf->rootfs.mount);
free(conf->rootfs.bdev_type);
free(conf->rootfs.options);
......
......@@ -38,6 +38,7 @@
#include "list.h"
#include "ringbuf.h"
#include "start.h" /* for lxc_handler */
#include "terminal.h"
#if HAVE_SCMP_FILTER_CTX
typedef void * scmp_filter_ctx;
......@@ -133,73 +134,16 @@ struct id_map {
unsigned long hostid, nsid, range;
};
/*
* Defines a structure containing a pty information for
* virtualizing a tty
* @name : the path name of the slave pty side
* @master : the file descriptor of the master
* @slave : the file descriptor of the slave
*/
struct lxc_pty_info {
char name[MAXPATHLEN];
int master;
int slave;
int busy;
};
/*
* Defines the number of tty configured and contains the
/* Defines the number of tty configured and contains the
* instantiated ptys
* @nbtty = number of configured ttys
*/
struct lxc_tty_info {
int nbtty;
struct lxc_pty_info *pty_info;
};
struct lxc_tty_state;
/*
* Defines the structure to store the console information
* @peer : the file descriptor put/get console traffic
* @name : the file name of the slave pty
*/
struct lxc_console {
int slave;
int master;
int peer;
struct lxc_pty_info peerpty;
struct lxc_epoll_descr *descr;
char *path;
char name[MAXPATHLEN];
struct termios *tios;
struct lxc_tty_state *tty_state;
struct /* lxc_console_log */ {
/* size of the log file */
uint64_t log_size;
/* path to the log file */
char *log_path;
/* fd to the log file */
int log_fd;
/* whether the log file will be rotated */
unsigned int log_rotate;
};
struct /* lxc_console_ringbuf */ {
/* size of the ringbuffer */
uint64_t buffer_size;
/* the in-memory ringbuffer */
struct lxc_ringbuf ringbuf;
};
struct lxc_terminal_info *tty;
};
/*
* Defines a structure to store the rootfs location, the
/* Defines a structure to store the rootfs location, the
* optionals pivot_root, rootfs mount paths
* @path : the rootfs source (directory or device)
* @mount : where it is mounted
......@@ -256,7 +200,7 @@ enum {
* @fstab : path to a fstab file format
* @caps : list of the capabilities to drop
* @keepcaps : list of the capabilities to keep
* @tty_info : tty data
* @ttys : tty data
* @console : console data
* @ttydir : directory (under /dev) in which to create console and ttys
* @lsm_aa_profile : apparmor profile to switch to or NULL
......@@ -311,10 +255,10 @@ struct lxc_conf {
struct lxc_list mount_list;
struct lxc_list caps;
struct lxc_list keepcaps;
struct lxc_tty_info tty_info;
struct lxc_tty_info ttys;
/* Comma-separated list of lxc.tty.max pty names. */
char *pty_names;
struct lxc_console console;
struct lxc_terminal console;
struct lxc_rootfs rootfs;
char *ttydir;
int close_all_fds;
......@@ -440,7 +384,7 @@ extern void lxc_conf_free(struct lxc_conf *conf);
extern int pin_rootfs(const char *rootfs);
extern int lxc_map_ids(struct lxc_list *idmap, pid_t pid);
extern int lxc_create_tty(const char *name, struct lxc_conf *conf);
extern void lxc_delete_tty(struct lxc_tty_info *tty_info);
extern void lxc_delete_tty(struct lxc_tty_info *ttys);
extern int lxc_clear_config_caps(struct lxc_conf *c);
extern int lxc_clear_config_keepcaps(struct lxc_conf *c);
extern int lxc_clear_cgroups(struct lxc_conf *c, const char *key, int version);
......
......@@ -176,7 +176,7 @@ static void exec_criu(struct criu_opts *opts)
FILE *mnts;
struct mntent mntent;
char buf[4096], tty_info[32];
char buf[4096], ttys[32];
size_t pos;
/* If we are currently in a cgroup /foo/bar, and the container is in a
......@@ -233,12 +233,12 @@ static void exec_criu(struct criu_opts *opts)
*/
static_args += 6;
tty_info[0] = 0;
if (load_tty_major_minor(opts->user->directory, tty_info, sizeof(tty_info)))
ttys[0] = 0;
if (load_tty_major_minor(opts->user->directory, ttys, sizeof(ttys)))
return;
/* --inherit-fd fd[%d]:tty[%s] */
if (tty_info[0])
if (ttys[0])
static_args += 2;
} else {
return;
......@@ -493,13 +493,13 @@ static void exec_criu(struct criu_opts *opts)
DECLARE_ARG("--restore-detached");
DECLARE_ARG("--restore-sibling");
if (tty_info[0]) {
if (ttys[0]) {
if (opts->console_fd < 0) {
ERROR("lxc.console.path configured on source host but not target");
goto err;
}
ret = snprintf(buf, sizeof(buf), "fd[%d]:%s", opts->console_fd, tty_info);
ret = snprintf(buf, sizeof(buf), "fd[%d]:%s", opts->console_fd, ttys);
if (ret < 0 || ret >= sizeof(buf))
goto err;
......
......@@ -47,7 +47,6 @@
#include "commands_utils.h"
#include "confile.h"
#include "confile_utils.h"
#include "console.h"
#include "criu.h"
#include "error.h"
#include "initutils.h"
......@@ -66,6 +65,7 @@
#include "storage/btrfs.h"
#include "storage/overlay.h"
#include "sync.h"
#include "terminal.h"
#include "utils.h"
#include "version.h"
......@@ -526,7 +526,7 @@ static int do_lxcapi_console_getfd(struct lxc_container *c, int *ttynum, int *ma
if (!c)
return -1;
return lxc_console_getfd(c, ttynum, masterfd);
return lxc_terminal_getfd(c, ttynum, masterfd);
}
WRAP_API_2(int, lxcapi_console_getfd, int *, int *)
......
......@@ -71,9 +71,9 @@
#include "commands_utils.h"
#include "conf.h"
#include "confile_utils.h"
#include "console.h"
#include "error.h"
#include "list.h"
#include "lsm/lsm.h"
#include "log.h"
#include "lxccontainer.h"
#include "lxclock.h"
......@@ -83,11 +83,11 @@
#include "namespace.h"
#include "network.h"
#include "start.h"
#include "sync.h"
#include "utils.h"
#include "lsm/lsm.h"
#include "storage/storage.h"
#include "storage/storage_utils.h"
#include "sync.h"
#include "terminal.h"
#include "utils.h"
lxc_log_define(lxc_start, lxc);
......@@ -529,15 +529,15 @@ int lxc_poll(const char *name, struct lxc_handler *handler)
}
if (has_console) {
struct lxc_console *console = &handler->conf->console;
struct lxc_terminal *console = &handler->conf->console;
ret = lxc_console_mainloop_add(&descr, console);
ret = lxc_terminal_mainloop_add(&descr, console);
if (ret < 0) {
ERROR("Failed to add console handlers to mainloop");
goto out_mainloop_console;
}
ret = lxc_console_mainloop_add(&descr_console, console);
ret = lxc_terminal_mainloop_add(&descr_console, console);
if (ret < 0) {
ERROR("Failed to add console handlers to console mainloop");
goto out_mainloop_console;
......@@ -804,14 +804,14 @@ int lxc_init(const char *name, struct lxc_handler *handler)
TRACE("Set up signal fd");
/* Do this after setting up signals since it might unblock SIGWINCH. */
ret = lxc_console_create(conf);
ret = lxc_terminal_setup(conf);
if (ret < 0) {
ERROR("Failed to create console");
goto out_restore_sigmask;
}
TRACE("Created console");
ret = lxc_pty_map_ids(conf, &conf->console);
ret = lxc_terminal_map_ids(conf, &conf->console);
if (ret < 0) {
ERROR("Failed to chown console");
goto out_restore_sigmask;
......@@ -824,7 +824,7 @@ int lxc_init(const char *name, struct lxc_handler *handler)
out_restore_sigmask:
sigprocmask(SIG_SETMASK, &handler->oldmask, NULL);
out_delete_tty:
lxc_delete_tty(&conf->tty_info);
lxc_delete_tty(&conf->ttys);
out_aborting:
lxc_set_state(name, handler, ABORTING);
out_close_maincmd_fd:
......@@ -950,8 +950,8 @@ void lxc_fini(const char *name, struct lxc_handler *handler)
if (ret < 0)
WARN("%s - Failed to restore signal mask", strerror(errno));
lxc_console_delete(&handler->conf->console);
lxc_delete_tty(&handler->conf->tty_info);
lxc_terminal_delete(&handler->conf->console);
lxc_delete_tty(&handler->conf->ttys);
/* The command socket is now closed, no more state clients can register
* themselves from now on. So free the list of state clients.
......@@ -1198,14 +1198,14 @@ static int do_start(void *data)
/* Some init's such as busybox will set sane tty settings on stdin,
* stdout, stderr which it thinks is the console. We already set them
* the way we wanted on the real terminal, and we want init to do its
* setup on its console ie. the pty allocated in lxc_console_create() so
* setup on its console ie. the pty allocated in lxc_terminal_setup() so
* make sure that that pty is stdin,stdout,stderr.
*/
if (handler->conf->console.slave >= 0) {
if (handler->backgrounded || handler->conf->is_execute == 0)
ret = set_stdfds(handler->conf->console.slave);
else
ret = lxc_console_set_stdfds(handler->conf->console.slave);
ret = lxc_terminal_set_stdfds(handler->conf->console.slave);
if (ret < 0) {
ERROR("Failed to redirect std{in,out,err} to pty file "
"descriptor %d", handler->conf->console.slave);
......@@ -1340,17 +1340,17 @@ out_error:
static int lxc_recv_ttys_from_child(struct lxc_handler *handler)
{
int i;
struct lxc_pty_info *pty_info;
struct lxc_terminal_info *tty;
int ret = -1;
int sock = handler->data_sock[1];
struct lxc_conf *conf = handler->conf;
struct lxc_tty_info *tty_info = &conf->tty_info;
struct lxc_tty_info *ttys = &conf->ttys;
if (!conf->tty)
return 0;
tty_info->pty_info = malloc(sizeof(*tty_info->pty_info) * conf->tty);
if (!tty_info->pty_info)
ttys->tty = malloc(sizeof(*ttys->tty) * conf->tty);
if (!ttys->tty)
return -1;
for (i = 0; i < conf->tty; i++) {
......@@ -1360,12 +1360,12 @@ static int lxc_recv_ttys_from_child(struct lxc_handler *handler)
if (ret < 0)
break;
pty_info = &tty_info->pty_info[i];
pty_info->busy = 0;
pty_info->master = ttyfds[0];
pty_info->slave = ttyfds[1];
tty = &ttys->tty[i];
tty->busy = 0;
tty->master = ttyfds[0];
tty->slave = ttyfds[1];
TRACE("Received pty with master fd %d and slave fd %d from "
"parent", pty_info->master, pty_info->slave);
"parent", tty->master, tty->slave);
}
if (ret < 0)
ERROR("Failed to receive %d ttys from child: %s", conf->tty,
......@@ -1373,7 +1373,7 @@ static int lxc_recv_ttys_from_child(struct lxc_handler *handler)
else
TRACE("Received %d ttys from child", conf->tty);
tty_info->nbtty = conf->tty;
ttys->nbtty = conf->tty;
return ret;
}
......
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