From 1bd051a6b0a34cb2b2e80584b9fb4643abf1a827 Mon Sep 17 00:00:00 2001 From: Serge Hallyn Date: Thu, 13 Sep 2012 09:39:07 -0500 Subject: [PATCH] link /dev/kmsg to /dev/console in the container This way init log messages can be seen on the console. If containerized syslog ever comes around, we can get rid of this. Signed-off-by: Serge Hallyn --- src/lxc/conf.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/lxc/conf.c b/src/lxc/conf.c index 4475b0319..8080d7d0b 100644 --- a/src/lxc/conf.c +++ b/src/lxc/conf.c @@ -1055,6 +1055,31 @@ static int setup_console(const struct lxc_rootfs *rootfs, return setup_ttydir_console(rootfs, console, ttydir); } +static int setup_kmsg(const struct lxc_rootfs *rootfs, + const struct lxc_console *console) +{ + char kpath[MAXPATHLEN]; + int ret; + + ret = snprintf(kpath, sizeof(kpath), "%s/dev/kmsg", rootfs->mount); + if (ret < 0 || ret >= sizeof(kpath)) + return -1; + + ret = unlink(kpath); + if (ret && errno != ENOENT) { + SYSERROR("error unlinking %s\n", kpath); + return -1; + } + + ret = symlink("console", kpath); + if (ret) { + SYSERROR("failed to create symlink for kmsg"); + return -1; + } + + return 0; +} + static int setup_cgroup(const char *name, struct lxc_list *cgroups) { struct lxc_list *iterator; @@ -2167,6 +2192,11 @@ int lxc_setup(const char *name, struct lxc_conf *lxc_conf) return -1; } + if (setup_kmsg(&lxc_conf->rootfs, &lxc_conf->console)) { + ERROR("failed to setup kmsg for '%s'", name); + return -1; + } + if (setup_tty(&lxc_conf->rootfs, &lxc_conf->tty_info, lxc_conf->ttydir)) { ERROR("failed to setup the ttys for '%s'", name); return -1;