tree-wide: struct lxc_terminal_info

parent dcad02f8
...@@ -848,7 +848,7 @@ static int lxc_setup_ttys(struct lxc_conf *conf) ...@@ -848,7 +848,7 @@ static int lxc_setup_ttys(struct lxc_conf *conf)
return 0; return 0;
for (i = 0; i < tty_info->nbtty; 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];
ret = snprintf(path, sizeof(path), "/dev/tty%d", i + 1); ret = snprintf(path, sizeof(path), "/dev/tty%d", i + 1);
if (ret < 0 || (size_t)ret >= sizeof(path)) if (ret < 0 || (size_t)ret >= sizeof(path))
...@@ -946,7 +946,7 @@ int lxc_allocate_ttys(const char *name, struct lxc_conf *conf) ...@@ -946,7 +946,7 @@ int lxc_allocate_ttys(const char *name, struct lxc_conf *conf)
} }
for (i = 0; i < conf->tty; i++) { 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, ret = openpty(&pty_info->master, &pty_info->slave,
pty_info->name, NULL, NULL); pty_info->name, NULL, NULL);
...@@ -987,7 +987,7 @@ void lxc_delete_tty(struct lxc_tty_info *tty_info) ...@@ -987,7 +987,7 @@ void lxc_delete_tty(struct lxc_tty_info *tty_info)
int i; int i;
for (i = 0; i < tty_info->nbtty; 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->master);
close(pty_info->slave); close(pty_info->slave);
...@@ -1011,7 +1011,7 @@ static int lxc_send_ttys_to_parent(struct lxc_handler *handler) ...@@ -1011,7 +1011,7 @@ static int lxc_send_ttys_to_parent(struct lxc_handler *handler)
for (i = 0; i < conf->tty; i++) { for (i = 0; i < conf->tty; i++) {
int ttyfds[2]; 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[0] = pty_info->master;
ttyfds[1] = pty_info->slave; ttyfds[1] = pty_info->slave;
......
...@@ -140,7 +140,7 @@ struct id_map { ...@@ -140,7 +140,7 @@ struct id_map {
* @master : the file descriptor of the master * @master : the file descriptor of the master
* @slave : the file descriptor of the slave * @slave : the file descriptor of the slave
*/ */
struct lxc_pty_info { struct lxc_terminal_info {
char name[MAXPATHLEN]; char name[MAXPATHLEN];
int master; int master;
int slave; int slave;
...@@ -154,7 +154,7 @@ struct lxc_pty_info { ...@@ -154,7 +154,7 @@ struct lxc_pty_info {
*/ */
struct lxc_tty_info { struct lxc_tty_info {
int nbtty; int nbtty;
struct lxc_pty_info *pty_info; struct lxc_terminal_info *pty_info;
}; };
struct lxc_tty_state; struct lxc_tty_state;
...@@ -168,7 +168,7 @@ struct lxc_terminal { ...@@ -168,7 +168,7 @@ struct lxc_terminal {
int slave; int slave;
int master; int master;
int peer; int peer;
struct lxc_pty_info peerpty; struct lxc_terminal_info peerpty;
struct lxc_epoll_descr *descr; struct lxc_epoll_descr *descr;
char *path; char *path;
char name[MAXPATHLEN]; char name[MAXPATHLEN];
......
...@@ -204,7 +204,7 @@ void lxc_terminal_signal_fini(struct lxc_tty_state *ts) ...@@ -204,7 +204,7 @@ void lxc_terminal_signal_fini(struct lxc_tty_state *ts)
free(ts); free(ts);
} }
static int lxc_terminal_truncate_log_file(struct lxc_pty *terminal) static int lxc_terminal_truncate_log_file(struct lxc_terminal *terminal)
{ {
/* be very certain things are kosher */ /* be very certain things are kosher */
if (!terminal->log_path || terminal->log_fd < 0) if (!terminal->log_path || terminal->log_fd < 0)
...@@ -213,56 +213,56 @@ static int lxc_terminal_truncate_log_file(struct lxc_pty *terminal) ...@@ -213,56 +213,56 @@ static int lxc_terminal_truncate_log_file(struct lxc_pty *terminal)
return lxc_unpriv(ftruncate(terminal->log_fd, 0)); return lxc_unpriv(ftruncate(terminal->log_fd, 0));
} }
static int lxc_console_rotate_log_file(struct lxc_pty *console) static int lxc_console_rotate_log_file(struct lxc_terminal *terminal)
{ {
int ret; int ret;
size_t len; size_t len;
char *tmp; char *tmp;
if (!console->log_path || console->log_rotate == 0) if (!terminal->log_path || terminal->log_rotate == 0)
return -EOPNOTSUPP; return -EOPNOTSUPP;
/* be very certain things are kosher */ /* be very certain things are kosher */
if (console->log_fd < 0) if (terminal->log_fd < 0)
return -EBADF; return -EBADF;
len = strlen(console->log_path) + sizeof(".1"); len = strlen(terminal->log_path) + sizeof(".1");
tmp = alloca(len); tmp = alloca(len);
ret = snprintf(tmp, len, "%s.1", console->log_path); ret = snprintf(tmp, len, "%s.1", terminal->log_path);
if (ret < 0 || (size_t)ret >= len) if (ret < 0 || (size_t)ret >= len)
return -EFBIG; return -EFBIG;
close(console->log_fd); close(terminal->log_fd);
console->log_fd = -1; terminal->log_fd = -1;
ret = lxc_unpriv(rename(console->log_path, tmp)); ret = lxc_unpriv(rename(terminal->log_path, tmp));
if (ret < 0) if (ret < 0)
return ret; return ret;
return lxc_terminal_create_log_file(console); return lxc_terminal_create_log_file(terminal);
} }
static int lxc_console_write_log_file(struct lxc_pty *console, char *buf, static int lxc_console_write_log_file(struct lxc_terminal *terminal, char *buf,
int bytes_read) int bytes_read)
{ {
int ret; int ret;
int64_t space_left = -1; int64_t space_left = -1;
struct stat st; struct stat st;
if (console->log_fd < 0) if (terminal->log_fd < 0)
return 0; return 0;
/* A log size <= 0 means that there's no limit on the size of the log /* A log size <= 0 means that there's no limit on the size of the log
* file at which point we simply ignore whether the log is supposed to * file at which point we simply ignore whether the log is supposed to
* be rotated or not. * be rotated or not.
*/ */
if (console->log_size <= 0) if (terminal->log_size <= 0)
return lxc_write_nointr(console->log_fd, buf, bytes_read); return lxc_write_nointr(terminal->log_fd, buf, bytes_read);
/* Get current size of the log file. */ /* Get current size of the log file. */
ret = fstat(console->log_fd, &st); ret = fstat(terminal->log_fd, &st);
if (ret < 0) { if (ret < 0) {
SYSERROR("Failed to stat the console log file descriptor"); SYSERROR("Failed to stat the terminal log file descriptor");
return -1; return -1;
} }
...@@ -273,38 +273,38 @@ static int lxc_console_write_log_file(struct lxc_pty *console, char *buf, ...@@ -273,38 +273,38 @@ static int lxc_console_write_log_file(struct lxc_pty *console, char *buf,
* questionable. Let's not risk anything and tell the user that * questionable. Let's not risk anything and tell the user that
* he's requesting us to do weird stuff. * he's requesting us to do weird stuff.
*/ */
if (console->log_rotate > 0 || console->log_size > 0) if (terminal->log_rotate > 0 || terminal->log_size > 0)
return -EINVAL; return -EINVAL;
/* I mean, sure log wherever you want to. */ /* I mean, sure log wherever you want to. */
return lxc_write_nointr(console->log_fd, buf, bytes_read); return lxc_write_nointr(terminal->log_fd, buf, bytes_read);
} }
space_left = console->log_size - st.st_size; space_left = terminal->log_size - st.st_size;
/* User doesn't want to rotate the log file and there's no more space /* User doesn't want to rotate the log file and there's no more space
* left so simply truncate it. * left so simply truncate it.
*/ */
if (space_left <= 0 && console->log_rotate <= 0) { if (space_left <= 0 && terminal->log_rotate <= 0) {
ret = lxc_terminal_truncate_log_file(console); ret = lxc_terminal_truncate_log_file(terminal);
if (ret < 0) if (ret < 0)
return ret; return ret;
if (bytes_read <= console->log_size) if (bytes_read <= terminal->log_size)
return lxc_write_nointr(console->log_fd, buf, bytes_read); return lxc_write_nointr(terminal->log_fd, buf, bytes_read);
/* Write as much as we can into the buffer and loose the rest. */ /* Write as much as we can into the buffer and loose the rest. */
return lxc_write_nointr(console->log_fd, buf, console->log_size); return lxc_write_nointr(terminal->log_fd, buf, terminal->log_size);
} }
/* There's enough space left. */ /* There's enough space left. */
if (bytes_read <= space_left) if (bytes_read <= space_left)
return lxc_write_nointr(console->log_fd, buf, bytes_read); return lxc_write_nointr(terminal->log_fd, buf, bytes_read);
/* There's not enough space left but at least write as much as we can /* There's not enough space left but at least write as much as we can
* into the old log file. * into the old log file.
*/ */
ret = lxc_write_nointr(console->log_fd, buf, space_left); ret = lxc_write_nointr(terminal->log_fd, buf, space_left);
if (ret < 0) if (ret < 0)
return -1; return -1;
...@@ -314,26 +314,26 @@ static int lxc_console_write_log_file(struct lxc_pty *console, char *buf, ...@@ -314,26 +314,26 @@ static int lxc_console_write_log_file(struct lxc_pty *console, char *buf,
/* There'd be more to write but we aren't instructed to rotate the log /* There'd be more to write but we aren't instructed to rotate the log
* file so simply return. There's no error on our side here. * file so simply return. There's no error on our side here.
*/ */
if (console->log_rotate > 0) if (terminal->log_rotate > 0)
ret = lxc_console_rotate_log_file(console); ret = lxc_console_rotate_log_file(terminal);
else else
ret = lxc_terminal_truncate_log_file(console); ret = lxc_terminal_truncate_log_file(terminal);
if (ret < 0) if (ret < 0)
return ret; return ret;
if (console->log_size < bytes_read) { if (terminal->log_size < bytes_read) {
/* Well, this is unfortunate because it means that there is more /* Well, this is unfortunate because it means that there is more
* to write than the user has granted us space. There are * to write than the user has granted us space. There are
* multiple ways to handle this but let's use the simplest one: * multiple ways to handle this but let's use the simplest one:
* write as much as we can, tell the user that there was more * write as much as we can, tell the user that there was more
* stuff to write and move on. * stuff to write and move on.
* Note that this scenario shouldn't actually happen with the * Note that this scenario shouldn't actually happen with the
* standard pty-based console that LXC allocates since it will * standard pty-based terminal that LXC allocates since it will
* be switched into raw mode. In raw mode only 1 byte at a time * be switched into raw mode. In raw mode only 1 byte at a time
* should be read and written. * should be read and written.
*/ */
WARN("Size of console log file is smaller than the bytes to write"); WARN("Size of terminal log file is smaller than the bytes to write");
ret = lxc_write_nointr(console->log_fd, buf, console->log_size); ret = lxc_write_nointr(terminal->log_fd, buf, terminal->log_size);
if (ret < 0) if (ret < 0)
return -1; return -1;
bytes_read -= ret; bytes_read -= ret;
...@@ -341,7 +341,7 @@ static int lxc_console_write_log_file(struct lxc_pty *console, char *buf, ...@@ -341,7 +341,7 @@ static int lxc_console_write_log_file(struct lxc_pty *console, char *buf,
} }
/* Yay, we made it. */ /* Yay, we made it. */
ret = lxc_write_nointr(console->log_fd, buf, bytes_read); ret = lxc_write_nointr(terminal->log_fd, buf, bytes_read);
if (ret < 0) if (ret < 0)
return -1; return -1;
bytes_read -= ret; bytes_read -= ret;
...@@ -1128,7 +1128,7 @@ int lxc_login_pty(int fd) ...@@ -1128,7 +1128,7 @@ int lxc_login_pty(int fd)
return 0; 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->name[0] = '\0';
pty->master = -EBADF; pty->master = -EBADF;
......
...@@ -235,7 +235,7 @@ extern int lxc_terminal_io_cb(int fd, uint32_t events, void *data, ...@@ -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_make_controlling_pty(int fd);
extern int lxc_login_pty(int fd); extern int lxc_login_pty(int fd);
extern void lxc_terminal_conf_free(struct lxc_terminal *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_info_init(struct lxc_terminal_info *pty);
extern void lxc_terminal_init(struct lxc_terminal *pty); extern void lxc_terminal_init(struct lxc_terminal *pty);
extern int lxc_terminal_map_ids(struct lxc_conf *c, struct lxc_terminal *pty); extern int lxc_terminal_map_ids(struct lxc_conf *c, struct lxc_terminal *pty);
......
...@@ -1340,7 +1340,7 @@ out_error: ...@@ -1340,7 +1340,7 @@ out_error:
static int lxc_recv_ttys_from_child(struct lxc_handler *handler) static int lxc_recv_ttys_from_child(struct lxc_handler *handler)
{ {
int i; int i;
struct lxc_pty_info *pty_info; struct lxc_terminal_info *pty_info;
int ret = -1; int ret = -1;
int sock = handler->data_sock[1]; int sock = handler->data_sock[1];
struct lxc_conf *conf = handler->conf; struct lxc_conf *conf = handler->conf;
......
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