[libvirt] [PATCH] LXC: mount /dev/pts/0 to /dev/console

Gao feng gaofeng at cn.fujitsu.com
Tue Oct 29 07:37:51 UTC 2013


Now, /dev/console is linked to the /dev/pts/0,
so for the process agetty, the tty device of
agetty is pts/0. this will cause login container
failed.
since pts/0 is not in the /etc/securetty. so
pam module pam_securetty will prevent the root
user logging on the system.

this patch doesn't make /dev/console a symbol but
binds /dev/pts/0 to it. so the tty device of
agetty will be console. root can login the system
successfully.

Signed-off-by: Gao feng <gaofeng at cn.fujitsu.com>
---
 src/lxc/lxc_container.c | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c
index 255c711..1cede41 100644
--- a/src/lxc/lxc_container.c
+++ b/src/lxc/lxc_container.c
@@ -1049,12 +1049,19 @@ static int lxcContainerSetupDevices(char **ttyPaths, size_t nttyPaths)
             return -1;
         }
         VIR_FREE(tty);
-        if (i == 0 &&
-            symlink(ttyPaths[i], "/dev/console") < 0) {
-            virReportSystemError(errno,
-                                 _("Failed to symlink %s to /dev/console"),
-                                 ttyPaths[i]);
-            return -1;
+        if (i == 0) {
+            if (virFileTouch("/dev/console", 0600) < 0) {
+                virReportSystemError(errno, "%s",
+                                     _("Failed to create /dev/console"));
+                return -1;
+            }
+
+            if (mount(ttyPaths[0], "/dev/console", NULL, MS_BIND, NULL) < 0) {
+                virReportSystemError(errno,
+                                     _("Failed to symlink %s to /dev/console"),
+                                     ttyPaths[i]);
+                return -1;
+            }
         }
     }
     return 0;
-- 
1.8.3.1




More information about the libvir-list mailing list