]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
Add the framework for a console
authordlezcano <dlezcano>
Tue, 25 Nov 2008 12:58:21 +0000 (12:58 +0000)
committerdlezcano <dlezcano>
Tue, 25 Nov 2008 12:58:21 +0000 (12:58 +0000)
From: Daniel Lezcano <dlezcano@fr.ibm.com>

Add the setup information to create a console. This temporary code will
be improved to take into account ttys and console.

Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
src/lxc/lxc_conf.c
src/lxc/lxc_conf.h

index e0661ef9df6ecf6ddc2be815110a79389ef743e8..a3b052c88652c48b988e0d085495f43901a4a232 100644 (file)
@@ -666,6 +666,19 @@ static int setup_rootfs(const char *name)
        return 0;
 }
 
+static int setup_console(const char *name, const char *tty)
+{
+       if (access("/dev/console", R_OK|W_OK))
+               return 0;
+       
+       if (mount(tty, "/dev/console", "none", MS_BIND, 0)) {
+               lxc_log_error("failed to mount the console");
+               return -1;
+       }
+
+       return 0;
+}
+
 static int setup_cgroup_cb(void* buffer, void *data)
 {
        char *key = buffer, *value;
@@ -1363,15 +1376,16 @@ static int delete_netdev(const char *name)
 
 int conf_destroy_network(const char *name)
 {
+#ifdef NETWORK_DESTROY
        if (delete_netdev(name)) {
                lxc_log_error("failed to remove the network devices");
                return -1;
        }
-
+#endif
        return 0;
 }
 
-int lxc_setup(const char *name)
+int lxc_setup(const char *name, const char *tty)
 {
        if (conf_has_utsname(name) && setup_utsname(name)) {
                lxc_log_error("failed to setup the utsname for '%s'", name);
@@ -1389,7 +1403,7 @@ int lxc_setup(const char *name)
        }
 
        if (conf_has_fstab(name) && setup_mount(name)) {
-               lxc_log_error("failed to setup the mount points for '%s'", name);
+               lxc_log_error("failed to setup the mounts for '%s'", name);
                return -LXC_ERROR_SETUP_MOUNT;
        }
 
@@ -1398,5 +1412,10 @@ int lxc_setup(const char *name)
                return -LXC_ERROR_SETUP_ROOTFS;
        }
 
+       if (tty[0] && setup_console(name, tty)) {
+               lxc_log_error("failed to setup the console for '%s'", name);
+               return -LXC_ERROR_SETUP_CONSOLE;
+       }
+
        return 0;
 }
index b6e64322811af440c2ab382520815852d7a57239..fe4b80fdff0ee0ac9e008097ac9aa0f58e921c80 100644 (file)
@@ -139,7 +139,7 @@ extern int conf_destroy_network(const char *name);
 /*
  * Configure the container from inside
  */
-extern int lxc_setup(const char *name);
+extern int lxc_setup(const char *name, const char *tty);
 
 extern int conf_has(const char *name, const char *info);
 
@@ -147,6 +147,7 @@ extern int conf_has(const char *name, const char *info);
 #define conf_has_rootfs(__name)  conf_has(__name, "rootfs")
 #define conf_has_utsname(__name) conf_has(__name, "utsname")
 #define conf_has_network(__name) conf_has(__name, "network")
+#define conf_has_console(__name) conf_has(__name, "console")
 #define conf_has_cgroup(__name) conf_has(__name, "cgroup")
 
 #endif