Commit Diff


commit - 284dcb53c6a7c69a62074b6fcdb926b110ff613a7f9d3a15b8e32312d52d8618
commit + 89df1c542b11e41c76a42ed23ab71683a3ff6b5f2bc8e5cbcfa2ed8739d1cd23
blob - e21253910eac814bc4dfa0073fa09b7ce2c5f11b3cfe26894d835bafa530afb1
blob + ba66aabc010dcdc1fa1d46093b6328b7c9fb0342144f0f35854eb86efccc0bd1
--- gotwebd/sockets.c	
+++ gotwebd/sockets.c	
@@ -122,7 +122,7 @@ sockets(struct gotwebd *env, int fd)
 	signal_add(&sigterm, NULL);
 
 #ifndef PROFILE
-	if (pledge("stdio inet recvfd sendfd", NULL) == -1)
+	if (pledge("stdio inet unix recvfd sendfd", NULL) == -1)
 		fatal("pledge");
 #endif
 
@@ -196,7 +196,7 @@ static void
 sockets_launch(struct gotwebd *env)
 {
 	struct socket *sock;
-	int i;
+	int i, have_unix = 0, have_inet = 0;
 
 	if (env->gotweb_pending != 0)
 		fatal("gotweb process not connected");
@@ -205,6 +205,27 @@ sockets_launch(struct gotwebd *env)
 		log_info("%s: configuring socket %d (%d)", __func__,
 		    sock->conf.id, sock->fd);
 
+		switch (sock->conf.af_type) {
+		case AF_UNIX:
+			if (listen(sock->fd, SOCKS_BACKLOG) == -1) {
+				fatal("cannot listen on %s",
+				    sock->conf.unix_socket_name);
+			}
+			have_unix = 1;
+			break;
+		case AF_INET:
+		case AF_INET6:
+			if (listen(sock->fd, SOMAXCONN) == -1) {
+				fatal("cannot listen on %s",
+				    sock->conf.addr.ifname);
+			}
+			have_inet = 1;
+			break;
+		default:
+			fatalx("unsupported address family type %d",
+			    sock->conf.af_type);
+		}
+
 		event_set(&sock->ev, sock->fd, EV_READ | EV_PERSIST,
 		    sockets_socket_accept, sock);
 
@@ -218,8 +239,16 @@ sockets_launch(struct gotwebd *env)
 	}
 
 #ifndef PROFILE
-	if (pledge("stdio inet sendfd", NULL) == -1)
-		fatal("pledge");
+	if (have_unix && have_inet) {
+		if (pledge("stdio inet unix sendfd", NULL) == -1)
+			fatal("pledge");
+	} else if (have_unix) {
+		if (pledge("stdio unix sendfd", NULL) == -1)
+			fatal("pledge");
+	} else if (have_inet) {
+		if (pledge("stdio inet sendfd", NULL) == -1)
+			fatal("pledge");
+	}
 #endif
 	for (i = 0; i < env->prefork; i++)
 		event_add(&env->iev_gotweb[i].ev, NULL);
@@ -499,11 +528,6 @@ sockets_unix_socket_listen(struct gotwebd *env, struct
 		return -1;
 	}
 
-	if (listen(u_fd, SOCKS_BACKLOG) == -1) {
-		log_warn("%s: listen", __func__);
-		return -1;
-	}
-
 	return u_fd;
 }
 
@@ -541,12 +565,6 @@ sockets_create_socket(struct address *a)
 		return -1;
 	}
 
-	if (listen(fd, SOMAXCONN) == -1) {
-		log_warn("%s, unable to listen on socket", __func__);
-		close(fd);
-		return -1;
-	}
-
 	return (fd);
 }