summaryrefslogtreecommitdiff
path: root/src/activate/activate.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2013-11-06 22:30:35 +0100
committerLennart Poettering <lennart@poettering.net>2013-11-06 23:03:12 +0100
commit175a3d25d0e8596d4ba0759aea3f89ee228e7d6d (patch)
tree95f09c22413d3109170fe0098ae1bdc1741c6354 /src/activate/activate.c
parenteceb8483e5a02e8e337486b89719a3b99cfcb7ce (diff)
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.
Diffstat (limited to 'src/activate/activate.c')
-rw-r--r--src/activate/activate.c30
1 files changed, 30 insertions, 0 deletions
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 ++;
}