summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2014-03-10 21:36:01 +0100
committerLennart Poettering <lennart@poettering.net>2014-03-10 21:36:01 +0100
commiteb0f0863f5af48865fb4569e2076d5f9e2313995 (patch)
tree4047c89fae039078eecb7ad3881dae8ce9d15c9b /src
parent1b9e5b126359a2a2ec37de1f94f046093abc74b8 (diff)
nspawn: don't try mknod() of /dev/console with the correct major/minor
We overmount /dev/console with an external pty anyway, hence there's no point in using the real major/minor when we create the node to overmount. Instead, use the one of /dev/null now. This fixes a race against the cgroup device controller setup we are using. In case /dev/console was create before the cgroup policy was applied all was good, but if created in the opposite order the mknod() would fail, since creating /dev/console is not allowed by it. Creating /dev/null instances is however permitted, and hence use it.
Diffstat (limited to 'src')
-rw-r--r--src/nspawn/nspawn.c25
1 files changed, 10 insertions, 15 deletions
diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c
index d8d0dae164..bef866a966 100644
--- a/src/nspawn/nspawn.c
+++ b/src/nspawn/nspawn.c
@@ -879,23 +879,19 @@ static int setup_ptmx(const char *dest) {
}
static int setup_dev_console(const char *dest, const char *console) {
+ _cleanup_umask_ mode_t u;
+ const char *to;
struct stat st;
- _cleanup_free_ char *to = NULL;
int r;
- _cleanup_umask_ mode_t u;
assert(dest);
assert(console);
u = umask(0000);
- if (stat(console, &st) < 0) {
- log_error("Failed to stat %s: %m", console);
+ if (stat("/dev/null", &st) < 0) {
+ log_error("Failed to stat /dev/null: %m");
return -errno;
-
- } else if (!S_ISCHR(st.st_mode)) {
- log_error("/dev/console is not a char device");
- return -EIO;
}
r = chmod_and_chown(console, 0600, 0, 0);
@@ -904,16 +900,15 @@ static int setup_dev_console(const char *dest, const char *console) {
return r;
}
- if (asprintf(&to, "%s/dev/console", dest) < 0)
- return log_oom();
-
/* We need to bind mount the right tty to /dev/console since
* ptys can only exist on pts file systems. To have something
- * to bind mount things on we create a device node first, that
- * has the right major/minor (note that the major minor
- * doesn't actually matter here, since we mount it over
- * anyway). */
+ * to bind mount things on we create a device node first, and
+ * use /dev/null for that since we the cgroups device policy
+ * allows us to create that freely, while we cannot create
+ * /dev/console. (Note that the major minor doesn't actually
+ * matter here, since we mount it over anyway). */
+ to = strappenda(dest, "/dev/console");
if (mknod(to, (st.st_mode & ~07777) | 0600, st.st_rdev) < 0) {
log_error("mknod() for /dev/console failed: %m");
return -errno;