commit c929736a36ab9616de454d901bd908e0c9512a26 from: Omar Polo date: Thu Jun 22 13:32:23 2023 UTC move gotd_child_proc to gotd.c make it opaque since it's unused outside of gotd.c. While here, drop the unused `nhelpers' field. ok/tweak stsp@ commit - a60eb2cc0fad47d21b6c6329245e25f548245c00 commit + c929736a36ab9616de454d901bd908e0c9512a26 blob - f15597dbd0e7299cbf018874f9d81d6c8dcaf403 blob + b25ad5a1cd86cf8276841b128f8b79f5b2f37899 --- gotd/gotd.c +++ gotd/gotd.c @@ -71,6 +71,15 @@ enum gotd_client_state { GOTD_CLIENT_STATE_NEW, GOTD_CLIENT_STATE_ACCESS_GRANTED, +}; + +struct gotd_child_proc { + pid_t pid; + enum gotd_procid type; + char repo_name[NAME_MAX]; + char repo_path[PATH_MAX]; + int pipe[2]; + struct gotd_imsgev iev; }; struct gotd_client { @@ -331,7 +340,7 @@ disconnect(struct gotd_client *client) { struct gotd_imsg_disconnect idisconnect; struct gotd_child_proc *proc = client->repo; - struct gotd_child_proc *listen_proc = &gotd.listen_proc; + struct gotd_child_proc *listen_proc = gotd.listen_proc; uint64_t slot; log_debug("uid %d: disconnecting", client->euid); @@ -703,7 +712,7 @@ recv_connect(uint32_t *client_id, struct imsg *imsg) client->euid, client->fd); done: if (err) { - struct gotd_child_proc *listen_proc = &gotd.listen_proc; + struct gotd_child_proc *listen_proc = gotd.listen_proc; struct gotd_imsg_disconnect idisconnect; idisconnect.client_id = client->id; @@ -753,11 +762,12 @@ gotd_shutdown(void) disconnect(c); } - proc = &gotd.listen_proc; + proc = gotd.listen_proc; msgbuf_clear(&proc->iev.ibuf.w); close(proc->iev.ibuf.fd); kill_proc(proc, 0); wait_for_child(proc->pid); + free(proc) log_info("terminating"); exit(0); @@ -960,7 +970,7 @@ gotd_dispatch_listener(int fd, short event, void *arg) { struct gotd_imsgev *iev = arg; struct imsgbuf *ibuf = &iev->ibuf; - struct gotd_child_proc *proc = &gotd.listen_proc; + struct gotd_child_proc *proc = gotd.listen_proc; ssize_t n; int shut = 0; struct imsg imsg; @@ -1488,8 +1498,12 @@ start_child(enum gotd_procid proc_id, const char *repo static void start_listener(char *argv0, const char *confpath, int daemonize, int verbosity) { - struct gotd_child_proc *proc = &gotd.listen_proc; + struct gotd_child_proc *proc; + proc = calloc(1, sizeof(*proc)); + if (proc == NULL) + fatal("calloc"); + proc->type = PROC_LISTEN; if (socketpair(AF_UNIX, SOCK_STREAM|SOCK_CLOEXEC|SOCK_NONBLOCK, @@ -1502,6 +1516,8 @@ start_listener(char *argv0, const char *confpath, int proc->iev.handler = gotd_dispatch_listener; proc->iev.events = EV_READ; proc->iev.handler_arg = NULL; + + gotd.listen_proc = proc; } static const struct got_error * @@ -1948,7 +1964,7 @@ main(int argc, char **argv) signal_add(&evsighup, NULL); signal_add(&evsigusr1, NULL); - gotd_imsg_event_add(&gotd.listen_proc.iev); + gotd_imsg_event_add(&gotd.listen_proc->iev); event_dispatch(); blob - 35d6e95f4881eb3c4ce60156fce684fa03070cb4 blob + e902d6f53b03f7682202e2b9b3d0af5fc28c25b6 --- gotd/gotd.h +++ gotd/gotd.h @@ -49,16 +49,6 @@ struct gotd_imsgev { void *handler_arg; struct event ev; short events; -}; - -struct gotd_child_proc { - pid_t pid; - enum gotd_procid type; - char repo_name[NAME_MAX]; - char repo_path[PATH_MAX]; - int pipe[2]; - struct gotd_imsgev iev; - size_t nhelpers; }; enum gotd_access { @@ -119,6 +109,8 @@ struct gotd_uid_connection_limit { uid_t uid; int max_connections; }; + +struct gotd_child_proc; struct gotd { pid_t pid; @@ -126,7 +118,7 @@ struct gotd { char user_name[32]; struct gotd_repolist repos; int nrepos; - struct gotd_child_proc listen_proc; + struct gotd_child_proc *listen_proc; struct timeval request_timeout; struct timeval auth_timeout; struct gotd_uid_connection_limit *connection_limits;