Commit Diff


commit - 96c0dd284ef3df7f654c887ac5458f9b14bdaf3b
commit + 684f094bd5486f616a55af9643414d29dcd6eaca
blob - 583f174d77f33c49012c2b1edaa62dda6711d22a
blob + c1e15a921e4a3bba07a8dcf1d04b0084fbe0b700
--- gotwebd/config.c
+++ gotwebd/config.c
@@ -45,6 +45,8 @@
 int
 config_init(struct gotwebd *env)
 {
+	int i;
+
 	strlcpy(env->httpd_chroot, D_HTTPD_CHROOT, sizeof(env->httpd_chroot));
 
 	env->prefork_gotwebd = GOTWEBD_NUMPROC;
@@ -53,6 +55,12 @@ config_init(struct gotwebd *env)
 	TAILQ_INIT(&env->sockets);
 	TAILQ_INIT(&env->addresses);
 
+	for (i = 0; i < PRIV_FDS__MAX; i++)
+		env->priv_fd[i] = -1;
+
+	for (i = 0; i < GOTWEB_PACK_NUM_TEMPFILES; i++)
+		env->pack_fds[i] = -1;
+
 	return 0;
 }
 
@@ -118,7 +126,6 @@ config_getsock(struct gotwebd *env, struct imsg *imsg)
 	struct socket *sock = NULL;
 	struct socket_conf sock_conf;
 	uint8_t *p = imsg->data;
-	int i;
 
 	if (IMSG_DATA_SIZE(imsg) != sizeof(sock_conf))
 		fatalx("%s: wrong size", __func__);
@@ -140,12 +147,6 @@ config_getsock(struct gotwebd *env, struct imsg *imsg)
 
 	TAILQ_INSERT_TAIL(&env->sockets, sock, entry);
 
-	for (i = 0; i < PRIV_FDS__MAX; i++)
-		sock->priv_fd[i] = -1;
-
-	for (i = 0; i < GOTWEB_PACK_NUM_TEMPFILES; i++)
-		sock->pack_fds[i] = -1;
-
 	/* log new socket info */
 	log_debug("%s: id=%d af_type=%s socket_path=%s",
 	    __func__, sock->conf.id,
@@ -159,7 +160,7 @@ config_getsock(struct gotwebd *env, struct imsg *imsg)
 }
 
 int
-config_setfd(struct gotwebd *env, struct socket *sock)
+config_setfd(struct gotwebd *env)
 {
 	int i, j, ret, fd;
 
@@ -172,8 +173,7 @@ config_setfd(struct gotwebd *env, struct socket *sock)
 			if (fd == -1)
 				fatal("got_opentemp");
 			if (imsg_compose_event(&env->iev_server[j],
-			    IMSG_CFG_FD, 0, -1, fd, &sock->conf.id,
-			    sizeof(sock->conf.id)) == -1)
+			    IMSG_CFG_FD, 0, -1, fd, NULL, 0) == -1)
 				fatal("imsg_compose_event IMSG_CFG_FD");
 
 			do {
@@ -191,34 +191,28 @@ config_setfd(struct gotwebd *env, struct socket *sock)
 int
 config_getfd(struct gotwebd *env, struct imsg *imsg)
 {
-	struct socket *sock;
-	uint8_t *p = imsg->data;
-	int sock_id, match = 0, i, j;
+	int match = 0, i, j;
+	const int nfds = GOTWEB_PACK_NUM_TEMPFILES + PRIV_FDS__MAX;
 
-	if (IMSG_DATA_SIZE(imsg) != sizeof(sock_id))
+	if (imsg_get_len(imsg) != 0)
 		fatalx("%s: wrong size", __func__);
 
-	memcpy(&sock_id, p, sizeof(sock_id));
+	for (i = 0; i < nfds; i++) {
+		if (i < PRIV_FDS__MAX && env->priv_fd[i] == -1) {
+			env->priv_fd[i] = imsg_get_fd(imsg);
+			log_debug("%s: assigning priv_fd %d",
+			    __func__, env->priv_fd[i]);
+			match = 1;
+			break;
+		}
 
-	TAILQ_FOREACH(sock, &env->sockets, entry) {
-		const int nfds = (GOTWEB_PACK_NUM_TEMPFILES + PRIV_FDS__MAX);
-		for (i = 0; i < nfds; i++) {
-			if (i < PRIV_FDS__MAX && sock->priv_fd[i] == -1) {
-				sock->priv_fd[i] = imsg_get_fd(imsg);
-				log_debug("%s: assigning socket %d priv_fd %d",
-				    __func__, sock_id, sock->priv_fd[i]);
-				match = 1;
-				break;
-			}
-
-			j = i - PRIV_FDS__MAX;
-			if (sock->pack_fds[j] == -1) {
-				sock->pack_fds[j] = imsg_get_fd(imsg);
-				log_debug("%s: assigning socket %d pack_fd %d",
-				    __func__, sock_id, sock->pack_fds[j]);
-				match = 1;
-				break;
-			}
+		j = i - PRIV_FDS__MAX;
+		if (env->pack_fds[j] == -1) {
+			env->pack_fds[j] = imsg_get_fd(imsg);
+			log_debug("%s: assigning pack_fd %d",
+			    __func__, env->pack_fds[j]);
+			match = 1;
+			break;
 		}
 	}
 
blob - fc312d210561de463f25df3bbab28ae5c81464b7
blob + 2d6b283b8754f11b722d6922464d28f6abab285f
--- gotwebd/gotweb.c
+++ gotwebd/gotweb.c
@@ -1069,7 +1069,6 @@ gotweb_load_got_path(struct repo_dir **rp, const char 
     struct request *c)
 {
 	const struct got_error *error = NULL;
-	struct socket *sock = c->sock;
 	struct server *srv = c->srv;
 	struct transport *t = c->t;
 	struct repo_dir *repo_dir;
@@ -1120,7 +1119,8 @@ gotweb_load_got_path(struct repo_dir **rp, const char 
 		goto err;
 	}
 
-	error = got_repo_open(&t->repo, repo_dir->path, NULL, sock->pack_fds);
+	error = got_repo_open(&t->repo, repo_dir->path, NULL,
+	    gotwebd_env->pack_fds);
 	if (error)
 		goto err;
 	error = gotweb_get_repo_description(&repo_dir->description, srv,
blob - 32eda3d20c62bbb4441bdb111146376cc3652467
blob + 0f92638b13967c3e742d3d69e1f190a470ecd26e
--- gotwebd/gotwebd.c
+++ gotwebd/gotwebd.c
@@ -442,9 +442,11 @@ gotwebd_configure(struct gotwebd *env)
 	TAILQ_FOREACH(sock, &env->sockets, entry) {
 		if (config_setsock(env, sock) == -1)
 			fatalx("%s: send socket error", __func__);
-		if (config_setfd(env, sock) == -1)
-			fatalx("%s: send priv_fd error", __func__);
 	}
+
+	/* send the temp files */
+	if (config_setfd(env) == -1)
+		fatalx("%s: send priv_fd error", __func__);
 
 	if (main_compose_sockets(env, IMSG_CFG_DONE, -1, NULL, 0) == -1)
 		fatal("main_compose_sockets IMSG_CFG_DONE");
blob - 54d00805fd26e7a6b11e21510aad032bf7d9e1bc
blob + 965575a81e6fa9466d7fa736d9d04e7fdd4d95e5
--- gotwebd/gotwebd.h
+++ gotwebd/gotwebd.h
@@ -325,9 +325,6 @@ struct socket {
 	struct socket_conf	 conf;
 
 	int		 fd;
-	int		 pack_fds[GOTWEB_PACK_NUM_TEMPFILES];
-	int		 priv_fd[PRIV_FDS__MAX];
-
 	struct event	 evt;
 	struct event	 ev;
 	struct event	 pause;
@@ -341,6 +338,9 @@ struct gotwebd {
 	struct serverlist	servers;
 	struct socketlist	sockets;
 	struct addresslist	addresses;
+
+	int		 pack_fds[GOTWEB_PACK_NUM_TEMPFILES];
+	int		 priv_fd[PRIV_FDS__MAX];
 
 	char		*user;
 	const char	*gotwebd_conffile;
@@ -514,7 +514,7 @@ int config_setserver(struct gotwebd *, struct server *
 int config_getserver(struct gotwebd *, struct imsg *);
 int config_setsock(struct gotwebd *, struct socket *);
 int config_getsock(struct gotwebd *, struct imsg *);
-int config_setfd(struct gotwebd *, struct socket *);
+int config_setfd(struct gotwebd *);
 int config_getfd(struct gotwebd *, struct imsg *);
 int config_getcfg(struct gotwebd *, struct imsg *);
 int config_init(struct gotwebd *);
blob - 11a5e5f7e684c772c6b9cfa2bcdf808956e086ed
blob + dbc0ab4e48c19dafe913f9d03942f1ec677e58aa
--- gotwebd/sockets.c
+++ gotwebd/sockets.c
@@ -584,7 +584,7 @@ sockets_socket_accept(int fd, short event, void *arg)
 
 	c->fd = s;
 	c->sock = sock;
-	memcpy(c->priv_fd, sock->priv_fd, sizeof(c->priv_fd));
+	memcpy(c->priv_fd, gotwebd_env->priv_fd, sizeof(c->priv_fd));
 	c->buf_pos = 0;
 	c->buf_len = 0;
 	c->request_started = 0;