Do not use the directory configuration

Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
---
 src/lxc/conf.c |   65 +++++++++++++++++++++++----------------------------------
 1 file changed, 27 insertions(+), 38 deletions(-)

Index: lxc/src/lxc/conf.c
===================================================================
--- lxc.orig/src/lxc/conf.c
+++ lxc/src/lxc/conf.c
@@ -401,28 +401,6 @@ static int configure_cgroup(const char *
 	return 0;
 }
 
-static int configure_tty(const char *name, int tty)
-{
-	char path[MAXPATHLEN];
-	char *nbtty;
-	int ret;
-
-	if (asprintf(&nbtty, "%d", tty) < 0) {
-		ERROR("failed to convert tty number");
-		return -1;
-	}
-
-	snprintf(path, MAXPATHLEN, LXCPATH "/%s", name);
-
-	ret = write_info(path, "tty", nbtty);
-	if (ret)
-		ERROR("failed to write the tty info");
-
-	free(nbtty);
-
-	return ret;
-}
-
 static int configure_find_fstype_cb(void* buffer, void *data)
 {
 	struct cbarg {
@@ -750,7 +728,7 @@ static int setup_utsname(struct utsname 
 	return 0;
 }
 
-static int setup_tty(const char *name, const struct lxc_tty_info *tty_info)
+static int setup_tty(const char *rootfs, const struct lxc_tty_info *tty_info)
 {
 	char path[MAXPATHLEN];
 	int i;
@@ -759,11 +737,8 @@ static int setup_tty(const char *name, c
 
 		struct lxc_pty_info *pty_info = &tty_info->pty_info[i];
 
-		if (conf_has_rootfs(name))
-			snprintf(path, MAXPATHLEN,
-				 LXCPATH "/%s/rootfs/dev/tty%d", name, i + 1);
-		else
-			snprintf(path, MAXPATHLEN, "/dev/tty%d", i + 1);
+		snprintf(path, sizeof(path), "%s/dev/tty%d",
+			 rootfs ? rootfs : "", i + 1);
 
 		/* At this point I can not use the "access" function
 		 * to check the file is present or not because it fails
@@ -771,7 +746,7 @@ static int setup_tty(const char *name, c
 
 		if (mount(pty_info->name, path, "none", MS_BIND, 0)) {
 			WARN("failed to mount '%s'->'%s'",
-					pty_info->name, path);
+			     pty_info->name, path);
 			continue;
 		}
 	}
@@ -862,11 +837,30 @@ out:
 	return 0;
 }
 
-static int setup_console(const char *name, const char *tty)
+static int setup_console(const char *rootfs, const char *tty)
 {
 	char console[MAXPATHLEN];
 
-	snprintf(console, MAXPATHLEN, LXCPATH "/%s/rootfs/dev/console", name);
+	snprintf(console, sizeof(console), "%s/dev/console", rootfs);
+
+	/* we have the rootfs with /dev/console but no tty
+	 * to be used as console, let's remap /dev/console
+	 * to /dev/null to avoid to log to the system console
+	 */
+	if (rootfs && !tty[0]) {
+
+		if (!access(console, F_OK)) {
+
+			if (mount("/dev/null", console, "none", MS_BIND, 0)) {
+				SYSERROR("failed to mount '/dev/null'->'%s'",
+					 console);
+				return -1;
+			}
+		}
+	}
+
+	if (!tty[0])
+		return 0;
 
 	if (access(console, R_OK|W_OK))
 		return 0;
@@ -1378,11 +1372,6 @@ int lxc_configure(const char *name, stru
 		return -1;
 	}
 
-	if (conf->tty && configure_tty(name, conf->tty)) {
-		ERROR("failed to configure the tty");
-		return -1;
-	}
-
 	return 0;
 }
 
@@ -1789,12 +1778,12 @@ int lxc_setup(const char *name, const ch
 		return -1;
 	}
 
-	if (cons[0] && setup_console(name, cons)) {
+	if (setup_console(lxc_conf.rootfs, cons)) {
 		ERROR("failed to setup the console for '%s'", name);
 		return -1;
 	}
 
-	if (lxc_conf.tty && setup_tty(name, tty_info)) {
+	if (setup_tty(lxc_conf.rootfs, tty_info)) {
 		ERROR("failed to setup the ttys for '%s'", name);
 		return -1;
 	}



