From: Daniel Golle Date: Sat, 12 Dec 2020 22:59:54 +0000 (+0000) Subject: treewide: replace local mkdir_p implementations X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=7f12c89d0b99a2f04e91b2327e74c049f6362b67;p=project%2Fprocd.git treewide: replace local mkdir_p implementations Replace local implementations of mkdir_p in favour of using the more robust implementation now added to libubox. Signed-off-by: Daniel Golle --- diff --git a/jail/cgroups.c b/jail/cgroups.c index cb2c7fe..fc2bbeb 100644 --- a/jail/cgroups.c +++ b/jail/cgroups.c @@ -39,8 +39,8 @@ #include #include #include +#include -#include "fs.h" #include "log.h" #include "cgroups.h" diff --git a/jail/fs.c b/jail/fs.c index 4201973..26bc282 100644 --- a/jail/fs.c +++ b/jail/fs.c @@ -32,6 +32,7 @@ #include #include #include +#include #include "elf.h" #include "fs.h" @@ -54,31 +55,6 @@ struct mount { struct avl_tree mounts; -int mkdir_p(char *dir, mode_t mask) -{ - char *l = strrchr(dir, '/'); - int ret; - - if (!l) - return 0; - - *l = '\0'; - - if (mkdir_p(dir, mask)) - return -1; - - *l = '/'; - - ret = mkdir(dir, mask); - if (ret && errno == EEXIST) - return 0; - - if (ret) - ERROR("mkdir(%s, %d) failed: %m\n", dir, mask); - - return ret; -} - static int do_mount(const char *root, const char *orig_source, const char *target, const char *filesystemtype, unsigned long orig_mountflags, unsigned long propflags, const char *optstr, int error, bool inner) { diff --git a/jail/fs.h b/jail/fs.h index 4fb9b76..945b37d 100644 --- a/jail/fs.h +++ b/jail/fs.h @@ -16,7 +16,6 @@ #include #include -int mkdir_p(char *dir, mode_t mask); int add_mount(const char *source, const char *target, const char *filesystemtype, unsigned long mountflags, unsigned long propflags, const char *optstr, int error); int add_mount_inner(const char *source, const char *target, const char *filesystemtype, diff --git a/jail/jail.c b/jail/jail.c index a143b53..c3a0ccd 100644 --- a/jail/jail.c +++ b/jail/jail.c @@ -55,12 +55,12 @@ #include "seccomp-oci.h" #include "cgroups.h" -#include #include #include #include #include #include +#include #include #ifndef CLONE_NEWCGROUP diff --git a/plug/hotplug.c b/plug/hotplug.c index de0511f..9aeb1c1 100644 --- a/plug/hotplug.c +++ b/plug/hotplug.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -108,18 +109,6 @@ static char *hotplug_msg_find_var(struct blob_attr *msg, const char *name) return NULL; } -static void mkdir_p(char *dir) -{ - char *l = strrchr(dir, '/'); - - if (l) { - *l = '\0'; - mkdir_p(dir); - *l = '/'; - mkdir(dir, 0755); - } -} - static void chgrp_error(const char *group, const char *target, const char *failed) { ERROR("cannot set group %s for %s (%s: %d)\n", @@ -163,7 +152,7 @@ static void handle_makedev(struct blob_attr *msg, struct blob_attr *data) char *d = strdup(blobmsg_get_string(tb[0])); d = dirname(d); - mkdir_p(d); + mkdir_p(d, 0755); free(d); if (!strcmp(subsystem, "block"))