]> granicus.if.org Git - apache/commitdiff
* server/listen.c: duplicate sockets correctly when using systemd socket
authorJan Kaluža <jkaluza@apache.org>
Tue, 8 Jul 2014 07:56:59 +0000 (07:56 +0000)
committerJan Kaluža <jkaluza@apache.org>
Tue, 8 Jul 2014 07:56:59 +0000 (07:56 +0000)
activation, fix addrlen in getsockname() call.

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1608686 13f79535-47bb-0310-9956-ffa450edef68

server/listen.c

index cded30e2e0e084d2ffb706c03dd39db04d3d1247..b8e8adeb0bed6088cb9c44672305b7e8aa189d5b 100644 (file)
@@ -285,7 +285,7 @@ static apr_status_t alloc_systemd_listener(process_rec * process,
 {
     apr_status_t rv;
     struct sockaddr sa;
-    socklen_t len;
+    socklen_t len = sizeof(struct sockaddr);
     apr_os_sock_info_t si;
     ap_listen_rec *rec;
     *out_rec = NULL;
@@ -303,6 +303,7 @@ static apr_status_t alloc_systemd_listener(process_rec * process,
 
     si.os_sock = &fd;
     si.family = sa.sa_family;
+    si.local = &sa;
     si.type = SOCK_STREAM;
     si.protocol = APR_PROTO_TCP;
 
@@ -771,23 +772,36 @@ AP_DECLARE(apr_status_t) ap_duplicate_listeners(server_rec *s, apr_pool_t *p,
             char *hostname;
             apr_port_t port;
             apr_sockaddr_t *sa;
-            duplr  = apr_palloc(p, sizeof(ap_listen_rec));
-            duplr->slave = NULL;
-            duplr->protocol = apr_pstrdup(p, lr->protocol);
-            hostname = apr_pstrdup(p, lr->bind_addr->hostname);
-            port = lr->bind_addr->port;
-            apr_sockaddr_info_get(&sa, hostname, APR_UNSPEC, port, 0, p);
-            duplr->bind_addr = sa;
-            duplr->next = NULL;
-            if ((stat = apr_socket_create(&duplr->sd, duplr->bind_addr->family,
-                                          SOCK_STREAM, 0, p)) != APR_SUCCESS) {
-                ap_log_perror(APLOG_MARK, APLOG_CRIT, 0, p, APLOGNO(02640)
-                              "ap_duplicate_socket: for address %pI, "
-                              "cannot duplicate a new socket!",
-                              duplr->bind_addr);
-                return stat;
+#ifdef HAVE_SYSTEMD
+            if (use_systemd) {
+                int thesock;
+                apr_os_sock_get(&thesock, lr->sd);
+                if ((stat = alloc_systemd_listener(p, thesock, &duplr))
+                    != APR_SUCCESS) {
+                    return stat;
+                }
+            }
+            else
+#endif
+            {
+                duplr  = apr_palloc(p, sizeof(ap_listen_rec));
+                duplr->slave = NULL;
+                duplr->protocol = apr_pstrdup(p, lr->protocol);
+                hostname = apr_pstrdup(p, lr->bind_addr->hostname);
+                port = lr->bind_addr->port;
+                apr_sockaddr_info_get(&sa, hostname, APR_UNSPEC, port, 0, p);
+                duplr->bind_addr = sa;
+                duplr->next = NULL;
+                if ((stat = apr_socket_create(&duplr->sd, duplr->bind_addr->family,
+                                            SOCK_STREAM, 0, p)) != APR_SUCCESS) {
+                    ap_log_perror(APLOG_MARK, APLOG_CRIT, 0, p, APLOGNO(02640)
+                                "ap_duplicate_socket: for address %pI, "
+                                "cannot duplicate a new socket!",
+                                duplr->bind_addr);
+                    return stat;
+                }
+                make_sock(p, duplr, 1);
             }
-            make_sock(p, duplr, 1);
 #if AP_NONBLOCK_WHEN_MULTI_LISTEN
             use_nonblock = (ap_listeners && ap_listeners->next);
             if ((stat = apr_socket_opt_set(duplr->sd, APR_SO_NONBLOCK, use_nonblock))