#include <getopt.h>
#include <errno.h>
#include <sys/file.h>
+#include <sys/stat.h>
+#include <sys/types.h>
#include "system-info-tool.h"
#include "system-info-tool-get.h"
return add_new_entry(key, value);
}
+static int mkdir_p(const char *path, mode_t mode)
+{
+ char dir[PATH_MAX] = { 0 , };
+ int ret;
+
+ if (!path || path[0] != '/')
+ return -EINVAL;
+
+ ret = snprintf(dir, PATH_MAX, "%s", path);
+ if (ret < 0)
+ return -EIO;
+
+ if (ret >= PATH_MAX)
+ return -ENAMETOOLONG;
+
+ for (char *p = strchr(dir + 1, '/'); p; p = strchr(p + 1, '/')) {
+ *p = '\0';
+ ret = mkdir(dir, mode);
+ if (ret < 0 && errno != EEXIST)
+ return -errno;
+ *p = '/';
+ }
+
+ ret = mkdir(dir, mode);
+ if (ret < 0 && errno != EEXIST)
+ return -errno;
+
+ return 0;
+}
+
static int system_info_tool_init_rw_database(void)
{
- return system("/usr/bin/mkdir -p "SYSTEM_INFO_DB_RW_PATH);
+ return mkdir_p(SYSTEM_INFO_DB_RW_PATH, 0755);
}
int system_info_tool_set(int argc, char *argv[])