From 45d5c67cb4879a094f42467570ffcb630a08155a Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Sun, 8 Sep 2019 18:24:23 +0200 Subject: [PATCH] main: Move storage directory creation into storage functionality --- src/main.c | 9 +-------- src/storage.c | 17 ++++++++++++++++- src/storage.h | 4 ++-- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/main.c b/src/main.c index 1198bf2f..365eb23f 100644 --- a/src/main.c +++ b/src/main.c @@ -451,15 +451,8 @@ int main(int argc, char *argv[]) exit_status = EXIT_FAILURE; - if (create_dirs(DAEMON_STORAGEDIR "/")) { - l_error("Failed to create " DAEMON_STORAGEDIR "/"); + if (!storage_create_dirs()) goto fail_dbus; - } - - if (create_dirs(DAEMON_STORAGEDIR "/hotspot/")) { - l_error("Failed to create " DAEMON_STORAGEDIR "/hotspot/"); - goto fail_dbus; - } genl = l_genl_new(); if (!genl) { diff --git a/src/storage.c b/src/storage.c index 8f8a6d71..e7ab3292 100644 --- a/src/storage.c +++ b/src/storage.c @@ -46,7 +46,7 @@ #define STORAGE_DIR_MODE (S_IRUSR | S_IWUSR | S_IXUSR) #define STORAGE_FILE_MODE (S_IRUSR | S_IWUSR) -int create_dirs(const char *filename) +static int create_dirs(const char *filename) { struct stat st; char *dir; @@ -165,6 +165,21 @@ error_create_dirs: return r; } +bool storage_create_dirs(void) +{ + if (create_dirs(DAEMON_STORAGEDIR "/")) { + l_error("Failed to create " DAEMON_STORAGEDIR "/"); + return false; + } + + if (create_dirs(DAEMON_STORAGEDIR "/hotspot/")) { + l_error("Failed to create " DAEMON_STORAGEDIR "/hotspot/"); + return false; + } + + return true; +} + char *storage_get_network_file_path(enum security type, const char *ssid) { char *path; diff --git a/src/storage.h b/src/storage.h index 6cb282ee..29e8a45d 100644 --- a/src/storage.h +++ b/src/storage.h @@ -25,14 +25,14 @@ struct l_settings; enum security; -int create_dirs(const char *filename); - ssize_t read_file(void *buffer, size_t len, const char *path_fmt, ...) __attribute__((format(printf, 3, 4))); ssize_t write_file(const void *buffer, size_t len, const char *path_fmt, ...) __attribute__((format(printf, 3, 4))); +bool storage_create_dirs(void); + const char *storage_network_ssid_from_path(const char *path, enum security *type); char *storage_get_network_file_path(enum security type, const char *ssid);