From 175a3d25d0e8596d4ba0759aea3f89ee228e7d6d Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 6 Nov 2013 22:30:35 +0100 Subject: active: rework make_socket_fd() to be based on socket_address_listen() Among other things this makes sure we set SO_REUSEADDR which is immensely useful. --- src/activate/activate.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'src/activate') diff --git a/src/activate/activate.c b/src/activate/activate.c index 738cd83c52..cf8c5cebdb 100644 --- a/src/activate/activate.c +++ b/src/activate/activate.c @@ -91,6 +91,35 @@ static int print_socket(const char* desc, int fd) { return 0; } +static int make_socket_fd(const char* address, int flags) { + _cleanup_free_ char *p = NULL; + SocketAddress a; + int fd, r; + + r = socket_address_parse(&a, address); + if (r < 0) { + log_error("Failed to parse socket: %s", strerror(-r)); + return r; + } + + fd = socket_address_listen(&a, flags, SOMAXCONN, SOCKET_ADDRESS_DEFAULT, NULL, false, false, 0755, 0644, NULL); + if (fd < 0) { + log_error("Failed to listen: %s", strerror(-r)); + return fd; + } + + r = socket_address_print(&a, &p); + if (r < 0) { + log_error("socket_address_print(): %s", strerror(-r)); + close_nointr_nofail(fd); + return r; + } + + log_info("Listening on %s", p); + + return fd; +} + static int open_sockets(int *epoll_fd, bool accept) { int n, fd, r; int count = 0; @@ -129,6 +158,7 @@ static int open_sockets(int *epoll_fd, bool accept) { return fd; } + assert(fd == SD_LISTEN_FDS_START + count); count ++; } -- cgit v1.2.3-54-g00ecf