ostbuild: Update user-chroot to bind mount /proc and /dev
This commit is contained in:
parent
ce7345d51e
commit
e68d0d25c0
|
|
@ -24,10 +24,15 @@
|
||||||
#define _GNU_SOURCE
|
#define _GNU_SOURCE
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <fcntl.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/prctl.h>
|
#include <sys/prctl.h>
|
||||||
|
#include <sys/mount.h>
|
||||||
#include <linux/securebits.h>
|
#include <linux/securebits.h>
|
||||||
|
#include <sched.h>
|
||||||
|
|
||||||
|
typedef unsigned int bool;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
fatal_errno (const char *message) __attribute__ ((noreturn));
|
fatal_errno (const char *message) __attribute__ ((noreturn));
|
||||||
|
|
@ -39,6 +44,22 @@ fatal_errno (const char *message)
|
||||||
exit (1);
|
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
|
int
|
||||||
main (int argc,
|
main (int argc,
|
||||||
char **argv)
|
char **argv)
|
||||||
|
|
@ -74,6 +95,11 @@ main (int argc,
|
||||||
SECBIT_NOROOT | SECBIT_NOROOT_LOCKED) < 0)
|
SECBIT_NOROOT | SECBIT_NOROOT_LOCKED) < 0)
|
||||||
fatal_errno ("prctl");
|
fatal_errno ("prctl");
|
||||||
|
|
||||||
|
if (unshare (CLONE_NEWNS) < 0)
|
||||||
|
fatal_errno ("unshare (CLONE_NEWNS)");
|
||||||
|
|
||||||
|
initialize_chroot (chroot_dir);
|
||||||
|
|
||||||
if (chroot (chroot_dir) < 0)
|
if (chroot (chroot_dir) < 0)
|
||||||
fatal_errno ("chroot");
|
fatal_errno ("chroot");
|
||||||
if (chdir ("/") < 0)
|
if (chdir ("/") < 0)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue