Attempt to create folders for binding AF_UNIX sockets

This commit is contained in:
Jeremy Lakeman 2014-04-11 16:49:01 +09:30
parent 1dc09f513c
commit c6e461bcb0
2 changed files with 10 additions and 0 deletions

View File

@ -20,6 +20,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include <limits.h> #include <limits.h>
#include <stdlib.h> #include <stdlib.h>
#include <assert.h> #include <assert.h>
#include <libgen.h>
#include "serval.h" #include "serval.h"
#include "conf.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); assert(addr->addrlen > sizeof addr->addr.sa_family);
if (addr->addr.sa_family == AF_UNIX && addr->local.sun_path[0] != '\0') { 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'); 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) if (unlink(addr->local.sun_path) == -1 && errno != ENOENT)
WARNF_perror("unlink(%s)", alloca_str_toprint(addr->local.sun_path)); WARNF_perror("unlink(%s)", alloca_str_toprint(addr->local.sun_path));
if (config.debug.io || config.debug.verbose_io) if (config.debug.io || config.debug.verbose_io)

View File

@ -30,6 +30,7 @@ teardown() {
get_servald_server_pidfile && stop_servald_server get_servald_server_pidfile && stop_servald_server
kill_all_servald_processes kill_all_servald_processes
assert_no_servald_processes assert_no_servald_processes
report_all_servald_servers
} }
# make sure servald config is blank # make sure servald config is blank