From: Daniel Lezcano Date: Tue, 22 Jun 2010 22:44:13 +0000 (+0200) Subject: fix default console to /dev/tty X-Git-Tag: lxc-0.7.1~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cd453b38b778652cb341062fbf3c38edefc3a478;p=thirdparty%2Flxc.git fix default console to /dev/tty 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 --- diff --git a/src/lxc/console.c b/src/lxc/console.c index 3c0d3788a..1ab2b29e1 100644 --- a/src/lxc/console.c +++ b/src/lxc/console.c @@ -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))