]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
console: add some pty helpers
authorChristian Brauner <christian.brauner@ubuntu.com>
Sat, 23 Dec 2017 11:19:51 +0000 (12:19 +0100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Fri, 19 Jan 2018 13:50:49 +0000 (14:50 +0100)
- int lxc_make_controlling_pty()
- int lxc_login_pty()
- void lxc_pty_conf_free()
- void lxc_pty_info_init()
- void lxc_pty_init()

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/conf.c
src/lxc/console.c
src/lxc/console.h
src/lxc/start.c

index ddfd84aa263157f4be80ce18f5fad8df6700ff79..b90a18f9dd9c366816d45f8db3bdc6614436bf23 100644 (file)
@@ -73,6 +73,7 @@
 #include "cgroup.h"
 #include "conf.h"
 #include "confile_utils.h"
+#include "console.h"
 #include "error.h"
 #include "log.h"
 #include "lxclock.h"
@@ -3489,8 +3490,7 @@ void lxc_conf_free(struct lxc_conf *conf)
                return;
        if (current_config == conf)
                current_config = NULL;
-       free(conf->console.log_path);
-       free(conf->console.path);
+       lxc_pty_conf_free(&conf->console);
        free(conf->rootfs.mount);
        free(conf->rootfs.bdev_type);
        free(conf->rootfs.options);
index 24d191adff661247b951e59d5f31b4f74271dcbf..81e1f37e0d2c4d8905169989e2e40baa77038996 100644 (file)
@@ -861,3 +861,58 @@ close_fds:
 
        return ret;
 }
+
+int lxc_make_controlling_pty(int fd)
+{
+       int ret;
+
+       setsid();
+
+       ret = ioctl(fd, TIOCSCTTY, (char *)NULL);
+       if (ret < 0)
+               return -1;
+
+       return 0;
+}
+
+int lxc_login_pty(int fd)
+{
+       int ret;
+
+       ret = lxc_make_controlling_pty(fd);
+       if (ret < 0)
+               return -1;
+
+       ret = lxc_console_set_stdfds(fd);
+       if (ret < 0)
+               return -1;
+
+       if (fd > STDERR_FILENO)
+               close(fd);
+
+       return 0;
+}
+
+void lxc_pty_info_init(struct lxc_pty_info *pty)
+{
+       pty->name[0] = '\0';
+       pty->master = -EBADF;
+       pty->slave = -EBADF;
+       pty->busy = -1;
+}
+
+void lxc_pty_init(struct lxc_console *pty)
+{
+       memset(pty, 0, sizeof(*pty));
+       pty->slave = -EBADF;
+       pty->master = -EBADF;
+       pty->peer = -EBADF;
+       pty->log_fd = -EBADF;
+       lxc_pty_info_init(&pty->peerpty);
+}
+
+void lxc_pty_conf_free(struct lxc_console *console)
+{
+       free(console->log_path);
+       free(console->path);
+}
index 779d1cac576a35348ed29b6920cf4fb0b873b9c9..dcdf364c4acf5f2d223057b3a0dd27406a1510b6 100644 (file)
@@ -230,4 +230,10 @@ extern void lxc_console_signal_fini(struct lxc_tty_state *ts);
 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_info_init(struct lxc_pty_info *pty);
+extern void lxc_pty_init(struct lxc_console *pty);
+
 #endif
index 3049d8c0fd7671a69775ac788bea5008b0f7a9ae..474a20e717bfa52c7a363ee1138c561cee6b8baf 100644 (file)
@@ -665,6 +665,7 @@ on_error:
 
 int lxc_init(const char *name, struct lxc_handler *handler)
 {
+       int ret;
        const char *loglevel;
        struct lxc_conf *conf = handler->conf;