console: struct lxc_terminal_state

parent 0e4be3cf
...@@ -143,8 +143,6 @@ struct lxc_tty_info { ...@@ -143,8 +143,6 @@ struct lxc_tty_info {
struct lxc_terminal_info *tty; struct lxc_terminal_info *tty;
}; };
struct lxc_tty_state;
/* Defines a structure to store the rootfs location, the /* Defines a structure to store the rootfs location, the
* optionals pivot_root, rootfs mount paths * optionals pivot_root, rootfs mount paths
* @path : the rootfs source (directory or device) * @path : the rootfs source (directory or device)
......
...@@ -88,7 +88,7 @@ void lxc_terminal_winsz(int srcfd, int dstfd) ...@@ -88,7 +88,7 @@ void lxc_terminal_winsz(int srcfd, int dstfd)
return; 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); lxc_terminal_winsz(ts->stdinfd, ts->masterfd);
...@@ -99,7 +99,7 @@ static void lxc_terminal_winch(struct lxc_tty_state *ts) ...@@ -99,7 +99,7 @@ static void lxc_terminal_winch(struct lxc_tty_state *ts)
void lxc_terminal_sigwinch(int sig) void lxc_terminal_sigwinch(int sig)
{ {
struct lxc_list *it; struct lxc_list *it;
struct lxc_tty_state *ts; struct lxc_terminal_state *ts;
lxc_list_for_each(it, &lxc_ttys) { lxc_list_for_each(it, &lxc_ttys) {
ts = it->elem; ts = it->elem;
...@@ -112,7 +112,7 @@ int lxc_terminal_signalfd_cb(int fd, uint32_t events, void *cbdata, ...@@ -112,7 +112,7 @@ int lxc_terminal_signalfd_cb(int fd, uint32_t events, void *cbdata,
{ {
ssize_t ret; ssize_t ret;
struct signalfd_siginfo siginfo; struct signalfd_siginfo siginfo;
struct lxc_tty_state *ts = cbdata; struct lxc_terminal_state *ts = cbdata;
ret = read(fd, &siginfo, sizeof(siginfo)); ret = read(fd, &siginfo, sizeof(siginfo));
if (ret < 0 || (size_t)ret < 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, ...@@ -131,12 +131,12 @@ int lxc_terminal_signalfd_cb(int fd, uint32_t events, void *cbdata,
return 0; 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; int ret;
bool istty; bool istty;
sigset_t mask; sigset_t mask;
struct lxc_tty_state *ts; struct lxc_terminal_state *ts;
ts = malloc(sizeof(*ts)); ts = malloc(sizeof(*ts));
if (!ts) if (!ts)
...@@ -189,7 +189,7 @@ on_error: ...@@ -189,7 +189,7 @@ on_error:
return ts; 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) { if (ts->sigfd >= 0) {
close(ts->sigfd); close(ts->sigfd);
...@@ -527,7 +527,7 @@ static void lxc_terminal_peer_proxy_free(struct lxc_terminal *terminal) ...@@ -527,7 +527,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) static int lxc_terminal_peer_proxy_alloc(struct lxc_terminal *terminal, int sockfd)
{ {
struct termios oldtermio; struct termios oldtermio;
struct lxc_tty_state *ts; struct lxc_terminal_state *ts;
int ret; int ret;
if (terminal->master < 0) { if (terminal->master < 0) {
...@@ -636,7 +636,7 @@ void lxc_terminal_free(struct lxc_conf *conf, int fd) ...@@ -636,7 +636,7 @@ void lxc_terminal_free(struct lxc_conf *conf, int fd)
static int lxc_terminal_peer_default(struct lxc_terminal *terminal) 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; const char *path = terminal->path;
int fd; int fd;
int ret = 0; int ret = 0;
...@@ -930,7 +930,7 @@ int lxc_terminal_set_stdfds(int fd) ...@@ -930,7 +930,7 @@ int lxc_terminal_set_stdfds(int fd)
int lxc_terminal_stdin_cb(int fd, uint32_t events, void *cbdata, int lxc_terminal_stdin_cb(int fd, uint32_t events, void *cbdata,
struct lxc_epoll_descr *descr) struct lxc_epoll_descr *descr)
{ {
struct lxc_tty_state *ts = cbdata; struct lxc_terminal_state *ts = cbdata;
char c; char c;
if (fd != ts->stdinfd) if (fd != ts->stdinfd)
...@@ -961,7 +961,7 @@ int lxc_terminal_stdin_cb(int fd, uint32_t events, void *cbdata, ...@@ -961,7 +961,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, int lxc_terminal_master_cb(int fd, uint32_t events, void *cbdata,
struct lxc_epoll_descr *descr) struct lxc_epoll_descr *descr)
{ {
struct lxc_tty_state *ts = cbdata; struct lxc_terminal_state *ts = cbdata;
char buf[LXC_TERMINAL_BUFFER_SIZE]; char buf[LXC_TERMINAL_BUFFER_SIZE];
int r, w; int r, w;
...@@ -995,7 +995,7 @@ int lxc_console(struct lxc_container *c, int ttynum, ...@@ -995,7 +995,7 @@ int lxc_console(struct lxc_container *c, int ttynum,
int ret, ttyfd, masterfd; int ret, ttyfd, masterfd;
struct lxc_epoll_descr descr; struct lxc_epoll_descr descr;
struct termios oldtios; struct termios oldtios;
struct lxc_tty_state *ts; struct lxc_terminal_state *ts;
int istty = 0; int istty = 0;
ttyfd = lxc_cmd_console(c->name, &ttynum, &masterfd, c->config_path); ttyfd = lxc_cmd_console(c->name, &ttynum, &masterfd, c->config_path);
......
...@@ -32,7 +32,9 @@ ...@@ -32,7 +32,9 @@
#include "list.h" #include "list.h"
#include "ringbuf.h" #include "ringbuf.h"
struct lxc_container;
struct lxc_conf; struct lxc_conf;
struct lxc_epoll_descr;
/* Defines a structure containing a pty information for virtualizing a tty /* Defines a structure containing a pty information for virtualizing a tty
* @name : the path name of the slave pty side * @name : the path name of the slave pty side
...@@ -46,6 +48,33 @@ struct lxc_terminal_info { ...@@ -46,6 +48,33 @@ struct lxc_terminal_info {
int busy; int busy;
}; };
struct lxc_terminal_state {
struct lxc_list node;
int stdinfd;
int stdoutfd;
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_terminal_stdin_cb(). Set to -1 to
* disable exiting the pty via a escape sequence.
*/
int escape;
/* Used internally by lxc_terminal_stdin_cb() to check whether an
* escape sequence has been received.
*/
int saw_escape;
/* Name of the container to forward the SIGWINCH event to. */
const char *winch_proxy;
/* Path of the container to forward the SIGWINCH event to. */
const char *winch_proxy_lxcpath;
/* File descriptor that accepts signals. If set to -1 no signal handler
* could be installed. This also means that the sigset_t oldmask member
* is meaningless.
*/
int sigfd;
sigset_t oldmask;
};
struct lxc_terminal { struct lxc_terminal {
int slave; int slave;
int master; int master;
...@@ -55,7 +84,7 @@ struct lxc_terminal { ...@@ -55,7 +84,7 @@ struct lxc_terminal {
char *path; char *path;
char name[MAXPATHLEN]; char name[MAXPATHLEN];
struct termios *tios; struct termios *tios;
struct lxc_tty_state *tty_state; struct lxc_terminal_state *tty_state;
struct /* lxc_console_log */ { struct /* lxc_console_log */ {
/* size of the log file */ /* size of the log file */
...@@ -71,7 +100,7 @@ struct lxc_terminal { ...@@ -71,7 +100,7 @@ struct lxc_terminal {
unsigned int log_rotate; unsigned int log_rotate;
}; };
struct /* lxc_pty_ringbuf */ { struct /* lxc_terminal_ringbuf */ {
/* size of the ringbuffer */ /* size of the ringbuffer */
uint64_t buffer_size; uint64_t buffer_size;
...@@ -80,36 +109,6 @@ struct lxc_terminal { ...@@ -80,36 +109,6 @@ struct lxc_terminal {
}; };
}; };
struct lxc_epoll_descr; /* defined in mainloop.h */
struct lxc_container; /* defined in lxccontainer.h */
struct lxc_tty_state
{
struct lxc_list node;
int stdinfd;
int stdoutfd;
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_terminal_stdin_cb(). Set to -1 to
* disable exiting the pty via a escape sequence.
*/
int escape;
/* Used internally by lxc_terminal_stdin_cb() to check whether an
* escape sequence has been received.
*/
int saw_escape;
/* Name of the container to forward the SIGWINCH event to. */
const char *winch_proxy;
/* Path of the container to forward the SIGWINCH event to. */
const char *winch_proxy_lxcpath;
/* File descriptor that accepts signals. If set to -1 no signal handler
* could be installed. This also means that the sigset_t oldmask member
* is meaningless.
*/
int sigfd;
sigset_t oldmask;
};
/* /*
* lxc_terminal_allocate: allocate the console or a tty * lxc_terminal_allocate: allocate the console or a tty
* *
...@@ -239,8 +238,8 @@ extern void lxc_terminal_winsz(int srcfd, int dstfd); ...@@ -239,8 +238,8 @@ extern void lxc_terminal_winsz(int srcfd, int dstfd);
* @srcfd : src for winsz in SIGWINCH handler * @srcfd : src for winsz in SIGWINCH handler
* @dstfd : dst 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 * Returns lxc_terminal_state structure on success or NULL on failure. The sigfd
* member of the returned lxc_tty_state can be select()/poll()ed/epoll()ed * member of the returned lxc_terminal_state can be select()/poll()ed/epoll()ed
* on (ie added to a mainloop) for signals. * on (ie added to a mainloop) for signals.
* *
* Must be called with process_lock held to protect the lxc_ttys list, or * Must be called with process_lock held to protect the lxc_ttys list, or
...@@ -255,7 +254,7 @@ extern void lxc_terminal_winsz(int srcfd, int dstfd); ...@@ -255,7 +254,7 @@ extern void lxc_terminal_winsz(int srcfd, int dstfd);
* *
* This function allocates memory. It is up to the caller to free it. * 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 * Handler for signal events. To be registered via the corresponding functions
...@@ -267,7 +266,7 @@ extern int lxc_terminal_signalfd_cb(int fd, uint32_t events, void *cbdata, ...@@ -267,7 +266,7 @@ extern int lxc_terminal_signalfd_cb(int fd, uint32_t events, void *cbdata,
/* /*
* lxc_terminal_signal_fini: uninstall signal handler * 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 * Restore the saved signal handler that was in effect at the time
* lxc_terminal_signal_init() was called. * lxc_terminal_signal_init() was called.
...@@ -275,7 +274,7 @@ extern int lxc_terminal_signalfd_cb(int fd, uint32_t events, void *cbdata, ...@@ -275,7 +274,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 * Must be called with process_lock held to protect the lxc_ttys list, or
* from a non-threaded context. * 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_write_ringbuffer(struct lxc_terminal *console);
extern int lxc_terminal_create_log_file(struct lxc_terminal *console); extern int lxc_terminal_create_log_file(struct lxc_terminal *console);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment