From 3d41d1c90aff8e4fac684ef3190037984db38051 Mon Sep 17 00:00:00 2001 From: Ariadne Conill Date: Tue, 28 Dec 2021 16:55:49 -0600 Subject: package: factor out /dev initialization to linux-specific helper function --- src/package.c | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) (limited to 'src/package.c') diff --git a/src/package.c b/src/package.c index 0e6a23a..cd00f18 100644 --- a/src/package.c +++ b/src/package.c @@ -756,6 +756,25 @@ int apk_ipkg_add_script(struct apk_installed_package *ipkg, return apk_ipkg_assign_script(ipkg, type, apk_blob_from_istream(is, size)); } +#ifdef __linux__ +static inline void make_device_tree(struct apk_database *db) +{ + if (faccessat(db->root_fd, "dev", F_OK, 0) == 0) return; + + mkdirat(db->root_fd, "dev", 0755); + mknodat(db->root_fd, "dev/null", S_IFCHR | 0666, makedev(1, 3)); + mknodat(db->root_fd, "dev/zero", S_IFCHR | 0666, makedev(1, 5)); + mknodat(db->root_fd, "dev/random", S_IFCHR | 0666, makedev(1, 8)); + mknodat(db->root_fd, "dev/urandom", S_IFCHR | 0666, makedev(1, 9)); + mknodat(db->root_fd, "dev/console", S_IFCHR | 0600, makedev(5, 1)); +} +#else +static inline void make_device_tree(struct apk_database *db) +{ + (void) db; +} +#endif + void apk_ipkg_run_script(struct apk_installed_package *ipkg, struct apk_database *db, unsigned int type, char **argv) @@ -782,14 +801,7 @@ void apk_ipkg_run_script(struct apk_installed_package *ipkg, db->script_dirs_checked = 1; if (faccessat(db->root_fd, "tmp", F_OK, 0) != 0) mkdirat(db->root_fd, "tmp", 01777); - if (faccessat(db->root_fd, "dev", F_OK, 0) != 0) { - mkdirat(db->root_fd, "dev", 0755); - mknodat(db->root_fd, "dev/null", S_IFCHR | 0666, makedev(1, 3)); - mknodat(db->root_fd, "dev/zero", S_IFCHR | 0666, makedev(1, 5)); - mknodat(db->root_fd, "dev/random", S_IFCHR | 0666, makedev(1, 8)); - mknodat(db->root_fd, "dev/urandom", S_IFCHR | 0666, makedev(1, 9)); - mknodat(db->root_fd, "dev/console", S_IFCHR | 0600, makedev(5, 1)); - } + make_device_tree(db); if (faccessat(db->root_fd, "var/cache/misc", F_OK, 0) != 0) { mkdirat(root_fd, "var", 0755); mkdirat(root_fd, "var/cache", 0755); -- cgit v1.2.3-70-g09d2