From 8901e601b30fe23c4904d615bf086558ea79f274 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Mon, 28 Dec 2015 12:34:33 +0100 Subject: unlink socket on flock failure MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/satd.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/satd.c b/src/satd.c index fe76516..738872c 100644 --- a/src/satd.c +++ b/src/satd.c @@ -54,7 +54,7 @@ USAGE("[-f]") static int create_socket(struct sockaddr_un *address) { - int fd = -1; + int fd = -1, bound = 0; ssize_t len; char *dir; int saved_errno; @@ -91,6 +91,7 @@ does_not_exist: t (fchown(fd, getuid(), getgid()) == -1); t (bind(fd, (struct sockaddr *)address, sizeof(*address)) == -1); /* EADDRINUSE just means that the file already exists, not that it is actually used. */ + bound = 1; /* Mark the socket as owned by a living process. */ t (flock(fd, LOCK_SH)); @@ -100,6 +101,8 @@ fail: saved_errno = errno; if (fd >= 0) close(fd); + if (bound) + unlink(address->sun_path); errno = saved_errno; return -1; } -- cgit v1.2.3-70-g09d2