summaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2014-06-04 13:10:43 +0200
committerLennart Poettering <lennart@poettering.net>2014-06-04 13:12:34 +0200
commitbd1fe7c79de3d81325afecb7ded46c1627f6c1df (patch)
tree85cf71bda8b14c84037c150aaba2fe5c28202af0 /src/shared
parentedf029b7fd9a5853a87d3ca99aac2922bb8a277e (diff)
socket: optionally remove sockets/FIFOs in the file system after use
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_;