[ostree] ostbuild: Update user-chroot to bind mount /proc and /dev



commit e68d0d25c0640373dfad113bd30212b6f7fa626a
Author: Colin Walters <walters verbum org>
Date:   Tue Dec 6 10:43:01 2011 -0500

    ostbuild: Update user-chroot to bind mount /proc and /dev

 src/ostbuild/ostbuild-user-chroot.c |   26 ++++++++++++++++++++++++++
 1 files changed, 26 insertions(+), 0 deletions(-)
---
diff --git a/src/ostbuild/ostbuild-user-chroot.c b/src/ostbuild/ostbuild-user-chroot.c
index f800fb1..8026748 100644
--- a/src/ostbuild/ostbuild-user-chroot.c
+++ b/src/ostbuild/ostbuild-user-chroot.c
@@ -24,10 +24,15 @@
 #define _GNU_SOURCE
 #include <unistd.h>
 #include <stdio.h>
+#include <fcntl.h>
 #include <stdlib.h>
 #include <sys/types.h>
 #include <sys/prctl.h>
+#include <sys/mount.h>
 #include <linux/securebits.h>
+#include <sched.h>
+
+typedef unsigned int bool;
 
 static void
 fatal_errno (const char *message) __attribute__ ((noreturn));
@@ -39,6 +44,22 @@ fatal_errno (const char *message)
   exit (1);
 }
 
+static void
+initialize_chroot (const char *path)
+{
+  char *subpath;
+
+  asprintf (&subpath, "%s/proc", path);
+  if (mount ("/proc", subpath, NULL, MS_BIND, NULL) < 0)
+    fatal_errno ("bind mounting proc");
+  free (subpath);
+  
+  asprintf (&subpath, "%s/dev", path);
+  if (mount ("/dev", subpath, NULL, MS_BIND, NULL) < 0)
+    fatal_errno ("bind mounting dev");
+  free (subpath);
+}
+
 int
 main (int      argc,
       char   **argv)
@@ -74,6 +95,11 @@ main (int      argc,
 	     SECBIT_NOROOT | SECBIT_NOROOT_LOCKED) < 0)
     fatal_errno ("prctl");
 
+  if (unshare (CLONE_NEWNS) < 0)
+    fatal_errno ("unshare (CLONE_NEWNS)");
+
+  initialize_chroot (chroot_dir);
+
   if (chroot (chroot_dir) < 0)
     fatal_errno ("chroot");
   if (chdir ("/") < 0)



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]