commit 58cdb97ce8d303a379c3c164bdfa61cb1524600f from: Omar Polo date: Thu Nov 16 23:05:54 2023 UTC gotwebd: send a UNIQUE temp fd main_compose_sockets() has the 'feature' of implicitly dup(2)'ing the passed file descriptior. But it's not what we need for the temp fds, since those needs to be unique per-children. debugged with stsp@ commit - 4056db6342e0499ecd1cd53b959f9a46eea64358 commit + 58cdb97ce8d303a379c3c164bdfa61cb1524600f blob - 775d88bd837ed1c57363aea14c95b1793c999afa blob + b35fa0bcfb79ea056b7d4831d3597333b7341e2a --- gotwebd/config.c +++ gotwebd/config.c @@ -165,18 +165,28 @@ config_getsock(struct gotwebd *env, struct imsg *imsg) int config_setfd(struct gotwebd *env, struct socket *sock) { - int i, fd; + int i, j, ret, fd; log_debug("%s: Allocating %d file descriptors", __func__, PRIV_FDS__MAX + GOTWEB_PACK_NUM_TEMPFILES); for (i = 0; i < PRIV_FDS__MAX + GOTWEB_PACK_NUM_TEMPFILES; i++) { - fd = got_opentempfd(); - if (fd == -1) - fatal("got_opentemp"); - if (main_compose_sockets(env, IMSG_CFG_FD, fd, - &sock->conf.id, sizeof(sock->conf.id)) == -1) - fatal("main_compose_sockets IMSG_CFG_FD"); + for (j = 0; j < env->nserver; ++j) { + fd = got_opentempfd(); + 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) + fatal("imsg_compose_event IMSG_CFG_FD"); + + do { + ret = imsg_flush(&env->iev_server[j].ibuf); + } while (ret == -1 && errno == EAGAIN); + if (ret == -1) + fatal("imsg_flush"); + imsg_event_add(&env->iev_server[j]); + } } return 0;