]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
fix default console to /dev/tty
authorDaniel Lezcano <daniel.lezcano@free.fr>
Tue, 22 Jun 2010 22:44:13 +0000 (00:44 +0200)
committerDaniel Lezcano <dlezcano@fr.ibm.com>
Tue, 22 Jun 2010 22:44:13 +0000 (00:44 +0200)
Fix default console output fall into the current tty.
Otherwise fall to /dev/null if no tty is available.

Fix at the same time, Xorg take 100% cpu.

Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
src/lxc/console.c

index 3c0d3788ab1f89620b4623fc183e8676f0f11a78..1ab2b29e13977798eb2b4adcd3a22a09c79be813 100644 (file)
@@ -139,6 +139,29 @@ out_close:
        return 1;
 }
 
+static get_default_console(char **console)
+{
+       int fd;
+
+       if (!access("/dev/tty", F_OK)) {
+               fd = open("/dev/tty", O_RDWR);
+               if (fd > 0) {
+                       close(fd);
+                       *console = strdup("/dev/tty");
+                       goto out;
+               }
+       }
+
+       if (!access("/dev/null", F_OK)) {
+               *console = strdup("/dev/null");
+               goto out;
+       }
+
+       ERROR("No suitable default console");
+out:
+       return *console ? 0 : -1;
+}
+
 int lxc_create_console(struct lxc_conf *conf)
 {
        struct termios tios;
@@ -148,8 +171,10 @@ int lxc_create_console(struct lxc_conf *conf)
        if (!conf->rootfs.path)
                return 0;
 
-       if (!console->path)
-               return 0;
+       if (!console->path && get_default_console(&console->path)) {
+               ERROR("failed to get default console");
+               return -1;
+       }
 
        if (openpty(&console->master, &console->slave,
                    console->name, NULL, NULL)) {
@@ -173,6 +198,8 @@ int lxc_create_console(struct lxc_conf *conf)
                goto err;
        }
 
+       DEBUG("using '%s' as console", console->path);
+
        console->peer = fd;
 
        if (!isatty(console->peer))