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;