Commit Diff


commit - 9a821f8c0f04bf9135bff60cc3ae3f4d109a02ee
commit + a01a91db06a943ef0cc8fbb7294786814a63b65c
blob - 1ed3f58637bba9b00a42e5a77c1eb39db2eca8e5
blob + 5681ee2d5b65838617fc49d0275cd8bd132d7774
--- ge.c
+++ ge.c
@@ -41,6 +41,12 @@ static const struct option opts[] = {
 };
 
 void
+drop_priv(void)
+{
+	return;
+}
+
+void
 load_local_cert(struct vhost *h, const char *hostname, const char *dir)
 {
 	char *cert, *key;
@@ -176,8 +182,7 @@ serve(const char *host, int port, const char *dir, str
 	freeaddrinfo(res0);
 
 	log_notice(NULL, "serving %s on port %d", dir, port);
-	loop(ctx, sock, -1, NULL);
-	return 0;
+	return server_main(ctx, NULL, sock, -1);
 }
 
 static __dead void
@@ -241,10 +246,6 @@ main(int argc, char **argv)
 	if (certs_dir == NULL)
 		certs_dir = data_dir();
 
-	if (load_default_mime(&conf.mime) == -1)
-		fatal("can't load default mime types");
-	sort_mime(&conf.mime);
-
 	/* set up the implicit vhost and location */
 
 	host = xcalloc(1, sizeof(*host));
@@ -272,9 +273,6 @@ main(int argc, char **argv)
 		free(tmp);
 	}
 
-	if ((loc->dirfd = open(loc->dir, O_RDONLY|O_DIRECTORY)) == -1)
-		fatal("can't open %s", loc->dir);
-
 	/* setup tls */
 
 	if ((tlsconf = tls_config_new()) == NULL)
blob - 936f80cafda9edac9433a65edc7ba5d1afce7855
blob + a79ad60f00bc40923cf88bb881e8514d66183a59
--- gmid.c
+++ gmid.c
@@ -56,24 +56,6 @@ static void
 dummy_handler(int signo)
 {
 	return;
-}
-
-void
-load_vhosts(void)
-{
-	struct vhost	*h;
-	struct location	*l;
-
-	TAILQ_FOREACH(h, &hosts, vhosts) {
-		TAILQ_FOREACH(l, &h->locations, locations) {
-			if (*l->dir == '\0')
-				continue;
-			l->dirfd = open(l->dir, O_RDONLY | O_DIRECTORY);
-			if (l->dirfd == -1)
-				fatal("open %s for domain %s: %s", l->dir,
-				    h->domain, strerror(errno));
-		}
-	}
 }
 
 int
@@ -184,18 +166,6 @@ setup_tls(void)
 		fatal("tls_configure: %s", tls_error(ctx));
 }
 
-static int
-listener_main(struct imsgbuf *ibuf)
-{
-	drop_priv();
-	if (load_default_mime(&conf.mime) == -1)
-		fatal("load_default_mime: %s", strerror(errno));
-	sort_mime(&conf.mime);
-	load_vhosts();
-	loop(ctx, sock4, sock6, ibuf);
-	return 0;
-}
-
 void
 init_config(void)
 {
@@ -364,7 +334,7 @@ serve(void)
 			close(p[0]);
 			imsg_init(&servibuf[i], p[1]);
 			setproctitle("server");
-			_exit(listener_main(&servibuf[i]));
+			_exit(server_main(ctx, &servibuf[i], sock4, sock6));
 		default:
 			close(p[1]);
 			imsg_init(&servibuf[i], p[0]);
blob - 0bf0e63a7ac6febc4a54846ed9e0ed76eda48b49
blob + a0a44a38910a6ae12758345757b62f32b298041f
--- gmid.h
+++ gmid.h
@@ -296,7 +296,6 @@ enum imsg_type {
 /* gmid.c */
 char		*data_dir(void);
 void		 load_local_cert(struct vhost*, const char*, const char*);
-void		 load_vhosts(void);
 int		 make_socket(int, int);
 void		 setup_tls(void);
 void		 init_config(void);
@@ -348,7 +347,7 @@ void		 client_write(struct bufferevent *, void *);
 void		 start_reply(struct client*, int, const char*);
 void		 client_close(struct client *);
 struct client	*client_by_id(int);
-void		 loop(struct tls*, int, int, struct imsgbuf*);
+int		 server_main(struct tls *, struct imsgbuf *, int, int);
 
 int		 client_tree_cmp(struct client *, struct client *);
 SPLAY_PROTOTYPE(client_tree_id, client, entry, client_tree_cmp);
blob - 8027b5fd8fda453b484f2832ea8b75b018a240e5
blob + 083b5c2767cd31ffcd2a93844e3a0c04bd76da14
--- server.c
+++ server.c
@@ -1367,7 +1367,7 @@ handle_siginfo(int fd, short ev, void *d)
 	log_info(NULL, "%d connected clients", connected_clients);
 }
 
-void
+static void
 loop(struct tls *ctx_, int sock4, int sock6, struct imsgbuf *ibuf)
 {
 	ctx = ctx_;
@@ -1402,9 +1402,39 @@ loop(struct tls *ctx_, int sock4, int sock6, struct im
 	sandbox_server_process();
 	event_dispatch();
 	_exit(0);
+}
+
+static void
+load_vhosts(void)
+{
+	struct vhost	*h;
+	struct location	*l;
+
+	TAILQ_FOREACH(h, &hosts, vhosts) {
+		TAILQ_FOREACH(l, &h->locations, locations) {
+			if (*l->dir == '\0')
+				continue;
+			l->dirfd = open(l->dir, O_RDONLY | O_DIRECTORY);
+			if (l->dirfd == -1)
+				fatal("open %s for domain %s: %s", l->dir,
+				    h->domain, strerror(errno));
+		}
+	}
 }
 
 int
+server_main(struct tls *ctx_, struct imsgbuf *ibuf, int sock4, int sock6)
+{
+	drop_priv();
+	if (load_default_mime(&conf.mime) == -1)
+		fatal("can't load default mime: %s", strerror(errno));
+	sort_mime(&conf.mime);
+	load_vhosts();
+	loop(ctx_, sock4, sock6, ibuf);
+	return 0;
+}
+
+int
 client_tree_cmp(struct client *a, struct client *b)
 {
 	if (a->id == b->id)