]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
console: move pty creation to separate function
authorChristian Brauner <christian.brauner@ubuntu.com>
Sat, 23 Dec 2017 10:59:36 +0000 (11:59 +0100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Tue, 9 Jan 2018 12:20:10 +0000 (13:20 +0100)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/console.c
src/lxc/console.h

index ac7999e4a9696b2978cfb5e3e53c5e0b195e070a..a650af6db77490d529b936c1e0bc2ee8c565c984 100644 (file)
@@ -709,24 +709,13 @@ int lxc_console_create_log_file(struct lxc_console *console)
        return 0;
 }
 
-int lxc_console_create(struct lxc_conf *conf)
+int lxc_pty_create(struct lxc_console *console)
 {
        int ret, saved_errno;
-       struct lxc_console *console = &conf->console;
-
-       if (!conf->rootfs.path) {
-               INFO("Container does not have a rootfs. The console will be "
-                    "shared with the host");
-               return 0;
-       }
-
-       if (console->path && !strcmp(console->path, "none")) {
-               INFO("No console was requested");
-               return 0;
-       }
 
        process_lock();
-       ret = openpty(&console->master, &console->slave, console->name, NULL, NULL);
+       ret = openpty(&console->master, &console->slave, console->name, NULL,
+                     NULL);
        saved_errno = errno;
        process_unlock();
        if (ret < 0) {
@@ -752,6 +741,33 @@ int lxc_console_create(struct lxc_conf *conf)
                goto err;
        }
 
+       return 0;
+
+err:
+       lxc_console_delete(console);
+       return -ENODEV;
+}
+
+int lxc_console_create(struct lxc_conf *conf)
+{
+       int ret;
+       struct lxc_console *console = &conf->console;
+
+       if (!conf->rootfs.path) {
+               INFO("Container does not have a rootfs. The console will be "
+                    "shared with the host");
+               return 0;
+       }
+
+       if (console->path && !strcmp(console->path, "none")) {
+               INFO("No console was requested");
+               return 0;
+       }
+
+       ret = lxc_pty_create(console);
+       if (ret < 0)
+               return -1;
+
        /* create console log file */
        ret = lxc_console_create_log_file(console);
        if (ret < 0)
index 375349e02917c6afeefc2b0d69ad80de0d7bbccf..f358437c32891bae431cfae7285b6a090b99b9b0 100644 (file)
@@ -82,6 +82,12 @@ extern int  lxc_console_allocate(struct lxc_conf *conf, int sockfd, int *ttynum)
  * automatically chowned to the uid/gid of the unprivileged user. For this
  * ttys_shift_ids() can be called.)
  */
+extern int lxc_pty_create(struct lxc_console *console);
+
+/**
+ * lxc_console_create: Create a new pty.
+ * - In addition to lxc_pty_create() also sets up all pty logs.
+ */
 extern int  lxc_console_create(struct lxc_conf *);
 
 /*