diff options
author | Ariadne Conill <ariadne@dereferenced.org> | 2021-12-28 16:55:49 -0600 |
---|---|---|
committer | Timo Teräs <timo.teras@iki.fi> | 2021-12-29 20:38:40 +0200 |
commit | 3d41d1c90aff8e4fac684ef3190037984db38051 (patch) | |
tree | f115e367b455ec9d6deacd15acfb901dd2c6468f /src/package.c | |
parent | 10b26851a4ab933d5af41f6e8836fed6bf62c267 (diff) | |
download | apk-tools-3d41d1c90aff8e4fac684ef3190037984db38051.tar.gz apk-tools-3d41d1c90aff8e4fac684ef3190037984db38051.tar.bz2 apk-tools-3d41d1c90aff8e4fac684ef3190037984db38051.tar.xz apk-tools-3d41d1c90aff8e4fac684ef3190037984db38051.zip |
package: factor out /dev initialization to linux-specific helper function
Diffstat (limited to 'src/package.c')
-rw-r--r-- | src/package.c | 28 |
1 files changed, 20 insertions, 8 deletions
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); |