You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by jk...@apache.org on 2014/07/08 09:56:59 UTC

svn commit: r1608686 - /httpd/httpd/trunk/server/listen.c

Author: jkaluza
Date: Tue Jul  8 07:56:59 2014
New Revision: 1608686

URL: http://svn.apache.org/r1608686
Log:
* server/listen.c: duplicate sockets correctly when using systemd socket
activation, fix addrlen in getsockname() call.


Modified:
    httpd/httpd/trunk/server/listen.c

Modified: httpd/httpd/trunk/server/listen.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/server/listen.c?rev=1608686&r1=1608685&r2=1608686&view=diff
==============================================================================
--- httpd/httpd/trunk/server/listen.c (original)
+++ httpd/httpd/trunk/server/listen.c Tue Jul  8 07:56:59 2014
@@ -285,7 +285,7 @@ static apr_status_t alloc_systemd_listen
 {
     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_listen
 
     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_li
             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))