[lxc-devel] [lxc/master] tree-wide: introduce consistent and agnostic naming for ptys, ttys, and consoles
brauner on Github
lxc-bot at linuxcontainers.org
Tue Feb 27 17:35:49 UTC 2018
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 411 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20180227/5d20d4e3/attachment.bin>
-------------- next part --------------
From 4ee8924665f3a7a038615c7fe9ea8c164884b957 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Tue, 27 Feb 2018 15:57:16 +0100
Subject: [PATCH 01/42] cgfsng: non-functional changes
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
src/lxc/cgroups/cgfsng.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/src/lxc/cgroups/cgfsng.c b/src/lxc/cgroups/cgfsng.c
index 08b49ede3..10c7ab2cf 100644
--- a/src/lxc/cgroups/cgfsng.c
+++ b/src/lxc/cgroups/cgfsng.c
@@ -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;
}
From fd2a9dc9cf12c9946d3ba8b233eee87faba64ea7 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Tue, 27 Feb 2018 15:57:31 +0100
Subject: [PATCH 02/42] tree-wide: s/struct lxc_console/struct lxc_pty/g
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
src/lxc/attach.c | 14 +++++++-------
src/lxc/commands.c | 2 +-
src/lxc/conf.c | 6 +++---
src/lxc/conf.h | 6 +++---
src/lxc/console.c | 36 ++++++++++++++++++------------------
src/lxc/console.h | 16 ++++++++--------
src/lxc/start.c | 2 +-
7 files changed, 41 insertions(+), 41 deletions(-)
diff --git a/src/lxc/attach.c b/src/lxc/attach.c
index 28c2cadfd..58e17fb6a 100644
--- a/src/lxc/attach.c
+++ b/src/lxc/attach.c
@@ -974,7 +974,7 @@ static int attach_child_main(struct attach_clone_payload *payload)
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_pty *pty)
{
int ret;
@@ -1001,7 +1001,7 @@ static int lxc_attach_pty(struct lxc_conf *conf, struct lxc_console *pty)
return -1;
}
-static int lxc_attach_pty_mainloop_init(struct lxc_console *pty,
+static int lxc_attach_pty_mainloop_init(struct lxc_pty *pty,
struct lxc_epoll_descr *descr)
{
int ret;
@@ -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_pty *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_pty *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_pty *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_pty *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_pty pty;
struct lxc_conf *conf;
struct attach_clone_payload payload = {0};
diff --git a/src/lxc/commands.c b/src/lxc/commands.c
index 2246b0c4a..7b919d28c 100644
--- a/src/lxc/commands.c
+++ b/src/lxc/commands.c
@@ -968,7 +968,7 @@ static int lxc_cmd_console_log_callback(int fd, struct lxc_cmd_req *req,
struct lxc_cmd_rsp rsp;
uint64_t buffer_size = handler->conf->console.buffer_size;
const struct lxc_cmd_console_log *log = req->data;
- struct lxc_console *console = &handler->conf->console;
+ struct lxc_pty *console = &handler->conf->console;
struct lxc_ringbuf *buf = &handler->conf->console.ringbuf;
rsp.ret = -EFAULT;
diff --git a/src/lxc/conf.c b/src/lxc/conf.c
index 1ec915191..944546c66 100644
--- a/src/lxc/conf.c
+++ b/src/lxc/conf.c
@@ -1578,7 +1578,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_pty *console)
{
char path[MAXPATHLEN];
int ret, fd;
@@ -1634,7 +1634,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_pty *console,
char *ttydir)
{
int ret, fd;
@@ -1720,7 +1720,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_pty *console, char *ttydir)
{
if (!ttydir)
diff --git a/src/lxc/conf.h b/src/lxc/conf.h
index 388c0518c..e5c39cda3 100644
--- a/src/lxc/conf.h
+++ b/src/lxc/conf.h
@@ -164,7 +164,7 @@ struct lxc_tty_state;
* @peer : the file descriptor put/get console traffic
* @name : the file name of the slave pty
*/
-struct lxc_console {
+struct lxc_pty {
int slave;
int master;
int peer;
@@ -177,7 +177,7 @@ struct lxc_console {
char name[MAXPATHLEN];
struct termios *tios;
struct lxc_tty_state *tty_state;
- struct /* lxc_console_ringbuf */ {
+ struct /* lxc_pty_ringbuf */ {
/* size of the ringbuffer */
uint64_t buffer_size;
@@ -308,7 +308,7 @@ struct lxc_conf {
struct lxc_tty_info tty_info;
/* Comma-separated list of lxc.tty.max pty names. */
char *pty_names;
- struct lxc_console console;
+ struct lxc_pty console;
struct lxc_rootfs rootfs;
char *ttydir;
int close_all_fds;
diff --git a/src/lxc/console.c b/src/lxc/console.c
index a415e6a68..4844c8a03 100644
--- a/src/lxc/console.c
+++ b/src/lxc/console.c
@@ -207,7 +207,7 @@ void lxc_console_signal_fini(struct lxc_tty_state *ts)
int lxc_console_cb_con(int fd, uint32_t events, void *data,
struct lxc_epoll_descr *descr)
{
- struct lxc_console *console = (struct lxc_console *)data;
+ struct lxc_pty *console = data;
char buf[LXC_CONSOLE_BUFFER_SIZE];
int r, w, w_log, w_rbuf;
@@ -263,7 +263,7 @@ int lxc_console_cb_con(int fd, uint32_t events, void *data,
return 0;
}
-static int lxc_console_mainloop_add_peer(struct lxc_console *console)
+static int lxc_console_mainloop_add_peer(struct lxc_pty *console)
{
int ret;
@@ -290,7 +290,7 @@ static int lxc_console_mainloop_add_peer(struct lxc_console *console)
}
int lxc_console_mainloop_add(struct lxc_epoll_descr *descr,
- struct lxc_console *console)
+ struct lxc_pty *console)
{
int ret;
@@ -365,7 +365,7 @@ int lxc_setup_tios(int fd, struct termios *oldtios)
return 0;
}
-static void lxc_console_peer_proxy_free(struct lxc_console *console)
+static void lxc_console_peer_proxy_free(struct lxc_pty *console)
{
if (console->tty_state) {
lxc_console_signal_fini(console->tty_state);
@@ -380,7 +380,7 @@ static void lxc_console_peer_proxy_free(struct lxc_console *console)
console->peer = -1;
}
-static int lxc_console_peer_proxy_alloc(struct lxc_console *console, int sockfd)
+static int lxc_console_peer_proxy_alloc(struct lxc_pty *console, int sockfd)
{
struct termios oldtermio;
struct lxc_tty_state *ts;
@@ -435,7 +435,7 @@ int lxc_console_allocate(struct lxc_conf *conf, int sockfd, int *ttyreq)
{
int masterfd = -1, ttynum;
struct lxc_tty_info *tty_info = &conf->tty_info;
- struct lxc_console *console = &conf->console;
+ struct lxc_pty *console = &conf->console;
if (*ttyreq == 0) {
if (lxc_console_peer_proxy_alloc(console, sockfd) < 0)
@@ -477,7 +477,7 @@ void lxc_console_free(struct lxc_conf *conf, int fd)
{
int i;
struct lxc_tty_info *tty_info = &conf->tty_info;
- struct lxc_console *console = &conf->console;
+ struct lxc_pty *console = &conf->console;
for (i = 0; i < tty_info->nbtty; i++) {
if (tty_info->pty_info[i].busy == fd)
@@ -490,7 +490,7 @@ void lxc_console_free(struct lxc_conf *conf, int fd)
}
}
-static int lxc_console_peer_default(struct lxc_console *console)
+static int lxc_console_peer_default(struct lxc_pty *console)
{
struct lxc_tty_state *ts;
const char *path = console->path;
@@ -559,7 +559,7 @@ static int lxc_console_peer_default(struct lxc_console *console)
return ret;
}
-int lxc_console_write_ringbuffer(struct lxc_console *console)
+int lxc_console_write_ringbuffer(struct lxc_pty *console)
{
char *r_addr;
ssize_t ret;
@@ -581,7 +581,7 @@ int lxc_console_write_ringbuffer(struct lxc_console *console)
return 0;
}
-void lxc_console_delete(struct lxc_console *console)
+void lxc_console_delete(struct lxc_pty *console)
{
int ret;
@@ -622,7 +622,7 @@ void lxc_console_delete(struct lxc_console *console)
* ringbuffer log file is (implementation wise not content wise) independent of
* the console log file.
*/
-static int lxc_console_create_ringbuf_log_file(struct lxc_console *console)
+static int lxc_console_create_ringbuf_log_file(struct lxc_pty *console)
{
if (!console->buffer_log_file)
return 0;
@@ -644,7 +644,7 @@ static int lxc_console_create_ringbuf_log_file(struct lxc_console *console)
* register a handler for the console's masterfd when we create the mainloop
* the console handler needs to see an allocated ringbuffer.
*/
-static int lxc_console_create_ringbuf(struct lxc_console *console)
+static int lxc_console_create_ringbuf(struct lxc_pty *console)
{
int ret;
struct lxc_ringbuf *buf = &console->ringbuf;
@@ -690,7 +690,7 @@ static int lxc_console_create_ringbuf(struct lxc_console *console)
* This is the console log file. Please note that the console log file is
* (implementation wise not content wise) independent of the console ringbuffer.
*/
-int lxc_console_create_log_file(struct lxc_console *console)
+int lxc_console_create_log_file(struct lxc_pty *console)
{
if (!console->log_path)
return 0;
@@ -705,7 +705,7 @@ int lxc_console_create_log_file(struct lxc_console *console)
return 0;
}
-int lxc_pty_create(struct lxc_console *console)
+int lxc_pty_create(struct lxc_pty *console)
{
int ret, saved_errno;
@@ -745,7 +745,7 @@ int lxc_pty_create(struct lxc_console *console)
int lxc_console_create(struct lxc_conf *conf)
{
int ret;
- struct lxc_console *console = &conf->console;
+ struct lxc_pty *console = &conf->console;
if (console->path && !strcmp(console->path, "none")) {
INFO("No console was requested");
@@ -1013,7 +1013,7 @@ void lxc_pty_info_init(struct lxc_pty_info *pty)
pty->busy = -1;
}
-void lxc_pty_init(struct lxc_console *pty)
+void lxc_pty_init(struct lxc_pty *pty)
{
memset(pty, 0, sizeof(*pty));
pty->slave = -EBADF;
@@ -1024,7 +1024,7 @@ void lxc_pty_init(struct lxc_console *pty)
lxc_pty_info_init(&pty->peerpty);
}
-void lxc_pty_conf_free(struct lxc_console *console)
+void lxc_pty_conf_free(struct lxc_pty *console)
{
free(console->buffer_log_file);
free(console->log_path);
@@ -1033,7 +1033,7 @@ void lxc_pty_conf_free(struct lxc_console *console)
lxc_ringbuf_release(&console->ringbuf);
}
-int lxc_pty_map_ids(struct lxc_conf *c, struct lxc_console *pty)
+int lxc_pty_map_ids(struct lxc_conf *c, struct lxc_pty *pty)
{
int ret;
diff --git a/src/lxc/console.h b/src/lxc/console.h
index a385ed1f7..f3a3b6f3e 100644
--- a/src/lxc/console.h
+++ b/src/lxc/console.h
@@ -82,7 +82,7 @@ extern int lxc_console_allocate(struct lxc_conf *conf, int sockfd, int *ttynum)
* automatically chowned to the uid/gid of the unprivileged user. For this
* ttys_shift_ids() can be called.)
*/
-extern int lxc_pty_create(struct lxc_console *console);
+extern int lxc_pty_create(struct lxc_pty *console);
/**
* lxc_console_create: Create a new pty.
@@ -98,7 +98,7 @@ extern int lxc_console_create(struct lxc_conf *);
* /dev/tty)
* Registered handlers in a mainloop are not automatically deleted.
*/
-extern void lxc_console_delete(struct lxc_console *);
+extern void lxc_console_delete(struct lxc_pty *);
/*
* lxc_console_free: mark the console or a tty as unallocated, free any
@@ -114,7 +114,7 @@ extern void lxc_console_free(struct lxc_conf *conf, int fd);
/*
* Register pty event handlers in an open mainloop
*/
-extern int lxc_console_mainloop_add(struct lxc_epoll_descr *, struct lxc_console *);
+extern int lxc_console_mainloop_add(struct lxc_epoll_descr *, struct lxc_pty *);
/*
* Handle SIGWINCH events on the allocated ptys.
@@ -227,16 +227,16 @@ extern int lxc_console_cb_signal_fd(int fd, uint32_t events, void *cbdata,
*/
extern void lxc_console_signal_fini(struct lxc_tty_state *ts);
-extern int lxc_console_write_ringbuffer(struct lxc_console *console);
-extern int lxc_console_create_log_file(struct lxc_console *console);
+extern int lxc_console_write_ringbuffer(struct lxc_pty *console);
+extern int lxc_console_create_log_file(struct lxc_pty *console);
extern int lxc_console_cb_con(int fd, uint32_t events, void *data,
struct lxc_epoll_descr *descr);
extern int lxc_make_controlling_pty(int fd);
extern int lxc_login_pty(int fd);
-extern void lxc_pty_conf_free(struct lxc_console *console);
+extern void lxc_pty_conf_free(struct lxc_pty *console);
extern void lxc_pty_info_init(struct lxc_pty_info *pty);
-extern void lxc_pty_init(struct lxc_console *pty);
-extern int lxc_pty_map_ids(struct lxc_conf *c, struct lxc_console *pty);
+extern void lxc_pty_init(struct lxc_pty *pty);
+extern int lxc_pty_map_ids(struct lxc_conf *c, struct lxc_pty *pty);
#endif
diff --git a/src/lxc/start.c b/src/lxc/start.c
index 5438ebda0..ebcd0c272 100644
--- a/src/lxc/start.c
+++ b/src/lxc/start.c
@@ -529,7 +529,7 @@ int lxc_poll(const char *name, struct lxc_handler *handler)
}
if (has_console) {
- struct lxc_console *console = &handler->conf->console;
+ struct lxc_pty *console = &handler->conf->console;
ret = lxc_console_mainloop_add(&descr, console);
if (ret < 0) {
From f0930cece090385cff4e84ab22720c0e6241b026 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Tue, 27 Feb 2018 16:09:32 +0100
Subject: [PATCH 03/42] console: lxc_terminal_winsz()
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
src/lxc/console.c | 8 ++++----
src/lxc/console.h | 4 ++--
2 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/src/lxc/console.c b/src/lxc/console.c
index 4844c8a03..62043efda 100644
--- a/src/lxc/console.c
+++ b/src/lxc/console.c
@@ -64,7 +64,7 @@ __attribute__((constructor)) void lxc_console_init(void)
lxc_list_init(&lxc_ttys);
}
-void lxc_console_winsz(int srcfd, int dstfd)
+void lxc_terminal_winsz(int srcfd, int dstfd)
{
int ret;
struct winsize wsz;
@@ -90,7 +90,7 @@ void lxc_console_winsz(int srcfd, int dstfd)
static void lxc_console_winch(struct lxc_tty_state *ts)
{
- lxc_console_winsz(ts->stdinfd, ts->masterfd);
+ lxc_terminal_winsz(ts->stdinfd, ts->masterfd);
if (ts->winch_proxy)
lxc_cmd_console_winch(ts->winch_proxy, ts->winch_proxy_lxcpath);
@@ -533,7 +533,7 @@ static int lxc_console_peer_default(struct lxc_pty *console)
goto on_error1;
}
- lxc_console_winsz(console->peer, console->master);
+ lxc_terminal_winsz(console->peer, console->master);
console->tios = malloc(sizeof(*console->tios));
if (!console->tios) {
@@ -895,7 +895,7 @@ int lxc_console(struct lxc_container *c, int ttynum,
istty = isatty(stdinfd);
if (istty) {
- lxc_console_winsz(stdinfd, masterfd);
+ lxc_terminal_winsz(stdinfd, masterfd);
lxc_cmd_console_winch(ts->winch_proxy, ts->winch_proxy_lxcpath);
} else {
INFO("File descriptor %d does not refer to a tty device", stdinfd);
diff --git a/src/lxc/console.h b/src/lxc/console.h
index f3a3b6f3e..6e10da91c 100644
--- a/src/lxc/console.h
+++ b/src/lxc/console.h
@@ -176,12 +176,12 @@ extern int lxc_setup_tios(int fd, struct termios *oldtios);
/*
- * lxc_console_winsz: propagte winsz from one terminal to another
+ * lxc_terminal_winsz: propagate winsz from one terminal to another
*
* @srcfd : terminal to get size from (typically a slave pty)
* @dstfd : terminal to set size on (typically a master pty)
*/
-extern void lxc_console_winsz(int srcfd, int dstfd);
+extern void lxc_terminal_winsz(int srcfd, int dstfd);
/*
* lxc_console_signal_init: install signal handler
From acab351978b9d4ad0267ff325b3d7d6f0d2e8c2d Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Tue, 27 Feb 2018 16:11:08 +0100
Subject: [PATCH 04/42] console: lxc_terminal_winch()
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
src/lxc/console.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/lxc/console.c b/src/lxc/console.c
index 62043efda..a841f4d2d 100644
--- a/src/lxc/console.c
+++ b/src/lxc/console.c
@@ -88,7 +88,7 @@ void lxc_terminal_winsz(int srcfd, int dstfd)
return;
}
-static void lxc_console_winch(struct lxc_tty_state *ts)
+static void lxc_terminal_winch(struct lxc_tty_state *ts)
{
lxc_terminal_winsz(ts->stdinfd, ts->masterfd);
@@ -103,7 +103,7 @@ void lxc_console_sigwinch(int sig)
lxc_list_for_each(it, &lxc_ttys) {
ts = it->elem;
- lxc_console_winch(ts);
+ lxc_terminal_winch(ts);
}
}
@@ -126,7 +126,7 @@ int lxc_console_cb_signal_fd(int fd, uint32_t events, void *cbdata,
}
if (siginfo.ssi_signo == SIGWINCH)
- lxc_console_winch(ts);
+ lxc_terminal_winch(ts);
return 0;
}
From 82ffb499ac2101f52cf412746e2a9bc8d15f7f1e Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Tue, 27 Feb 2018 16:12:51 +0100
Subject: [PATCH 05/42] console: lxc_terminal_sigwinch()
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
src/lxc/commands.c | 2 +-
src/lxc/console.c | 2 +-
src/lxc/console.h | 4 ++--
3 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/src/lxc/commands.c b/src/lxc/commands.c
index 7b919d28c..fbb1eb87f 100644
--- a/src/lxc/commands.c
+++ b/src/lxc/commands.c
@@ -685,7 +685,7 @@ static int lxc_cmd_console_winch_callback(int fd, struct lxc_cmd_req *req,
{
struct lxc_cmd_rsp rsp = { .data = 0 };
- lxc_console_sigwinch(SIGWINCH);
+ lxc_terminal_sigwinch(SIGWINCH);
return lxc_cmd_rsp_send(fd, &rsp);
}
diff --git a/src/lxc/console.c b/src/lxc/console.c
index a841f4d2d..59566adfa 100644
--- a/src/lxc/console.c
+++ b/src/lxc/console.c
@@ -96,7 +96,7 @@ static void lxc_terminal_winch(struct lxc_tty_state *ts)
lxc_cmd_console_winch(ts->winch_proxy, ts->winch_proxy_lxcpath);
}
-void lxc_console_sigwinch(int sig)
+void lxc_terminal_sigwinch(int sig)
{
struct lxc_list *it;
struct lxc_tty_state *ts;
diff --git a/src/lxc/console.h b/src/lxc/console.h
index 6e10da91c..82b5fb937 100644
--- a/src/lxc/console.h
+++ b/src/lxc/console.h
@@ -119,7 +119,7 @@ extern int lxc_console_mainloop_add(struct lxc_epoll_descr *, struct lxc_pty *)
/*
* Handle SIGWINCH events on the allocated ptys.
*/
-extern void lxc_console_sigwinch(int sig);
+extern void lxc_terminal_sigwinch(int sig);
/*
* Connect to one of the ptys given to the container via lxc.tty.max.
@@ -199,7 +199,7 @@ extern void lxc_terminal_winsz(int srcfd, int dstfd);
* Note that the signal handler isn't installed as a classic asychronous
* handler, rather signalfd(2) is used so that we can handle the signal when
* we're ready for it. This avoids deadlocks since a signal handler (ie
- * lxc_console_sigwinch()) would need to take the thread mutex to prevent
+ * lxc_terminal_sigwinch()) would need to take the thread mutex to prevent
* lxc_ttys list corruption, but using the fd we can provide the tty_state
* needed to the callback (lxc_console_cb_signal_fd()).
*
From 3c7b79e0956fcad3e0c7e23e3ee688e04492644c Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Tue, 27 Feb 2018 16:21:15 +0100
Subject: [PATCH 06/42] commands: lxc_cmd_terimal_winch()
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
src/lxc/commands.c | 14 +++++++-------
src/lxc/commands.h | 4 ++--
src/lxc/console.c | 4 ++--
3 files changed, 11 insertions(+), 11 deletions(-)
diff --git a/src/lxc/commands.c b/src/lxc/commands.c
index fbb1eb87f..3354c333f 100644
--- a/src/lxc/commands.c
+++ b/src/lxc/commands.c
@@ -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,8 +680,8 @@ 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 };
@@ -1114,7 +1114,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,
diff --git a/src/lxc/commands.h b/src/lxc/commands.h
index e24ef7a5c..816cd7483 100644
--- a/src/lxc/commands.h
+++ b/src/lxc/commands.h
@@ -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);
/*
diff --git a/src/lxc/console.c b/src/lxc/console.c
index 59566adfa..487936d67 100644
--- a/src/lxc/console.c
+++ b/src/lxc/console.c
@@ -93,7 +93,7 @@ static void lxc_terminal_winch(struct lxc_tty_state *ts)
lxc_terminal_winsz(ts->stdinfd, ts->masterfd);
if (ts->winch_proxy)
- lxc_cmd_console_winch(ts->winch_proxy, ts->winch_proxy_lxcpath);
+ lxc_cmd_terminal_winch(ts->winch_proxy, ts->winch_proxy_lxcpath);
}
void lxc_terminal_sigwinch(int sig)
@@ -896,7 +896,7 @@ int lxc_console(struct lxc_container *c, int ttynum,
istty = isatty(stdinfd);
if (istty) {
lxc_terminal_winsz(stdinfd, masterfd);
- lxc_cmd_console_winch(ts->winch_proxy, ts->winch_proxy_lxcpath);
+ lxc_cmd_terminal_winch(ts->winch_proxy, ts->winch_proxy_lxcpath);
} else {
INFO("File descriptor %d does not refer to a tty device", stdinfd);
}
From 8f74c0fa8adf033ca191630036930eded21a10f4 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Tue, 27 Feb 2018 16:26:25 +0100
Subject: [PATCH 07/42] console: lxc_terminal_signalfd_cb()
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
src/lxc/console.c | 10 +++++-----
src/lxc/console.h | 4 ++--
2 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/src/lxc/console.c b/src/lxc/console.c
index 487936d67..933f77550 100644
--- a/src/lxc/console.c
+++ b/src/lxc/console.c
@@ -107,8 +107,8 @@ void lxc_terminal_sigwinch(int sig)
}
}
-int lxc_console_cb_signal_fd(int fd, uint32_t events, void *cbdata,
- struct lxc_epoll_descr *descr)
+int lxc_terminal_signalfd_cb(int fd, uint32_t events, void *cbdata,
+ struct lxc_epoll_descr *descr)
{
ssize_t ret;
struct signalfd_siginfo siginfo;
@@ -121,7 +121,7 @@ int lxc_console_cb_signal_fd(int fd, uint32_t events, void *cbdata,
}
if (siginfo.ssi_signo == SIGTERM) {
- DEBUG("Received SIGTERM. Detaching from the console");
+ DEBUG("Received SIGTERM. Detaching from the terminal");
return LXC_MAINLOOP_CLOSE;
}
@@ -280,7 +280,7 @@ static int lxc_console_mainloop_add_peer(struct lxc_pty *console)
return 0;
ret = lxc_mainloop_add_handler(console->descr, console->tty_state->sigfd,
- lxc_console_cb_signal_fd, console->tty_state);
+ lxc_terminal_signalfd_cb, console->tty_state);
if (ret < 0) {
WARN("Failed to add signal handler to mainloop");
return -1;
@@ -909,7 +909,7 @@ int lxc_console(struct lxc_container *c, int ttynum,
if (ts->sigfd != -1) {
ret = lxc_mainloop_add_handler(&descr, ts->sigfd,
- lxc_console_cb_signal_fd, ts);
+ lxc_terminal_signalfd_cb, ts);
if (ret < 0) {
ERROR("Failed to add signal handler to mainloop");
goto close_mainloop;
diff --git a/src/lxc/console.h b/src/lxc/console.h
index 82b5fb937..5bd90cf76 100644
--- a/src/lxc/console.h
+++ b/src/lxc/console.h
@@ -201,7 +201,7 @@ extern void lxc_terminal_winsz(int srcfd, int dstfd);
* we're ready for it. This avoids deadlocks since a signal handler (ie
* lxc_terminal_sigwinch()) would need to take the thread mutex to prevent
* lxc_ttys list corruption, but using the fd we can provide the tty_state
- * needed to the callback (lxc_console_cb_signal_fd()).
+ * needed to the callback (lxc_terminal_signalfd_cb()).
*
* This function allocates memory. It is up to the caller to free it.
*/
@@ -211,7 +211,7 @@ extern struct lxc_tty_state *lxc_console_signal_init(int srcfd, int dstfd);
* Handler for signal events. To be registered via the corresponding functions
* declared and defined in mainloop.{c,h} or lxc_console_mainloop_add().
*/
-extern int lxc_console_cb_signal_fd(int fd, uint32_t events, void *cbdata,
+extern int lxc_terminal_signalfd_cb(int fd, uint32_t events, void *cbdata,
struct lxc_epoll_descr *descr);
/*
From 08179589e90b1f39064c83373f1d59bda88aa580 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Tue, 27 Feb 2018 16:28:15 +0100
Subject: [PATCH 08/42] console: lxc_terminal_signal_init()
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
src/lxc/console.c | 8 ++++----
src/lxc/console.h | 8 ++++----
2 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/src/lxc/console.c b/src/lxc/console.c
index 933f77550..d869091f8 100644
--- a/src/lxc/console.c
+++ b/src/lxc/console.c
@@ -131,7 +131,7 @@ int lxc_terminal_signalfd_cb(int fd, uint32_t events, void *cbdata,
return 0;
}
-struct lxc_tty_state *lxc_console_signal_init(int srcfd, int dstfd)
+struct lxc_tty_state *lxc_terminal_signal_init(int srcfd, int dstfd)
{
int ret;
bool istty;
@@ -412,7 +412,7 @@ static int lxc_console_peer_proxy_alloc(struct lxc_pty *console, int sockfd)
if (lxc_setup_tios(console->peerpty.slave, &oldtermio) < 0)
goto err1;
- ts = lxc_console_signal_init(console->peerpty.master, console->master);
+ ts = lxc_terminal_signal_init(console->peerpty.master, console->master);
if (!ts)
goto err1;
@@ -526,7 +526,7 @@ static int lxc_console_peer_default(struct lxc_pty *console)
goto on_error1;
}
- ts = lxc_console_signal_init(console->peer, console->master);
+ ts = lxc_terminal_signal_init(console->peer, console->master);
console->tty_state = ts;
if (!ts) {
WARN("Failed to install signal handler");
@@ -883,7 +883,7 @@ int lxc_console(struct lxc_container *c, int ttynum,
if (ret < 0)
TRACE("Process is already group leader");
- ts = lxc_console_signal_init(stdinfd, masterfd);
+ ts = lxc_terminal_signal_init(stdinfd, masterfd);
if (!ts) {
ret = -1;
goto close_fds;
diff --git a/src/lxc/console.h b/src/lxc/console.h
index 5bd90cf76..0d77f5006 100644
--- a/src/lxc/console.h
+++ b/src/lxc/console.h
@@ -184,7 +184,7 @@ extern int lxc_setup_tios(int fd, struct termios *oldtios);
extern void lxc_terminal_winsz(int srcfd, int dstfd);
/*
- * lxc_console_signal_init: install signal handler
+ * lxc_terminal_signal_init: install signal handler
*
* @srcfd : src for winsz in SIGWINCH handler
* @dstfd : dst for winsz in SIGWINCH handler
@@ -205,7 +205,7 @@ extern void lxc_terminal_winsz(int srcfd, int dstfd);
*
* This function allocates memory. It is up to the caller to free it.
*/
-extern struct lxc_tty_state *lxc_console_signal_init(int srcfd, int dstfd);
+extern struct lxc_tty_state *lxc_terminal_signal_init(int srcfd, int dstfd);
/*
* Handler for signal events. To be registered via the corresponding functions
@@ -217,10 +217,10 @@ extern int lxc_terminal_signalfd_cb(int fd, uint32_t events, void *cbdata,
/*
* lxc_console_signal_fini: uninstall signal handler
*
- * @ts : the lxc_tty_state returned by lxc_console_signal_init
+ * @ts : the lxc_tty_state returned by lxc_terminal_signal_init
*
* Restore the saved signal handler that was in effect at the time
- * lxc_console_signal_init() was called.
+ * lxc_terminal_signal_init() was called.
*
* Must be called with process_lock held to protect the lxc_ttys list, or
* from a non-threaded context.
From dfcadc3708ec088d7b0b6747ac5c0d07e03172f2 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Tue, 27 Feb 2018 16:29:23 +0100
Subject: [PATCH 09/42] console: lxc_terminal_signal_fini()
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
src/lxc/console.c | 8 ++++----
src/lxc/console.h | 4 ++--
2 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/src/lxc/console.c b/src/lxc/console.c
index d869091f8..eff37846a 100644
--- a/src/lxc/console.c
+++ b/src/lxc/console.c
@@ -189,7 +189,7 @@ struct lxc_tty_state *lxc_terminal_signal_init(int srcfd, int dstfd)
return ts;
}
-void lxc_console_signal_fini(struct lxc_tty_state *ts)
+void lxc_terminal_signal_fini(struct lxc_tty_state *ts)
{
if (ts->sigfd >= 0) {
close(ts->sigfd);
@@ -220,7 +220,7 @@ int lxc_console_cb_con(int fd, uint32_t events, void *data,
console->master = -EBADF;
} else if (fd == console->peer) {
if (console->tty_state) {
- lxc_console_signal_fini(console->tty_state);
+ lxc_terminal_signal_fini(console->tty_state);
console->tty_state = NULL;
}
console->peer = -EBADF;
@@ -368,7 +368,7 @@ int lxc_setup_tios(int fd, struct termios *oldtios)
static void lxc_console_peer_proxy_free(struct lxc_pty *console)
{
if (console->tty_state) {
- lxc_console_signal_fini(console->tty_state);
+ lxc_terminal_signal_fini(console->tty_state);
console->tty_state = NULL;
}
close(console->peerpty.master);
@@ -965,7 +965,7 @@ int lxc_console(struct lxc_container *c, int ttynum,
lxc_mainloop_close(&descr);
sigwinch_fini:
- lxc_console_signal_fini(ts);
+ lxc_terminal_signal_fini(ts);
close_fds:
close(masterfd);
diff --git a/src/lxc/console.h b/src/lxc/console.h
index 0d77f5006..3360dfeee 100644
--- a/src/lxc/console.h
+++ b/src/lxc/console.h
@@ -215,7 +215,7 @@ extern int lxc_terminal_signalfd_cb(int fd, uint32_t events, void *cbdata,
struct lxc_epoll_descr *descr);
/*
- * lxc_console_signal_fini: uninstall signal handler
+ * lxc_terminal_signal_fini: uninstall signal handler
*
* @ts : the lxc_tty_state returned by lxc_terminal_signal_init
*
@@ -225,7 +225,7 @@ extern int lxc_terminal_signalfd_cb(int fd, uint32_t events, void *cbdata,
* Must be called with process_lock held to protect the lxc_ttys list, or
* from a non-threaded context.
*/
-extern void lxc_console_signal_fini(struct lxc_tty_state *ts);
+extern void lxc_terminal_signal_fini(struct lxc_tty_state *ts);
extern int lxc_console_write_ringbuffer(struct lxc_pty *console);
extern int lxc_console_create_log_file(struct lxc_pty *console);
From 3cd40a8f8b147d9912a2ab56ae371018417c5dac Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Tue, 27 Feb 2018 16:31:22 +0100
Subject: [PATCH 10/42] console: lxc_terminal_io_cb()
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
src/lxc/console.c | 58 +++++++++++++++++++++++++++----------------------------
src/lxc/console.h | 2 +-
2 files changed, 30 insertions(+), 30 deletions(-)
diff --git a/src/lxc/console.c b/src/lxc/console.c
index eff37846a..42fd942af 100644
--- a/src/lxc/console.c
+++ b/src/lxc/console.c
@@ -51,7 +51,7 @@
#include <../include/openpty.h>
#endif
-#define LXC_CONSOLE_BUFFER_SIZE 1024
+#define LXC_TERMINAL_BUFFER_SIZE 1024
lxc_log_define(console, lxc);
@@ -204,26 +204,26 @@ void lxc_terminal_signal_fini(struct lxc_tty_state *ts)
free(ts);
}
-int lxc_console_cb_con(int fd, uint32_t events, void *data,
+int lxc_terminal_io_cb(int fd, uint32_t events, void *data,
struct lxc_epoll_descr *descr)
{
- struct lxc_pty *console = data;
- char buf[LXC_CONSOLE_BUFFER_SIZE];
+ struct lxc_pty *terminal = data;
+ char buf[LXC_TERMINAL_BUFFER_SIZE];
int r, w, w_log, w_rbuf;
w = r = lxc_read_nointr(fd, buf, sizeof(buf));
if (r <= 0) {
- INFO("Console client on fd %d has exited", fd);
+ INFO("Terminal client on fd %d has exited", fd);
lxc_mainloop_del_handler(descr, fd);
- if (fd == console->master) {
- console->master = -EBADF;
- } else if (fd == console->peer) {
- if (console->tty_state) {
- lxc_terminal_signal_fini(console->tty_state);
- console->tty_state = NULL;
+ if (fd == terminal->master) {
+ terminal->master = -EBADF;
+ } else if (fd == terminal->peer) {
+ if (terminal->tty_state) {
+ lxc_terminal_signal_fini(terminal->tty_state);
+ terminal->tty_state = NULL;
}
- console->peer = -EBADF;
+ terminal->peer = -EBADF;
} else {
ERROR("Handler received unexpected file descriptor");
}
@@ -232,33 +232,33 @@ int lxc_console_cb_con(int fd, uint32_t events, void *data,
return LXC_MAINLOOP_CLOSE;
}
- if (fd == console->peer)
- w = lxc_write_nointr(console->master, buf, r);
+ if (fd == terminal->peer)
+ w = lxc_write_nointr(terminal->master, buf, r);
w_rbuf = w_log = 0;
- if (fd == console->master) {
+ if (fd == terminal->master) {
/* write to peer first */
- if (console->peer >= 0)
- w = lxc_write_nointr(console->peer, buf, r);
+ if (terminal->peer >= 0)
+ w = lxc_write_nointr(terminal->peer, buf, r);
- /* write to console ringbuffer */
- if (console->buffer_size > 0)
- w_rbuf = lxc_ringbuf_write(&console->ringbuf, buf, r);
+ /* write to terminal ringbuffer */
+ if (terminal->buffer_size > 0)
+ w_rbuf = lxc_ringbuf_write(&terminal->ringbuf, buf, r);
- /* write to console log */
- if (console->log_fd >= 0)
- w_log = lxc_write_nointr(console->log_fd, buf, r);
+ /* write to terminal log */
+ if (terminal->log_fd >= 0)
+ w_log = lxc_write_nointr(terminal->log_fd, buf, r);
}
if (w != r)
- WARN("Console short write r:%d != w:%d", r, w);
+ WARN("Short write on terminal r:%d != w:%d", r, w);
if (w_rbuf < 0)
- TRACE("%s - Failed to write %d bytes to console ringbuffer",
+ TRACE("%s - Failed to write %d bytes to terminal ringbuffer",
strerror(-w_rbuf), r);
if (w_log < 0)
- TRACE("Failed to write %d bytes to console log", r);
+ TRACE("Failed to write %d bytes to terminal log", r);
return 0;
}
@@ -269,7 +269,7 @@ static int lxc_console_mainloop_add_peer(struct lxc_pty *console)
if (console->peer >= 0) {
ret = lxc_mainloop_add_handler(console->descr, console->peer,
- lxc_console_cb_con, console);
+ lxc_terminal_io_cb, console);
if (ret < 0) {
WARN("Failed to add console peer handler to mainloop");
return -1;
@@ -300,7 +300,7 @@ int lxc_console_mainloop_add(struct lxc_epoll_descr *descr,
}
ret = lxc_mainloop_add_handler(descr, console->master,
- lxc_console_cb_con, console);
+ lxc_terminal_io_cb, console);
if (ret < 0) {
ERROR("Failed to add handler for %d to mainloop", console->master);
return -1;
@@ -839,7 +839,7 @@ int lxc_console_cb_tty_master(int fd, uint32_t events, void *cbdata,
struct lxc_epoll_descr *descr)
{
struct lxc_tty_state *ts = cbdata;
- char buf[LXC_CONSOLE_BUFFER_SIZE];
+ char buf[LXC_TERMINAL_BUFFER_SIZE];
int r, w;
if (fd != ts->masterfd)
diff --git a/src/lxc/console.h b/src/lxc/console.h
index 3360dfeee..91a4ae43b 100644
--- a/src/lxc/console.h
+++ b/src/lxc/console.h
@@ -229,7 +229,7 @@ extern void lxc_terminal_signal_fini(struct lxc_tty_state *ts);
extern int lxc_console_write_ringbuffer(struct lxc_pty *console);
extern int lxc_console_create_log_file(struct lxc_pty *console);
-extern int lxc_console_cb_con(int fd, uint32_t events, void *data,
+extern int lxc_terminal_io_cb(int fd, uint32_t events, void *data,
struct lxc_epoll_descr *descr);
extern int lxc_make_controlling_pty(int fd);
From f1f909e35429997986573086fad17c5b94598b9d Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Tue, 27 Feb 2018 16:34:00 +0100
Subject: [PATCH 11/42] console: lxc_terminal_mainloop_add_peer()
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
src/lxc/console.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/lxc/console.c b/src/lxc/console.c
index 42fd942af..dfb589fa2 100644
--- a/src/lxc/console.c
+++ b/src/lxc/console.c
@@ -263,7 +263,7 @@ int lxc_terminal_io_cb(int fd, uint32_t events, void *data,
return 0;
}
-static int lxc_console_mainloop_add_peer(struct lxc_pty *console)
+static int lxc_terminal_mainloop_add_peer(struct lxc_pty *console)
{
int ret;
@@ -310,7 +310,7 @@ int lxc_console_mainloop_add(struct lxc_epoll_descr *descr,
* does attach to it in lxc_console_allocate().
*/
console->descr = descr;
- ret = lxc_console_mainloop_add_peer(console);
+ ret = lxc_terminal_mainloop_add_peer(console);
if (ret < 0)
return -1;
@@ -419,7 +419,7 @@ static int lxc_console_peer_proxy_alloc(struct lxc_pty *console, int sockfd)
console->tty_state = ts;
console->peer = console->peerpty.slave;
console->peerpty.busy = sockfd;
- ret = lxc_console_mainloop_add_peer(console);
+ ret = lxc_terminal_mainloop_add_peer(console);
if (ret < 0)
goto err1;
From 0a936fb2e5fb7d521fa7763f211c3851f57054f3 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Tue, 27 Feb 2018 16:34:55 +0100
Subject: [PATCH 12/42] console: lxc_terminal_mainloop_add()
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
src/lxc/attach.c | 2 +-
src/lxc/console.c | 2 +-
src/lxc/console.h | 8 ++++----
src/lxc/start.c | 4 ++--
4 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/src/lxc/attach.c b/src/lxc/attach.c
index 58e17fb6a..f4e1e9906 100644
--- a/src/lxc/attach.c
+++ b/src/lxc/attach.c
@@ -1012,7 +1012,7 @@ static int lxc_attach_pty_mainloop_init(struct lxc_pty *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);
diff --git a/src/lxc/console.c b/src/lxc/console.c
index dfb589fa2..82c0b71db 100644
--- a/src/lxc/console.c
+++ b/src/lxc/console.c
@@ -289,7 +289,7 @@ static int lxc_terminal_mainloop_add_peer(struct lxc_pty *console)
return 0;
}
-int lxc_console_mainloop_add(struct lxc_epoll_descr *descr,
+int lxc_terminal_mainloop_add(struct lxc_epoll_descr *descr,
struct lxc_pty *console)
{
int ret;
diff --git a/src/lxc/console.h b/src/lxc/console.h
index 91a4ae43b..b7f05f5a4 100644
--- a/src/lxc/console.h
+++ b/src/lxc/console.h
@@ -114,7 +114,7 @@ extern void lxc_console_free(struct lxc_conf *conf, int fd);
/*
* Register pty event handlers in an open mainloop
*/
-extern int lxc_console_mainloop_add(struct lxc_epoll_descr *, struct lxc_pty *);
+extern int lxc_terminal_mainloop_add(struct lxc_epoll_descr *, struct lxc_pty *);
/*
* Handle SIGWINCH events on the allocated ptys.
@@ -153,7 +153,7 @@ extern int lxc_console_set_stdfds(int fd);
/*
* Handler for events on the stdin fd of the pty. To be registered via the
* corresponding functions declared and defined in mainloop.{c,h} or
- * lxc_console_mainloop_add().
+ * lxc_terminal_mainloop_add().
* This function exits the loop cleanly when an EPOLLHUP event is received.
*/
extern int lxc_console_cb_tty_stdin(int fd, uint32_t events, void *cbdata,
@@ -162,7 +162,7 @@ extern int lxc_console_cb_tty_stdin(int fd, uint32_t events, void *cbdata,
/*
* Handler for events on the master fd of the pty. To be registered via the
* corresponding functions declared and defined in mainloop.{c,h} or
- * lxc_console_mainloop_add().
+ * lxc_terminal_mainloop_add().
* This function exits the loop cleanly when an EPOLLHUP event is received.
*/
extern int lxc_console_cb_tty_master(int fd, uint32_t events, void *cbdata,
@@ -209,7 +209,7 @@ extern struct lxc_tty_state *lxc_terminal_signal_init(int srcfd, int dstfd);
/*
* Handler for signal events. To be registered via the corresponding functions
- * declared and defined in mainloop.{c,h} or lxc_console_mainloop_add().
+ * declared and defined in mainloop.{c,h} or lxc_terminal_mainloop_add().
*/
extern int lxc_terminal_signalfd_cb(int fd, uint32_t events, void *cbdata,
struct lxc_epoll_descr *descr);
diff --git a/src/lxc/start.c b/src/lxc/start.c
index ebcd0c272..d735082d4 100644
--- a/src/lxc/start.c
+++ b/src/lxc/start.c
@@ -531,13 +531,13 @@ int lxc_poll(const char *name, struct lxc_handler *handler)
if (has_console) {
struct lxc_pty *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;
From dcd7ff1fab73a4791fe4907449a1879cb08e8f27 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Tue, 27 Feb 2018 16:36:09 +0100
Subject: [PATCH 13/42] console: lxc_terminal_peer_proxy_free()
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
src/lxc/console.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/lxc/console.c b/src/lxc/console.c
index 82c0b71db..9906ab652 100644
--- a/src/lxc/console.c
+++ b/src/lxc/console.c
@@ -365,7 +365,7 @@ int lxc_setup_tios(int fd, struct termios *oldtios)
return 0;
}
-static void lxc_console_peer_proxy_free(struct lxc_pty *console)
+static void lxc_terminal_peer_proxy_free(struct lxc_pty *console)
{
if (console->tty_state) {
lxc_terminal_signal_fini(console->tty_state);
@@ -427,7 +427,7 @@ static int lxc_console_peer_proxy_alloc(struct lxc_pty *console, int sockfd)
return 0;
err1:
- lxc_console_peer_proxy_free(console);
+ lxc_terminal_peer_proxy_free(console);
return -1;
}
@@ -486,7 +486,7 @@ void lxc_console_free(struct lxc_conf *conf, int fd)
if (console->peerpty.busy == fd) {
lxc_mainloop_del_handler(console->descr, console->peerpty.slave);
- lxc_console_peer_proxy_free(console);
+ lxc_terminal_peer_proxy_free(console);
}
}
From db0363fe062aa8ccde55f17d48ae6d54eb4b4938 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Tue, 27 Feb 2018 16:36:49 +0100
Subject: [PATCH 14/42] console: lxc_terminal_peer_proxy_alloc()
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
src/lxc/console.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/lxc/console.c b/src/lxc/console.c
index 9906ab652..b533e81a9 100644
--- a/src/lxc/console.c
+++ b/src/lxc/console.c
@@ -380,7 +380,7 @@ static void lxc_terminal_peer_proxy_free(struct lxc_pty *console)
console->peer = -1;
}
-static int lxc_console_peer_proxy_alloc(struct lxc_pty *console, int sockfd)
+static int lxc_terminal_peer_proxy_alloc(struct lxc_pty *console, int sockfd)
{
struct termios oldtermio;
struct lxc_tty_state *ts;
@@ -438,7 +438,7 @@ int lxc_console_allocate(struct lxc_conf *conf, int sockfd, int *ttyreq)
struct lxc_pty *console = &conf->console;
if (*ttyreq == 0) {
- if (lxc_console_peer_proxy_alloc(console, sockfd) < 0)
+ if (lxc_terminal_peer_proxy_alloc(console, sockfd) < 0)
goto out;
masterfd = console->peerpty.master;
goto out;
From 0a728fe4e1b4546a979657cc153e0acf6f0c82d9 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Tue, 27 Feb 2018 16:38:12 +0100
Subject: [PATCH 15/42] console: lxc_terminal_allocate()
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
src/lxc/commands.c | 2 +-
src/lxc/console.c | 4 ++--
src/lxc/console.h | 6 +++---
3 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/src/lxc/commands.c b/src/lxc/commands.c
index 3354c333f..2e699ffa7 100644
--- a/src/lxc/commands.c
+++ b/src/lxc/commands.c
@@ -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;
diff --git a/src/lxc/console.c b/src/lxc/console.c
index b533e81a9..c651ea030 100644
--- a/src/lxc/console.c
+++ b/src/lxc/console.c
@@ -307,7 +307,7 @@ int lxc_terminal_mainloop_add(struct lxc_epoll_descr *descr,
}
/* We cache the descr so that we can add an fd to it when someone
- * does attach to it in lxc_console_allocate().
+ * does attach to it in lxc_terminal_allocate().
*/
console->descr = descr;
ret = lxc_terminal_mainloop_add_peer(console);
@@ -431,7 +431,7 @@ static int lxc_terminal_peer_proxy_alloc(struct lxc_pty *console, int sockfd)
return -1;
}
-int lxc_console_allocate(struct lxc_conf *conf, int sockfd, int *ttyreq)
+int lxc_terminal_allocate(struct lxc_conf *conf, int sockfd, int *ttyreq)
{
int masterfd = -1, ttynum;
struct lxc_tty_info *tty_info = &conf->tty_info;
diff --git a/src/lxc/console.h b/src/lxc/console.h
index b7f05f5a4..a64e7c254 100644
--- a/src/lxc/console.h
+++ b/src/lxc/console.h
@@ -61,14 +61,14 @@ struct lxc_tty_state
};
/*
- * lxc_console_allocate: allocate the console or a tty
+ * lxc_terminal_allocate: allocate the console or a tty
*
* @conf : the configuration of the container to allocate from
* @sockfd : the socket fd whose remote side when closed, will be an
* indication that the console or tty is no longer in use
* @ttyreq : the tty requested to be opened, -1 for any, 0 for the console
*/
-extern int lxc_console_allocate(struct lxc_conf *conf, int sockfd, int *ttynum);
+extern int lxc_terminal_allocate(struct lxc_conf *conf, int sockfd, int *ttynum);
/*
* Create a new pty:
@@ -102,7 +102,7 @@ extern void lxc_console_delete(struct lxc_pty *);
/*
* lxc_console_free: mark the console or a tty as unallocated, free any
- * resources allocated by lxc_console_allocate().
+ * resources allocated by lxc_terminal_allocate().
*
* @conf : the configuration of the container whose tty was closed
* @fd : the socket fd whose remote side was closed, which indicated
From 1a692ad53a2e1537ded784edb6c9b7786a777cb5 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Tue, 27 Feb 2018 16:42:30 +0100
Subject: [PATCH 16/42] console: lxc_terminal_free()
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
src/lxc/commands.c | 4 ++--
src/lxc/console.c | 2 +-
src/lxc/console.h | 4 ++--
3 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/src/lxc/commands.c b/src/lxc/commands.c
index 2e699ffa7..a87eb97f2 100644
--- a/src/lxc/commands.c
+++ b/src/lxc/commands.c
@@ -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;
}
@@ -1142,7 +1142,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);
diff --git a/src/lxc/console.c b/src/lxc/console.c
index c651ea030..680c59e1a 100644
--- a/src/lxc/console.c
+++ b/src/lxc/console.c
@@ -473,7 +473,7 @@ int lxc_terminal_allocate(struct lxc_conf *conf, int sockfd, int *ttyreq)
return masterfd;
}
-void lxc_console_free(struct lxc_conf *conf, int fd)
+void lxc_terminal_free(struct lxc_conf *conf, int fd)
{
int i;
struct lxc_tty_info *tty_info = &conf->tty_info;
diff --git a/src/lxc/console.h b/src/lxc/console.h
index a64e7c254..d0d7d9241 100644
--- a/src/lxc/console.h
+++ b/src/lxc/console.h
@@ -101,7 +101,7 @@ extern int lxc_console_create(struct lxc_conf *);
extern void lxc_console_delete(struct lxc_pty *);
/*
- * lxc_console_free: mark the console or a tty as unallocated, free any
+ * lxc_terminal_free: mark the console or a tty as unallocated, free any
* resources allocated by lxc_terminal_allocate().
*
* @conf : the configuration of the container whose tty was closed
@@ -109,7 +109,7 @@ extern void lxc_console_delete(struct lxc_pty *);
* the console or tty is no longer in use. this is used to match
* which console/tty is being freed.
*/
-extern void lxc_console_free(struct lxc_conf *conf, int fd);
+extern void lxc_terminal_free(struct lxc_conf *conf, int fd);
/*
* Register pty event handlers in an open mainloop
From 8166992858a01e6ae56d12c3f947a2542d0b5157 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Tue, 27 Feb 2018 16:44:57 +0100
Subject: [PATCH 17/42] console: lxc_terminal_peer_default()
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
src/lxc/console.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/lxc/console.c b/src/lxc/console.c
index 680c59e1a..dc734ba82 100644
--- a/src/lxc/console.c
+++ b/src/lxc/console.c
@@ -490,7 +490,7 @@ void lxc_terminal_free(struct lxc_conf *conf, int fd)
}
}
-static int lxc_console_peer_default(struct lxc_pty *console)
+static int lxc_terminal_peer_default(struct lxc_pty *console)
{
struct lxc_tty_state *ts;
const char *path = console->path;
@@ -729,7 +729,7 @@ int lxc_pty_create(struct lxc_pty *console)
goto err;
}
- ret = lxc_console_peer_default(console);
+ ret = lxc_terminal_peer_default(console);
if (ret < 0) {
ERROR("Failed to allocate a peer pty device");
goto err;
From 849f158649691c95696256a4afd69856cc956abb Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Tue, 27 Feb 2018 16:46:05 +0100
Subject: [PATCH 18/42] console: lxc_terminal_write_ringbuffer()
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
src/lxc/commands.c | 2 +-
src/lxc/console.c | 4 ++--
src/lxc/console.h | 2 +-
3 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/src/lxc/commands.c b/src/lxc/commands.c
index a87eb97f2..d27d4fa65 100644
--- a/src/lxc/commands.c
+++ b/src/lxc/commands.c
@@ -996,7 +996,7 @@ static int lxc_cmd_console_log_callback(int fd, struct lxc_cmd_req *req,
if (!console->buffer_log_file)
goto out;
- rsp.ret = lxc_console_write_ringbuffer(console);
+ rsp.ret = lxc_terminal_write_ringbuffer(console);
if (rsp.ret < 0)
goto out;
}
diff --git a/src/lxc/console.c b/src/lxc/console.c
index dc734ba82..8372d8979 100644
--- a/src/lxc/console.c
+++ b/src/lxc/console.c
@@ -559,7 +559,7 @@ static int lxc_terminal_peer_default(struct lxc_pty *console)
return ret;
}
-int lxc_console_write_ringbuffer(struct lxc_pty *console)
+int lxc_terminal_write_ringbuffer(struct lxc_pty *console)
{
char *r_addr;
ssize_t ret;
@@ -585,7 +585,7 @@ void lxc_console_delete(struct lxc_pty *console)
{
int ret;
- ret = lxc_console_write_ringbuffer(console);
+ ret = lxc_terminal_write_ringbuffer(console);
if (ret < 0)
WARN("Failed to write console log to disk");
diff --git a/src/lxc/console.h b/src/lxc/console.h
index d0d7d9241..a4d56d601 100644
--- a/src/lxc/console.h
+++ b/src/lxc/console.h
@@ -227,7 +227,7 @@ extern int lxc_terminal_signalfd_cb(int fd, uint32_t events, void *cbdata,
*/
extern void lxc_terminal_signal_fini(struct lxc_tty_state *ts);
-extern int lxc_console_write_ringbuffer(struct lxc_pty *console);
+extern int lxc_terminal_write_ringbuffer(struct lxc_pty *console);
extern int lxc_console_create_log_file(struct lxc_pty *console);
extern int lxc_terminal_io_cb(int fd, uint32_t events, void *data,
struct lxc_epoll_descr *descr);
From 77cc7ca8db0f1d4d6847a382ea792fe6bf7e85bd Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Tue, 27 Feb 2018 16:47:19 +0100
Subject: [PATCH 19/42] console: lxc_terminal_init()
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
src/lxc/console.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/lxc/console.c b/src/lxc/console.c
index 8372d8979..bf0c6551c 100644
--- a/src/lxc/console.c
+++ b/src/lxc/console.c
@@ -59,7 +59,7 @@ static struct lxc_list lxc_ttys;
typedef void (*sighandler_t)(int);
-__attribute__((constructor)) void lxc_console_init(void)
+__attribute__((constructor)) void lxc_terminal_init(void)
{
lxc_list_init(&lxc_ttys);
}
From 6edbfe00d0ef95dcb8bb34e5fc2f24740f64bfd3 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Tue, 27 Feb 2018 16:48:21 +0100
Subject: [PATCH 20/42] console: lxc_terminal_delete()
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
src/lxc/attach.c | 4 ++--
src/lxc/console.c | 6 +++---
src/lxc/console.h | 2 +-
src/lxc/start.c | 2 +-
4 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/src/lxc/attach.c b/src/lxc/attach.c
index f4e1e9906..d19bc1b9d 100644
--- a/src/lxc/attach.c
+++ b/src/lxc/attach.c
@@ -996,7 +996,7 @@ static int lxc_attach_pty(struct lxc_conf *conf, struct lxc_pty *pty)
return 0;
on_error:
- lxc_console_delete(pty);
+ lxc_terminal_delete(pty);
lxc_pty_conf_free(pty);
return -1;
}
@@ -1386,7 +1386,7 @@ 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_terminal_delete(&pty);
lxc_pty_conf_free(&pty);
}
lxc_proc_put_context_info(init_ctx);
diff --git a/src/lxc/console.c b/src/lxc/console.c
index bf0c6551c..5f772fd94 100644
--- a/src/lxc/console.c
+++ b/src/lxc/console.c
@@ -581,7 +581,7 @@ int lxc_terminal_write_ringbuffer(struct lxc_pty *console)
return 0;
}
-void lxc_console_delete(struct lxc_pty *console)
+void lxc_terminal_delete(struct lxc_pty *console)
{
int ret;
@@ -738,7 +738,7 @@ int lxc_pty_create(struct lxc_pty *console)
return 0;
err:
- lxc_console_delete(console);
+ lxc_terminal_delete(console);
return -ENODEV;
}
@@ -774,7 +774,7 @@ int lxc_console_create(struct lxc_conf *conf)
return 0;
err:
- lxc_console_delete(console);
+ lxc_terminal_delete(console);
return -ENODEV;
}
diff --git a/src/lxc/console.h b/src/lxc/console.h
index a4d56d601..d8e8d532c 100644
--- a/src/lxc/console.h
+++ b/src/lxc/console.h
@@ -98,7 +98,7 @@ extern int lxc_console_create(struct lxc_conf *);
* /dev/tty)
* Registered handlers in a mainloop are not automatically deleted.
*/
-extern void lxc_console_delete(struct lxc_pty *);
+extern void lxc_terminal_delete(struct lxc_pty *);
/*
* lxc_terminal_free: mark the console or a tty as unallocated, free any
diff --git a/src/lxc/start.c b/src/lxc/start.c
index d735082d4..e28d3faee 100644
--- a/src/lxc/start.c
+++ b/src/lxc/start.c
@@ -950,7 +950,7 @@ 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_terminal_delete(&handler->conf->console);
lxc_delete_tty(&handler->conf->tty_info);
/* The command socket is now closed, no more state clients can register
From 4b58ab11fae29c62746de1ad57541a6c8de89c29 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Tue, 27 Feb 2018 16:48:57 +0100
Subject: [PATCH 21/42] console: lxc_terminal_create_ringbuf_log_file()
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
src/lxc/console.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/lxc/console.c b/src/lxc/console.c
index 5f772fd94..a0568f8ed 100644
--- a/src/lxc/console.c
+++ b/src/lxc/console.c
@@ -622,7 +622,7 @@ void lxc_terminal_delete(struct lxc_pty *console)
* ringbuffer log file is (implementation wise not content wise) independent of
* the console log file.
*/
-static int lxc_console_create_ringbuf_log_file(struct lxc_pty *console)
+static int lxc_terminal_create_ringbuf_log_file(struct lxc_pty *console)
{
if (!console->buffer_log_file)
return 0;
@@ -767,7 +767,7 @@ int lxc_console_create(struct lxc_conf *conf)
goto err;
/* create console ringbuffer log file */
- ret = lxc_console_create_ringbuf_log_file(console);
+ ret = lxc_terminal_create_ringbuf_log_file(console);
if (ret < 0)
goto err;
From 9ba1995366d31679ac010e1acea797c2a0364fac Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Tue, 27 Feb 2018 16:49:28 +0100
Subject: [PATCH 22/42] console: lxc_terminal_create_ringbuf()
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
src/lxc/console.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/lxc/console.c b/src/lxc/console.c
index a0568f8ed..1f837526d 100644
--- a/src/lxc/console.c
+++ b/src/lxc/console.c
@@ -644,7 +644,7 @@ static int lxc_terminal_create_ringbuf_log_file(struct lxc_pty *console)
* register a handler for the console's masterfd when we create the mainloop
* the console handler needs to see an allocated ringbuffer.
*/
-static int lxc_console_create_ringbuf(struct lxc_pty *console)
+static int lxc_terminal_create_ringbuf(struct lxc_pty *console)
{
int ret;
struct lxc_ringbuf *buf = &console->ringbuf;
@@ -762,7 +762,7 @@ int lxc_console_create(struct lxc_conf *conf)
goto err;
/* create console ringbuffer */
- ret = lxc_console_create_ringbuf(console);
+ ret = lxc_terminal_create_ringbuf(console);
if (ret < 0)
goto err;
From cdceae40827762685a1a7e0e9f2fc0373b28c8b4 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Tue, 27 Feb 2018 16:50:08 +0100
Subject: [PATCH 23/42] console: lxc_terminal_create_log_file()
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
src/lxc/commands.c | 2 +-
src/lxc/console.c | 4 ++--
src/lxc/console.h | 2 +-
3 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/src/lxc/commands.c b/src/lxc/commands.c
index d27d4fa65..c0ee8e812 100644
--- a/src/lxc/commands.c
+++ b/src/lxc/commands.c
@@ -1053,7 +1053,7 @@ static int lxc_cmd_console_log_callback(int fd, struct lxc_cmd_req *req,
if (rsp.ret < 0)
goto out;
- rsp.ret = lxc_console_create_log_file(console);
+ rsp.ret = lxc_terminal_create_log_file(console);
} else if (rsp.datalen > 0) {
lxc_ringbuf_move_read_addr(buf, rsp.datalen);
}
diff --git a/src/lxc/console.c b/src/lxc/console.c
index 1f837526d..3da373bc8 100644
--- a/src/lxc/console.c
+++ b/src/lxc/console.c
@@ -690,7 +690,7 @@ static int lxc_terminal_create_ringbuf(struct lxc_pty *console)
* This is the console log file. Please note that the console log file is
* (implementation wise not content wise) independent of the console ringbuffer.
*/
-int lxc_console_create_log_file(struct lxc_pty *console)
+int lxc_terminal_create_log_file(struct lxc_pty *console)
{
if (!console->log_path)
return 0;
@@ -757,7 +757,7 @@ int lxc_console_create(struct lxc_conf *conf)
return -1;
/* create console log file */
- ret = lxc_console_create_log_file(console);
+ ret = lxc_terminal_create_log_file(console);
if (ret < 0)
goto err;
diff --git a/src/lxc/console.h b/src/lxc/console.h
index d8e8d532c..617a9b178 100644
--- a/src/lxc/console.h
+++ b/src/lxc/console.h
@@ -228,7 +228,7 @@ extern int lxc_terminal_signalfd_cb(int fd, uint32_t events, void *cbdata,
extern void lxc_terminal_signal_fini(struct lxc_tty_state *ts);
extern int lxc_terminal_write_ringbuffer(struct lxc_pty *console);
-extern int lxc_console_create_log_file(struct lxc_pty *console);
+extern int lxc_terminal_create_log_file(struct lxc_pty *console);
extern int lxc_terminal_io_cb(int fd, uint32_t events, void *data,
struct lxc_epoll_descr *descr);
From 724e31b5b17eb7acb06578b651b16b1e4955beea Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Tue, 27 Feb 2018 16:51:40 +0100
Subject: [PATCH 24/42] console: lxc_terminal_create()
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
src/lxc/console.c | 2 +-
src/lxc/console.h | 8 ++++----
src/lxc/start.c | 4 ++--
3 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/src/lxc/console.c b/src/lxc/console.c
index 3da373bc8..fae869dd0 100644
--- a/src/lxc/console.c
+++ b/src/lxc/console.c
@@ -742,7 +742,7 @@ int lxc_pty_create(struct lxc_pty *console)
return -ENODEV;
}
-int lxc_console_create(struct lxc_conf *conf)
+int lxc_terminal_create(struct lxc_conf *conf)
{
int ret;
struct lxc_pty *console = &conf->console;
diff --git a/src/lxc/console.h b/src/lxc/console.h
index 617a9b178..09b138778 100644
--- a/src/lxc/console.h
+++ b/src/lxc/console.h
@@ -85,15 +85,15 @@ extern int lxc_terminal_allocate(struct lxc_conf *conf, int sockfd, int *ttynum
extern int lxc_pty_create(struct lxc_pty *console);
/**
- * lxc_console_create: Create a new pty.
+ * lxc_terminal_create: Create a new pty.
* - In addition to lxc_pty_create() also sets up all pty logs.
*/
-extern int lxc_console_create(struct lxc_conf *);
+extern int lxc_terminal_create(struct lxc_conf *);
/*
- * Delete a pty created via lxc_console_create():
+ * Delete a pty created via lxc_terminal_create():
* - set old terminal settings
- * - memory allocated via lxc_console_create() is free()ed.
+ * - memory allocated via lxc_terminal_create() is free()ed.
* - close master/slave pty pair and allocated fd for the peer (usually
* /dev/tty)
* Registered handlers in a mainloop are not automatically deleted.
diff --git a/src/lxc/start.c b/src/lxc/start.c
index e28d3faee..579da8cbe 100644
--- a/src/lxc/start.c
+++ b/src/lxc/start.c
@@ -804,7 +804,7 @@ 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_create(conf);
if (ret < 0) {
ERROR("Failed to create console");
goto out_restore_sigmask;
@@ -1198,7 +1198,7 @@ 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_create() so
* make sure that that pty is stdin,stdout,stderr.
*/
if (handler->conf->console.slave >= 0) {
From 3610245ed58c68465b5ceb18006940ad2ed916c9 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Tue, 27 Feb 2018 16:53:18 +0100
Subject: [PATCH 25/42] console: lxc_terminal_set_stdfds()
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
src/lxc/console.c | 4 ++--
src/lxc/console.h | 2 +-
src/lxc/start.c | 2 +-
3 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/src/lxc/console.c b/src/lxc/console.c
index fae869dd0..03c920419 100644
--- a/src/lxc/console.c
+++ b/src/lxc/console.c
@@ -778,7 +778,7 @@ int lxc_terminal_create(struct lxc_conf *conf)
return -ENODEV;
}
-int lxc_console_set_stdfds(int fd)
+int lxc_terminal_set_stdfds(int fd)
{
if (fd < 0)
return 0;
@@ -995,7 +995,7 @@ int lxc_login_pty(int fd)
if (ret < 0)
return -1;
- ret = lxc_console_set_stdfds(fd);
+ ret = lxc_terminal_set_stdfds(fd);
if (ret < 0)
return -1;
diff --git a/src/lxc/console.h b/src/lxc/console.h
index 09b138778..2c3f675a8 100644
--- a/src/lxc/console.h
+++ b/src/lxc/console.h
@@ -148,7 +148,7 @@ extern int lxc_console_getfd(struct lxc_container *c, int *ttynum,
* fd is made a duplicate of a specific standard file descriptor iff the
* standard file descriptor refers to a pty.
*/
-extern int lxc_console_set_stdfds(int fd);
+extern int lxc_terminal_set_stdfds(int fd);
/*
* Handler for events on the stdin fd of the pty. To be registered via the
diff --git a/src/lxc/start.c b/src/lxc/start.c
index 579da8cbe..ef87d136f 100644
--- a/src/lxc/start.c
+++ b/src/lxc/start.c
@@ -1205,7 +1205,7 @@ static int do_start(void *data)
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);
From 7799676b9c72ee8f86a46ccef8919214bf4d7084 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Tue, 27 Feb 2018 16:55:56 +0100
Subject: [PATCH 26/42] console: lxc_terminal_stdin_cb()
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
src/lxc/console.c | 6 +++---
src/lxc/console.h | 8 ++++----
2 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/src/lxc/console.c b/src/lxc/console.c
index 03c920419..9fb45ba17 100644
--- a/src/lxc/console.c
+++ b/src/lxc/console.c
@@ -804,8 +804,8 @@ int lxc_terminal_set_stdfds(int fd)
return 0;
}
-int lxc_console_cb_tty_stdin(int fd, uint32_t events, void *cbdata,
- struct lxc_epoll_descr *descr)
+int lxc_terminal_stdin_cb(int fd, uint32_t events, void *cbdata,
+ struct lxc_epoll_descr *descr)
{
struct lxc_tty_state *ts = cbdata;
char c;
@@ -917,7 +917,7 @@ int lxc_console(struct lxc_container *c, int ttynum,
}
ret = lxc_mainloop_add_handler(&descr, ts->stdinfd,
- lxc_console_cb_tty_stdin, ts);
+ lxc_terminal_stdin_cb, ts);
if (ret < 0) {
ERROR("Failed to add stdin handler");
goto close_mainloop;
diff --git a/src/lxc/console.h b/src/lxc/console.h
index 2c3f675a8..34db30388 100644
--- a/src/lxc/console.h
+++ b/src/lxc/console.h
@@ -40,11 +40,11 @@ struct lxc_tty_state
int masterfd;
/* Escape sequence to use for exiting the pty. A single char can be
* specified. The pty can then exited by doing: Ctrl + specified_char + q.
- * This field is checked by lxc_console_cb_tty_stdin(). Set to -1 to
+ * This field is checked by lxc_terminal_stdin_cb(). Set to -1 to
* disable exiting the pty via a escape sequence.
*/
int escape;
- /* Used internally by lxc_console_cb_tty_stdin() to check whether an
+ /* Used internally by lxc_terminal_stdin_cb() to check whether an
* escape sequence has been received.
*/
int saw_escape;
@@ -156,8 +156,8 @@ extern int lxc_terminal_set_stdfds(int fd);
* lxc_terminal_mainloop_add().
* This function exits the loop cleanly when an EPOLLHUP event is received.
*/
-extern int lxc_console_cb_tty_stdin(int fd, uint32_t events, void *cbdata,
- struct lxc_epoll_descr *descr);
+extern int lxc_terminal_stdin_cb(int fd, uint32_t events, void *cbdata,
+ struct lxc_epoll_descr *descr);
/*
* Handler for events on the master fd of the pty. To be registered via the
From ff98884f026cda81494e8725e1f26872603b17ea Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Tue, 27 Feb 2018 16:58:02 +0100
Subject: [PATCH 27/42] console: lxc_terminal_master_cb()
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
src/lxc/console.c | 6 +++---
src/lxc/console.h | 4 ++--
2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/src/lxc/console.c b/src/lxc/console.c
index 9fb45ba17..555afd390 100644
--- a/src/lxc/console.c
+++ b/src/lxc/console.c
@@ -835,8 +835,8 @@ int lxc_terminal_stdin_cb(int fd, uint32_t events, void *cbdata,
return 0;
}
-int lxc_console_cb_tty_master(int fd, uint32_t events, void *cbdata,
- struct lxc_epoll_descr *descr)
+int lxc_terminal_master_cb(int fd, uint32_t events, void *cbdata,
+ struct lxc_epoll_descr *descr)
{
struct lxc_tty_state *ts = cbdata;
char buf[LXC_TERMINAL_BUFFER_SIZE];
@@ -924,7 +924,7 @@ int lxc_console(struct lxc_container *c, int ttynum,
}
ret = lxc_mainloop_add_handler(&descr, ts->masterfd,
- lxc_console_cb_tty_master, ts);
+ lxc_terminal_master_cb, ts);
if (ret < 0) {
ERROR("Failed to add master handler");
goto close_mainloop;
diff --git a/src/lxc/console.h b/src/lxc/console.h
index 34db30388..cc69cbd79 100644
--- a/src/lxc/console.h
+++ b/src/lxc/console.h
@@ -165,8 +165,8 @@ extern int lxc_terminal_stdin_cb(int fd, uint32_t events, void *cbdata,
* lxc_terminal_mainloop_add().
* This function exits the loop cleanly when an EPOLLHUP event is received.
*/
-extern int lxc_console_cb_tty_master(int fd, uint32_t events, void *cbdata,
- struct lxc_epoll_descr *descr);
+extern int lxc_terminal_master_cb(int fd, uint32_t events, void *cbdata,
+ struct lxc_epoll_descr *descr);
/*
* Setup new terminal properties. The old terminal settings are stored in
From e56bdb1822b244f6b87144cbb210c4ac7aa6a0cf Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Tue, 27 Feb 2018 16:58:49 +0100
Subject: [PATCH 28/42] console: lxc_terminal_getfd()
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
src/lxc/console.c | 2 +-
src/lxc/console.h | 2 +-
src/lxc/lxccontainer.c | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/lxc/console.c b/src/lxc/console.c
index 555afd390..399355618 100644
--- a/src/lxc/console.c
+++ b/src/lxc/console.c
@@ -860,7 +860,7 @@ int lxc_terminal_master_cb(int fd, uint32_t events, void *cbdata,
return 0;
}
-int lxc_console_getfd(struct lxc_container *c, int *ttynum, int *masterfd)
+int lxc_terminal_getfd(struct lxc_container *c, int *ttynum, int *masterfd)
{
return lxc_cmd_console(c->name, ttynum, masterfd, c->config_path);
}
diff --git a/src/lxc/console.h b/src/lxc/console.h
index cc69cbd79..97d017158 100644
--- a/src/lxc/console.h
+++ b/src/lxc/console.h
@@ -140,7 +140,7 @@ extern int lxc_console(struct lxc_container *c, int ttynum,
* Set ttynum to -1 to allocate the first available pty, or to a value within
* the range specified by lxc.tty.max to allocate a specific pty.
*/
-extern int lxc_console_getfd(struct lxc_container *c, int *ttynum,
+extern int lxc_terminal_getfd(struct lxc_container *c, int *ttynum,
int *masterfd);
/*
diff --git a/src/lxc/lxccontainer.c b/src/lxc/lxccontainer.c
index 117034e8b..fb82707c4 100644
--- a/src/lxc/lxccontainer.c
+++ b/src/lxc/lxccontainer.c
@@ -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 *)
From 61401f15806365e50c01e27144b1eb811a0b62fb Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Tue, 27 Feb 2018 17:05:43 +0100
Subject: [PATCH 29/42] console: s/console/terminal/g
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
src/lxc/console.c | 294 +++++++++++++++++++++++++++---------------------------
1 file changed, 147 insertions(+), 147 deletions(-)
diff --git a/src/lxc/console.c b/src/lxc/console.c
index 399355618..bd2a21184 100644
--- a/src/lxc/console.c
+++ b/src/lxc/console.c
@@ -53,7 +53,7 @@
#define LXC_TERMINAL_BUFFER_SIZE 1024
-lxc_log_define(console, lxc);
+lxc_log_define(terminal, lxc);
static struct lxc_list lxc_ttys;
@@ -263,24 +263,24 @@ int lxc_terminal_io_cb(int fd, uint32_t events, void *data,
return 0;
}
-static int lxc_terminal_mainloop_add_peer(struct lxc_pty *console)
+static int lxc_terminal_mainloop_add_peer(struct lxc_pty *terminal)
{
int ret;
- if (console->peer >= 0) {
- ret = lxc_mainloop_add_handler(console->descr, console->peer,
- lxc_terminal_io_cb, console);
+ if (terminal->peer >= 0) {
+ ret = lxc_mainloop_add_handler(terminal->descr, terminal->peer,
+ lxc_terminal_io_cb, terminal);
if (ret < 0) {
- WARN("Failed to add console peer handler to mainloop");
+ WARN("Failed to add terminal peer handler to mainloop");
return -1;
}
}
- if (!console->tty_state || console->tty_state->sigfd < 0)
+ if (!terminal->tty_state || terminal->tty_state->sigfd < 0)
return 0;
- ret = lxc_mainloop_add_handler(console->descr, console->tty_state->sigfd,
- lxc_terminal_signalfd_cb, console->tty_state);
+ ret = lxc_mainloop_add_handler(terminal->descr, terminal->tty_state->sigfd,
+ lxc_terminal_signalfd_cb, terminal->tty_state);
if (ret < 0) {
WARN("Failed to add signal handler to mainloop");
return -1;
@@ -290,27 +290,27 @@ static int lxc_terminal_mainloop_add_peer(struct lxc_pty *console)
}
int lxc_terminal_mainloop_add(struct lxc_epoll_descr *descr,
- struct lxc_pty *console)
+ struct lxc_pty *terminal)
{
int ret;
- if (console->master < 0) {
- INFO("no console");
+ if (terminal->master < 0) {
+ INFO("Terminal is not initialized");
return 0;
}
- ret = lxc_mainloop_add_handler(descr, console->master,
- lxc_terminal_io_cb, console);
+ ret = lxc_mainloop_add_handler(descr, terminal->master,
+ lxc_terminal_io_cb, terminal);
if (ret < 0) {
- ERROR("Failed to add handler for %d to mainloop", console->master);
+ ERROR("Failed to add handler for %d to mainloop", terminal->master);
return -1;
}
/* We cache the descr so that we can add an fd to it when someone
* does attach to it in lxc_terminal_allocate().
*/
- console->descr = descr;
- ret = lxc_terminal_mainloop_add_peer(console);
+ terminal->descr = descr;
+ ret = lxc_terminal_mainloop_add_peer(terminal);
if (ret < 0)
return -1;
@@ -365,69 +365,69 @@ int lxc_setup_tios(int fd, struct termios *oldtios)
return 0;
}
-static void lxc_terminal_peer_proxy_free(struct lxc_pty *console)
+static void lxc_terminal_peer_proxy_free(struct lxc_pty *terminal)
{
- if (console->tty_state) {
- lxc_terminal_signal_fini(console->tty_state);
- console->tty_state = NULL;
+ if (terminal->tty_state) {
+ lxc_terminal_signal_fini(terminal->tty_state);
+ terminal->tty_state = NULL;
}
- close(console->peerpty.master);
- close(console->peerpty.slave);
- console->peerpty.master = -1;
- console->peerpty.slave = -1;
- console->peerpty.busy = -1;
- console->peerpty.name[0] = '\0';
- console->peer = -1;
+ close(terminal->peerpty.master);
+ close(terminal->peerpty.slave);
+ terminal->peerpty.master = -1;
+ terminal->peerpty.slave = -1;
+ terminal->peerpty.busy = -1;
+ terminal->peerpty.name[0] = '\0';
+ terminal->peer = -1;
}
-static int lxc_terminal_peer_proxy_alloc(struct lxc_pty *console, int sockfd)
+static int lxc_terminal_peer_proxy_alloc(struct lxc_pty *terminal, int sockfd)
{
struct termios oldtermio;
struct lxc_tty_state *ts;
int ret;
- if (console->master < 0) {
- ERROR("console not set up");
+ if (terminal->master < 0) {
+ ERROR("Terminal not set up");
return -1;
}
- if (console->peerpty.busy != -1 || console->peer != -1) {
- NOTICE("console already in use");
+ if (terminal->peerpty.busy != -1 || terminal->peer != -1) {
+ NOTICE("Terminal already in use");
return -1;
}
- if (console->tty_state) {
- ERROR("console already has tty_state");
+ if (terminal->tty_state) {
+ ERROR("Terminal already has tty_state");
return -1;
}
/* this is the proxy pty that will be given to the client, and that
* the real pty master will send to / recv from
*/
- ret = openpty(&console->peerpty.master, &console->peerpty.slave,
- console->peerpty.name, NULL, NULL);
+ ret = openpty(&terminal->peerpty.master, &terminal->peerpty.slave,
+ terminal->peerpty.name, NULL, NULL);
if (ret) {
SYSERROR("failed to create proxy pty");
return -1;
}
- if (lxc_setup_tios(console->peerpty.slave, &oldtermio) < 0)
+ if (lxc_setup_tios(terminal->peerpty.slave, &oldtermio) < 0)
goto err1;
- ts = lxc_terminal_signal_init(console->peerpty.master, console->master);
+ ts = lxc_terminal_signal_init(terminal->peerpty.master, terminal->master);
if (!ts)
goto err1;
- console->tty_state = ts;
- console->peer = console->peerpty.slave;
- console->peerpty.busy = sockfd;
- ret = lxc_terminal_mainloop_add_peer(console);
+ terminal->tty_state = ts;
+ terminal->peer = terminal->peerpty.slave;
+ terminal->peerpty.busy = sockfd;
+ ret = lxc_terminal_mainloop_add_peer(terminal);
if (ret < 0)
goto err1;
- DEBUG("%d %s peermaster:%d sockfd:%d", lxc_raw_getpid(), __FUNCTION__, console->peerpty.master, sockfd);
+ DEBUG("%d peermaster:%d sockfd:%d", lxc_raw_getpid(), terminal->peerpty.master, sockfd);
return 0;
err1:
- lxc_terminal_peer_proxy_free(console);
+ lxc_terminal_peer_proxy_free(terminal);
return -1;
}
@@ -435,12 +435,12 @@ int lxc_terminal_allocate(struct lxc_conf *conf, int sockfd, int *ttyreq)
{
int masterfd = -1, ttynum;
struct lxc_tty_info *tty_info = &conf->tty_info;
- struct lxc_pty *console = &conf->console;
+ struct lxc_pty *terminal = &conf->console;
if (*ttyreq == 0) {
- if (lxc_terminal_peer_proxy_alloc(console, sockfd) < 0)
+ if (lxc_terminal_peer_proxy_alloc(terminal, sockfd) < 0)
goto out;
- masterfd = console->peerpty.master;
+ masterfd = terminal->peerpty.master;
goto out;
}
@@ -477,27 +477,27 @@ void lxc_terminal_free(struct lxc_conf *conf, int fd)
{
int i;
struct lxc_tty_info *tty_info = &conf->tty_info;
- struct lxc_pty *console = &conf->console;
+ struct lxc_pty *terminal = &conf->console;
for (i = 0; i < tty_info->nbtty; i++) {
if (tty_info->pty_info[i].busy == fd)
tty_info->pty_info[i].busy = 0;
}
- if (console->peerpty.busy == fd) {
- lxc_mainloop_del_handler(console->descr, console->peerpty.slave);
- lxc_terminal_peer_proxy_free(console);
+ if (terminal->peerpty.busy == fd) {
+ lxc_mainloop_del_handler(terminal->descr, terminal->peerpty.slave);
+ lxc_terminal_peer_proxy_free(terminal);
}
}
-static int lxc_terminal_peer_default(struct lxc_pty *console)
+static int lxc_terminal_peer_default(struct lxc_pty *terminal)
{
struct lxc_tty_state *ts;
- const char *path = console->path;
+ const char *path = terminal->path;
int fd;
int ret = 0;
- /* If no console was given, try current controlling terminal, there
+ /* If no terminal was given, try current controlling terminal, there
* won't be one if we were started as a daemon (-d).
*/
if (!path && !access("/dev/tty", F_OK)) {
@@ -514,59 +514,59 @@ static int lxc_terminal_peer_default(struct lxc_pty *console)
goto out;
}
- console->peer = lxc_unpriv(open(path, O_RDWR | O_CLOEXEC));
- if (console->peer < 0) {
+ terminal->peer = lxc_unpriv(open(path, O_RDWR | O_CLOEXEC));
+ if (terminal->peer < 0) {
ERROR("Failed to open \"%s\": %s", path, strerror(errno));
return -ENOTTY;
}
DEBUG("using \"%s\" as peer tty device", path);
- if (!isatty(console->peer)) {
+ if (!isatty(terminal->peer)) {
ERROR("file descriptor for file \"%s\" does not refer to a tty device", path);
goto on_error1;
}
- ts = lxc_terminal_signal_init(console->peer, console->master);
- console->tty_state = ts;
+ ts = lxc_terminal_signal_init(terminal->peer, terminal->master);
+ terminal->tty_state = ts;
if (!ts) {
WARN("Failed to install signal handler");
goto on_error1;
}
- lxc_terminal_winsz(console->peer, console->master);
+ lxc_terminal_winsz(terminal->peer, terminal->master);
- console->tios = malloc(sizeof(*console->tios));
- if (!console->tios) {
+ terminal->tios = malloc(sizeof(*terminal->tios));
+ if (!terminal->tios) {
SYSERROR("failed to allocate memory");
goto on_error1;
}
- if (lxc_setup_tios(console->peer, console->tios) < 0)
+ if (lxc_setup_tios(terminal->peer, terminal->tios) < 0)
goto on_error2;
else
goto out;
on_error2:
- free(console->tios);
- console->tios = NULL;
+ free(terminal->tios);
+ terminal->tios = NULL;
on_error1:
- close(console->peer);
- console->peer = -1;
+ close(terminal->peer);
+ terminal->peer = -1;
ret = -ENOTTY;
out:
return ret;
}
-int lxc_terminal_write_ringbuffer(struct lxc_pty *console)
+int lxc_terminal_write_ringbuffer(struct lxc_pty *terminal)
{
char *r_addr;
ssize_t ret;
uint64_t used;
- struct lxc_ringbuf *buf = &console->ringbuf;
+ struct lxc_ringbuf *buf = &terminal->ringbuf;
- if (!console->buffer_log_file)
+ if (!terminal->buffer_log_file)
return 0;
used = lxc_ringbuf_used(buf);
@@ -574,81 +574,81 @@ int lxc_terminal_write_ringbuffer(struct lxc_pty *console)
return 0;
r_addr = lxc_ringbuf_get_read_addr(buf);
- ret = lxc_write_nointr(console->buffer_log_file_fd, r_addr, used);
+ ret = lxc_write_nointr(terminal->buffer_log_file_fd, r_addr, used);
if (ret < 0)
return -EIO;
return 0;
}
-void lxc_terminal_delete(struct lxc_pty *console)
+void lxc_terminal_delete(struct lxc_pty *terminal)
{
int ret;
- ret = lxc_terminal_write_ringbuffer(console);
+ ret = lxc_terminal_write_ringbuffer(terminal);
if (ret < 0)
- WARN("Failed to write console log to disk");
+ WARN("Failed to write terminal log to disk");
- if (console->tios && console->peer >= 0) {
- ret = tcsetattr(console->peer, TCSAFLUSH, console->tios);
+ if (terminal->tios && terminal->peer >= 0) {
+ ret = tcsetattr(terminal->peer, TCSAFLUSH, terminal->tios);
if (ret < 0)
WARN("%s - Failed to set old terminal settings", strerror(errno));
}
- free(console->tios);
- console->tios = NULL;
+ free(terminal->tios);
+ terminal->tios = NULL;
- if (console->peer >= 0)
- close(console->peer);
- console->peer = -1;
+ if (terminal->peer >= 0)
+ close(terminal->peer);
+ terminal->peer = -1;
- if (console->master >= 0)
- close(console->master);
- console->master = -1;
+ if (terminal->master >= 0)
+ close(terminal->master);
+ terminal->master = -1;
- if (console->slave >= 0)
- close(console->slave);
- console->slave = -1;
+ if (terminal->slave >= 0)
+ close(terminal->slave);
+ terminal->slave = -1;
- if (console->log_fd >= 0)
- close(console->log_fd);
- console->log_fd = -1;
+ if (terminal->log_fd >= 0)
+ close(terminal->log_fd);
+ terminal->log_fd = -1;
- if (console->buffer_log_file_fd >= 0)
- close(console->buffer_log_file_fd);
- console->buffer_log_file_fd = -1;
+ if (terminal->buffer_log_file_fd >= 0)
+ close(terminal->buffer_log_file_fd);
+ terminal->buffer_log_file_fd = -1;
}
-/* This is the console ringbuffer log file. Please note that the console
+/* This is the terminal ringbuffer log file. Please note that the terminal
* ringbuffer log file is (implementation wise not content wise) independent of
- * the console log file.
+ * the terminal log file.
*/
-static int lxc_terminal_create_ringbuf_log_file(struct lxc_pty *console)
+static int lxc_terminal_create_ringbuf_log_file(struct lxc_pty *terminal)
{
- if (!console->buffer_log_file)
+ if (!terminal->buffer_log_file)
return 0;
- console->buffer_log_file_fd = lxc_unpriv(open(console->buffer_log_file,
+ terminal->buffer_log_file_fd = lxc_unpriv(open(terminal->buffer_log_file,
O_CLOEXEC | O_RDWR | O_CREAT | O_TRUNC, 0600));
- if (console->buffer_log_file_fd < 0) {
- SYSERROR("Failed to open console ringbuffer log file \"%s\"",
- console->buffer_log_file);
+ if (terminal->buffer_log_file_fd < 0) {
+ SYSERROR("Failed to open terminal ringbuffer log file \"%s\"",
+ terminal->buffer_log_file);
return -EIO;
}
- DEBUG("Using \"%s\" as console ringbuffer log file", console->buffer_log_file);
+ DEBUG("Using \"%s\" as terminal ringbuffer log file", terminal->buffer_log_file);
return 0;
}
/**
* Note that this function needs to run before the mainloop starts. Since we
- * register a handler for the console's masterfd when we create the mainloop
- * the console handler needs to see an allocated ringbuffer.
+ * register a handler for the terminal's masterfd when we create the mainloop
+ * the terminal handler needs to see an allocated ringbuffer.
*/
-static int lxc_terminal_create_ringbuf(struct lxc_pty *console)
+static int lxc_terminal_create_ringbuf(struct lxc_pty *terminal)
{
int ret;
- struct lxc_ringbuf *buf = &console->ringbuf;
- uint64_t size = console->buffer_size;
+ struct lxc_ringbuf *buf = &terminal->ringbuf;
+ uint64_t size = terminal->buffer_size;
/* no ringbuffer previously allocated and no ringbuffer requested */
if (!buf->addr && size <= 0)
@@ -661,7 +661,7 @@ static int lxc_terminal_create_ringbuf(struct lxc_pty *console)
buf->r_off = 0;
buf->w_off = 0;
buf->size = 0;
- TRACE("Deallocated console ringbuffer");
+ TRACE("Deallocated terminal ringbuffer");
return 0;
}
@@ -670,46 +670,46 @@ static int lxc_terminal_create_ringbuf(struct lxc_pty *console)
/* check wether the requested size for the ringbuffer has changed */
if (buf->addr && buf->size != size) {
- TRACE("Console ringbuffer size changed from %" PRIu64
- " to %" PRIu64 " bytes. Deallocating console ringbuffer",
+ TRACE("Terminal ringbuffer size changed from %" PRIu64
+ " to %" PRIu64 " bytes. Deallocating terminal ringbuffer",
buf->size, size);
lxc_ringbuf_release(buf);
}
ret = lxc_ringbuf_create(buf, size);
if (ret < 0) {
- ERROR("Failed to setup %" PRIu64 " byte console ringbuffer", size);
+ ERROR("Failed to setup %" PRIu64 " byte terminal ringbuffer", size);
return -1;
}
- TRACE("Allocated %" PRIu64 " byte console ringbuffer", size);
+ TRACE("Allocated %" PRIu64 " byte terminal ringbuffer", size);
return 0;
}
/**
- * This is the console log file. Please note that the console log file is
- * (implementation wise not content wise) independent of the console ringbuffer.
+ * This is the terminal log file. Please note that the terminal log file is
+ * (implementation wise not content wise) independent of the terminal ringbuffer.
*/
-int lxc_terminal_create_log_file(struct lxc_pty *console)
+int lxc_terminal_create_log_file(struct lxc_pty *terminal)
{
- if (!console->log_path)
+ if (!terminal->log_path)
return 0;
- console->log_fd = lxc_unpriv(open(console->log_path, O_CLOEXEC | O_RDWR | O_CREAT | O_APPEND, 0600));
- if (console->log_fd < 0) {
- SYSERROR("Failed to open console log file \"%s\"", console->log_path);
+ terminal->log_fd = lxc_unpriv(open(terminal->log_path, O_CLOEXEC | O_RDWR | O_CREAT | O_APPEND, 0600));
+ if (terminal->log_fd < 0) {
+ SYSERROR("Failed to open terminal log file \"%s\"", terminal->log_path);
return -1;
}
- DEBUG("Using \"%s\" as console log file", console->log_path);
+ DEBUG("Using \"%s\" as terminal log file", terminal->log_path);
return 0;
}
-int lxc_pty_create(struct lxc_pty *console)
+int lxc_pty_create(struct lxc_pty *terminal)
{
int ret, saved_errno;
- ret = openpty(&console->master, &console->slave, console->name, NULL,
+ ret = openpty(&terminal->master, &terminal->slave, terminal->name, NULL,
NULL);
saved_errno = errno;
if (ret < 0) {
@@ -717,19 +717,19 @@ int lxc_pty_create(struct lxc_pty *console)
return -1;
}
- ret = fcntl(console->master, F_SETFD, FD_CLOEXEC);
+ ret = fcntl(terminal->master, F_SETFD, FD_CLOEXEC);
if (ret < 0) {
- SYSERROR("Failed to set FD_CLOEXEC flag on console master");
+ SYSERROR("Failed to set FD_CLOEXEC flag on terminal master");
goto err;
}
- ret = fcntl(console->slave, F_SETFD, FD_CLOEXEC);
+ ret = fcntl(terminal->slave, F_SETFD, FD_CLOEXEC);
if (ret < 0) {
- SYSERROR("Failed to set FD_CLOEXEC flag on console slave");
+ SYSERROR("Failed to set FD_CLOEXEC flag on terminal slave");
goto err;
}
- ret = lxc_terminal_peer_default(console);
+ ret = lxc_terminal_peer_default(terminal);
if (ret < 0) {
ERROR("Failed to allocate a peer pty device");
goto err;
@@ -738,43 +738,43 @@ int lxc_pty_create(struct lxc_pty *console)
return 0;
err:
- lxc_terminal_delete(console);
+ lxc_terminal_delete(terminal);
return -ENODEV;
}
int lxc_terminal_create(struct lxc_conf *conf)
{
int ret;
- struct lxc_pty *console = &conf->console;
+ struct lxc_pty *terminal = &conf->console;
- if (console->path && !strcmp(console->path, "none")) {
- INFO("No console was requested");
+ if (terminal->path && !strcmp(terminal->path, "none")) {
+ INFO("No terminal was requested");
return 0;
}
- ret = lxc_pty_create(console);
+ ret = lxc_pty_create(terminal);
if (ret < 0)
return -1;
- /* create console log file */
- ret = lxc_terminal_create_log_file(console);
+ /* create terminal log file */
+ ret = lxc_terminal_create_log_file(terminal);
if (ret < 0)
goto err;
- /* create console ringbuffer */
- ret = lxc_terminal_create_ringbuf(console);
+ /* create terminal ringbuffer */
+ ret = lxc_terminal_create_ringbuf(terminal);
if (ret < 0)
goto err;
- /* create console ringbuffer log file */
- ret = lxc_terminal_create_ringbuf_log_file(console);
+ /* create terminal ringbuffer log file */
+ ret = lxc_terminal_create_ringbuf_log_file(terminal);
if (ret < 0)
goto err;
return 0;
err:
- lxc_terminal_delete(console);
+ lxc_terminal_delete(terminal);
return -ENODEV;
}
@@ -817,7 +817,7 @@ int lxc_terminal_stdin_cb(int fd, uint32_t events, void *cbdata,
return LXC_MAINLOOP_CLOSE;
if (ts->escape >= 1) {
- /* we want to exit the console with Ctrl+a q */
+ /* we want to exit the terminal with Ctrl+a q */
if (c == ts->escape && !ts->saw_escape) {
ts->saw_escape = 1;
return 0;
@@ -1024,13 +1024,13 @@ void lxc_pty_init(struct lxc_pty *pty)
lxc_pty_info_init(&pty->peerpty);
}
-void lxc_pty_conf_free(struct lxc_pty *console)
+void lxc_pty_conf_free(struct lxc_pty *terminal)
{
- free(console->buffer_log_file);
- free(console->log_path);
- free(console->path);
- if (console->buffer_size > 0 && console->ringbuf.addr)
- lxc_ringbuf_release(&console->ringbuf);
+ free(terminal->buffer_log_file);
+ free(terminal->log_path);
+ free(terminal->path);
+ if (terminal->buffer_size > 0 && terminal->ringbuf.addr)
+ lxc_ringbuf_release(&terminal->ringbuf);
}
int lxc_pty_map_ids(struct lxc_conf *c, struct lxc_pty *pty)
From b272a0b437c552976fba1dde767900a6f3ccdcf1 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Tue, 27 Feb 2018 17:08:46 +0100
Subject: [PATCH 30/42] console: lxc_terminal_setup()
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
src/lxc/console.c | 2 +-
src/lxc/console.h | 8 ++++----
src/lxc/start.c | 4 ++--
3 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/src/lxc/console.c b/src/lxc/console.c
index bd2a21184..1a1e7da33 100644
--- a/src/lxc/console.c
+++ b/src/lxc/console.c
@@ -742,7 +742,7 @@ int lxc_pty_create(struct lxc_pty *terminal)
return -ENODEV;
}
-int lxc_terminal_create(struct lxc_conf *conf)
+int lxc_terminal_setup(struct lxc_conf *conf)
{
int ret;
struct lxc_pty *terminal = &conf->console;
diff --git a/src/lxc/console.h b/src/lxc/console.h
index 97d017158..e234545a2 100644
--- a/src/lxc/console.h
+++ b/src/lxc/console.h
@@ -85,15 +85,15 @@ extern int lxc_terminal_allocate(struct lxc_conf *conf, int sockfd, int *ttynum
extern int lxc_pty_create(struct lxc_pty *console);
/**
- * lxc_terminal_create: Create a new pty.
+ * lxc_terminal_setup: Create a new pty.
* - In addition to lxc_pty_create() also sets up all pty logs.
*/
-extern int lxc_terminal_create(struct lxc_conf *);
+extern int lxc_terminal_setup(struct lxc_conf *);
/*
- * Delete a pty created via lxc_terminal_create():
+ * Delete a pty created via lxc_terminal_setup():
* - set old terminal settings
- * - memory allocated via lxc_terminal_create() is free()ed.
+ * - memory allocated via lxc_terminal_setup() is free()ed.
* - close master/slave pty pair and allocated fd for the peer (usually
* /dev/tty)
* Registered handlers in a mainloop are not automatically deleted.
diff --git a/src/lxc/start.c b/src/lxc/start.c
index ef87d136f..08abb00ba 100644
--- a/src/lxc/start.c
+++ b/src/lxc/start.c
@@ -804,7 +804,7 @@ 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_terminal_create(conf);
+ ret = lxc_terminal_setup(conf);
if (ret < 0) {
ERROR("Failed to create console");
goto out_restore_sigmask;
@@ -1198,7 +1198,7 @@ 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_terminal_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) {
From bad0541f0952b4558b22b9ca7d20ad18f82c5c32 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Tue, 27 Feb 2018 17:09:38 +0100
Subject: [PATCH 31/42] console: lxc_terminal_create()
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
src/lxc/attach.c | 2 +-
src/lxc/console.c | 4 ++--
src/lxc/console.h | 4 ++--
3 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/src/lxc/attach.c b/src/lxc/attach.c
index d19bc1b9d..ad059e8c3 100644
--- a/src/lxc/attach.c
+++ b/src/lxc/attach.c
@@ -980,7 +980,7 @@ static int lxc_attach_pty(struct lxc_conf *conf, struct lxc_pty *pty)
lxc_pty_init(pty);
- ret = lxc_pty_create(pty);
+ ret = lxc_terminal_create(pty);
if (ret < 0) {
SYSERROR("Failed to create pty");
return -1;
diff --git a/src/lxc/console.c b/src/lxc/console.c
index 1a1e7da33..9caa44c77 100644
--- a/src/lxc/console.c
+++ b/src/lxc/console.c
@@ -705,7 +705,7 @@ int lxc_terminal_create_log_file(struct lxc_pty *terminal)
return 0;
}
-int lxc_pty_create(struct lxc_pty *terminal)
+int lxc_terminal_create(struct lxc_pty *terminal)
{
int ret, saved_errno;
@@ -752,7 +752,7 @@ int lxc_terminal_setup(struct lxc_conf *conf)
return 0;
}
- ret = lxc_pty_create(terminal);
+ ret = lxc_terminal_create(terminal);
if (ret < 0)
return -1;
diff --git a/src/lxc/console.h b/src/lxc/console.h
index e234545a2..02f5a641e 100644
--- a/src/lxc/console.h
+++ b/src/lxc/console.h
@@ -82,11 +82,11 @@ extern int lxc_terminal_allocate(struct lxc_conf *conf, int sockfd, int *ttynum
* automatically chowned to the uid/gid of the unprivileged user. For this
* ttys_shift_ids() can be called.)
*/
-extern int lxc_pty_create(struct lxc_pty *console);
+extern int lxc_terminal_create(struct lxc_pty *console);
/**
* lxc_terminal_setup: Create a new pty.
- * - In addition to lxc_pty_create() also sets up all pty logs.
+ * - In addition to lxc_terminal_create() also sets up all pty logs.
*/
extern int lxc_terminal_setup(struct lxc_conf *);
From 9e7e0e0f33ac066243ff9e27ca663cba6164eabd Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Tue, 27 Feb 2018 17:10:58 +0100
Subject: [PATCH 32/42] console: lxc_terminal_info_init()
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
src/lxc/console.c | 4 ++--
src/lxc/console.h | 2 +-
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/lxc/console.c b/src/lxc/console.c
index 9caa44c77..23c995fec 100644
--- a/src/lxc/console.c
+++ b/src/lxc/console.c
@@ -1005,7 +1005,7 @@ int lxc_login_pty(int fd)
return 0;
}
-void lxc_pty_info_init(struct lxc_pty_info *pty)
+void lxc_terminal_info_init(struct lxc_pty_info *pty)
{
pty->name[0] = '\0';
pty->master = -EBADF;
@@ -1021,7 +1021,7 @@ void lxc_pty_init(struct lxc_pty *pty)
pty->peer = -EBADF;
pty->log_fd = -EBADF;
pty->buffer_log_file_fd = -EBADF;
- lxc_pty_info_init(&pty->peerpty);
+ lxc_terminal_info_init(&pty->peerpty);
}
void lxc_pty_conf_free(struct lxc_pty *terminal)
diff --git a/src/lxc/console.h b/src/lxc/console.h
index 02f5a641e..15fa4c271 100644
--- a/src/lxc/console.h
+++ b/src/lxc/console.h
@@ -235,7 +235,7 @@ extern int lxc_terminal_io_cb(int fd, uint32_t events, void *data,
extern int lxc_make_controlling_pty(int fd);
extern int lxc_login_pty(int fd);
extern void lxc_pty_conf_free(struct lxc_pty *console);
-extern void lxc_pty_info_init(struct lxc_pty_info *pty);
+extern void lxc_terminal_info_init(struct lxc_pty_info *pty);
extern void lxc_pty_init(struct lxc_pty *pty);
extern int lxc_pty_map_ids(struct lxc_conf *c, struct lxc_pty *pty);
From 6c4b08262da8126cd341b50fe35fb9cfae8c8f63 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Tue, 27 Feb 2018 17:11:44 +0100
Subject: [PATCH 33/42] console: lxc_terminal_init()
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
src/lxc/attach.c | 4 ++--
src/lxc/console.c | 4 ++--
src/lxc/console.h | 2 +-
3 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/src/lxc/attach.c b/src/lxc/attach.c
index ad059e8c3..d5f7006b1 100644
--- a/src/lxc/attach.c
+++ b/src/lxc/attach.c
@@ -978,7 +978,7 @@ static int lxc_attach_pty(struct lxc_conf *conf, struct lxc_pty *pty)
{
int ret;
- lxc_pty_init(pty);
+ lxc_terminal_init(pty);
ret = lxc_terminal_create(pty);
if (ret < 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
diff --git a/src/lxc/console.c b/src/lxc/console.c
index 23c995fec..f4ac988d6 100644
--- a/src/lxc/console.c
+++ b/src/lxc/console.c
@@ -59,7 +59,7 @@ static struct lxc_list lxc_ttys;
typedef void (*sighandler_t)(int);
-__attribute__((constructor)) void lxc_terminal_init(void)
+__attribute__((constructor)) void lxc_terminal_init_global(void)
{
lxc_list_init(&lxc_ttys);
}
@@ -1013,7 +1013,7 @@ void lxc_terminal_info_init(struct lxc_pty_info *pty)
pty->busy = -1;
}
-void lxc_pty_init(struct lxc_pty *pty)
+void lxc_terminal_init(struct lxc_pty *pty)
{
memset(pty, 0, sizeof(*pty));
pty->slave = -EBADF;
diff --git a/src/lxc/console.h b/src/lxc/console.h
index 15fa4c271..a81e67db5 100644
--- a/src/lxc/console.h
+++ b/src/lxc/console.h
@@ -236,7 +236,7 @@ extern int lxc_make_controlling_pty(int fd);
extern int lxc_login_pty(int fd);
extern void lxc_pty_conf_free(struct lxc_pty *console);
extern void lxc_terminal_info_init(struct lxc_pty_info *pty);
-extern void lxc_pty_init(struct lxc_pty *pty);
+extern void lxc_terminal_init(struct lxc_pty *pty);
extern int lxc_pty_map_ids(struct lxc_conf *c, struct lxc_pty *pty);
#endif
From 894e8dcd951beccd8ebbf0c06bcf9bf4f6ed0c73 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Tue, 27 Feb 2018 17:14:03 +0100
Subject: [PATCH 34/42] console: lxc_terminal_conf_free()
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
src/lxc/attach.c | 4 ++--
src/lxc/conf.c | 2 +-
src/lxc/console.c | 2 +-
src/lxc/console.h | 2 +-
4 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/src/lxc/attach.c b/src/lxc/attach.c
index d5f7006b1..e389c5853 100644
--- a/src/lxc/attach.c
+++ b/src/lxc/attach.c
@@ -997,7 +997,7 @@ static int lxc_attach_pty(struct lxc_conf *conf, struct lxc_pty *pty)
on_error:
lxc_terminal_delete(pty);
- lxc_pty_conf_free(pty);
+ lxc_terminal_conf_free(pty);
return -1;
}
@@ -1387,7 +1387,7 @@ int lxc_attach(const char *name, const char *lxcpath,
if (options->attach_flags & LXC_ATTACH_ALLOCATE_PTY) {
lxc_terminal_delete(&pty);
- lxc_pty_conf_free(&pty);
+ lxc_terminal_conf_free(&pty);
}
lxc_proc_put_context_info(init_ctx);
return ret_parent;
diff --git a/src/lxc/conf.c b/src/lxc/conf.c
index 944546c66..3e33363ed 100644
--- a/src/lxc/conf.c
+++ b/src/lxc/conf.c
@@ -3787,7 +3787,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);
diff --git a/src/lxc/console.c b/src/lxc/console.c
index f4ac988d6..f2111e639 100644
--- a/src/lxc/console.c
+++ b/src/lxc/console.c
@@ -1024,7 +1024,7 @@ void lxc_terminal_init(struct lxc_pty *pty)
lxc_terminal_info_init(&pty->peerpty);
}
-void lxc_pty_conf_free(struct lxc_pty *terminal)
+void lxc_terminal_conf_free(struct lxc_pty *terminal)
{
free(terminal->buffer_log_file);
free(terminal->log_path);
diff --git a/src/lxc/console.h b/src/lxc/console.h
index a81e67db5..5893570fd 100644
--- a/src/lxc/console.h
+++ b/src/lxc/console.h
@@ -234,7 +234,7 @@ extern int lxc_terminal_io_cb(int fd, uint32_t events, void *data,
extern int lxc_make_controlling_pty(int fd);
extern int lxc_login_pty(int fd);
-extern void lxc_pty_conf_free(struct lxc_pty *console);
+extern void lxc_terminal_conf_free(struct lxc_pty *console);
extern void lxc_terminal_info_init(struct lxc_pty_info *pty);
extern void lxc_terminal_init(struct lxc_pty *pty);
extern int lxc_pty_map_ids(struct lxc_conf *c, struct lxc_pty *pty);
From 5400eeafe887f16723dcff099977a9265086cf37 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Tue, 27 Feb 2018 17:15:06 +0100
Subject: [PATCH 35/42] console: lxc_terminal_map_ids()
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
src/lxc/attach.c | 2 +-
src/lxc/console.c | 2 +-
src/lxc/console.h | 2 +-
src/lxc/start.c | 2 +-
4 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/src/lxc/attach.c b/src/lxc/attach.c
index e389c5853..4e5bbfdb8 100644
--- a/src/lxc/attach.c
+++ b/src/lxc/attach.c
@@ -987,7 +987,7 @@ static int lxc_attach_pty(struct lxc_conf *conf, struct lxc_pty *pty)
}
/* 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;
diff --git a/src/lxc/console.c b/src/lxc/console.c
index f2111e639..dcd14e588 100644
--- a/src/lxc/console.c
+++ b/src/lxc/console.c
@@ -1033,7 +1033,7 @@ void lxc_terminal_conf_free(struct lxc_pty *terminal)
lxc_ringbuf_release(&terminal->ringbuf);
}
-int lxc_pty_map_ids(struct lxc_conf *c, struct lxc_pty *pty)
+int lxc_terminal_map_ids(struct lxc_conf *c, struct lxc_pty *pty)
{
int ret;
diff --git a/src/lxc/console.h b/src/lxc/console.h
index 5893570fd..81d882a6a 100644
--- a/src/lxc/console.h
+++ b/src/lxc/console.h
@@ -237,6 +237,6 @@ extern int lxc_login_pty(int fd);
extern void lxc_terminal_conf_free(struct lxc_pty *console);
extern void lxc_terminal_info_init(struct lxc_pty_info *pty);
extern void lxc_terminal_init(struct lxc_pty *pty);
-extern int lxc_pty_map_ids(struct lxc_conf *c, struct lxc_pty *pty);
+extern int lxc_terminal_map_ids(struct lxc_conf *c, struct lxc_pty *pty);
#endif
diff --git a/src/lxc/start.c b/src/lxc/start.c
index 08abb00ba..fcb3280af 100644
--- a/src/lxc/start.c
+++ b/src/lxc/start.c
@@ -811,7 +811,7 @@ int lxc_init(const char *name, struct lxc_handler *handler)
}
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;
From cf9c2d6df59f00f8df70aab2bbb5bea766f636b0 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Tue, 27 Feb 2018 17:52:55 +0100
Subject: [PATCH 36/42] tree-wide: s/struct lxc_pty/lxc_terminal/g
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
src/lxc/attach.c | 14 +++++++-------
src/lxc/commands.c | 2 +-
src/lxc/conf.c | 6 +++---
src/lxc/conf.h | 4 ++--
src/lxc/console.c | 36 ++++++++++++++++++------------------
src/lxc/console.h | 16 ++++++++--------
src/lxc/start.c | 2 +-
7 files changed, 40 insertions(+), 40 deletions(-)
diff --git a/src/lxc/attach.c b/src/lxc/attach.c
index 4e5bbfdb8..919fa17e6 100644
--- a/src/lxc/attach.c
+++ b/src/lxc/attach.c
@@ -974,7 +974,7 @@ static int attach_child_main(struct attach_clone_payload *payload)
rexit(EXIT_FAILURE);
}
-static int lxc_attach_pty(struct lxc_conf *conf, struct lxc_pty *pty)
+static int lxc_attach_pty(struct lxc_conf *conf, struct lxc_terminal *pty)
{
int ret;
@@ -1001,7 +1001,7 @@ static int lxc_attach_pty(struct lxc_conf *conf, struct lxc_pty *pty)
return -1;
}
-static int lxc_attach_pty_mainloop_init(struct lxc_pty *pty,
+static int lxc_attach_pty_mainloop_init(struct lxc_terminal *pty,
struct lxc_epoll_descr *descr)
{
int ret;
@@ -1022,7 +1022,7 @@ static int lxc_attach_pty_mainloop_init(struct lxc_pty *pty,
return 0;
}
-static inline void lxc_attach_pty_close_master(struct lxc_pty *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_pty *pty)
pty->master = -EBADF;
}
-static inline void lxc_attach_pty_close_slave(struct lxc_pty *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_pty *pty)
pty->slave = -EBADF;
}
-static inline void lxc_attach_pty_close_peer(struct lxc_pty *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_pty *pty)
pty->peer = -EBADF;
}
-static inline void lxc_attach_pty_close_log(struct lxc_pty *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_pty pty;
+ struct lxc_terminal pty;
struct lxc_conf *conf;
struct attach_clone_payload payload = {0};
diff --git a/src/lxc/commands.c b/src/lxc/commands.c
index c0ee8e812..f84a1b7aa 100644
--- a/src/lxc/commands.c
+++ b/src/lxc/commands.c
@@ -968,7 +968,7 @@ static int lxc_cmd_console_log_callback(int fd, struct lxc_cmd_req *req,
struct lxc_cmd_rsp rsp;
uint64_t buffer_size = handler->conf->console.buffer_size;
const struct lxc_cmd_console_log *log = req->data;
- struct lxc_pty *console = &handler->conf->console;
+ struct lxc_terminal *console = &handler->conf->console;
struct lxc_ringbuf *buf = &handler->conf->console.ringbuf;
rsp.ret = -EFAULT;
diff --git a/src/lxc/conf.c b/src/lxc/conf.c
index 3e33363ed..699bc8d12 100644
--- a/src/lxc/conf.c
+++ b/src/lxc/conf.c
@@ -1578,7 +1578,7 @@ static int setup_personality(int persona)
}
static int lxc_setup_dev_console(const struct lxc_rootfs *rootfs,
- const struct lxc_pty *console)
+ const struct lxc_terminal *console)
{
char path[MAXPATHLEN];
int ret, fd;
@@ -1634,7 +1634,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_pty *console,
+ const struct lxc_terminal *console,
char *ttydir)
{
int ret, fd;
@@ -1720,7 +1720,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_pty *console, char *ttydir)
+ const struct lxc_terminal *console, char *ttydir)
{
if (!ttydir)
diff --git a/src/lxc/conf.h b/src/lxc/conf.h
index e5c39cda3..219be1e5f 100644
--- a/src/lxc/conf.h
+++ b/src/lxc/conf.h
@@ -164,7 +164,7 @@ struct lxc_tty_state;
* @peer : the file descriptor put/get console traffic
* @name : the file name of the slave pty
*/
-struct lxc_pty {
+struct lxc_terminal {
int slave;
int master;
int peer;
@@ -308,7 +308,7 @@ struct lxc_conf {
struct lxc_tty_info tty_info;
/* Comma-separated list of lxc.tty.max pty names. */
char *pty_names;
- struct lxc_pty console;
+ struct lxc_terminal console;
struct lxc_rootfs rootfs;
char *ttydir;
int close_all_fds;
diff --git a/src/lxc/console.c b/src/lxc/console.c
index dcd14e588..76d12a037 100644
--- a/src/lxc/console.c
+++ b/src/lxc/console.c
@@ -207,7 +207,7 @@ void lxc_terminal_signal_fini(struct lxc_tty_state *ts)
int lxc_terminal_io_cb(int fd, uint32_t events, void *data,
struct lxc_epoll_descr *descr)
{
- struct lxc_pty *terminal = data;
+ struct lxc_terminal *terminal = data;
char buf[LXC_TERMINAL_BUFFER_SIZE];
int r, w, w_log, w_rbuf;
@@ -263,7 +263,7 @@ int lxc_terminal_io_cb(int fd, uint32_t events, void *data,
return 0;
}
-static int lxc_terminal_mainloop_add_peer(struct lxc_pty *terminal)
+static int lxc_terminal_mainloop_add_peer(struct lxc_terminal *terminal)
{
int ret;
@@ -290,7 +290,7 @@ static int lxc_terminal_mainloop_add_peer(struct lxc_pty *terminal)
}
int lxc_terminal_mainloop_add(struct lxc_epoll_descr *descr,
- struct lxc_pty *terminal)
+ struct lxc_terminal *terminal)
{
int ret;
@@ -365,7 +365,7 @@ int lxc_setup_tios(int fd, struct termios *oldtios)
return 0;
}
-static void lxc_terminal_peer_proxy_free(struct lxc_pty *terminal)
+static void lxc_terminal_peer_proxy_free(struct lxc_terminal *terminal)
{
if (terminal->tty_state) {
lxc_terminal_signal_fini(terminal->tty_state);
@@ -380,7 +380,7 @@ static void lxc_terminal_peer_proxy_free(struct lxc_pty *terminal)
terminal->peer = -1;
}
-static int lxc_terminal_peer_proxy_alloc(struct lxc_pty *terminal, int sockfd)
+static int lxc_terminal_peer_proxy_alloc(struct lxc_terminal *terminal, int sockfd)
{
struct termios oldtermio;
struct lxc_tty_state *ts;
@@ -435,7 +435,7 @@ int lxc_terminal_allocate(struct lxc_conf *conf, int sockfd, int *ttyreq)
{
int masterfd = -1, ttynum;
struct lxc_tty_info *tty_info = &conf->tty_info;
- struct lxc_pty *terminal = &conf->console;
+ struct lxc_terminal *terminal = &conf->console;
if (*ttyreq == 0) {
if (lxc_terminal_peer_proxy_alloc(terminal, sockfd) < 0)
@@ -477,7 +477,7 @@ void lxc_terminal_free(struct lxc_conf *conf, int fd)
{
int i;
struct lxc_tty_info *tty_info = &conf->tty_info;
- struct lxc_pty *terminal = &conf->console;
+ struct lxc_terminal *terminal = &conf->console;
for (i = 0; i < tty_info->nbtty; i++) {
if (tty_info->pty_info[i].busy == fd)
@@ -490,7 +490,7 @@ void lxc_terminal_free(struct lxc_conf *conf, int fd)
}
}
-static int lxc_terminal_peer_default(struct lxc_pty *terminal)
+static int lxc_terminal_peer_default(struct lxc_terminal *terminal)
{
struct lxc_tty_state *ts;
const char *path = terminal->path;
@@ -559,7 +559,7 @@ static int lxc_terminal_peer_default(struct lxc_pty *terminal)
return ret;
}
-int lxc_terminal_write_ringbuffer(struct lxc_pty *terminal)
+int lxc_terminal_write_ringbuffer(struct lxc_terminal *terminal)
{
char *r_addr;
ssize_t ret;
@@ -581,7 +581,7 @@ int lxc_terminal_write_ringbuffer(struct lxc_pty *terminal)
return 0;
}
-void lxc_terminal_delete(struct lxc_pty *terminal)
+void lxc_terminal_delete(struct lxc_terminal *terminal)
{
int ret;
@@ -622,7 +622,7 @@ void lxc_terminal_delete(struct lxc_pty *terminal)
* ringbuffer log file is (implementation wise not content wise) independent of
* the terminal log file.
*/
-static int lxc_terminal_create_ringbuf_log_file(struct lxc_pty *terminal)
+static int lxc_terminal_create_ringbuf_log_file(struct lxc_terminal *terminal)
{
if (!terminal->buffer_log_file)
return 0;
@@ -644,7 +644,7 @@ static int lxc_terminal_create_ringbuf_log_file(struct lxc_pty *terminal)
* register a handler for the terminal's masterfd when we create the mainloop
* the terminal handler needs to see an allocated ringbuffer.
*/
-static int lxc_terminal_create_ringbuf(struct lxc_pty *terminal)
+static int lxc_terminal_create_ringbuf(struct lxc_terminal *terminal)
{
int ret;
struct lxc_ringbuf *buf = &terminal->ringbuf;
@@ -690,7 +690,7 @@ static int lxc_terminal_create_ringbuf(struct lxc_pty *terminal)
* This is the terminal log file. Please note that the terminal log file is
* (implementation wise not content wise) independent of the terminal ringbuffer.
*/
-int lxc_terminal_create_log_file(struct lxc_pty *terminal)
+int lxc_terminal_create_log_file(struct lxc_terminal *terminal)
{
if (!terminal->log_path)
return 0;
@@ -705,7 +705,7 @@ int lxc_terminal_create_log_file(struct lxc_pty *terminal)
return 0;
}
-int lxc_terminal_create(struct lxc_pty *terminal)
+int lxc_terminal_create(struct lxc_terminal *terminal)
{
int ret, saved_errno;
@@ -745,7 +745,7 @@ int lxc_terminal_create(struct lxc_pty *terminal)
int lxc_terminal_setup(struct lxc_conf *conf)
{
int ret;
- struct lxc_pty *terminal = &conf->console;
+ struct lxc_terminal *terminal = &conf->console;
if (terminal->path && !strcmp(terminal->path, "none")) {
INFO("No terminal was requested");
@@ -1013,7 +1013,7 @@ void lxc_terminal_info_init(struct lxc_pty_info *pty)
pty->busy = -1;
}
-void lxc_terminal_init(struct lxc_pty *pty)
+void lxc_terminal_init(struct lxc_terminal *pty)
{
memset(pty, 0, sizeof(*pty));
pty->slave = -EBADF;
@@ -1024,7 +1024,7 @@ void lxc_terminal_init(struct lxc_pty *pty)
lxc_terminal_info_init(&pty->peerpty);
}
-void lxc_terminal_conf_free(struct lxc_pty *terminal)
+void lxc_terminal_conf_free(struct lxc_terminal *terminal)
{
free(terminal->buffer_log_file);
free(terminal->log_path);
@@ -1033,7 +1033,7 @@ void lxc_terminal_conf_free(struct lxc_pty *terminal)
lxc_ringbuf_release(&terminal->ringbuf);
}
-int lxc_terminal_map_ids(struct lxc_conf *c, struct lxc_pty *pty)
+int lxc_terminal_map_ids(struct lxc_conf *c, struct lxc_terminal *pty)
{
int ret;
diff --git a/src/lxc/console.h b/src/lxc/console.h
index 81d882a6a..abcc1f951 100644
--- a/src/lxc/console.h
+++ b/src/lxc/console.h
@@ -82,7 +82,7 @@ extern int lxc_terminal_allocate(struct lxc_conf *conf, int sockfd, int *ttynum
* automatically chowned to the uid/gid of the unprivileged user. For this
* ttys_shift_ids() can be called.)
*/
-extern int lxc_terminal_create(struct lxc_pty *console);
+extern int lxc_terminal_create(struct lxc_terminal *console);
/**
* lxc_terminal_setup: Create a new pty.
@@ -98,7 +98,7 @@ extern int lxc_terminal_setup(struct lxc_conf *);
* /dev/tty)
* Registered handlers in a mainloop are not automatically deleted.
*/
-extern void lxc_terminal_delete(struct lxc_pty *);
+extern void lxc_terminal_delete(struct lxc_terminal *);
/*
* lxc_terminal_free: mark the console or a tty as unallocated, free any
@@ -114,7 +114,7 @@ extern void lxc_terminal_free(struct lxc_conf *conf, int fd);
/*
* Register pty event handlers in an open mainloop
*/
-extern int lxc_terminal_mainloop_add(struct lxc_epoll_descr *, struct lxc_pty *);
+extern int lxc_terminal_mainloop_add(struct lxc_epoll_descr *, struct lxc_terminal *);
/*
* Handle SIGWINCH events on the allocated ptys.
@@ -227,16 +227,16 @@ extern int lxc_terminal_signalfd_cb(int fd, uint32_t events, void *cbdata,
*/
extern void lxc_terminal_signal_fini(struct lxc_tty_state *ts);
-extern int lxc_terminal_write_ringbuffer(struct lxc_pty *console);
-extern int lxc_terminal_create_log_file(struct lxc_pty *console);
+extern int lxc_terminal_write_ringbuffer(struct lxc_terminal *console);
+extern int lxc_terminal_create_log_file(struct lxc_terminal *console);
extern int lxc_terminal_io_cb(int fd, uint32_t events, void *data,
struct lxc_epoll_descr *descr);
extern int lxc_make_controlling_pty(int fd);
extern int lxc_login_pty(int fd);
-extern void lxc_terminal_conf_free(struct lxc_pty *console);
+extern void lxc_terminal_conf_free(struct lxc_terminal *console);
extern void lxc_terminal_info_init(struct lxc_pty_info *pty);
-extern void lxc_terminal_init(struct lxc_pty *pty);
-extern int lxc_terminal_map_ids(struct lxc_conf *c, struct lxc_pty *pty);
+extern void lxc_terminal_init(struct lxc_terminal *pty);
+extern int lxc_terminal_map_ids(struct lxc_conf *c, struct lxc_terminal *pty);
#endif
diff --git a/src/lxc/start.c b/src/lxc/start.c
index fcb3280af..b300a82d9 100644
--- a/src/lxc/start.c
+++ b/src/lxc/start.c
@@ -529,7 +529,7 @@ int lxc_poll(const char *name, struct lxc_handler *handler)
}
if (has_console) {
- struct lxc_pty *console = &handler->conf->console;
+ struct lxc_terminal *console = &handler->conf->console;
ret = lxc_terminal_mainloop_add(&descr, console);
if (ret < 0) {
From 0286f81e64dc05205714ba39d9f004f6419d7228 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Tue, 27 Feb 2018 17:58:34 +0100
Subject: [PATCH 37/42] tree-wide: struct lxc_terminal_info
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
src/lxc/conf.c | 8 ++++----
src/lxc/conf.h | 6 +++---
src/lxc/console.c | 2 +-
src/lxc/console.h | 2 +-
src/lxc/start.c | 2 +-
5 files changed, 10 insertions(+), 10 deletions(-)
diff --git a/src/lxc/conf.c b/src/lxc/conf.c
index 699bc8d12..bd13db039 100644
--- a/src/lxc/conf.c
+++ b/src/lxc/conf.c
@@ -848,7 +848,7 @@ static int lxc_setup_ttys(struct lxc_conf *conf)
return 0;
for (i = 0; i < tty_info->nbtty; i++) {
- struct lxc_pty_info *pty_info = &tty_info->pty_info[i];
+ struct lxc_terminal_info *pty_info = &tty_info->pty_info[i];
ret = snprintf(path, sizeof(path), "/dev/tty%d", i + 1);
if (ret < 0 || (size_t)ret >= sizeof(path))
@@ -946,7 +946,7 @@ int lxc_allocate_ttys(const char *name, struct lxc_conf *conf)
}
for (i = 0; i < conf->tty; i++) {
- struct lxc_pty_info *pty_info = &tty_info->pty_info[i];
+ struct lxc_terminal_info *pty_info = &tty_info->pty_info[i];
ret = openpty(&pty_info->master, &pty_info->slave,
pty_info->name, NULL, NULL);
@@ -987,7 +987,7 @@ void lxc_delete_tty(struct lxc_tty_info *tty_info)
int i;
for (i = 0; i < tty_info->nbtty; i++) {
- struct lxc_pty_info *pty_info = &tty_info->pty_info[i];
+ struct lxc_terminal_info *pty_info = &tty_info->pty_info[i];
close(pty_info->master);
close(pty_info->slave);
@@ -1011,7 +1011,7 @@ 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 *pty_info = &tty_info->pty_info[i];
ttyfds[0] = pty_info->master;
ttyfds[1] = pty_info->slave;
diff --git a/src/lxc/conf.h b/src/lxc/conf.h
index 219be1e5f..e9ad3324c 100644
--- a/src/lxc/conf.h
+++ b/src/lxc/conf.h
@@ -140,7 +140,7 @@ struct id_map {
* @master : the file descriptor of the master
* @slave : the file descriptor of the slave
*/
-struct lxc_pty_info {
+struct lxc_terminal_info {
char name[MAXPATHLEN];
int master;
int slave;
@@ -154,7 +154,7 @@ struct lxc_pty_info {
*/
struct lxc_tty_info {
int nbtty;
- struct lxc_pty_info *pty_info;
+ struct lxc_terminal_info *pty_info;
};
struct lxc_tty_state;
@@ -168,7 +168,7 @@ struct lxc_terminal {
int slave;
int master;
int peer;
- struct lxc_pty_info peerpty;
+ struct lxc_terminal_info peerpty;
struct lxc_epoll_descr *descr;
char *path;
char *log_path;
diff --git a/src/lxc/console.c b/src/lxc/console.c
index 76d12a037..33fd153a7 100644
--- a/src/lxc/console.c
+++ b/src/lxc/console.c
@@ -1005,7 +1005,7 @@ int lxc_login_pty(int fd)
return 0;
}
-void lxc_terminal_info_init(struct lxc_pty_info *pty)
+void lxc_terminal_info_init(struct lxc_terminal_info *pty)
{
pty->name[0] = '\0';
pty->master = -EBADF;
diff --git a/src/lxc/console.h b/src/lxc/console.h
index abcc1f951..17b280648 100644
--- a/src/lxc/console.h
+++ b/src/lxc/console.h
@@ -235,7 +235,7 @@ extern int lxc_terminal_io_cb(int fd, uint32_t events, void *data,
extern int lxc_make_controlling_pty(int fd);
extern int lxc_login_pty(int fd);
extern void lxc_terminal_conf_free(struct lxc_terminal *console);
-extern void lxc_terminal_info_init(struct lxc_pty_info *pty);
+extern void lxc_terminal_info_init(struct lxc_terminal_info *pty);
extern void lxc_terminal_init(struct lxc_terminal *pty);
extern int lxc_terminal_map_ids(struct lxc_conf *c, struct lxc_terminal *pty);
diff --git a/src/lxc/start.c b/src/lxc/start.c
index b300a82d9..fbe50d321 100644
--- a/src/lxc/start.c
+++ b/src/lxc/start.c
@@ -1340,7 +1340,7 @@ static int do_start(void *data)
static int lxc_recv_ttys_from_child(struct lxc_handler *handler)
{
int i;
- struct lxc_pty_info *pty_info;
+ struct lxc_terminal_info *pty_info;
int ret = -1;
int sock = handler->data_sock[1];
struct lxc_conf *conf = handler->conf;
From 7039cb9f762a7eacf3c52b0437d2e1114c2ad1d4 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Tue, 27 Feb 2018 18:15:45 +0100
Subject: [PATCH 38/42] console: move struct lxc_terminal{_info}
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
src/lxc/conf.h | 48 +-----------------------------------------------
src/lxc/console.h | 46 +++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 46 insertions(+), 48 deletions(-)
diff --git a/src/lxc/conf.h b/src/lxc/conf.h
index e9ad3324c..b3e7a7087 100644
--- a/src/lxc/conf.h
+++ b/src/lxc/conf.h
@@ -35,6 +35,7 @@
#endif
#include <stdbool.h>
+#include "console.h"
#include "list.h"
#include "ringbuf.h"
#include "start.h" /* for lxc_handler */
@@ -133,20 +134,6 @@ 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_terminal_info {
- char name[MAXPATHLEN];
- int master;
- int slave;
- int busy;
-};
-
/*
* Defines the number of tty configured and contains the
* instantiated ptys
@@ -159,39 +146,6 @@ struct lxc_tty_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_terminal {
- int slave;
- int master;
- int peer;
- struct lxc_terminal_info peerpty;
- struct lxc_epoll_descr *descr;
- char *path;
- char *log_path;
- int log_fd;
- unsigned int log_rotate;
- char name[MAXPATHLEN];
- struct termios *tios;
- struct lxc_tty_state *tty_state;
- struct /* lxc_pty_ringbuf */ {
- /* size of the ringbuffer */
- uint64_t buffer_size;
-
- /* path to the log file for the ringbuffer */
- char *buffer_log_file;
-
- /* fd to the log file for the ringbuffer */
- int buffer_log_file_fd;
-
- /* the in-memory ringbuffer */
- struct lxc_ringbuf ringbuf;
- };
-};
-
/*
* Defines a structure to store the rootfs location, the
* optionals pivot_root, rootfs mount paths
diff --git a/src/lxc/console.h b/src/lxc/console.h
index 17b280648..e83bd8cdb 100644
--- a/src/lxc/console.h
+++ b/src/lxc/console.h
@@ -24,11 +24,55 @@
#ifndef __LXC_CONSOLE_H
#define __LXC_CONSOLE_H
+#include "config.h"
+
#include <signal.h>
#include <stdio.h>
-#include "conf.h"
#include "list.h"
+#include "ringbuf.h"
+
+struct lxc_conf;
+
+/* 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_terminal_info {
+ char name[MAXPATHLEN];
+ int master;
+ int slave;
+ int busy;
+};
+
+struct lxc_terminal {
+ int slave;
+ int master;
+ int peer;
+ struct lxc_terminal_info peerpty;
+ struct lxc_epoll_descr *descr;
+ char *path;
+ char *log_path;
+ int log_fd;
+ unsigned int log_rotate;
+ char name[MAXPATHLEN];
+ struct termios *tios;
+ struct lxc_tty_state *tty_state;
+ struct /* lxc_pty_ringbuf */ {
+ /* size of the ringbuffer */
+ uint64_t buffer_size;
+
+ /* path to the log file for the ringbuffer */
+ char *buffer_log_file;
+
+ /* fd to the log file for the ringbuffer */
+ int buffer_log_file_fd;
+
+ /* the in-memory ringbuffer */
+ struct lxc_ringbuf ringbuf;
+ };
+};
struct lxc_epoll_descr; /* defined in mainloop.h */
struct lxc_container; /* defined in lxccontainer.h */
From 755aea3dcdf98967dfd5d085a2055570ba386843 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Tue, 27 Feb 2018 18:20:00 +0100
Subject: [PATCH 39/42] console: s/pty_info/tty/g
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
src/lxc/conf.c | 58 +++++++++++++++++++++++++++----------------------------
src/lxc/conf.h | 2 +-
src/lxc/console.c | 12 ++++++------
src/lxc/start.c | 16 +++++++--------
4 files changed, 43 insertions(+), 45 deletions(-)
diff --git a/src/lxc/conf.c b/src/lxc/conf.c
index bd13db039..0f985e803 100644
--- a/src/lxc/conf.c
+++ b/src/lxc/conf.c
@@ -848,7 +848,7 @@ static int lxc_setup_ttys(struct lxc_conf *conf)
return 0;
for (i = 0; i < tty_info->nbtty; i++) {
- struct lxc_terminal_info *pty_info = &tty_info->pty_info[i];
+ struct lxc_terminal_info *tty = &tty_info->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,17 +910,17 @@ 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;
}
@@ -939,17 +939,15 @@ int lxc_allocate_ttys(const char *name, struct lxc_conf *conf)
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");
+ tty_info->tty = malloc(sizeof(*tty_info->tty) * conf->tty);
+ if (!tty_info->tty)
return -ENOMEM;
- }
for (i = 0; i < conf->tty; i++) {
- struct lxc_terminal_info *pty_info = &tty_info->pty_info[i];
+ struct lxc_terminal_info *tty = &tty_info->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;
@@ -958,22 +956,22 @@ int lxc_allocate_ttys(const char *name, struct lxc_conf *conf)
}
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;
@@ -987,14 +985,14 @@ void lxc_delete_tty(struct lxc_tty_info *tty_info)
int i;
for (i = 0; i < tty_info->nbtty; i++) {
- struct lxc_terminal_info *pty_info = &tty_info->pty_info[i];
+ struct lxc_terminal_info *tty = &tty_info->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;
+ free(tty_info->tty);
+ tty_info->tty = NULL;
tty_info->nbtty = 0;
}
@@ -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_terminal_info *pty_info = &tty_info->pty_info[i];
+ struct lxc_terminal_info *tty = &tty_info->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)
diff --git a/src/lxc/conf.h b/src/lxc/conf.h
index b3e7a7087..fe3d7c39a 100644
--- a/src/lxc/conf.h
+++ b/src/lxc/conf.h
@@ -141,7 +141,7 @@ struct id_map {
*/
struct lxc_tty_info {
int nbtty;
- struct lxc_terminal_info *pty_info;
+ struct lxc_terminal_info *tty;
};
struct lxc_tty_state;
diff --git a/src/lxc/console.c b/src/lxc/console.c
index 33fd153a7..75168a4fa 100644
--- a/src/lxc/console.c
+++ b/src/lxc/console.c
@@ -448,7 +448,7 @@ int lxc_terminal_allocate(struct lxc_conf *conf, int sockfd, int *ttyreq)
if (*ttyreq > tty_info->nbtty)
goto out;
- if (tty_info->pty_info[*ttyreq - 1].busy)
+ if (tty_info->tty[*ttyreq - 1].busy)
goto out;
/* the requested tty is available */
@@ -457,7 +457,7 @@ int lxc_terminal_allocate(struct lxc_conf *conf, int sockfd, int *ttyreq)
}
/* search for next available tty, fixup index tty1 => [0] */
- for (ttynum = 1; ttynum <= tty_info->nbtty && tty_info->pty_info[ttynum - 1].busy; ttynum++)
+ for (ttynum = 1; ttynum <= tty_info->nbtty && tty_info->tty[ttynum - 1].busy; ttynum++)
;
/* we didn't find any available slot for tty */
@@ -467,8 +467,8 @@ int lxc_terminal_allocate(struct lxc_conf *conf, int sockfd, int *ttyreq)
*ttyreq = ttynum;
out_tty:
- tty_info->pty_info[ttynum - 1].busy = sockfd;
- masterfd = tty_info->pty_info[ttynum - 1].master;
+ tty_info->tty[ttynum - 1].busy = sockfd;
+ masterfd = tty_info->tty[ttynum - 1].master;
out:
return masterfd;
}
@@ -480,8 +480,8 @@ void lxc_terminal_free(struct lxc_conf *conf, int fd)
struct lxc_terminal *terminal = &conf->console;
for (i = 0; i < tty_info->nbtty; i++) {
- if (tty_info->pty_info[i].busy == fd)
- tty_info->pty_info[i].busy = 0;
+ if (tty_info->tty[i].busy == fd)
+ tty_info->tty[i].busy = 0;
}
if (terminal->peerpty.busy == fd) {
diff --git a/src/lxc/start.c b/src/lxc/start.c
index fbe50d321..d70e71644 100644
--- a/src/lxc/start.c
+++ b/src/lxc/start.c
@@ -1340,7 +1340,7 @@ static int do_start(void *data)
static int lxc_recv_ttys_from_child(struct lxc_handler *handler)
{
int i;
- struct lxc_terminal_info *pty_info;
+ struct lxc_terminal_info *tty;
int ret = -1;
int sock = handler->data_sock[1];
struct lxc_conf *conf = handler->conf;
@@ -1349,8 +1349,8 @@ static int lxc_recv_ttys_from_child(struct lxc_handler *handler)
if (!conf->tty)
return 0;
- tty_info->pty_info = malloc(sizeof(*tty_info->pty_info) * conf->tty);
- if (!tty_info->pty_info)
+ tty_info->tty = malloc(sizeof(*tty_info->tty) * conf->tty);
+ if (!tty_info->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 = &tty_info->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,
From 0a096437ab66555116bed80e72fe84241b311382 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Tue, 27 Feb 2018 18:23:07 +0100
Subject: [PATCH 40/42] console: s/tty_info/ttys/g
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
src/lxc/conf.c | 40 ++++++++++++++++++++--------------------
src/lxc/conf.h | 9 ++++-----
src/lxc/console.c | 22 +++++++++++-----------
src/lxc/criu.c | 12 ++++++------
src/lxc/start.c | 14 +++++++-------
5 files changed, 48 insertions(+), 49 deletions(-)
diff --git a/src/lxc/conf.c b/src/lxc/conf.c
index 0f985e803..5725a9abe 100644
--- a/src/lxc/conf.c
+++ b/src/lxc/conf.c
@@ -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_terminal_info *tty = &tty_info->tty[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))
@@ -926,32 +926,32 @@ static int lxc_setup_ttys(struct lxc_conf *conf)
}
}
- 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->tty = malloc(sizeof(*tty_info->tty) * conf->tty);
- if (!tty_info->tty)
+ ttys->tty = malloc(sizeof(*ttys->tty) * conf->tty);
+ if (!ttys->tty)
return -ENOMEM;
for (i = 0; i < conf->tty; i++) {
- struct lxc_terminal_info *tty = &tty_info->tty[i];
+ struct lxc_terminal_info *tty = &ttys->tty[i];
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;
}
@@ -974,33 +974,33 @@ int lxc_allocate_ttys(const char *name, struct lxc_conf *conf)
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_terminal_info *tty = &tty_info->tty[i];
+ for (i = 0; i < ttys->nbtty; i++) {
+ struct lxc_terminal_info *tty = &ttys->tty[i];
close(tty->master);
close(tty->slave);
}
- free(tty_info->tty);
- tty_info->tty = 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;
@@ -1009,7 +1009,7 @@ static int lxc_send_ttys_to_parent(struct lxc_handler *handler)
for (i = 0; i < conf->tty; i++) {
int ttyfds[2];
- struct lxc_terminal_info *tty = &tty_info->tty[i];
+ struct lxc_terminal_info *tty = &ttys->tty[i];
ttyfds[0] = tty->master;
ttyfds[1] = tty->slave;
@@ -1065,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;
}
diff --git a/src/lxc/conf.h b/src/lxc/conf.h
index fe3d7c39a..467bfffcd 100644
--- a/src/lxc/conf.h
+++ b/src/lxc/conf.h
@@ -134,8 +134,7 @@ struct id_map {
unsigned long hostid, nsid, range;
};
-/*
- * 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
*/
@@ -204,7 +203,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
@@ -259,7 +258,7 @@ 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_terminal console;
@@ -388,7 +387,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);
diff --git a/src/lxc/console.c b/src/lxc/console.c
index 75168a4fa..2694d99bd 100644
--- a/src/lxc/console.c
+++ b/src/lxc/console.c
@@ -434,7 +434,7 @@ static int lxc_terminal_peer_proxy_alloc(struct lxc_terminal *terminal, int sock
int lxc_terminal_allocate(struct lxc_conf *conf, int sockfd, int *ttyreq)
{
int masterfd = -1, ttynum;
- struct lxc_tty_info *tty_info = &conf->tty_info;
+ struct lxc_tty_info *ttys = &conf->ttys;
struct lxc_terminal *terminal = &conf->console;
if (*ttyreq == 0) {
@@ -445,10 +445,10 @@ int lxc_terminal_allocate(struct lxc_conf *conf, int sockfd, int *ttyreq)
}
if (*ttyreq > 0) {
- if (*ttyreq > tty_info->nbtty)
+ if (*ttyreq > ttys->nbtty)
goto out;
- if (tty_info->tty[*ttyreq - 1].busy)
+ if (ttys->tty[*ttyreq - 1].busy)
goto out;
/* the requested tty is available */
@@ -457,18 +457,18 @@ int lxc_terminal_allocate(struct lxc_conf *conf, int sockfd, int *ttyreq)
}
/* search for next available tty, fixup index tty1 => [0] */
- for (ttynum = 1; ttynum <= tty_info->nbtty && tty_info->tty[ttynum - 1].busy; ttynum++)
+ for (ttynum = 1; ttynum <= ttys->nbtty && ttys->tty[ttynum - 1].busy; ttynum++)
;
/* we didn't find any available slot for tty */
- if (ttynum > tty_info->nbtty)
+ if (ttynum > ttys->nbtty)
goto out;
*ttyreq = ttynum;
out_tty:
- tty_info->tty[ttynum - 1].busy = sockfd;
- masterfd = tty_info->tty[ttynum - 1].master;
+ ttys->tty[ttynum - 1].busy = sockfd;
+ masterfd = ttys->tty[ttynum - 1].master;
out:
return masterfd;
}
@@ -476,12 +476,12 @@ int lxc_terminal_allocate(struct lxc_conf *conf, int sockfd, int *ttyreq)
void lxc_terminal_free(struct lxc_conf *conf, int fd)
{
int i;
- struct lxc_tty_info *tty_info = &conf->tty_info;
+ struct lxc_tty_info *ttys = &conf->ttys;
struct lxc_terminal *terminal = &conf->console;
- for (i = 0; i < tty_info->nbtty; i++) {
- if (tty_info->tty[i].busy == fd)
- tty_info->tty[i].busy = 0;
+ for (i = 0; i < ttys->nbtty; i++) {
+ if (ttys->tty[i].busy == fd)
+ ttys->tty[i].busy = 0;
}
if (terminal->peerpty.busy == fd) {
diff --git a/src/lxc/criu.c b/src/lxc/criu.c
index f92863d86..f60a6e155 100644
--- a/src/lxc/criu.c
+++ b/src/lxc/criu.c
@@ -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;
diff --git a/src/lxc/start.c b/src/lxc/start.c
index d70e71644..bc8067e8f 100644
--- a/src/lxc/start.c
+++ b/src/lxc/start.c
@@ -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:
@@ -951,7 +951,7 @@ void lxc_fini(const char *name, struct lxc_handler *handler)
WARN("%s - Failed to restore signal mask", strerror(errno));
lxc_terminal_delete(&handler->conf->console);
- lxc_delete_tty(&handler->conf->tty_info);
+ 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.
@@ -1344,13 +1344,13 @@ static int lxc_recv_ttys_from_child(struct lxc_handler *handler)
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->tty = malloc(sizeof(*tty_info->tty) * conf->tty);
- if (!tty_info->tty)
+ ttys->tty = malloc(sizeof(*ttys->tty) * conf->tty);
+ if (!ttys->tty)
return -1;
for (i = 0; i < conf->tty; i++) {
@@ -1360,7 +1360,7 @@ static int lxc_recv_ttys_from_child(struct lxc_handler *handler)
if (ret < 0)
break;
- tty = &tty_info->tty[i];
+ tty = &ttys->tty[i];
tty->busy = 0;
tty->master = ttyfds[0];
tty->slave = ttyfds[1];
@@ -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;
}
From aa67da3bfb8e2b27efa9e938ca6d40d24b9759bf Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Tue, 27 Feb 2018 18:25:41 +0100
Subject: [PATCH 41/42] console: struct lxc_terminal_state
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
src/lxc/conf.h | 2 --
src/lxc/console.c | 22 ++++++++---------
src/lxc/console.h | 72 +++++++++++++++++++++++++++----------------------------
3 files changed, 47 insertions(+), 49 deletions(-)
diff --git a/src/lxc/conf.h b/src/lxc/conf.h
index 467bfffcd..77cb0fa10 100644
--- a/src/lxc/conf.h
+++ b/src/lxc/conf.h
@@ -143,8 +143,6 @@ struct lxc_tty_info {
struct lxc_terminal_info *tty;
};
-struct lxc_tty_state;
-
/*
* Defines a structure to store the rootfs location, the
* optionals pivot_root, rootfs mount paths
diff --git a/src/lxc/console.c b/src/lxc/console.c
index 2694d99bd..053f73e3d 100644
--- a/src/lxc/console.c
+++ b/src/lxc/console.c
@@ -88,7 +88,7 @@ void lxc_terminal_winsz(int srcfd, int dstfd)
return;
}
-static void lxc_terminal_winch(struct lxc_tty_state *ts)
+static void lxc_terminal_winch(struct lxc_terminal_state *ts)
{
lxc_terminal_winsz(ts->stdinfd, ts->masterfd);
@@ -99,7 +99,7 @@ static void lxc_terminal_winch(struct lxc_tty_state *ts)
void lxc_terminal_sigwinch(int sig)
{
struct lxc_list *it;
- struct lxc_tty_state *ts;
+ struct lxc_terminal_state *ts;
lxc_list_for_each(it, &lxc_ttys) {
ts = it->elem;
@@ -112,7 +112,7 @@ int lxc_terminal_signalfd_cb(int fd, uint32_t events, void *cbdata,
{
ssize_t ret;
struct signalfd_siginfo siginfo;
- struct lxc_tty_state *ts = cbdata;
+ struct lxc_terminal_state *ts = cbdata;
ret = read(fd, &siginfo, sizeof(siginfo));
if (ret < 0 || (size_t)ret < sizeof(siginfo)) {
@@ -131,12 +131,12 @@ int lxc_terminal_signalfd_cb(int fd, uint32_t events, void *cbdata,
return 0;
}
-struct lxc_tty_state *lxc_terminal_signal_init(int srcfd, int dstfd)
+struct lxc_terminal_state *lxc_terminal_signal_init(int srcfd, int dstfd)
{
int ret;
bool istty;
sigset_t mask;
- struct lxc_tty_state *ts;
+ struct lxc_terminal_state *ts;
ts = malloc(sizeof(*ts));
if (!ts)
@@ -189,7 +189,7 @@ struct lxc_tty_state *lxc_terminal_signal_init(int srcfd, int dstfd)
return ts;
}
-void lxc_terminal_signal_fini(struct lxc_tty_state *ts)
+void lxc_terminal_signal_fini(struct lxc_terminal_state *ts)
{
if (ts->sigfd >= 0) {
close(ts->sigfd);
@@ -383,7 +383,7 @@ static void lxc_terminal_peer_proxy_free(struct lxc_terminal *terminal)
static int lxc_terminal_peer_proxy_alloc(struct lxc_terminal *terminal, int sockfd)
{
struct termios oldtermio;
- struct lxc_tty_state *ts;
+ struct lxc_terminal_state *ts;
int ret;
if (terminal->master < 0) {
@@ -492,7 +492,7 @@ void lxc_terminal_free(struct lxc_conf *conf, int fd)
static int lxc_terminal_peer_default(struct lxc_terminal *terminal)
{
- struct lxc_tty_state *ts;
+ struct lxc_terminal_state *ts;
const char *path = terminal->path;
int fd;
int ret = 0;
@@ -807,7 +807,7 @@ int lxc_terminal_set_stdfds(int fd)
int lxc_terminal_stdin_cb(int fd, uint32_t events, void *cbdata,
struct lxc_epoll_descr *descr)
{
- struct lxc_tty_state *ts = cbdata;
+ struct lxc_terminal_state *ts = cbdata;
char c;
if (fd != ts->stdinfd)
@@ -838,7 +838,7 @@ int lxc_terminal_stdin_cb(int fd, uint32_t events, void *cbdata,
int lxc_terminal_master_cb(int fd, uint32_t events, void *cbdata,
struct lxc_epoll_descr *descr)
{
- struct lxc_tty_state *ts = cbdata;
+ struct lxc_terminal_state *ts = cbdata;
char buf[LXC_TERMINAL_BUFFER_SIZE];
int r, w;
@@ -872,7 +872,7 @@ int lxc_console(struct lxc_container *c, int ttynum,
int ret, ttyfd, masterfd;
struct lxc_epoll_descr descr;
struct termios oldtios;
- struct lxc_tty_state *ts;
+ struct lxc_terminal_state *ts;
int istty = 0;
ttyfd = lxc_cmd_console(c->name, &ttynum, &masterfd, c->config_path);
diff --git a/src/lxc/console.h b/src/lxc/console.h
index e83bd8cdb..4c3fff55a 100644
--- a/src/lxc/console.h
+++ b/src/lxc/console.h
@@ -32,7 +32,9 @@
#include "list.h"
#include "ringbuf.h"
+struct lxc_container;
struct lxc_conf;
+struct lxc_epoll_descr;
/* Defines a structure containing a pty information for virtualizing a tty
* @name : the path name of the slave pty side
@@ -46,37 +48,7 @@ struct lxc_terminal_info {
int busy;
};
-struct lxc_terminal {
- int slave;
- int master;
- int peer;
- struct lxc_terminal_info peerpty;
- struct lxc_epoll_descr *descr;
- char *path;
- char *log_path;
- int log_fd;
- unsigned int log_rotate;
- char name[MAXPATHLEN];
- struct termios *tios;
- struct lxc_tty_state *tty_state;
- struct /* lxc_pty_ringbuf */ {
- /* size of the ringbuffer */
- uint64_t buffer_size;
-
- /* path to the log file for the ringbuffer */
- char *buffer_log_file;
-
- /* fd to the log file for the ringbuffer */
- int buffer_log_file_fd;
-
- /* the in-memory ringbuffer */
- struct lxc_ringbuf ringbuf;
- };
-};
-
-struct lxc_epoll_descr; /* defined in mainloop.h */
-struct lxc_container; /* defined in lxccontainer.h */
-struct lxc_tty_state
+struct lxc_terminal_state
{
struct lxc_list node;
int stdinfd;
@@ -104,6 +76,34 @@ struct lxc_tty_state
sigset_t oldmask;
};
+struct lxc_terminal {
+ int slave;
+ int master;
+ int peer;
+ struct lxc_terminal_info peerpty;
+ struct lxc_epoll_descr *descr;
+ char *path;
+ char *log_path;
+ int log_fd;
+ unsigned int log_rotate;
+ char name[MAXPATHLEN];
+ struct termios *tios;
+ struct lxc_terminal_state *tty_state;
+ struct /* lxc_terminal_ringbuf */ {
+ /* size of the ringbuffer */
+ uint64_t buffer_size;
+
+ /* path to the log file for the ringbuffer */
+ char *buffer_log_file;
+
+ /* fd to the log file for the ringbuffer */
+ int buffer_log_file_fd;
+
+ /* the in-memory ringbuffer */
+ struct lxc_ringbuf ringbuf;
+ };
+};
+
/*
* lxc_terminal_allocate: allocate the console or a tty
*
@@ -233,8 +233,8 @@ extern void lxc_terminal_winsz(int srcfd, int dstfd);
* @srcfd : src for winsz in SIGWINCH handler
* @dstfd : dst for winsz in SIGWINCH handler
*
- * Returns lxc_tty_state structure on success or NULL on failure. The sigfd
- * member of the returned lxc_tty_state can be select()/poll()ed/epoll()ed
+ * Returns lxc_terminal_state structure on success or NULL on failure. The sigfd
+ * member of the returned lxc_terminal_state can be select()/poll()ed/epoll()ed
* on (ie added to a mainloop) for signals.
*
* Must be called with process_lock held to protect the lxc_ttys list, or
@@ -249,7 +249,7 @@ extern void lxc_terminal_winsz(int srcfd, int dstfd);
*
* This function allocates memory. It is up to the caller to free it.
*/
-extern struct lxc_tty_state *lxc_terminal_signal_init(int srcfd, int dstfd);
+extern struct lxc_terminal_state *lxc_terminal_signal_init(int srcfd, int dstfd);
/*
* Handler for signal events. To be registered via the corresponding functions
@@ -261,7 +261,7 @@ extern int lxc_terminal_signalfd_cb(int fd, uint32_t events, void *cbdata,
/*
* lxc_terminal_signal_fini: uninstall signal handler
*
- * @ts : the lxc_tty_state returned by lxc_terminal_signal_init
+ * @ts : the lxc_terminal_state returned by lxc_terminal_signal_init
*
* Restore the saved signal handler that was in effect at the time
* lxc_terminal_signal_init() was called.
@@ -269,7 +269,7 @@ extern int lxc_terminal_signalfd_cb(int fd, uint32_t events, void *cbdata,
* Must be called with process_lock held to protect the lxc_ttys list, or
* from a non-threaded context.
*/
-extern void lxc_terminal_signal_fini(struct lxc_tty_state *ts);
+extern void lxc_terminal_signal_fini(struct lxc_terminal_state *ts);
extern int lxc_terminal_write_ringbuffer(struct lxc_terminal *console);
extern int lxc_terminal_create_log_file(struct lxc_terminal *console);
From c162ac3d1a089acc07db505db0f707587b05bcbf Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Tue, 27 Feb 2018 18:31:31 +0100
Subject: [PATCH 42/42] tree-wide: console.<c,h> -> terminal.<c,h>
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
src/lxc/Makefile.am | 4 ++--
src/lxc/attach.c | 2 +-
src/lxc/commands.c | 2 +-
src/lxc/conf.c | 4 ++--
src/lxc/conf.h | 2 +-
src/lxc/lxccontainer.c | 2 +-
src/lxc/start.c | 8 ++++----
src/lxc/{console.c => terminal.c} | 2 +-
src/lxc/{console.h => terminal.h} | 0
9 files changed, 13 insertions(+), 13 deletions(-)
rename src/lxc/{console.c => terminal.c} (99%)
rename src/lxc/{console.h => terminal.h} (100%)
diff --git a/src/lxc/Makefile.am b/src/lxc/Makefile.am
index ba41e7340..fb799c8db 100644
--- a/src/lxc/Makefile.am
+++ b/src/lxc/Makefile.am
@@ -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 \
diff --git a/src/lxc/attach.c b/src/lxc/attach.c
index 919fa17e6..243c91c65 100644
--- a/src/lxc/attach.c
+++ b/src/lxc/attach.c
@@ -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
diff --git a/src/lxc/commands.c b/src/lxc/commands.c
index f84a1b7aa..11d9ad84e 100644
--- a/src/lxc/commands.c
+++ b/src/lxc/commands.c
@@ -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"
/*
diff --git a/src/lxc/conf.c b/src/lxc/conf.c
index 5725a9abe..69b014719 100644
--- a/src/lxc/conf.c
+++ b/src/lxc/conf.c
@@ -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>
diff --git a/src/lxc/conf.h b/src/lxc/conf.h
index 77cb0fa10..a9017ed6e 100644
--- a/src/lxc/conf.h
+++ b/src/lxc/conf.h
@@ -35,10 +35,10 @@
#endif
#include <stdbool.h>
-#include "console.h"
#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;
diff --git a/src/lxc/lxccontainer.c b/src/lxc/lxccontainer.c
index fb82707c4..ede0be58f 100644
--- a/src/lxc/lxccontainer.c
+++ b/src/lxc/lxccontainer.c
@@ -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"
diff --git a/src/lxc/start.c b/src/lxc/start.c
index bc8067e8f..eb7331f8a 100644
--- a/src/lxc/start.c
+++ b/src/lxc/start.c
@@ -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);
diff --git a/src/lxc/console.c b/src/lxc/terminal.c
similarity index 99%
rename from src/lxc/console.c
rename to src/lxc/terminal.c
index 053f73e3d..59a0830fe 100644
--- a/src/lxc/console.c
+++ b/src/lxc/terminal.c
@@ -38,11 +38,11 @@
#include "commands.h"
#include "conf.h"
#include "config.h"
-#include "console.h"
#include "log.h"
#include "lxclock.h"
#include "mainloop.h"
#include "start.h" /* for struct lxc_handler */
+#include "terminal.h"
#include "utils.h"
#if HAVE_PTY_H
diff --git a/src/lxc/console.h b/src/lxc/terminal.h
similarity index 100%
rename from src/lxc/console.h
rename to src/lxc/terminal.h
More information about the lxc-devel
mailing list