+ /* While running the command, bind-mount /dev, /proc, /sys
+ * into the chroot. However we must be careful to unmount them
+ * afterwards because otherwise they would interfere with
+ * future mount and unmount operations.
+ *
+ * We deliberately allow these commands to fail silently, BUT
+ * if a mount fails, don't unmount the corresponding mount.
+ */
+ sysroot_dev = sysroot_path ("/dev");
+ sysroot_dev_pts = sysroot_path ("/dev/pts");
+ sysroot_proc = sysroot_path ("/proc");
+ sysroot_selinux = sysroot_path ("/selinux");
+ sysroot_sys = sysroot_path ("/sys");
+
+ if (sysroot_dev == NULL || sysroot_dev_pts == NULL ||
+ sysroot_proc == NULL || sysroot_selinux == NULL ||
+ sysroot_sys == NULL) {
+ reply_with_perror ("malloc");
+ free (sysroot_dev);
+ free (sysroot_dev_pts);
+ free (sysroot_proc);
+ free (sysroot_selinux);
+ free (sysroot_sys);
+ return NULL;
+ }
+
+ r = command (NULL, NULL, "mount", "--bind", "/dev", sysroot_dev, NULL);
+ dev_ok = r != -1;
+ r = command (NULL, NULL, "mount", "--bind", "/dev/pts", sysroot_dev_pts, NULL);
+ dev_pts_ok = r != -1;
+ r = command (NULL, NULL, "mount", "--bind", "/proc", sysroot_proc, NULL);
+ proc_ok = r != -1;
+ r = command (NULL, NULL, "mount", "--bind", "/selinux", sysroot_selinux, NULL);
+ selinux_ok = r != -1;
+ r = command (NULL, NULL, "mount", "--bind", "/sys", sysroot_sys, NULL);
+ sys_ok = r != -1;
+