]> git.proxmox.com Git - mirror_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>
Tue, 9 Jan 2018 12:20:14 +0000 (13:20 +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

index affc41e16bdb464177e327045cf13d60234be96f..4cab6e74c0d9cd7b589872215398e4606c10ff86 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"
@@ -3720,11 +3721,7 @@ void lxc_conf_free(struct lxc_conf *conf)
                return;
        if (current_config == conf)
                current_config = NULL;
-       free(conf->console.buffer_log_file);
-       free(conf->console.log_path);
-       free(conf->console.path);
-       if (conf->console.buffer_size > 0 && conf->console.ringbuf.addr)
-               lxc_ringbuf_release(&conf->console.ringbuf);
+       lxc_pty_conf_free(&conf->console);
        free(conf->rootfs.mount);
        free(conf->rootfs.bdev_type);
        free(conf->rootfs.options);
index a650af6db77490d529b936c1e0bc2ee8c565c984..aceaa45091c9bf9a6d222624f54ae8f378c1c06d 100644 (file)
@@ -985,3 +985,62 @@ 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;
+       pty->buffer_log_file_fd = -EBADF;
+       lxc_pty_info_init(&pty->peerpty);
+}
+
+void lxc_pty_conf_free(struct lxc_console *console)
+{
+       free(console->buffer_log_file);
+       free(console->log_path);
+       free(console->path);
+       if (console->buffer_size > 0 && console->ringbuf.addr)
+               lxc_ringbuf_release(&console->ringbuf);
+}
index f358437c32891bae431cfae7285b6a090b99b9b0..bd54ed3bbca176d529072b279f18bd28f6957647 100644 (file)
@@ -232,4 +232,10 @@ extern int lxc_console_create_log_file(struct lxc_console *console);
 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