1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2025-01-25 06:03:40 +03:00

socket-label: tweak socket_address_listen() a bit

This changes two things when binding to AF_UNIX file system sockets:

1. When wethe socket already exists in the fs, and unlink() on it fails,
   don't bother to bind() a second time: since nothing changed it won't
   work either.

2. Also use SELinux-aware bind() for the second attempt.
This commit is contained in:
Lennart Poettering 2017-12-27 16:59:44 +01:00
parent 294d46f138
commit 706d7c27ad

View File

@ -124,10 +124,13 @@ int socket_address_listen(
r = mac_selinux_bind(fd, &a->sockaddr.sa, a->size);
if (r == -EADDRINUSE) {
/* Unlink and try again */
(void) unlink(p);
if (bind(fd, &a->sockaddr.sa, a->size) < 0)
return -errno;
} else if (r < 0)
if (unlink(p) < 0)
return r; /* didn't work, return original error */
r = mac_selinux_bind(fd, &a->sockaddr.sa, a->size);
}
if (r < 0)
return r;
}
} else {