Commit Diff


commit - e60184561282aa8cc9526ea2e80ca84266ec07ab
commit + 61d4bd062ed92c7c334c663c16f86fd80d09edf7
blob - 1358883401f1dd6e5ee11d565febab287239d368
blob + 3f49c317df61f0920a4cbe046bf927f5ead20532
--- gotwebd/gotwebd.conf.5
+++ gotwebd/gotwebd.conf.5
@@ -58,6 +58,21 @@ environment of
 If not specified then
 .Pa /var/www
 will be used.
+.It Ic listen on Ar address Ic port Ar number
+Configure an address and port for incoming FastCGI connections.
+Valid
+.Ar address
+arguments are hostnames, IPv4 and IPv6 addresses.
+The
+.Ar port
+argument may be number or a service name defined in
+.Xr services 5 .
+May be specified multiple times to build up a list of listening sockets.
+.It Ic listen on socket Ar path
+Configure a
+.Ux Ns -domain
+socket for incoming FastCGI connections.
+May be specified multiple times to build up a list of listening sockets.
 .It Ic prefork Ar number
 Run the specified number of server processes.
 .Xr gotwebd 8
@@ -67,14 +82,22 @@ Set the path to the default unix socket.
 Defaults to
 .Pa /var/www/run/gotweb.sock .
 .El
+.Pp
+If no
+.Ic listen
+directive is used,
+.Xr gotwebd 8
+will listen on the
+.Ux Ns -domain
+socket at
+.Pa /var/www/run/gotweb.sock .
 .Sh SERVER CONFIGURATION
 At least one server context must exist for
 .Xr gotwebd 8
 to function.
 In case no server context is defined in the configuration file, a default
-server context will be used, which listens on a unix socket at
-.Pa /var/www/run/gotweb.sock
-and uses default parameters for all applicable settings.
+server context will be used which uses default parameters for all
+applicable settings.
 .Pp
 A server context is declared with a unique
 .Ar name ,
@@ -92,19 +115,6 @@ Set the path to a custom Cascading Style Sheet (CSS) t
 If this option is not specified then the default style sheet
 .Sq gotweb.css
 will be used.
-.It Ic listen on Ar address Ic port Ar number
-Configure an address and port for incoming FastCGI connections.
-Valid
-.Ar address
-arguments are hostnames, IPv4 and IPv6 addresses.
-The
-.Ar port
-argument may be number or a service name defined in
-.Xr services 5 .
-.Pp
-May be specified multiple times to build up a list of listening sockets.
-.It Ic listen on socket Ar path
-Set the path to the unix socket used by the server.
 .It Ic logo Ar path
 Set the path to an image file containing a logo to be displayed.
 Defaults to
@@ -203,9 +213,11 @@ implicit
 .Ux
 socket.
 .Bd -literal -offset indent
+listen on 127.0.0.1 port 9000
+listen on ::1 port 9000
+
 server "localhost" {
-	listen on 127.0.0.1 port 9000
-	listen on ::1 port 9000
+	site_name "my public repos"
 }
 .Ed
 .Sh SEE ALSO
blob - a0fde1eafb66028107363d6beae5bb5acc7fd2a5
blob + 5d08e6330815244d0f093676cb7171f5881355b9
--- gotwebd/gotwebd.h
+++ gotwebd/gotwebd.h
@@ -287,7 +287,6 @@ TAILQ_HEAD(addresslist, address);
 
 struct server {
 	TAILQ_ENTRY(server)	 entry;
-	struct addresslist	al;
 
 	char		 name[GOTWEBD_MAXTEXT];
 
blob - 11da7e60c5c605bd07cb1abcbca71e6c7c4d6044
blob + 15d246c916137d3d1efe5080a25591b154346650
--- gotwebd/parse.y
+++ gotwebd/parse.y
@@ -95,10 +95,10 @@ static struct server		*conf_new_server(const char *);
 int				 getservice(const char *);
 int				 n;
 
-int		 get_addrs(const char *, const char *, struct server *);
-int		 get_unix_addr(const char *, struct server *);
+int		 get_addrs(const char *, const char *);
+int		 get_unix_addr(const char *);
 int		 addr_dup_check(struct addresslist *, struct address *);
-int		 add_addr(struct server *, struct address *);
+int		 add_addr(struct address *);
 
 typedef struct {
 	union {
@@ -216,6 +216,38 @@ main		: PREFORK NUMBER {
 			}
 			free($2);
 		}
+		| LISTEN ON listen_addr PORT STRING {
+			if (get_addrs($3, $5) == -1) {
+				yyerror("could not get addrs");
+				YYERROR;
+			}
+			free($3);
+			free($5);
+		}
+		| LISTEN ON listen_addr PORT NUMBER {
+			char portno[32];
+			int n;
+
+			n = snprintf(portno, sizeof(portno), "%lld",
+			    (long long)$5);
+			if (n < 0 || (size_t)n >= sizeof(portno))
+				fatalx("port number too long: %lld",
+				    (long long)$5);
+
+			if (get_addrs($3, portno) == -1) {
+				yyerror("could not get addrs");
+				YYERROR;
+			}
+			free($3);
+		}
+		| LISTEN ON SOCKET STRING {
+			if (get_unix_addr($4) == -1) {
+				yyerror("can't listen on %s", $4);
+				free($4);
+				YYERROR;
+			}
+			free($4);
+		}
 		;
 
 server		: SERVER STRING {
@@ -320,38 +352,6 @@ serveropts1	: REPOS_PATH STRING {
 			}
 			free($2);
 		}
-		| LISTEN ON listen_addr PORT STRING {
-			if (get_addrs($3, $5, new_srv) == -1) {
-				yyerror("could not get addrs");
-				YYERROR;
-			}
-			free($3);
-			free($5);
-		}
-		| LISTEN ON listen_addr PORT NUMBER {
-			char portno[32];
-			int n;
-
-			n = snprintf(portno, sizeof(portno), "%lld",
-			    (long long)$5);
-			if (n < 0 || (size_t)n >= sizeof(portno))
-				fatalx("port number too long: %lld",
-				    (long long)$5);
-
-			if (get_addrs($3, portno, new_srv) == -1) {
-				yyerror("could not get addrs");
-				YYERROR;
-			}
-			free($3);
-		}
-		| LISTEN ON SOCKET STRING {
-			if (get_unix_addr($4, new_srv) == -1) {
-				yyerror("can't listen on %s", $4);
-				free($4);
-				YYERROR;
-			}
-			free($4);
-		}
 		| SHOW_SITE_OWNER boolean {
 			new_srv->show_site_owner = $2;
 		}
@@ -806,7 +806,6 @@ int
 parse_config(const char *filename, struct gotwebd *env)
 {
 	struct sym *sym, *next;
-	struct server *srv;
 	int n;
 
 	if (config_init(env) == -1)
@@ -848,12 +847,11 @@ parse_config(const char *filename, struct gotwebd *env
 	if (gotwebd->server_cnt == 0)
 		add_default_server();
 
-	/* add the implicit listen on socket where missing */
-	TAILQ_FOREACH(srv, &gotwebd->servers, entry) {
-		if (!TAILQ_EMPTY(&srv->al))
-			continue;
-		if (get_unix_addr(env->unix_socket_name, srv) == -1)
-			yyerror("can't listen on %s", env->unix_socket_name);
+	/* add the implicit listen on socket */
+	if (TAILQ_EMPTY(&gotwebd->addresses)) {
+		const char *path = D_HTTPD_CHROOT D_UNIX_SOCKET;
+		if (get_unix_addr(path) == -1)
+			yyerror("can't listen on %s", path);
 	}
 
 	if (errors)
@@ -916,7 +914,6 @@ conf_new_server(const char *name)
 	srv->summary_commits_display = D_MAXSLCOMMDISP;
 	srv->summary_tags_display = D_MAXSLTAGDISP;
 
-	TAILQ_INIT(&srv->al);
 	TAILQ_INSERT_TAIL(&gotwebd->servers, srv, entry);
 	gotwebd->server_cnt++;
 
@@ -999,7 +996,7 @@ symget(const char *nam)
 }
 
 int
-get_addrs(const char *hostname, const char *servname, struct server *new_srv)
+get_addrs(const char *hostname, const char *servname)
 {
 	struct addrinfo hints, *res0, *res;
 	int error;
@@ -1054,7 +1051,7 @@ get_addrs(const char *hostname, const char *servname, 
 			fatalx("unknown address family %d", res->ai_family);
 		}
 
-		if (add_addr(new_srv, h) == -1) {
+		if (add_addr(h) == -1) {
 			freeaddrinfo(res0);
 			return -1;
 		}
@@ -1064,7 +1061,7 @@ get_addrs(const char *hostname, const char *servname, 
 }
 
 int
-get_unix_addr(const char *path, struct server *new_srv)
+get_unix_addr(const char *path)
 {
 	struct address *h;
 	struct sockaddr_un *sun;
@@ -1085,7 +1082,7 @@ get_unix_addr(const char *path, struct server *new_srv
 		return (-1);
 	}
 
-	return add_addr(new_srv, h);
+	return add_addr(h);
 }
 
 int
@@ -1107,25 +1104,13 @@ addr_dup_check(struct addresslist *al, struct address 
 }
 
 int
-add_addr(struct server *new_srv, struct address *h)
+add_addr(struct address *h)
 {
-	struct server *srv;
-	struct address *dup;
-
-	TAILQ_FOREACH(srv, &gotwebd->servers, entry) {
-		if (addr_dup_check(&srv->al, h) == -1) {
-			free(h);
-			return 0;
-		}
-	}
-
 	if (addr_dup_check(&gotwebd->addresses, h) == 0) {
-		if ((dup = calloc(1, sizeof(*dup))) == NULL)
-			fatal("%s: calloc", __func__);
-		memcpy(dup, h, sizeof(*dup));
-		TAILQ_INSERT_TAIL(&gotwebd->addresses, dup, entry);
+		TAILQ_INSERT_TAIL(&gotwebd->addresses, h, entry);
+		return (0);
 	}
 
-	TAILQ_INSERT_TAIL(&new_srv->al, h, entry);
+	free(h);
 	return (0);
 }