michael-o commented on a change in pull request #382:
URL: https://github.com/apache/tomcat/pull/382#discussion_r532284639



##########
File path: java/org/apache/tomcat/util/net/AprEndpoint.java
##########
@@ -292,52 +295,79 @@ public void bind() throws Exception {
 
         // Create the pool for the server socket
         serverSockPool = Pool.create(rootPool);
+
         // Create the APR address that will be bound
-        String addressStr = null;
-        if (getAddress() != null) {
-            addressStr = getAddress().getHostAddress();
-        }
-        int family = Socket.APR_INET;
-        if (Library.APR_HAVE_IPV6) {
-            if (addressStr == null) {
-                if (!OS.IS_BSD) {
+        if (getPath() != null) {
+            if (Library.APR_HAVE_UNIX) {
+                hostname = getPath().toString();
+                family = Socket.APR_UNIX;
+            }
+            else {
+                throw new 
Exception(sm.getString("endpoint.init.unixnotavail"));
+            }
+        }
+        else {
+
+            if (getAddress() != null) {
+                hostname = getAddress().getHostAddress();
+            }
+            family = Socket.APR_INET;
+            if (Library.APR_HAVE_IPV6) {
+                if (hostname == null) {
+                    if (!OS.IS_BSD) {
+                        family = Socket.APR_UNSPEC;
+                    }
+                } else if (hostname.indexOf(':') >= 0) {
                     family = Socket.APR_UNSPEC;
                 }
-            } else if (addressStr.indexOf(':') >= 0) {
-                family = Socket.APR_UNSPEC;
             }
-         }
+        }
+
+        long sockAddress = Address.info(hostname, family, getPortWithOffset(), 
0, rootPool);
 
-        long inetAddress = Address.info(addressStr, family, 
getPortWithOffset(), 0, rootPool);
         // Create the APR server socket
-        serverSock = Socket.create(Address.getInfo(inetAddress).family,
+        if (family == Socket.APR_UNIX) {
+            serverSock = Socket.create(family, Socket.SOCK_STREAM, 0, 
rootPool);
+        }
+        else {
+            serverSock = Socket.create(Address.getInfo(sockAddress).family,
                 Socket.SOCK_STREAM,
                 Socket.APR_PROTO_TCP, rootPool);
-        if (OS.IS_UNIX) {
-            Socket.optSet(serverSock, Socket.APR_SO_REUSEADDR, 1);
-        }
-        if (Library.APR_HAVE_IPV6) {
-            if (getIpv6v6only()) {
-                Socket.optSet(serverSock, Socket.APR_IPV6_V6ONLY, 1);
-            } else {
-                Socket.optSet(serverSock, Socket.APR_IPV6_V6ONLY, 0);
+            if (OS.IS_UNIX) {
+                Socket.optSet(serverSock, Socket.APR_SO_REUSEADDR, 1);
+            }
+            if (Library.APR_HAVE_IPV6) {
+                if (getIpv6v6only()) {
+                    Socket.optSet(serverSock, Socket.APR_IPV6_V6ONLY, 1);
+                } else {
+                    Socket.optSet(serverSock, Socket.APR_IPV6_V6ONLY, 0);
+                }
             }
+            // Deal with the firewalls that tend to drop the inactive sockets
+            Socket.optSet(serverSock, Socket.APR_SO_KEEPALIVE, 1);
         }
-        // Deal with the firewalls that tend to drop the inactive sockets
-        Socket.optSet(serverSock, Socket.APR_SO_KEEPALIVE, 1);
+
         // Bind the server socket
-        int ret = Socket.bind(serverSock, inetAddress);
+        int ret = Socket.bind(serverSock, sockAddress);
         if (ret != 0) {
             throw new Exception(sm.getString("endpoint.init.bind", "" + ret, 
Error.strerror(ret)));
         }
+
         // Start listening on the server socket
         ret = Socket.listen(serverSock, getAcceptCount());
         if (ret != 0) {
             throw new Exception(sm.getString("endpoint.init.listen", "" + ret, 
Error.strerror(ret)));
         }
-        if (OS.IS_WIN32 || OS.IS_WIN64) {
-            // On Windows set the reuseaddr flag after the bind/listen
-            Socket.optSet(serverSock, Socket.APR_SO_REUSEADDR, 1);
+
+        if (family == Socket.APR_UNIX) {

Review comment:
       Not necessarily:
   ```
   $ ll /var/run/
   total 100
   -rw-r--r--  1 root   wheel       0 2020-11-29 11:45 clean_var
   -rw-------  1 root   wheel       4 2020-11-29 10:45 cron.pid
   drwxr-xr-x  3 root   wheel     512 2020-07-12 11:56 cups/
   drwxr-xr-x  2 root   wheel     512 2020-10-16 19:12 dbus/
   -rw-------  1 root   wheel       3 2020-11-29 10:45 devd.pid
   srw-rw-rw-  1 root   wheel       0 2020-11-29 10:45 devd.pipe=
   srw-rw-rw-  1 root   wheel       0 2020-11-29 10:45 devd.seqpacket.pipe=
   drwxr-xr-x  2 root   wheel     512 2020-11-29 10:45 dhclient/
   -rw-r--r--  1 root   wheel    8067 2020-11-29 10:45 dmesg.boot
   -rw-r--r--  1 root   wheel       5 2020-11-29 10:45 httpd.pid
   -r--r--r--  1 root   wheel     310 2020-11-29 11:45 ld-elf.so.hints
   -r--r--r--  1 root   wheel     139 2020-11-29 11:45 ld-elf32.so.hints
   srw-rw-rw-  1 root   wheel       0 2020-11-29 10:45 log=
   srw-------  1 root   wheel       0 2020-11-29 10:45 logpriv=
   drwxr-x---  2 nexus  nexus     512 2020-09-29 12:54 nexus2/
   -r--r--r--  1 root   wheel     220 2020-11-29 10:45 os-release
   drwxr-xr-x  2 root   wheel     512 2020-07-23 00:26 poudriere/
   -rw-------  1 root   wheel       3 2020-11-29 10:45 powerd.pid
   drwxrwx---  2 root   network   512 2020-07-02 04:39 ppp/
   drwxr-xr-x  2 redis  redis     512 2020-11-29 10:45 redis/
   drwxr-xr-x  4 root   wheel     512 2020-11-30 00:14 resolvconf/
   -rw-r--r--  1 root   wheel       0 2020-11-29 10:45 rtsold.dump
   -rw-r--r--  1 root   wheel       3 2020-11-29 10:45 rtsold.pid
   -rw-------  1 root   wheel      79 2020-11-29 10:45 sendmail.pid
   -rw-r--r--  1 root   wheel       5 2020-11-29 10:45 sshd.pid
   drwx--x--x  3 root   wheel     512 2020-07-23 01:12 sudo/
   -rw-------  1 root   wheel       3 2020-11-29 10:45 syslog.pid
   -rw-r--r--  1 root   wheel       0 2020-11-29 10:45 syslogd.sockets
   drwx------  2 _tss   _tss      512 2020-07-12 15:33 tpm/
   -rw-r--r--  1 root   wheel     788 2020-11-29 20:03 utx.active
   drwxr-xr-x  2 root   wheel     512 2020-07-02 04:39 wpa_supplicant/
   ```




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to