]> git.proxmox.com Git - mirror_lxc.git/commitdiff
console: adapt lxc_console_mainloop_add()
authorChristian Brauner <christian.brauner@ubuntu.com>
Sat, 23 Dec 2017 12:25:44 +0000 (13:25 +0100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Tue, 9 Jan 2018 12:20:17 +0000 (13:20 +0100)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/console.c
src/lxc/console.h
src/lxc/start.c
src/lxc/tools/lxc_attach.c

index aceaa45091c9bf9a6d222624f54ae8f378c1c06d..2f107b5e61570b39c6856db6232309c804512b5b 100644 (file)
@@ -285,31 +285,25 @@ static int lxc_console_mainloop_add_peer(struct lxc_console *console)
        return 0;
 }
 
-extern int lxc_console_mainloop_add(struct lxc_epoll_descr *descr,
-                                   struct lxc_conf *conf)
+int lxc_console_mainloop_add(struct lxc_epoll_descr *descr,
+                            struct lxc_console *console)
 {
        int ret;
-       struct lxc_console *console = &conf->console;
-
-       if (!conf->rootfs.path) {
-               INFO("no rootfs, no console.");
-               return 0;
-       }
 
        if (console->master < 0) {
                INFO("no console");
                return 0;
        }
 
-       if (lxc_mainloop_add_handler(descr, console->master,
-                                    lxc_console_cb_con, console)) {
-               ERROR("failed to add to mainloop console handler for '%d'",
-                     console->master);
+       ret = lxc_mainloop_add_handler(descr, console->master,
+                                      lxc_console_cb_con, console);
+       if (ret < 0) {
+               ERROR("Failed to add handler for %d to mainloop", console->master);
                return -1;
        }
 
-       /* we cache the descr so that we can add an fd to it when someone
-        * does attach to it in lxc_console_allocate()
+       /* We cache the descr so that we can add an fd to it when someone
+        * does attach to it in lxc_console_allocate().
         */
        console->descr = descr;
        ret = lxc_console_mainloop_add_peer(console);
index bd54ed3bbca176d529072b279f18bd28f6957647..b456746e484e7602f271bb02480920a69c810eec 100644 (file)
@@ -114,7 +114,7 @@ extern void lxc_console_free(struct lxc_conf *conf, int fd);
 /*
  * Register pty event handlers in an open mainloop
  */
-extern int  lxc_console_mainloop_add(struct lxc_epoll_descr *, struct lxc_conf *);
+extern int  lxc_console_mainloop_add(struct lxc_epoll_descr *, struct lxc_console *);
 
 /*
  * Handle SIGWINCH events on the allocated ptys.
index a66881e561f3e2d13056e38b1eb6aa432a7c096e..c12728d613864b26679b2fb39132f8da04ae97ca 100644 (file)
@@ -468,6 +468,7 @@ int lxc_set_state(const char *name, struct lxc_handler *handler,
 int lxc_poll(const char *name, struct lxc_handler *handler)
 {
        int ret;
+       bool has_console = (handler->conf->rootfs.path != NULL);
        struct lxc_epoll_descr descr, descr_console;
 
        ret = lxc_mainloop_open(&descr);
@@ -476,10 +477,12 @@ int lxc_poll(const char *name, struct lxc_handler *handler)
                goto out_sigfd;
        }
 
-       ret = lxc_mainloop_open(&descr_console);
-       if (ret < 0) {
-               ERROR("Failed to create console mainloop");
-               goto out_mainloop;
+       if (has_console) {
+               ret = lxc_mainloop_open(&descr_console);
+               if (ret < 0) {
+                       ERROR("Failed to create console mainloop");
+                       goto out_mainloop;
+               }
        }
 
        ret = lxc_mainloop_add_handler(&descr, handler->sigfd, signal_handler, handler);
@@ -488,16 +491,20 @@ int lxc_poll(const char *name, struct lxc_handler *handler)
                goto out_mainloop_console;
        }
 
-       ret = lxc_console_mainloop_add(&descr, handler->conf);
-       if (ret < 0) {
-               ERROR("Failed to add console handlers to mainloop");
-               goto out_mainloop_console;
-       }
+       if (has_console) {
+               struct lxc_console *console = &handler->conf->console;
 
-       ret = lxc_console_mainloop_add(&descr_console, handler->conf);
-       if (ret < 0) {
-               ERROR("Failed to add console handlers to console mainloop");
-               goto out_mainloop_console;
+               ret = lxc_console_mainloop_add(&descr, console);
+               if (ret < 0) {
+                       ERROR("Failed to add console handlers to mainloop");
+                       goto out_mainloop_console;
+               }
+
+               ret = lxc_console_mainloop_add(&descr_console, console);
+               if (ret < 0) {
+                       ERROR("Failed to add console handlers to console mainloop");
+                       goto out_mainloop_console;
+               }
        }
 
        ret = lxc_cmd_mainloop_add(name, &descr, handler);
@@ -514,15 +521,19 @@ int lxc_poll(const char *name, struct lxc_handler *handler)
        if (ret < 0 || !handler->init_died)
                goto out_mainloop;
 
-       ret = lxc_mainloop(&descr_console, 0);
+       if (has_console)
+               ret = lxc_mainloop(&descr_console, 0);
+
 
 out_mainloop:
        lxc_mainloop_close(&descr);
        TRACE("Closed mainloop");
 
 out_mainloop_console:
-       lxc_mainloop_close(&descr_console);
-       TRACE("Closed console mainloop");
+       if (has_console) {
+               lxc_mainloop_close(&descr_console);
+               TRACE("Closed console mainloop");
+       }
 
 out_sigfd:
        close(handler->sigfd);
index ccd1787dff350519f969e7ac0d1f82f088870c7f..b5c89270c1f2ed595568a02ba1e95909c3ded493 100644 (file)
@@ -356,7 +356,7 @@ static int get_pty_on_host(struct lxc_container *c, struct wrapargs *wrap, int *
                goto err2;
        }
 
-       if (lxc_console_mainloop_add(&descr, conf) < 0) {
+       if (lxc_console_mainloop_add(&descr, &conf->console) < 0) {
                fprintf(stderr, "Failed to add handlers to lxc mainloop.\n");
                goto err3;
        }