summaryrefslogtreecommitdiffhomepage
path: root/src/config.c
diff options
context:
space:
mode:
authorHans Dedecker <dedeckeh@gmail.com>2016-12-29 12:33:39 +0100
committerHans Dedecker <dedeckeh@gmail.com>2016-12-29 13:49:26 +0100
commit0572d1abbadf7b955f2788d04ca3d00f45963e6a (patch)
tree4d9e7b40a94a0b4a7d7d805826cf180ec069d786 /src/config.c
parentec833f4381607dda4fd73b8aef842c778300176a (diff)
config: Create statefile dir
Create statefile dir if the specified dir does not yet exist Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
Diffstat (limited to 'src/config.c')
-rw-r--r--src/config.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/config.c b/src/config.c
index a3cb2be..c0c1215 100644
--- a/src/config.c
+++ b/src/config.c
@@ -3,6 +3,9 @@
#include <signal.h>
#include <arpa/inet.h>
#include <unistd.h>
+#include <libgen.h>
+#include <string.h>
+#include <sys/stat.h>
#include <uci.h>
#include <uci_blob.h>
@@ -140,6 +143,30 @@ const struct uci_blob_param_list odhcpd_attr_list = {
.params = odhcpd_attrs,
};
+static 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)
+ syslog(LOG_ERR, "mkdir(%s, %d) failed: %s\n", dir, mask, strerror(errno));
+
+ return ret;
+}
static struct interface* get_interface(const char *name)
{
@@ -626,6 +653,12 @@ void odhcpd_reload(void)
}
}
+ if (config.dhcp_statefile) {
+ char *path = strdup(config.dhcp_statefile);
+
+ mkdir_p(dirname(path), 0755);
+ free(path);
+ }
#ifdef WITH_UBUS
ubus_apply_network();