aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@member.fsf.org>2015-12-29 16:18:54 +0100
committerMattias Andrée <maandree@member.fsf.org>2015-12-29 16:18:54 +0100
commit6789835ba4df321d684cc489f872ef8b045a7a19 (patch)
tree56bf75ba1783fc6e5a2c710e0f793d42a73d1b74
parentm (diff)
downloadsat-6789835ba4df321d684cc489f872ef8b045a7a19.tar.gz
sat-6789835ba4df321d684cc489f872ef8b045a7a19.tar.bz2
sat-6789835ba4df321d684cc489f872ef8b045a7a19.tar.xz
fix possible race condition
Signed-off-by: Mattias Andrée <maandree@member.fsf.org>
Diffstat (limited to '')
-rw-r--r--src/satd.c16
1 files changed, 7 insertions, 9 deletions
diff --git a/src/satd.c b/src/satd.c
index 5530b6b..be50082 100644
--- a/src/satd.c
+++ b/src/satd.c
@@ -72,19 +72,17 @@ create_socket(struct sockaddr_un *address)
if (fd == -1) {
t (errno != ENOENT);
goto does_not_exist;
- } else {
- if (flock(fd, LOCK_EX | LOCK_NB) == -1) {
- t (errno != EWOULDBLOCK);
- fprintf(stderr, "%s: the daemon's socket file is already in use.\n", argv0);
- errno = 0;
- goto fail;
- }
- flock(fd, LOCK_UN);
- close(fd), fd = -1;
+ } else if (flock(fd, LOCK_EX | LOCK_NB) == -1) {
+ t (errno != EWOULDBLOCK);
+ fprintf(stderr, "%s: the daemon's socket file is already in use.\n", argv0);
+ errno = 0;
+ goto fail;
}
/* Create socket. */
unlink(address->sun_path);
+ flock(fd, LOCK_UN);
+ close(fd), fd = -1;
does_not_exist:
t ((fd = socket(PF_UNIX, SOCK_STREAM, 0)) == -1);
t (fchmod(fd, S_IRWXU) == -1);