From: Christian Brauner Date: Wed, 24 Feb 2021 15:07:23 +0000 (+0100) Subject: commands: s/LXC_CMD_CONSOLE/LXC_CMD_GET_TTY_FD/g X-Git-Tag: lxc-5.0.0~269^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7e85a2c423464568039d7c9ce41b07e8955f9abe;p=thirdparty%2Flxc.git commands: s/LXC_CMD_CONSOLE/LXC_CMD_GET_TTY_FD/g Signed-off-by: Christian Brauner --- diff --git a/src/lxc/commands.c b/src/lxc/commands.c index fbea538c6..327a856e0 100644 --- a/src/lxc/commands.c +++ b/src/lxc/commands.c @@ -65,7 +65,7 @@ lxc_log_define(commands, lxc); static const char *lxc_cmd_str(lxc_cmd_t cmd) { static const char *const cmdname[LXC_CMD_MAX] = { - [LXC_CMD_CONSOLE] = "console", + [LXC_CMD_GET_TTY_FD] = "get_tty_fd", [LXC_CMD_TERMINAL_WINCH] = "terminal_winch", [LXC_CMD_STOP] = "stop", [LXC_CMD_GET_STATE] = "get_state", @@ -131,14 +131,13 @@ static int __transfer_cgroup_fd(struct unix_fds *fds, struct cgroup_fd *fd) * the response data is <= a void * worth of data, it will be * stored directly in data and datalen will be 0. * - * As a special case, the response for LXC_CMD_CONSOLE is created - * here as it contains an fd for the ptx pty passed through the - * unix socket. + * As a special case, the response for LXC_CMD_GET_TTY_FD is created here as + * it contains an fd for the ptx pty passed through the unix socket. */ static int lxc_cmd_rsp_recv(int sock, struct lxc_cmd_rr *cmd) { __do_free void *__private_ptr = NULL; - struct lxc_cmd_console_rsp_data *data_console = NULL; + struct lxc_cmd_tty_rsp_data *data_console = NULL; call_cleaner(put_unix_fds) struct unix_fds *fds = &(struct unix_fds){}; struct lxc_cmd_rsp *rsp = &cmd->rsp; int cur_cmd = cmd->req.cmd, fret = 0; @@ -165,7 +164,7 @@ static int lxc_cmd_rsp_recv(int sock, struct lxc_cmd_rr *cmd) __fallthrough; case LXC_CMD_GET_DEVPTS_FD: __fallthrough; - case LXC_CMD_CONSOLE: + case LXC_CMD_GET_TTY_FD: fds->fd_count_max = 1; break; case LXC_CMD_GET_CGROUP_CTX: @@ -238,7 +237,7 @@ static int lxc_cmd_rsp_recv(int sock, struct lxc_cmd_rr *cmd) /* Don't pointlessly allocate. */ rsp->data = (void *)cmd->req.data; break; - case LXC_CMD_CONSOLE: /* data */ + case LXC_CMD_GET_TTY_FD: /* data */ /* * recv() returns 0 bytes when a tty cannot be allocated, * rsp->ret is < 0 when the peer permission check failed @@ -246,10 +245,10 @@ static int lxc_cmd_rsp_recv(int sock, struct lxc_cmd_rr *cmd) if (ret == 0 || rsp->ret < 0) return 0; - __private_ptr = malloc(sizeof(struct lxc_cmd_console_rsp_data)); + __private_ptr = malloc(sizeof(struct lxc_cmd_tty_rsp_data)); if (!__private_ptr) return syserrno_set(fret ?: -ENOMEM, "Failed to receive response for command \"%s\"", cur_cmdstr); - data_console = (struct lxc_cmd_console_rsp_data *)__private_ptr; + data_console = (struct lxc_cmd_tty_rsp_data *)__private_ptr; data_console->ptxfd = move_fd(fds->fd[0]); data_console->ttynum = PTR_TO_INT(rsp->data); @@ -271,9 +270,9 @@ static int lxc_cmd_rsp_recv(int sock, struct lxc_cmd_rr *cmd) if (rsp->datalen == 0) { DEBUG("Command \"%s\" requested no additional data", cur_cmdstr); /* - * Note that LXC_CMD_CONSOLE historically allocates memory to - * return info to the caller. That's why we jump to no_data so - * we ensure that the allocated data is wiped if we return + * Note that LXC_CMD_GET_TTY_FD historically allocates memory + * to return info to the caller. That's why we jump to no_data + * so we ensure that the allocated data is wiped if we return * early here. */ goto no_data; @@ -449,13 +448,13 @@ static int lxc_cmd_send(const char *name, struct lxc_cmd_rr *cmd, * * Returns the size of the response message on success, < 0 on failure * - * Note that there is a special case for LXC_CMD_CONSOLE. For this command - * the fd cannot be closed because it is used as a placeholder to indicate - * that a particular tty slot is in use. The fd is also used as a signal to - * the container that when the caller dies or closes the fd, the container - * will notice the fd on its side of the socket in its mainloop select and - * then free the slot with lxc_cmd_fd_cleanup(). The socket fd will be - * returned in the cmd response structure. + * Note that there is a special case for LXC_CMD_GET_TTY_FD. For this command + * the fd cannot be closed because it is used as a placeholder to indicate that + * a particular tty slot is in use. The fd is also used as a signal to the + * container that when the caller dies or closes the fd, the container will + * notice the fd on its side of the socket in its mainloop select and then free + * the slot with lxc_cmd_fd_cleanup(). The socket fd will be returned in the + * cmd response structure. */ static int lxc_cmd(const char *name, struct lxc_cmd_rr *cmd, int *stopped, const char *lxcpath, const char *hashed_sock_name) @@ -464,7 +463,7 @@ static int lxc_cmd(const char *name, struct lxc_cmd_rr *cmd, int *stopped, int ret = -1; bool stay_connected = false; - if (cmd->req.cmd == LXC_CMD_CONSOLE || + if (cmd->req.cmd == LXC_CMD_GET_TTY_FD || cmd->req.cmd == LXC_CMD_ADD_STATE_CLIENT) stay_connected = true; @@ -1133,7 +1132,7 @@ static int lxc_cmd_terminal_winch_callback(int fd, struct lxc_cmd_req *req, } /* - * lxc_cmd_console: Open an fd to a tty in the container + * lxc_cmd_get_tty_fd: Open an fd to a tty in the container * * @name : name of container to connect to * @ttynum : in: the tty to open or -1 for next available @@ -1143,13 +1142,13 @@ static int lxc_cmd_terminal_winch_callback(int fd, struct lxc_cmd_req *req, * * Returns fd holding tty allocated on success, < 0 on failure */ -int lxc_cmd_console(const char *name, int *ttynum, int *fd, const char *lxcpath) +int lxc_cmd_get_tty_fd(const char *name, int *ttynum, int *fd, const char *lxcpath) { - __do_free struct lxc_cmd_console_rsp_data *rspdata = NULL; + __do_free struct lxc_cmd_tty_rsp_data *rspdata = NULL; int ret, stopped; struct lxc_cmd_rr cmd = { .req = { - .cmd = LXC_CMD_CONSOLE, + .cmd = LXC_CMD_GET_TTY_FD, .data = INT_TO_PTR(*ttynum), }, }; @@ -1175,9 +1174,9 @@ int lxc_cmd_console(const char *name, int *ttynum, int *fd, const char *lxcpath) return log_info(ret, "Alloced fd %d for tty %d via socket %d", *fd, rspdata->ttynum, ret); } -static int lxc_cmd_console_callback(int fd, struct lxc_cmd_req *req, - struct lxc_handler *handler, - struct lxc_epoll_descr *descr) +static int lxc_cmd_get_tty_fd_callback(int fd, struct lxc_cmd_req *req, + struct lxc_handler *handler, + struct lxc_epoll_descr *descr) { int ptxfd, ret; struct lxc_cmd_rsp rsp = { @@ -1846,7 +1845,7 @@ static int lxc_cmd_process(int fd, struct lxc_cmd_req *req, struct lxc_epoll_descr *); callback cb[LXC_CMD_MAX] = { - [LXC_CMD_CONSOLE] = lxc_cmd_console_callback, + [LXC_CMD_GET_TTY_FD] = lxc_cmd_get_tty_fd_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, diff --git a/src/lxc/commands.h b/src/lxc/commands.h index ec9683870..de17b5663 100644 --- a/src/lxc/commands.h +++ b/src/lxc/commands.h @@ -21,7 +21,7 @@ #define LXC_CMD_REAP_CLIENT_FD 1 typedef enum { - LXC_CMD_CONSOLE = 0, + LXC_CMD_GET_TTY_FD = 0, LXC_CMD_TERMINAL_WINCH = 1, LXC_CMD_STOP = 2, LXC_CMD_GET_STATE = 3, @@ -67,7 +67,7 @@ struct lxc_cmd_rr { struct lxc_cmd_rsp rsp; }; -struct lxc_cmd_console_rsp_data { +struct lxc_cmd_tty_rsp_data { int ptxfd; int ttynum; }; @@ -81,7 +81,8 @@ struct lxc_cmd_console_log { }; __hidden extern int lxc_cmd_terminal_winch(const char *name, const char *lxcpath); -__hidden extern int lxc_cmd_console(const char *name, int *ttynum, int *fd, const char *lxcpath); +__hidden extern int lxc_cmd_get_tty_fd(const char *name, int *ttynum, int *fd, + const char *lxcpath); /* * Get the 'real' cgroup path (as seen in /proc/self/cgroup) for a container * for a particular subsystem diff --git a/src/lxc/terminal.c b/src/lxc/terminal.c index 6614c2661..726a430ee 100644 --- a/src/lxc/terminal.c +++ b/src/lxc/terminal.c @@ -1078,7 +1078,7 @@ int lxc_terminal_ptx_cb(int fd, uint32_t events, void *cbdata, int lxc_terminal_getfd(struct lxc_container *c, int *ttynum, int *ptxfd) { - return lxc_cmd_console(c->name, ttynum, ptxfd, c->config_path); + return lxc_cmd_get_tty_fd(c->name, ttynum, ptxfd, c->config_path); } int lxc_console(struct lxc_container *c, int ttynum, @@ -1094,7 +1094,7 @@ int lxc_console(struct lxc_container *c, int ttynum, }; int istty = 0; - ttyfd = lxc_cmd_console(c->name, &ttynum, &ptxfd, c->config_path); + ttyfd = lxc_cmd_get_tty_fd(c->name, &ttynum, &ptxfd, c->config_path); if (ttyfd < 0) return -1;