summaryrefslogtreecommitdiff
path: root/src/core/socket.c
diff options
context:
space:
mode:
authorChristos Trochalakis <yatiohi@ideopolis.gr>2015-07-01 14:39:53 +0300
committerChristos Trochalakis <yatiohi@ideopolis.gr>2015-07-01 16:43:03 +0300
commit54255c64e6d223deb7d3863e426e78c443fda37c (patch)
treec4236e9de47603b9e90f4a3a0b25b272525a8755 /src/core/socket.c
parent52a321d839b366d40fdd72bbb6c494016fa3d608 (diff)
socket: Set SO_REUSEPORT before bind()
bind() fails if it is called before setting SO_REUSEPORT and another process is already binded to the same addess. A new reuse_port option has been introduced to socket_address_listen() to set the option as part of socket initialization.
Diffstat (limited to 'src/core/socket.c')
-rw-r--r--src/core/socket.c7
1 files changed, 1 insertions, 6 deletions
diff --git a/src/core/socket.c b/src/core/socket.c
index d3178e642b..693cbc6080 100644
--- a/src/core/socket.c
+++ b/src/core/socket.c
@@ -922,12 +922,6 @@ static void socket_apply_socket_options(Socket *s, int fd) {
if (setsockopt(fd, SOL_TCP, TCP_CONGESTION, s->tcp_congestion, strlen(s->tcp_congestion)+1) < 0)
log_unit_warning_errno(UNIT(s), errno, "TCP_CONGESTION failed: %m");
- if (s->reuse_port) {
- int b = s->reuse_port;
- if (setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, &b, sizeof(b)) < 0)
- log_unit_warning_errno(UNIT(s), errno, "SO_REUSEPORT failed: %m");
- }
-
if (s->smack_ip_in) {
r = mac_smack_apply_ip_in_fd(fd, s->smack_ip_in);
if (r < 0)
@@ -1183,6 +1177,7 @@ static int socket_open_fds(Socket *s) {
s->backlog,
s->bind_ipv6_only,
s->bind_to_device,
+ s->reuse_port,
s->free_bind,
s->transparent,
s->directory_mode,