diff options
author | Mattias Andrée <maandree@member.fsf.org> | 2015-12-28 12:34:33 +0100 |
---|---|---|
committer | Mattias Andrée <maandree@member.fsf.org> | 2015-12-28 12:34:33 +0100 |
commit | 8901e601b30fe23c4904d615bf086558ea79f274 (patch) | |
tree | b060ed3bf573cb6a2251198e33397ebc84684266 | |
parent | doc (diff) | |
download | sat-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.c | 5 |
1 files changed, 4 insertions, 1 deletions
@@ -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; } |