"GOT", but the "O" is a cute, smiling pufferfish. Index | Thread | Search

From:
Omar Polo <op@omarpolo.com>
Subject:
gotwebd: reduce struct server size for compatibility
To:
gameoftrees@openbsd.org
Date:
Mon, 05 Sep 2022 19:13:15 +0200

Download raw body.

Thread
keeping GOTWEBD_REPO_CACHESIZE * sizeof(struct cache_repo) inside the
struct server makes it too large on linux for being sent over imsg.

Instead, just store a pointer and allocate the array when it's
received on the child processes.  As a follow-up (post-release maybe)
we could even allow the cache size to be customizable via
gotwebd.conf.

With this, I'm able to run gotwebd behind nginx on linux (in vmd) :)

ok?


diff /home/op/w/got
commit - e15c42decfa8a80fb91cc1e19b467efc34a8c05d
path + /home/op/w/got
blob - 29bdf6301687d8ed6e4ae5f52d25ea757efd3176
file + gotwebd/config.c
--- gotwebd/config.c
+++ gotwebd/config.c
@@ -82,7 +82,9 @@ config_setserver(struct gotwebd *env, struct server *s
 	struct privsep *ps = env->gotwebd_ps;
 
 	memcpy(&ssrv, srv, sizeof(ssrv));
-	proc_compose(ps, PROC_SOCKS, IMSG_CFG_SRV, &ssrv, sizeof(ssrv));
+	if (proc_compose(ps, PROC_SOCKS, IMSG_CFG_SRV, &ssrv, sizeof(ssrv))
+	    == -1)
+		fatal("proc_compose");
 	 return 0;
 }
 
@@ -97,7 +99,6 @@ config_getserver(struct gotwebd *env, struct imsg *ims
 	srv = calloc(1, sizeof(*srv));
 	if (srv == NULL)
 		fatalx("%s: calloc", __func__);
-	memcpy(srv, p, sizeof(*srv));
 
 	if (IMSG_DATA_SIZE(imsg) != sizeof(*srv)) {
 		log_debug("%s: imsg size error", __func__);
@@ -105,6 +106,13 @@ config_getserver(struct gotwebd *env, struct imsg *ims
 		return 1;
 	}
 
+	memcpy(srv, p, sizeof(*srv));
+	srv->cached_repos = calloc(GOTWEBD_REPO_CACHESIZE,
+	    sizeof(*srv->cached_repos));
+	if (srv->cached_repos == NULL)
+		fatal("%s: calloc", __func__);
+	srv->ncached_repos = 0;
+
 	/* log server info */
 	log_debug("%s: server=%s fcgi_socket=%s unix_socket=%s", __func__,
 	    srv->name, srv->fcgi_socket ? "yes" : "no", srv->unix_socket ?
blob - 401b70e6dff3d9c32b2e251335998950b2a3ee8b
file + gotwebd/gotweb.c
--- gotwebd/gotweb.c
+++ gotwebd/gotweb.c
@@ -2002,7 +2002,7 @@ cache_repo(struct got_repository **new, struct server 
 	struct cached_repo *cr;
 	int evicted = 0;
 
-	if (srv->ncached_repos >= nitems(srv->cached_repos)) {
+	if (srv->ncached_repos >= GOTWEBD_REPO_CACHESIZE) {
 		cr = &srv->cached_repos[srv->ncached_repos - 1];
 		error = got_repo_close(cr->repo);
 		memset(cr, 0, sizeof(*cr));
blob - ac7f962b1abdcfe1c535e8bc210c9f619e7a2cbc
file + gotwebd/gotwebd.h
--- gotwebd/gotwebd.h
+++ gotwebd/gotwebd.h
@@ -256,7 +256,7 @@ struct server {
 	TAILQ_ENTRY(server)	 entry;
 	struct addresslist	al;
 
-	struct cached_repo	cached_repos[GOTWEBD_REPO_CACHESIZE];
+	struct cached_repo	*cached_repos;
 	int		 ncached_repos;
 
 	char		 name[GOTWEBD_MAXTEXT];