summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Golle2020-12-12 22:59:54 +0000
committerDaniel Golle2020-12-12 22:59:54 +0000
commit7f12c89d0b99a2f04e91b2327e74c049f6362b67 (patch)
tree41ba6c1a02553cc9d0d118192c94487a1be948db
parent111416d10b121e5dff3e279c784847f5300aaeec (diff)
downloadprocd-7f12c89d0b99a2f04e91b2327e74c049f6362b67.tar.gz
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 <daniel@makrotopia.org>
-rw-r--r--jail/cgroups.c2
-rw-r--r--jail/fs.c26
-rw-r--r--jail/fs.h1
-rw-r--r--jail/jail.c2
-rw-r--r--plug/hotplug.c15
5 files changed, 5 insertions, 41 deletions
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 <libubox/avl-cmp.h>
#include <libubox/blobmsg.h>
#include <libubox/list.h>
+#include <libubox/utils.h>
-#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 <libubox/avl-cmp.h>
#include <libubox/blobmsg.h>
#include <libubox/list.h>
+#include <libubox/utils.h>
#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 <sys/mount.h>
#include <libubox/blobmsg.h>
-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 <libubox/utils.h>
#include <libubox/blobmsg.h>
#include <libubox/blobmsg_json.h>
#include <libubox/list.h>
#include <libubox/vlist.h>
#include <libubox/uloop.h>
+#include <libubox/utils.h>
#include <libubus.h>
#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 <libubox/blobmsg_json.h>
#include <libubox/json_script.h>
#include <libubox/uloop.h>
+#include <libubox/utils.h>
#include <json-c/json.h>
#include <errno.h>
@@ -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"))