From: Christian Brauner Date: Wed, 17 Jun 2020 21:55:32 +0000 (+0200) Subject: tree-wide: use "ptmx" and "pts" as terminal terms X-Git-Tag: lxc-5.0.0~416 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cecf3e8368669c1921d30474c5ca75537f69e067;p=thirdparty%2Flxc.git tree-wide: use "ptmx" and "pts" as terminal terms Signed-off-by: Christian Brauner --- diff --git a/src/lxc/attach.c b/src/lxc/attach.c index 57c7f4617..1b7e5c650 100644 --- a/src/lxc/attach.c +++ b/src/lxc/attach.c @@ -629,7 +629,7 @@ static signed long get_personality(const char *name, const char *lxcpath) struct attach_clone_payload { int ipc_socket; - int terminal_slave_fd; + int terminal_pts_fd; lxc_attach_options_t *options; struct lxc_proc_context_info *init_ctx; lxc_attach_exec_t exec_function; @@ -639,7 +639,7 @@ struct attach_clone_payload { static void lxc_put_attach_clone_payload(struct attach_clone_payload *p) { close_prot_errno_disarm(p->ipc_socket); - close_prot_errno_disarm(p->terminal_slave_fd); + close_prot_errno_disarm(p->terminal_pts_fd); if (p->init_ctx) { lxc_proc_put_context_info(p->init_ctx); p->init_ctx = NULL; @@ -860,13 +860,13 @@ static int attach_child_main(struct attach_clone_payload *payload) } if (options->attach_flags & LXC_ATTACH_TERMINAL) { - ret = lxc_terminal_prepare_login(payload->terminal_slave_fd); + ret = lxc_terminal_prepare_login(payload->terminal_pts_fd); if (ret < 0) { - SYSERROR("Failed to prepare terminal file descriptor %d", payload->terminal_slave_fd); + SYSERROR("Failed to prepare terminal file descriptor %d", payload->terminal_pts_fd); goto on_error; } - TRACE("Prepared terminal file descriptor %d", payload->terminal_slave_fd); + TRACE("Prepared terminal file descriptor %d", payload->terminal_pts_fd); } /* Avoid unnecessary syscalls. */ @@ -936,14 +936,14 @@ static int lxc_attach_terminal_mainloop_init(struct lxc_terminal *terminal, return 0; } -static inline void lxc_attach_terminal_close_master(struct lxc_terminal *terminal) +static inline void lxc_attach_terminal_close_ptmx(struct lxc_terminal *terminal) { - close_prot_errno_disarm(terminal->master); + close_prot_errno_disarm(terminal->ptmx); } -static inline void lxc_attach_terminal_close_slave(struct lxc_terminal *terminal) +static inline void lxc_attach_terminal_close_pts(struct lxc_terminal *terminal) { - close_prot_errno_disarm(terminal->slave); + close_prot_errno_disarm(terminal->pts); } static inline void lxc_attach_terminal_close_peer(struct lxc_terminal *terminal) @@ -1173,7 +1173,7 @@ int lxc_attach(struct lxc_container *container, lxc_attach_exec_t exec_function, free(cwd); lxc_proc_close_ns_fd(init_ctx); if (options->attach_flags & LXC_ATTACH_TERMINAL) - lxc_attach_terminal_close_slave(&terminal); + lxc_attach_terminal_close_pts(&terminal); /* Attach to cgroup, if requested. */ if (options->attach_flags & LXC_ATTACH_MOVE_TO_CGROUP) { @@ -1336,7 +1336,7 @@ int lxc_attach(struct lxc_container *container, lxc_attach_exec_t exec_function, close_prot_errno_disarm(ipc_sockets[0]); if (options->attach_flags & LXC_ATTACH_TERMINAL) { - lxc_attach_terminal_close_master(&terminal); + lxc_attach_terminal_close_ptmx(&terminal); lxc_attach_terminal_close_peer(&terminal); lxc_attach_terminal_close_log(&terminal); } @@ -1381,7 +1381,7 @@ int lxc_attach(struct lxc_container *container, lxc_attach_exec_t exec_function, payload.ipc_socket = ipc_sockets[1]; payload.options = options; payload.init_ctx = init_ctx; - payload.terminal_slave_fd = terminal.slave; + payload.terminal_pts_fd = terminal.pts; payload.exec_function = exec_function; payload.exec_payload = exec_payload; @@ -1411,7 +1411,7 @@ int lxc_attach(struct lxc_container *container, lxc_attach_exec_t exec_function, } if (options->attach_flags & LXC_ATTACH_TERMINAL) - lxc_attach_terminal_close_slave(&terminal); + lxc_attach_terminal_close_pts(&terminal); /* Tell grandparent the pid of the pid of the newly created child. */ ret = lxc_write_nointr(ipc_sockets[1], &pid, sizeof(pid)); diff --git a/src/lxc/commands.c b/src/lxc/commands.c index 25c409e3b..4c21c752d 100644 --- a/src/lxc/commands.c +++ b/src/lxc/commands.c @@ -108,7 +108,7 @@ static const char *lxc_cmd_str(lxc_cmd_t cmd) * 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 master pty passed through the + * here as it contains an fd for the ptmx pty passed through the * unix socket. */ static int lxc_cmd_rsp_recv(int sock, struct lxc_cmd_rr *cmd) @@ -139,7 +139,7 @@ static int lxc_cmd_rsp_recv(int sock, struct lxc_cmd_rr *cmd) ENOMEM, "Failed to receive response for command \"%s\"", lxc_cmd_str(cmd->req.cmd)); - rspdata->masterfd = move_fd(fd_rsp); + rspdata->ptmxfd = move_fd(fd_rsp); rspdata->ttynum = PTR_TO_INT(rsp->data); rsp->data = rspdata; } @@ -844,7 +844,7 @@ static int lxc_cmd_terminal_winch_callback(int fd, struct lxc_cmd_req *req, * @name : name of container to connect to * @ttynum : in: the tty to open or -1 for next available * : out: the tty allocated - * @fd : out: file descriptor for master side of pty + * @fd : out: file descriptor for ptmx side of pty * @lxcpath : the lxcpath in which the container is running * * Returns fd holding tty allocated on success, < 0 on failure @@ -871,11 +871,11 @@ int lxc_cmd_console(const char *name, int *ttynum, int *fd, const char *lxcpath) if (ret == 0) return log_error(-1, "tty number %d invalid, busy or all ttys busy", *ttynum); - if (rspdata->masterfd < 0) + if (rspdata->ptmxfd < 0) return log_error(-1, "Unable to allocate fd for tty %d", rspdata->ttynum); ret = cmd.rsp.ret; /* socket fd */ - *fd = rspdata->masterfd; + *fd = rspdata->ptmxfd; *ttynum = rspdata->ttynum; return log_info(ret, "Alloced fd %d for tty %d via socket %d", *fd, rspdata->ttynum, ret); @@ -885,17 +885,17 @@ static int lxc_cmd_console_callback(int fd, struct lxc_cmd_req *req, struct lxc_handler *handler, struct lxc_epoll_descr *descr) { - int masterfd, ret; + int ptmxfd, ret; struct lxc_cmd_rsp rsp; int ttynum = PTR_TO_INT(req->data); - masterfd = lxc_terminal_allocate(handler->conf, fd, &ttynum); - if (masterfd < 0) + ptmxfd = lxc_terminal_allocate(handler->conf, fd, &ttynum); + if (ptmxfd < 0) return LXC_CMD_REAP_CLIENT_FD; memset(&rsp, 0, sizeof(rsp)); rsp.data = INT_TO_PTR(ttynum); - ret = lxc_abstract_unix_send_fds(fd, &masterfd, 1, &rsp, sizeof(rsp)); + ret = lxc_abstract_unix_send_fds(fd, &ptmxfd, 1, &rsp, sizeof(rsp)); if (ret < 0) { lxc_terminal_free(handler->conf, fd); return log_error_errno(LXC_CMD_REAP_CLIENT_FD, errno, diff --git a/src/lxc/commands.h b/src/lxc/commands.h index 878998832..3624a1497 100644 --- a/src/lxc/commands.h +++ b/src/lxc/commands.h @@ -61,7 +61,7 @@ struct lxc_cmd_rr { }; struct lxc_cmd_console_rsp_data { - int masterfd; + int ptmxfd; int ttynum; }; diff --git a/src/lxc/conf.c b/src/lxc/conf.c index 428d06a2b..13f7619fd 100644 --- a/src/lxc/conf.c +++ b/src/lxc/conf.c @@ -921,33 +921,33 @@ int lxc_allocate_ttys(struct lxc_conf *conf) for (size_t i = 0; i < ttys->max; i++) { struct lxc_terminal_info *tty = &ttys->tty[i]; - tty->master = -EBADF; - tty->slave = -EBADF; - ret = openpty(&tty->master, &tty->slave, NULL, NULL, NULL); + tty->ptmx = -EBADF; + tty->pts = -EBADF; + ret = openpty(&tty->ptmx, &tty->pts, NULL, NULL, NULL); if (ret < 0) { ttys->max = i; return log_error_errno(-ENOTTY, ENOTTY, "Failed to create tty %zu", i); } - ret = ttyname_r(tty->slave, tty->name, sizeof(tty->name)); + ret = ttyname_r(tty->pts, tty->name, sizeof(tty->name)); if (ret < 0) { ttys->max = i; - return log_error_errno(-ENOTTY, ENOTTY, "Failed to retrieve name of tty %zu slave", i); + return log_error_errno(-ENOTTY, ENOTTY, "Failed to retrieve name of tty %zu pts", i); } - DEBUG("Created tty \"%s\" with master fd %d and slave fd %d", - tty->name, tty->master, tty->slave); + DEBUG("Created tty \"%s\" with ptmx fd %d and pts fd %d", + tty->name, tty->ptmx, tty->pts); /* Prevent leaking the file descriptors to the container */ - ret = fd_cloexec(tty->master, true); + ret = fd_cloexec(tty->ptmx, true); if (ret < 0) - SYSWARN("Failed to set FD_CLOEXEC flag on master fd %d of tty device \"%s\"", - tty->master, tty->name); + SYSWARN("Failed to set FD_CLOEXEC flag on ptmx fd %d of tty device \"%s\"", + tty->ptmx, tty->name); - ret = fd_cloexec(tty->slave, true); + ret = fd_cloexec(tty->pts, true); if (ret < 0) - SYSWARN("Failed to set FD_CLOEXEC flag on slave fd %d of tty device \"%s\"", - tty->slave, tty->name); + SYSWARN("Failed to set FD_CLOEXEC flag on pts fd %d of tty device \"%s\"", + tty->pts, tty->name); tty->busy = -1; } @@ -964,8 +964,8 @@ void lxc_delete_tty(struct lxc_tty_info *ttys) for (int i = 0; i < ttys->max; i++) { struct lxc_terminal_info *tty = &ttys->tty[i]; - close_prot_errno_disarm(tty->master); - close_prot_errno_disarm(tty->slave); + close_prot_errno_disarm(tty->ptmx); + close_prot_errno_disarm(tty->pts); } free_disarm(ttys->tty); @@ -986,15 +986,15 @@ static int lxc_send_ttys_to_parent(struct lxc_handler *handler) int ttyfds[2]; struct lxc_terminal_info *tty = &ttys->tty[i]; - ttyfds[0] = tty->master; - ttyfds[1] = tty->slave; + ttyfds[0] = tty->ptmx; + ttyfds[1] = tty->pts; ret = lxc_abstract_unix_send_fds(sock, ttyfds, 2, NULL, 0); if (ret < 0) break; - TRACE("Sent tty \"%s\" with master fd %d and slave fd %d to parent", - tty->name, tty->master, tty->slave); + TRACE("Sent tty \"%s\" with ptmx fd %d and pts fd %d to parent", + tty->name, tty->ptmx, tty->pts); } if (ret < 0) @@ -1615,7 +1615,7 @@ static int lxc_setup_dev_console(const struct lxc_rootfs *rootfs, if (ret < 0 && errno != EEXIST) return log_error_errno(-errno, errno, "Failed to create console"); - ret = fchmod(console->slave, S_IXUSR | S_IXGRP); + ret = fchmod(console->pts, S_IXUSR | S_IXGRP); if (ret < 0) return log_error_errno(-errno, errno, "Failed to set mode \"0%o\" to \"%s\"", S_IXUSR | S_IXGRP, console->name); @@ -1686,7 +1686,7 @@ static int lxc_setup_ttydir_console(const struct lxc_rootfs *rootfs, if (ret < 0 && errno != EEXIST) return log_error_errno(-errno, errno, "Failed to create console"); - ret = fchmod(console->slave, S_IXUSR | S_IXGRP); + ret = fchmod(console->pts, S_IXUSR | S_IXGRP); if (ret < 0) return log_error_errno(-errno, errno, "Failed to set mode \"0%o\" to \"%s\"", S_IXUSR | S_IXGRP, console->name); @@ -2546,10 +2546,10 @@ struct lxc_conf *lxc_conf_init(void) new->console.path = NULL; new->console.peer = -1; new->console.proxy.busy = -1; - new->console.proxy.master = -1; - new->console.proxy.slave = -1; - new->console.master = -1; - new->console.slave = -1; + new->console.proxy.ptmx = -1; + new->console.proxy.pts = -1; + new->console.ptmx = -1; + new->console.pts = -1; new->console.name[0] = '\0'; memset(&new->console.ringbuf, 0, sizeof(struct lxc_ringbuf)); new->maincmd_fd = -1; diff --git a/src/lxc/criu.c b/src/lxc/criu.c index a8af09f7b..19f2a173f 100644 --- a/src/lxc/criu.c +++ b/src/lxc/criu.c @@ -1020,7 +1020,7 @@ static void do_restore(struct lxc_container *c, int status_pipe, struct migrate_ os.action = "restore"; os.user = opts; os.c = c; - os.console_fd = c->lxc_conf->console.slave; + os.console_fd = c->lxc_conf->console.pts; os.criu_version = criu_version; os.handler = handler; diff --git a/src/lxc/lxccontainer.c b/src/lxc/lxccontainer.c index 57abcbd7b..f872a5f70 100644 --- a/src/lxc/lxccontainer.c +++ b/src/lxc/lxccontainer.c @@ -537,12 +537,12 @@ static bool do_lxcapi_unfreeze(struct lxc_container *c) WRAP_API(bool, lxcapi_unfreeze) -static int do_lxcapi_console_getfd(struct lxc_container *c, int *ttynum, int *masterfd) +static int do_lxcapi_console_getfd(struct lxc_container *c, int *ttynum, int *ptmxfd) { if (!c) return -1; - return lxc_terminal_getfd(c, ttynum, masterfd); + return lxc_terminal_getfd(c, ttynum, ptmxfd); } WRAP_API_2(int, lxcapi_console_getfd, int *, int *) diff --git a/src/lxc/lxccontainer.h b/src/lxc/lxccontainer.h index a9eaeb76b..b4ec1d6d5 100644 --- a/src/lxc/lxccontainer.h +++ b/src/lxc/lxccontainer.h @@ -563,7 +563,7 @@ struct lxc_container { * \param c Container. * \param[in,out] ttynum Terminal number to attempt to allocate, * or \c -1 to allocate the first available tty. - * \param[out] masterfd File descriptor referring to the master side of the pty. + * \param[out] ptmxfd File descriptor referring to the ptmx side of the pty. * * \return tty file descriptor number on success, or \c -1 on * failure. @@ -575,7 +575,7 @@ struct lxc_container { * descriptor when no longer required so that it may be allocated * by another caller. */ - int (*console_getfd)(struct lxc_container *c, int *ttynum, int *masterfd); + int (*console_getfd)(struct lxc_container *c, int *ttynum, int *ptmxfd); /*! * \brief Allocate and run a console tty. diff --git a/src/lxc/start.c b/src/lxc/start.c index fa84461c3..5d5797226 100644 --- a/src/lxc/start.c +++ b/src/lxc/start.c @@ -1249,14 +1249,14 @@ static int do_start(void *data) * setup on its console ie. the pty allocated in lxc_terminal_setup() so * make sure that that pty is stdin,stdout,stderr. */ - if (handler->conf->console.slave >= 0) { + if (handler->conf->console.pts >= 0) { if (handler->daemonize || !handler->conf->is_execute) - ret = set_stdfds(handler->conf->console.slave); + ret = set_stdfds(handler->conf->console.pts); else - ret = lxc_terminal_set_stdfds(handler->conf->console.slave); + ret = lxc_terminal_set_stdfds(handler->conf->console.pts); if (ret < 0) { ERROR("Failed to redirect std{in,out,err} to pty file descriptor %d", - handler->conf->console.slave); + handler->conf->console.pts); goto out_warn_father; } } @@ -1283,7 +1283,7 @@ static int do_start(void *data) close_prot_errno_disarm(handler->sigfd); - if (handler->conf->console.slave < 0 && handler->daemonize) { + if (handler->conf->console.pts < 0 && handler->daemonize) { if (devnull_fd < 0) { devnull_fd = open_devnull(); if (devnull_fd < 0) @@ -1435,9 +1435,9 @@ static int lxc_recv_ttys_from_child(struct lxc_handler *handler) tty = &ttys->tty[i]; tty->busy = -1; - tty->master = ttyfds[0]; - tty->slave = ttyfds[1]; - TRACE("Received pty with master fd %d and slave fd %d from child", tty->master, tty->slave); + tty->ptmx = ttyfds[0]; + tty->pts = ttyfds[1]; + TRACE("Received pty with ptmx fd %d and pts fd %d from child", tty->ptmx, tty->pts); } if (ret < 0) diff --git a/src/lxc/terminal.c b/src/lxc/terminal.c index c883b1c8c..e58db5c46 100644 --- a/src/lxc/terminal.c +++ b/src/lxc/terminal.c @@ -65,7 +65,7 @@ void lxc_terminal_winsz(int srcfd, int dstfd) static void lxc_terminal_winch(struct lxc_terminal_state *ts) { - lxc_terminal_winsz(ts->stdinfd, ts->masterfd); + lxc_terminal_winsz(ts->stdinfd, ts->ptmxfd); } int lxc_terminal_signalfd_cb(int fd, uint32_t events, void *cbdata, @@ -105,7 +105,7 @@ struct lxc_terminal_state *lxc_terminal_signal_init(int srcfd, int dstfd) memset(ts, 0, sizeof(*ts)); ts->stdinfd = srcfd; - ts->masterfd = dstfd; + ts->ptmxfd = dstfd; ts->sigfd = -1; ret = sigemptyset(&mask); @@ -330,8 +330,8 @@ int lxc_terminal_io_cb(int fd, uint32_t events, void *data, INFO("Terminal client on fd %d has exited", fd); lxc_mainloop_del_handler(descr, fd); - if (fd == terminal->master) { - terminal->master = -EBADF; + if (fd == terminal->ptmx) { + terminal->ptmx = -EBADF; } else if (fd == terminal->peer) { lxc_terminal_signal_fini(terminal); terminal->peer = -EBADF; @@ -344,10 +344,10 @@ int lxc_terminal_io_cb(int fd, uint32_t events, void *data, } if (fd == terminal->peer) - w = lxc_write_nointr(terminal->master, buf, r); + w = lxc_write_nointr(terminal->ptmx, buf, r); w_rbuf = w_log = 0; - if (fd == terminal->master) { + if (fd == terminal->ptmx) { /* write to peer first */ if (terminal->peer >= 0) w = lxc_write_nointr(terminal->peer, buf, r); @@ -406,16 +406,16 @@ int lxc_terminal_mainloop_add(struct lxc_epoll_descr *descr, { int ret; - if (terminal->master < 0) { + if (terminal->ptmx < 0) { INFO("Terminal is not initialized"); return 0; } - ret = lxc_mainloop_add_handler(descr, terminal->master, + ret = lxc_mainloop_add_handler(descr, terminal->ptmx, lxc_terminal_io_cb, terminal); if (ret < 0) { - ERROR("Failed to add handler for terminal master fd %d to " - "mainloop", terminal->master); + ERROR("Failed to add handler for terminal ptmx fd %d to " + "mainloop", terminal->ptmx); return -1; } @@ -483,11 +483,11 @@ static void lxc_terminal_peer_proxy_free(struct lxc_terminal *terminal) { lxc_terminal_signal_fini(terminal); - close(terminal->proxy.master); - terminal->proxy.master = -1; + close(terminal->proxy.ptmx); + terminal->proxy.ptmx = -1; - close(terminal->proxy.slave); - terminal->proxy.slave = -1; + close(terminal->proxy.pts); + terminal->proxy.pts = -1; terminal->proxy.busy = -1; @@ -503,7 +503,7 @@ static int lxc_terminal_peer_proxy_alloc(struct lxc_terminal *terminal, struct termios oldtermio; struct lxc_terminal_state *ts; - if (terminal->master < 0) { + if (terminal->ptmx < 0) { ERROR("Terminal not set up"); return -1; } @@ -519,51 +519,51 @@ static int lxc_terminal_peer_proxy_alloc(struct lxc_terminal *terminal, } /* This is the proxy terminal that will be given to the client, and - * that the real terminal master will send to / recv from. + * that the real terminal ptmx will send to / recv from. */ - ret = openpty(&terminal->proxy.master, &terminal->proxy.slave, NULL, + ret = openpty(&terminal->proxy.ptmx, &terminal->proxy.pts, NULL, NULL, NULL); if (ret < 0) { SYSERROR("Failed to open proxy terminal"); return -1; } - ret = ttyname_r(terminal->proxy.slave, terminal->proxy.name, + ret = ttyname_r(terminal->proxy.pts, terminal->proxy.name, sizeof(terminal->proxy.name)); if (ret < 0) { - SYSERROR("Failed to retrieve name of proxy terminal slave"); + SYSERROR("Failed to retrieve name of proxy terminal pts"); goto on_error; } - ret = fd_cloexec(terminal->proxy.master, true); + ret = fd_cloexec(terminal->proxy.ptmx, true); if (ret < 0) { - SYSERROR("Failed to set FD_CLOEXEC flag on proxy terminal master"); + SYSERROR("Failed to set FD_CLOEXEC flag on proxy terminal ptmx"); goto on_error; } - ret = fd_cloexec(terminal->proxy.slave, true); + ret = fd_cloexec(terminal->proxy.pts, true); if (ret < 0) { - SYSERROR("Failed to set FD_CLOEXEC flag on proxy terminal slave"); + SYSERROR("Failed to set FD_CLOEXEC flag on proxy terminal pts"); goto on_error; } - ret = lxc_setup_tios(terminal->proxy.slave, &oldtermio); + ret = lxc_setup_tios(terminal->proxy.pts, &oldtermio); if (ret < 0) goto on_error; - ts = lxc_terminal_signal_init(terminal->proxy.master, terminal->master); + ts = lxc_terminal_signal_init(terminal->proxy.ptmx, terminal->ptmx); if (!ts) goto on_error; terminal->tty_state = ts; - terminal->peer = terminal->proxy.slave; + terminal->peer = terminal->proxy.pts; terminal->proxy.busy = sockfd; ret = lxc_terminal_mainloop_add_peer(terminal); if (ret < 0) goto on_error; - NOTICE("Opened proxy terminal with master fd %d and slave fd %d", - terminal->proxy.master, terminal->proxy.slave); + NOTICE("Opened proxy terminal with ptmx fd %d and pts fd %d", + terminal->proxy.ptmx, terminal->proxy.pts); return 0; on_error: @@ -574,7 +574,7 @@ on_error: int lxc_terminal_allocate(struct lxc_conf *conf, int sockfd, int *ttyreq) { int ttynum; - int masterfd = -1; + int ptmxfd = -1; struct lxc_tty_info *ttys = &conf->ttys; struct lxc_terminal *terminal = &conf->console; @@ -585,7 +585,7 @@ int lxc_terminal_allocate(struct lxc_conf *conf, int sockfd, int *ttyreq) if (ret < 0) goto out; - masterfd = terminal->proxy.master; + ptmxfd = terminal->proxy.ptmx; goto out; } @@ -614,10 +614,10 @@ int lxc_terminal_allocate(struct lxc_conf *conf, int sockfd, int *ttyreq) out_tty: ttys->tty[ttynum - 1].busy = sockfd; - masterfd = ttys->tty[ttynum - 1].master; + ptmxfd = ttys->tty[ttynum - 1].ptmx; out: - return masterfd; + return ptmxfd; } void lxc_terminal_free(struct lxc_conf *conf, int fd) @@ -633,7 +633,7 @@ void lxc_terminal_free(struct lxc_conf *conf, int fd) if (terminal->proxy.busy != fd) return; - lxc_mainloop_del_handler(terminal->descr, terminal->proxy.slave); + lxc_mainloop_del_handler(terminal->descr, terminal->proxy.pts); lxc_terminal_peer_proxy_free(terminal); } @@ -666,14 +666,14 @@ static int lxc_terminal_peer_default(struct lxc_terminal *terminal) goto on_error_free_tios; } - ts = lxc_terminal_signal_init(terminal->peer, terminal->master); + ts = lxc_terminal_signal_init(terminal->peer, terminal->ptmx); terminal->tty_state = ts; if (!ts) { WARN("Failed to install signal handler"); goto on_error_free_tios; } - lxc_terminal_winsz(terminal->peer, terminal->master); + lxc_terminal_winsz(terminal->peer, terminal->ptmx); terminal->tios = malloc(sizeof(*terminal->tios)); if (!terminal->tios) @@ -749,13 +749,13 @@ void lxc_terminal_delete(struct lxc_terminal *terminal) close(terminal->peer); terminal->peer = -1; - if (terminal->master >= 0) - close(terminal->master); - terminal->master = -1; + if (terminal->ptmx >= 0) + close(terminal->ptmx); + terminal->ptmx = -1; - if (terminal->slave >= 0) - close(terminal->slave); - terminal->slave = -1; + if (terminal->pts >= 0) + close(terminal->pts); + terminal->pts = -1; if (terminal->log_fd >= 0) close(terminal->log_fd); @@ -764,7 +764,7 @@ void lxc_terminal_delete(struct lxc_terminal *terminal) /** * Note that this function needs to run before the mainloop starts. Since we - * register a handler for the terminal's masterfd when we create the mainloop + * register a handler for the terminal's ptmxfd when we create the mainloop * the terminal handler needs to see an allocated ringbuffer. */ static int lxc_terminal_create_ringbuf(struct lxc_terminal *terminal) @@ -832,27 +832,27 @@ int lxc_terminal_create(struct lxc_terminal *terminal) { int ret; - ret = openpty(&terminal->master, &terminal->slave, NULL, NULL, NULL); + ret = openpty(&terminal->ptmx, &terminal->pts, NULL, NULL, NULL); if (ret < 0) { SYSERROR("Failed to open terminal"); return -1; } - ret = ttyname_r(terminal->slave, terminal->name, sizeof(terminal->name)); + ret = ttyname_r(terminal->pts, terminal->name, sizeof(terminal->name)); if (ret < 0) { - SYSERROR("Failed to retrieve name of terminal slave"); + SYSERROR("Failed to retrieve name of terminal pts"); goto err; } - ret = fd_cloexec(terminal->master, true); + ret = fd_cloexec(terminal->ptmx, true); if (ret < 0) { - SYSERROR("Failed to set FD_CLOEXEC flag on terminal master"); + SYSERROR("Failed to set FD_CLOEXEC flag on terminal ptmx"); goto err; } - ret = fd_cloexec(terminal->slave, true); + ret = fd_cloexec(terminal->pts, true); if (ret < 0) { - SYSERROR("Failed to set FD_CLOEXEC flag on terminal slave"); + SYSERROR("Failed to set FD_CLOEXEC flag on terminal pts"); goto err; } @@ -956,21 +956,21 @@ int lxc_terminal_stdin_cb(int fd, uint32_t events, void *cbdata, ts->saw_escape = 0; } - ret = lxc_write_nointr(ts->masterfd, &c, 1); + ret = lxc_write_nointr(ts->ptmxfd, &c, 1); if (ret <= 0) return LXC_MAINLOOP_CLOSE; return LXC_MAINLOOP_CONTINUE; } -int lxc_terminal_master_cb(int fd, uint32_t events, void *cbdata, +int lxc_terminal_ptmx_cb(int fd, uint32_t events, void *cbdata, struct lxc_epoll_descr *descr) { int r, w; char buf[LXC_TERMINAL_BUFFER_SIZE]; struct lxc_terminal_state *ts = cbdata; - if (fd != ts->masterfd) + if (fd != ts->ptmxfd) return LXC_MAINLOOP_CLOSE; r = lxc_read_nointr(fd, buf, sizeof(buf)); @@ -984,16 +984,16 @@ int lxc_terminal_master_cb(int fd, uint32_t events, void *cbdata, return LXC_MAINLOOP_CONTINUE; } -int lxc_terminal_getfd(struct lxc_container *c, int *ttynum, int *masterfd) +int lxc_terminal_getfd(struct lxc_container *c, int *ttynum, int *ptmxfd) { - return lxc_cmd_console(c->name, ttynum, masterfd, c->config_path); + return lxc_cmd_console(c->name, ttynum, ptmxfd, c->config_path); } int lxc_console(struct lxc_container *c, int ttynum, int stdinfd, int stdoutfd, int stderrfd, int escape) { - int masterfd, ret, ttyfd; + int ptmxfd, ret, ttyfd; struct lxc_epoll_descr descr; struct termios oldtios; struct lxc_terminal_state *ts; @@ -1002,7 +1002,7 @@ int lxc_console(struct lxc_container *c, int ttynum, }; int istty = 0; - ttyfd = lxc_cmd_console(c->name, &ttynum, &masterfd, c->config_path); + ttyfd = lxc_cmd_console(c->name, &ttynum, &ptmxfd, c->config_path); if (ttyfd < 0) return -1; @@ -1010,7 +1010,7 @@ int lxc_console(struct lxc_container *c, int ttynum, if (ret < 0) TRACE("Process is already group leader"); - ts = lxc_terminal_signal_init(stdinfd, masterfd); + ts = lxc_terminal_signal_init(stdinfd, ptmxfd); if (!ts) { ret = -1; goto close_fds; @@ -1021,8 +1021,8 @@ int lxc_console(struct lxc_container *c, int ttynum, istty = isatty(stdinfd); if (istty) { - lxc_terminal_winsz(stdinfd, masterfd); - lxc_terminal_winsz(ts->stdinfd, ts->masterfd); + lxc_terminal_winsz(stdinfd, ptmxfd); + lxc_terminal_winsz(ts->stdinfd, ts->ptmxfd); } else { INFO("File descriptor %d does not refer to a terminal", stdinfd); } @@ -1049,10 +1049,10 @@ int lxc_console(struct lxc_container *c, int ttynum, goto close_mainloop; } - ret = lxc_mainloop_add_handler(&descr, ts->masterfd, - lxc_terminal_master_cb, ts); + ret = lxc_mainloop_add_handler(&descr, ts->ptmxfd, + lxc_terminal_ptmx_cb, ts); if (ret < 0) { - ERROR("Failed to add master handler"); + ERROR("Failed to add ptmx handler"); goto close_mainloop; } @@ -1093,7 +1093,7 @@ sigwinch_fini: lxc_terminal_signal_fini(&terminal); close_fds: - close(masterfd); + close(ptmxfd); close(ttyfd); return ret; @@ -1133,16 +1133,16 @@ int lxc_terminal_prepare_login(int fd) void lxc_terminal_info_init(struct lxc_terminal_info *terminal) { terminal->name[0] = '\0'; - terminal->master = -EBADF; - terminal->slave = -EBADF; + terminal->ptmx = -EBADF; + terminal->pts = -EBADF; terminal->busy = -1; } void lxc_terminal_init(struct lxc_terminal *terminal) { memset(terminal, 0, sizeof(*terminal)); - terminal->slave = -EBADF; - terminal->master = -EBADF; + terminal->pts = -EBADF; + terminal->ptmx = -EBADF; terminal->peer = -EBADF; terminal->log_fd = -EBADF; lxc_terminal_info_init(&terminal->proxy); @@ -1167,13 +1167,13 @@ int lxc_terminal_map_ids(struct lxc_conf *c, struct lxc_terminal *terminal) if (strcmp(terminal->name, "") == 0) return 0; - ret = userns_exec_mapped_root(terminal->name, terminal->slave, c); + ret = userns_exec_mapped_root(terminal->name, terminal->pts, c); if (ret < 0) { return log_error(-1, "Failed to chown terminal %d(%s)", - terminal->slave, terminal->name); + terminal->pts, terminal->name); } - TRACE("Chowned terminal %d(%s)", terminal->slave, terminal->name); + TRACE("Chowned terminal %d(%s)", terminal->pts, terminal->name); return 0; } diff --git a/src/lxc/terminal.h b/src/lxc/terminal.h index 1283cb337..4d21f33d9 100644 --- a/src/lxc/terminal.h +++ b/src/lxc/terminal.h @@ -15,14 +15,14 @@ struct lxc_conf; struct lxc_epoll_descr; struct lxc_terminal_info { - /* the path name of the slave side */ + /* the path name of the pts side */ char name[PATH_MAX]; - /* the file descriptor of the master */ - int master; + /* the file descriptor of the ptmx */ + int ptmx; - /* the file descriptor of the slave */ - int slave; + /* the file descriptor of the pts */ + int pts; /* whether the terminal is currently used */ int busy; @@ -32,7 +32,7 @@ struct lxc_terminal_state { struct lxc_list node; int stdinfd; int stdoutfd; - int masterfd; + int ptmxfd; /* Escape sequence to use for exiting the terminal. A single char can * be specified. The terminal can then exited by doing: Ctrl + @@ -57,8 +57,8 @@ struct lxc_terminal_state { }; struct lxc_terminal { - int slave; - int master; + int pts; + int ptmx; int peer; struct lxc_terminal_info proxy; struct lxc_epoll_descr *descr; @@ -102,10 +102,10 @@ extern int lxc_terminal_allocate(struct lxc_conf *conf, int sockfd, int *ttynum /** * Create a new terminal: - * - calls openpty() to allocate a master/slave pair - * - sets the FD_CLOEXEC flag on the master/slave fds + * - calls openpty() to allocate a ptmx/pts pair + * - sets the FD_CLOEXEC flag on the ptmx/pts fds * - allocates either the current controlling terminal (default) or a user - * specified terminal as proxy for the newly created master/slave pair + * specified terminal as proxy for the newly created ptmx/pts pair * - sets up SIGWINCH handler, winsz, and new terminal settings * (Handlers for SIGWINCH and I/O are not registered in a mainloop.) */ @@ -164,7 +164,7 @@ extern int lxc_console(struct lxc_container *c, int ttynum, * the range specified by lxc.tty.max to allocate a specific tty. */ extern int lxc_terminal_getfd(struct lxc_container *c, int *ttynum, - int *masterfd); + int *ptmxfd); /** * Make fd a duplicate of the standard file descriptors. The fd is made a @@ -183,12 +183,12 @@ 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 terminal. To be registered via + * Handler for events on the ptmx fd of the terminal. To be registered via * the corresponding functions declared and defined in mainloop.{c,h} or * lxc_terminal_mainloop_add(). * This function exits the loop cleanly when an EPOLLHUP event is received. */ -extern int lxc_terminal_master_cb(int fd, uint32_t events, void *cbdata, +extern int lxc_terminal_ptmx_cb(int fd, uint32_t events, void *cbdata, struct lxc_epoll_descr *descr); /** @@ -202,9 +202,9 @@ extern int lxc_setup_tios(int fd, struct termios *oldtios); * lxc_terminal_winsz: propagate winsz from one terminal to another * * @srcfd - * - terminal to get size from (typically a slave pty) + * - terminal to get size from (typically a pts pty) * @dstfd - * - terminal to set size on (typically a master pty) + * - terminal to set size on (typically a ptmx pty) */ extern void lxc_terminal_winsz(int srcfd, int dstfd);