From 9ffeaae6e088a89f0118de2292a7c406745bbdc6 Mon Sep 17 00:00:00 2001 From: John Crispin Date: Thu, 30 May 2013 15:41:19 +0200 Subject: [PATCH] make sure path exists before mknod is called Signed-off-by: John Crispin --- hotplug.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/hotplug.c b/hotplug.c index f7e2ce9..c2276ed 100644 --- a/hotplug.c +++ b/hotplug.c @@ -66,6 +66,18 @@ 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 handle_makedev(struct blob_attr *msg, struct blob_attr *data) { static struct blobmsg_policy mkdev_policy[2] = { @@ -80,6 +92,12 @@ static void handle_makedev(struct blob_attr *msg, struct blob_attr *data) blobmsg_parse_array(mkdev_policy, 2, tb, blobmsg_data(data), blobmsg_data_len(data)); if (tb[0] && tb[1] && minor && major && subsystem) { mode_t m = S_IFCHR; + char *d = strdup(blobmsg_get_string(tb[0])); + + d = dirname(d); + mkdir_p(d); + free(d); + if (!strcmp(subsystem, "block")) m = S_IFBLK; mknod(blobmsg_get_string(tb[0]), -- 2.30.2