[systemd-devel] [PATCH] nspawn: allow bind-mounting char and block files

Alban Crequy muadda at gmail.com
Thu Jan 22 04:25:51 PST 2015


From: Alban Crequy <alban at endocode.com>

---
 src/nspawn/nspawn.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c
index 3fce3ad..db57b24 100644
--- a/src/nspawn/nspawn.c
+++ b/src/nspawn/nspawn.c
@@ -911,8 +911,7 @@ static int mount_binds(const char *dest, char **l, bool ro) {
                         return -errno;
                 }
 
-                /* Create the mount point, but be conservative -- refuse to create block
-                 * and char devices. */
+                /* Create the mount point */
                 if (S_ISDIR(source_st.st_mode)) {
                         r = mkdir_label(where, 0755);
                         if (r < 0 && errno != EEXIST)
@@ -929,6 +928,10 @@ static int mount_binds(const char *dest, char **l, bool ro) {
                         r = touch(where);
                         if (r < 0)
                                 return log_error_errno(r, "Failed to create mount point %s: %m", where);
+                } else if (S_ISCHR(source_st.st_mode) || !S_ISBLK(source_st.st_mode)) {
+                        r = mknod(where, source_st.st_mode, source_st.st_rdev) < 0;
+                        if (r < 0 && errno != EEXIST)
+                                return log_error_errno(errno, "Failed to create mount point %s: %m", where);
                 } else {
                         log_error("Refusing to create mountpoint for file: %s", *x);
                         return -ENOTSUP;
-- 
2.1.4



More information about the systemd-devel mailing list