diff --git a/src/ostbuild/ostbuild-user-chroot.c b/src/ostbuild/ostbuild-user-chroot.c index f800fb1f..80267485 100644 --- a/src/ostbuild/ostbuild-user-chroot.c +++ b/src/ostbuild/ostbuild-user-chroot.c @@ -24,10 +24,15 @@ #define _GNU_SOURCE #include #include +#include #include #include #include +#include #include +#include + +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)