aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@member.fsf.org>2015-12-28 12:34:33 +0100
committerMattias Andrée <maandree@member.fsf.org>2015-12-28 12:34:33 +0100
commit8901e601b30fe23c4904d615bf086558ea79f274 (patch)
treeb060ed3bf573cb6a2251198e33397ebc84684266
parentdoc (diff)
downloadsat-8901e601b30fe23c4904d615bf086558ea79f274.tar.gz
sat-8901e601b30fe23c4904d615bf086558ea79f274.tar.bz2
sat-8901e601b30fe23c4904d615bf086558ea79f274.tar.xz
unlink socket on flock failure
Signed-off-by: Mattias Andrée <maandree@member.fsf.org>
Diffstat (limited to '')
-rw-r--r--src/satd.c5
1 files changed, 4 insertions, 1 deletions
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;
}