#include <stdlib.h>
#include <sys/mount.h>
#include <sys/stat.h>
+#include <sys/sysmacros.h>
#include <sys/types.h>
#include <syslog.h>
#include <unistd.h>
return r;
}
+static const struct pakfire_devnode {
+ const char* path;
+ int major;
+ int minor;
+ mode_t mode;
+} devnodes[] = {
+ { "/dev/null", 1, 3, S_IFCHR|S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH, },
+ { "/dev/zero", 1, 5, S_IFCHR|S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH, },
+ { "/dev/full", 1, 7, S_IFCHR|S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH, },
+ { "/dev/random", 1, 8, S_IFCHR|S_IRUSR|S_IRGRP|S_IROTH, },
+ { "/dev/urandom", 1, 9, S_IFCHR|S_IRUSR|S_IRGRP|S_IROTH, },
+ { "/dev/kmsg", 1, 11, S_IFCHR|S_IRUSR|S_IRGRP|S_IROTH, },
+ { "/dev/tty", 5, 0, S_IFCHR|S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH, },
+ { "/dev/console", 5, 1, S_IFCHR|S_IRUSR|S_IWUSR, },
+ { "/dev/ptmx", 5, 2, S_IFCHR|S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH, },
+ { "/dev/rtc0", 252, 0, S_IFCHR|S_IRUSR|S_IWUSR, },
+ { NULL },
+};
+
+static const struct pakfire_symlink {
+ const char* target;
+ const char* path;
+} symlinks[] = {
+ { "/proc/self/fd", "/dev/fd", },
+ { "/proc/self/fd/0", "/dev/stdin" },
+ { "/proc/self/fd/1", "/dev/stdout" },
+ { "/proc/self/fd/2", "/dev/stderr" },
+ { "/proc/kcore", "/dev/core" },
+ { NULL },
+};
+
+static int pakfire_populate_dev(Pakfire pakfire) {
+ // Create device nodes
+ for (const struct pakfire_devnode* devnode = devnodes; devnode->path; devnode++) {
+ DEBUG(pakfire, "Creating device node %s\n", devnode->path);
+
+ char* path = pakfire_make_path(pakfire, devnode->path);
+ dev_t dev = makedev(devnode->major, devnode->minor);
+
+ int r = mknod(path, devnode->mode, dev);
+ if (r) {
+ ERROR(pakfire, "Could not create %s: %s\n", devnode->path, strerror(errno));
+ free(path);
+
+ return r;
+ }
+
+ free(path);
+ }
+
+ // Create symlinks
+ for (const struct pakfire_symlink* s = symlinks; s->target; s++) {
+ DEBUG(pakfire, "Creating symlink %s -> %s\n", s->path, s->target);
+
+ char* path = pakfire_make_path(pakfire, s->path);
+
+ int r = symlink(s->target, path);
+ if (r) {
+ ERROR(pakfire, "Could not create symlink %s: %s\n", s->path, strerror(errno));
+ free(path);
+
+ return r;
+ }
+
+ free(path);
+ }
+
+ return 0;
+}
+
PAKFIRE_EXPORT int pakfire_activate(Pakfire pakfire) {
if (strcmp(pakfire->path, "/") == 0)
return 0;
return r;
}
+ // Populate /dev
+ r = pakfire_populate_dev(pakfire);
+ if (r)
+ return r;
+
return 0;
}
# Settings array.
self.settings = {
- "enable_loop_devices" : self.config.get_bool("builder", "use_loop_devices", True),
"enable_ccache" : self.config.get_bool("builder", "use_ccache", True),
"buildroot_tmpfs" : self.config.get_bool("builder", "use_tmpfs", False),
}
# Lock the build environment
self.lock()
- # Populate /dev
- self.populate_dev()
-
# Setup domain name resolution in chroot
self.setup_dns()
shutil.copy2(file_in, file_out)
- def populate_dev(self):
- nodes = [
- "/dev/null",
- "/dev/zero",
- "/dev/full",
- "/dev/random",
- "/dev/urandom",
- "/dev/tty",
- "/dev/ptmx",
- "/dev/kmsg",
- "/dev/rtc0",
- "/dev/console",
- ]
-
- # If we need loop devices (which are optional) we create them here.
- if self.settings["enable_loop_devices"]:
- for i in range(0, 7):
- nodes.append("/dev/loop%d" % i)
-
- for node in nodes:
- # Stat the original node of the host system and copy it to
- # the build chroot.
- try:
- node_stat = os.stat(node)
-
- # If it cannot be found, just go on.
- except OSError:
- continue
-
- self._create_node(node, node_stat.st_mode, node_stat.st_rdev)
-
- os.symlink("/proc/self/fd/0", self.chrootPath("dev", "stdin"))
- os.symlink("/proc/self/fd/1", self.chrootPath("dev", "stdout"))
- os.symlink("/proc/self/fd/2", self.chrootPath("dev", "stderr"))
- os.symlink("/proc/self/fd", self.chrootPath("dev", "fd"))
-
def chrootPath(self, *args):
# Remove all leading slashes
_args = []
for i in ("/etc/resolv.conf", "/etc/hosts"):
self.copyin(i, i)
- def _create_node(self, filename, mode, device):
- self.log.debug("Create node: %s (%s)" % (filename, mode))
-
- filename = self.chrootPath(filename)
-
- # Create parent directory if it is missing.
- dirname = os.path.dirname(filename)
- if not os.path.exists(dirname):
- os.makedirs(dirname)
-
- os.mknod(filename, mode, device)
-
def execute_root(self, command, **kwargs):
"""
Executes the given command outside the build chroot.