i've lost my brain! i'm not a c programmer. someone who knows what
he's doing, should have a look on it.

it errors out with:

lxc-start 1392232180.856 INFO     lxc_conf - Creating initial consoles
under /usr/lib64/lxc/rootfs/dev
lxc-start 1392232180.856 INFO     lxc_conf - Populating /dev under
/usr/lib64/lxc/rootfs in_userns:1
lxc-start 1392232180.856 INFO     lxc_conf - Populated /dev under
/usr/lib64/lxc/rootfs in_userns:1
lxc-start 1392232180.856 INFO     lxc_conf - created
/usr/lib64/lxc/rootfs/dev/lxc
lxc-start 1392232180.856 INFO     lxc_conf - console has been setup on
lxc/console
lxc-start 1392232180.856 INFO     lxc_conf - 4 tty(s) has been setup
lxc-start 1392232180.856 DEBUG    lxc_conf - created
'/usr/lib64/lxc/rootfs/lxc_putold' directory
lxc-start 1392232180.856 DEBUG    lxc_conf - mountpoint for old rootfs
is '/usr/lib64/lxc/rootfs/lxc_putold'
lxc-start 1392232180.856 DEBUG    lxc_conf - pivot_root syscall to
'/usr/lib64/lxc/rootfs' successful
lxc-start 1392232180.861 INFO     lxc_conf - lazy unmount of '/lxc_putold'
lxc-start 1392232180.861 WARN     lxc_conf - failed to unmount '/lxc_putold/dev'
lxc-start 1392232180.861 WARN     lxc_conf - failed to unmount
'/lxc_putold/dev/pts'
lxc-start 1392232180.861 WARN     lxc_conf - failed to unmount
'/lxc_putold/dev/shm'
lxc-start 1392232180.861 WARN     lxc_conf - failed to unmount
'/lxc_putold/proc'
lxc-start 1392232180.861 WARN     lxc_conf - failed to unmount
'/lxc_putold/proc/sys/fs/binfmt_misc'
lxc-start 1392232180.861 WARN     lxc_conf - failed to unmount '/lxc_putold/sys'
lxc-start 1392232180.861 WARN     lxc_conf - failed to unmount
'/lxc_putold/boot'
lxc-start 1392232180.861 WARN     lxc_conf - failed to unmount
'/lxc_putold/media/dataa'
lxc-start 1392232180.861 WARN     lxc_conf - failed to unmount
'/lxc_putold/cgroup/cpuset'
lxc-start 1392232180.861 WARN     lxc_conf - failed to unmount
'/lxc_putold/cgroup/cpu'
lxc-start 1392232180.861 WARN     lxc_conf - failed to unmount
'/lxc_putold/cgroup/cpuacct'
lxc-start 1392232180.861 WARN     lxc_conf - failed to unmount
'/lxc_putold/cgroup/memory'
lxc-start 1392232180.861 WARN     lxc_conf - failed to unmount
'/lxc_putold/cgroup/devices'
lxc-start 1392232180.861 WARN     lxc_conf - failed to unmount
'/lxc_putold/cgroup/freezer'
lxc-start 1392232180.861 WARN     lxc_conf - failed to unmount
'/lxc_putold/cgroup/net_cls'
lxc-start 1392232180.861 WARN     lxc_conf - failed to unmount
'/lxc_putold/cgroup/blkio'
lxc-start 1392232180.861 ERROR    lxc_conf - Invalid argument - failed
to mount a new instance of '/dev/pts'
lxc-start 1392232180.861 ERROR    lxc_conf - failed to setup the new
pts instance
lxc-start 1392232180.861 ERROR    lxc_start - failed to setup the container
lxc-start 1392232180.861 ERROR    lxc_sync - invalid sequence number
1. expected 2
lxc-start 1392232180.862 WARN     lxc_conf - failed to remove interface '(null)'
lxc-start 1392232180.878 ERROR    lxc_start - failed to spawn 'fedora1'

/stephan

-- 
Software is like sex, it's better when it's free!
diff --git a/src/lxc/conf.c b/src/lxc/conf.c
index 81dcb42..472dbdc 100644
--- a/src/lxc/conf.c
+++ b/src/lxc/conf.c
@@ -164,6 +164,9 @@ struct caps_opt {
 	int value;
 };
 
+bool get_mapped_rootid(struct lxc_conf *conf, enum idtype idtype,
+			unsigned long *val);
+
 static int instanciate_veth(struct lxc_handler *, struct lxc_netdev *);
 static int instanciate_macvlan(struct lxc_handler *, struct lxc_netdev *);
 static int instanciate_vlan(struct lxc_handler *, struct lxc_netdev *);
@@ -1380,49 +1383,77 @@ struct lxc_devs {
 	mode_t mode;
 	int maj;
 	int min;
+	int bindmount;
 };
 
 static const struct lxc_devs lxc_devs[] = {
-	{ "null",	S_IFCHR | S_IRWXU | S_IRWXG | S_IRWXO, 1, 3	},
-	{ "zero",	S_IFCHR | S_IRWXU | S_IRWXG | S_IRWXO, 1, 5	},
-	{ "full",	S_IFCHR | S_IRWXU | S_IRWXG | S_IRWXO, 1, 7	},
-	{ "urandom",	S_IFCHR | S_IRWXU | S_IRWXG | S_IRWXO, 1, 9	},
-	{ "random",	S_IFCHR | S_IRWXU | S_IRWXG | S_IRWXO, 1, 8	},
-	{ "tty",	S_IFCHR | S_IRWXU | S_IRWXG | S_IRWXO, 5, 0	},
-	{ "console",	S_IFCHR | S_IRUSR | S_IWUSR,	       5, 1	},
+	{ "null",	S_IFCHR | S_IRWXU | S_IRWXG | S_IRWXO, 1, 3, 1	},
+	{ "zero",	S_IFCHR | S_IRWXU | S_IRWXG | S_IRWXO, 1, 5, 1	},
+	{ "full",	S_IFCHR | S_IRWXU | S_IRWXG | S_IRWXO, 1, 7, 1	},
+	{ "urandom",	S_IFCHR | S_IRWXU | S_IRWXG | S_IRWXO, 1, 9, 1	},
+	{ "random",	S_IFCHR | S_IRWXU | S_IRWXG | S_IRWXO, 1, 8, 1	},
+	{ "tty",	S_IFCHR | S_IRWXU | S_IRWXG | S_IRWXO, 5, 0, 1	},
+	{ "console",	S_IFCHR | S_IRUSR | S_IWUSR,	       5, 1, 0	},
 };
 
-static int setup_autodev(const char *root)
+static int setup_autodev(const char *root, struct lxc_conf *conf)
 {
 	int ret;
-	char path[MAXPATHLEN];
+	char path[MAXPATHLEN], src[MAXPATHLEN];
 	int i;
+	int in_userns;
+	unsigned long val;
 	mode_t cmask;
 
 	INFO("Creating initial consoles under %s/dev\n", root);
 
+	in_userns = 0;
+	if (get_mapped_rootid(conf, ID_TYPE_UID, &val))
+		in_userns = 1;
+
 	ret = snprintf(path, MAXPATHLEN, "%s/dev", root);
 	if (ret < 0 || ret >= MAXPATHLEN) {
 		ERROR("Error calculating container /dev location");
 		return -1;
 	}
 
-	INFO("Populating /dev under %s\n", root);
+	INFO("Populating /dev under %s in_userns:%d", root, in_userns);
 	cmask = umask(S_IXUSR | S_IXGRP | S_IXOTH);
 	for (i = 0; i < sizeof(lxc_devs) / sizeof(lxc_devs[0]); i++) {
 		const struct lxc_devs *d = &lxc_devs[i];
 		ret = snprintf(path, MAXPATHLEN, "%s/dev/%s", root, d->name);
 		if (ret < 0 || ret >= MAXPATHLEN)
 			return -1;
-		ret = mknod(path, d->mode, makedev(d->maj, d->min));
-		if (ret && errno != EEXIST) {
-			SYSERROR("Error creating %s\n", d->name);
-			return -1;
+		if (in_userns > 0) {
+			// not for console! see setup_ttydir_console()
+			if (d->bindmount < 1)
+				continue;
+
+			ret = creat(path, 0440);
+			if (ret==-1 && errno != EEXIST) {
+				SYSERROR("error creating %s\n", path);
+				return -1;
+			}
+
+			ret = snprintf(src, MAXPATHLEN, "/dev/%s", d->name);
+			if (ret < 0 || ret >= MAXPATHLEN)
+				return -1;
+
+			if (mount(src, path, "none", MS_BIND, NULL)) {
+				SYSERROR("failed to mount '%s'->'%s'", src, path);
+				return -1;
+			}
+		} else {
+			ret = mknod(path, d->mode, makedev(d->maj, d->min));
+			if (ret && errno != EEXIST) {
+				SYSERROR("Error creating %s\n", d->name);
+				return -1;
+			}
 		}
 	}
 	umask(cmask);
 
-	INFO("Populated /dev under %s\n", root);
+	INFO("Populated /dev under %s in_userns:%d", root, in_userns);
 	return 0;
 }
 
@@ -3570,7 +3601,7 @@ int lxc_setup(struct lxc_handler *handler)
 			ERROR("failed to run autodev hooks for container '%s'.", name);
 			return -1;
 		}
-		if (setup_autodev(lxc_conf->rootfs.mount)) {
+		if (setup_autodev(lxc_conf->rootfs.mount, lxc_conf)) {
 			ERROR("failed to populate /dev in the container");
 			return -1;
 		}
_______________________________________________
lxc-devel mailing list
[email protected]
http://lists.linuxcontainers.org/listinfo/lxc-devel

Reply via email to