diff options
author | Mattias Andrée <maandree@member.fsf.org> | 2015-12-29 16:18:54 +0100 |
---|---|---|
committer | Mattias Andrée <maandree@member.fsf.org> | 2015-12-29 16:18:54 +0100 |
commit | 6789835ba4df321d684cc489f872ef8b045a7a19 (patch) | |
tree | 56bf75ba1783fc6e5a2c710e0f793d42a73d1b74 /src | |
parent | m (diff) | |
download | sat-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.c | 16 |
1 files changed, 7 insertions, 9 deletions
@@ -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); |