diff options
author | John Crispin <blogic@openwrt.org> | 2013-05-30 15:41:19 +0200 |
---|---|---|
committer | John Crispin <blogic@openwrt.org> | 2013-05-30 15:41:19 +0200 |
commit | 9ffeaae6e088a89f0118de2292a7c406745bbdc6 (patch) | |
tree | 9291d697ae32116a0b7920bed55d40a3aac71b2b | |
parent | dee028e96adea719fade27462c13c878f7dca3e1 (diff) | |
download | unitd-9ffeaae6e088a89f0118de2292a7c406745bbdc6.tar unitd-9ffeaae6e088a89f0118de2292a7c406745bbdc6.zip |
make sure path exists before mknod is called
Signed-off-by: John Crispin <blogic@openwrt.org>
-rw-r--r-- | hotplug.c | 18 |
1 files changed, 18 insertions, 0 deletions
@@ -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]), |