From c6e461bcb0a0cd6b4ed055f089adc27c7e22c4ab Mon Sep 17 00:00:00 2001 From: Jeremy Lakeman Date: Fri, 11 Apr 2014 16:49:01 +0930 Subject: [PATCH] Attempt to create folders for binding AF_UNIX sockets --- socket.c | 9 +++++++++ tests/server | 1 + 2 files changed, 10 insertions(+) diff --git a/socket.c b/socket.c index 16d2cbb2..c9cb537b 100644 --- a/socket.c +++ b/socket.c @@ -20,6 +20,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include #include #include +#include #include "serval.h" #include "conf.h" @@ -204,6 +205,14 @@ int _socket_bind(struct __sourceloc __whence, int sock, const struct socket_addr assert(addr->addrlen > sizeof addr->addr.sa_family); if (addr->addr.sa_family == AF_UNIX && addr->local.sun_path[0] != '\0') { assert(addr->local.sun_path[addr->addrlen - sizeof addr->local.sun_family - 1] == '\0'); + // make sure the path exists, create it if we can + size_t dirsiz = strlen(addr->local.sun_path) + 1; + char dir_buf[dirsiz]; + strcpy(dir_buf, addr->local.sun_path); + const char *dir = dirname(dir_buf); // modifies dir_buf[] + if (mkdirs_info(dir, 0700) == -1) + return WHY_perror("mkdirs()"); + // remove a previous socket if (unlink(addr->local.sun_path) == -1 && errno != ENOENT) WARNF_perror("unlink(%s)", alloca_str_toprint(addr->local.sun_path)); if (config.debug.io || config.debug.verbose_io) diff --git a/tests/server b/tests/server index 0c8695ca..e6891022 100755 --- a/tests/server +++ b/tests/server @@ -30,6 +30,7 @@ teardown() { get_servald_server_pidfile && stop_servald_server kill_all_servald_processes assert_no_servald_processes + report_all_servald_servers } # make sure servald config is blank