From 42119bbdc23a677b2bdce82508b78b0d5b0bcbd4 Mon Sep 17 00:00:00 2001 From: Alex 'AdUser' Z Date: Sat, 3 Dec 2016 17:33:43 +1000 Subject: [PATCH] * daemon.c : create statedir if not found --- src/daemon.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/daemon.c b/src/daemon.c index 21ab317..3158c7f 100644 --- a/src/daemon.c +++ b/src/daemon.c @@ -258,6 +258,20 @@ int main(int argc, char *argv[]) { } } + if (appconfig.statedir_path[0] != '\0') { + struct stat st; + if (stat(appconfig.statedir_path, &st) < 0) { + if (errno == ENOENT) { + mode_t mode = S_IRWXU | S_IRGRP | S_IXGRP; /* 0750 */ + mkdir(appconfig.statedir_path, mode); + } else { + f2b_log_msg(log_error, "statedir not exists or unaccessible: %s", strerror(errno)); + } + } else if (!S_ISDIR(st.st_mode)) { + f2b_log_msg(log_error, "statedir not a directory: %s", strerror(errno)); + } + } + if (appconfig.csocket_path[0] != '\0') appconfig.csock = f2b_csocket_create(appconfig.csocket_path);