]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Create ptmx as a device
authorSerge Hallyn <serge.hallyn@canonical.com>
Wed, 31 Aug 2011 18:18:33 +0000 (13:18 -0500)
committerEric Blake <eblake@redhat.com>
Fri, 2 Sep 2011 02:11:50 +0000 (20:11 -0600)
Hi,

I'm seeing an issue with udev and libvirt-lxc.  Libvirt-lxc creates
/dev/ptmx as a symlink to /dev/pts/ptmx.  When udev starts up, it
checks the device type, sees ptmx is 'not right', and replaces it
with a 'proper' ptmx.

In lxc, /dev/ptmx is bind-mounted from /dev/pts/ptmx instead of being
symlinked, so udev sees the right device type and leaves it alone.

A patch like the following seems to work for me.  Would there be
any objections to this?

>From 4c5035de52de7e06a0de9c5d0bab8c87a806cba7 Mon Sep 17 00:00:00 2001
From: Ubuntu <ubuntu@domU-12-31-39-14-F0-B3.compute-1.internal>
Date: Wed, 31 Aug 2011 18:15:54 +0000
Subject: [PATCH 1/1] make ptmx a bind mount rather than symlink

udev on some systems checks the device type of /dev/ptmx, and replaces it if
not as expected.  The symlink created by libvirt-lxc therefore gets replaced.
By creating it as a bind mount, the device type is correct and udev leaves it
alone.

Signed-off-by: Serge Hallyn <serge.hallyn@canonical.com>
src/lxc/lxc_container.c

index e42532855e3b30c5b5edfbb94b8df868bf015ee0..6991aecc7a07207c5e59855339e5072f60ab0a4e 100644 (file)
@@ -543,18 +543,18 @@ static int lxcContainerPopulateDevices(void)
         }
     }
 
+    dev_t dev = makedev(LXC_DEV_MAJ_TTY, LXC_DEV_MIN_PTMX);
+    if (mknod("/dev/ptmx", S_IFCHR, dev) < 0 ||
+        chmod("/dev/ptmx", 0666)) {
+        virReportSystemError(errno, "%s",
+                             _("Failed to make device /dev/ptmx"));
+        return -1;
+    }
+
     if (access("/dev/pts/ptmx", W_OK) == 0) {
-        if (symlink("/dev/pts/ptmx", "/dev/ptmx") < 0) {
-            virReportSystemError(errno, "%s",
-                                 _("Failed to create symlink /dev/ptmx to /dev/pts/ptmx"));
-            return -1;
-        }
-    } else {
-        dev_t dev = makedev(LXC_DEV_MAJ_TTY, LXC_DEV_MIN_PTMX);
-        if (mknod("/dev/ptmx", S_IFCHR, dev) < 0 ||
-            chmod("/dev/ptmx", 0666)) {
+        if (mount("/dev/pts/ptmx", "/dev/ptmx", "ptmx", MS_BIND, NULL) < 0) {
             virReportSystemError(errno, "%s",
-                                 _("Failed to make device /dev/ptmx"));
+                                 _("Failed to bind-mount /dev/ptmx to /dev/pts/ptmx"));
             return -1;
         }
     }