From: Tomas Krizek Date: Fri, 10 Jan 2020 15:42:52 +0000 (+0100) Subject: daemon/network: unix socket pre-bind handling X-Git-Tag: v5.0.0~6^2~9 X-Git-Url: http://git.ipfire.org/gitweb/?a=commitdiff_plain;h=d9b7792c4d48e0f959c8eee162ac1691d5904fac;p=thirdparty%2Fknot-resolver.git daemon/network: unix socket pre-bind handling Unlink the unix address in case the file exists, e.g. from previous unclean run. Also attempt to create the directory for unix socket in case it doesn't exist. --- diff --git a/daemon/network.c b/daemon/network.c index d41436fba..08dd8dde0 100644 --- a/daemon/network.c +++ b/daemon/network.c @@ -22,6 +22,7 @@ #include "daemon/worker.h" #include +#include #include #include @@ -263,6 +264,14 @@ static int open_endpoint(struct network *net, struct endpoint *ep, } if (sa) { + if (sa->sa_family == AF_UNIX) { + struct sockaddr_un *sun = (struct sockaddr_un*)sa; + char *dirc = strdup(sun->sun_path); + char *dname = dirname(dirc); + (void)unlink(sun->sun_path); /** Attempt to unlink if socket path exists. */ + (void)mkdir(dname, S_IRWXU|S_IRWXG); /** Attempt to create dir. */ + free(dirc); + } ep->fd = io_bind(sa, ep->flags.sock_type, &ep->flags); if (ep->fd < 0) return ep->fd; }