summaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/socket-util.c15
-rw-r--r--src/shared/socket-util.h1
2 files changed, 16 insertions, 0 deletions
diff --git a/src/shared/socket-util.c b/src/shared/socket-util.c
index 997a1ceba3..92564e3193 100644
--- a/src/shared/socket-util.c
+++ b/src/shared/socket-util.c
@@ -625,6 +625,21 @@ int getsockname_pretty(int fd, char **ret) {
return sockaddr_pretty(&sa.sa, salen, false, ret);
}
+int socket_address_unlink(SocketAddress *a) {
+ assert(a);
+
+ if (socket_address_family(a) != AF_UNIX)
+ return 0;
+
+ if (a->sockaddr.un.sun_path[0] == 0)
+ return 0;
+
+ if (unlink(a->sockaddr.un.sun_path) < 0)
+ return -errno;
+
+ return 1;
+}
+
static const char* const netlink_family_table[] = {
[NETLINK_ROUTE] = "route",
[NETLINK_FIREWALL] = "firewall",
diff --git a/src/shared/socket-util.h b/src/shared/socket-util.h
index efaaf82ab1..f938f86200 100644
--- a/src/shared/socket-util.h
+++ b/src/shared/socket-util.h
@@ -70,6 +70,7 @@ int socket_address_parse(SocketAddress *a, const char *s);
int socket_address_parse_netlink(SocketAddress *a, const char *s);
int socket_address_print(const SocketAddress *a, char **p);
int socket_address_verify(const SocketAddress *a) _pure_;
+int socket_address_unlink(SocketAddress *a);
bool socket_address_can_accept(const SocketAddress *a) _pure_;