commit 789434649a5946c62ea73cf86e25f2c14a2c25f5 from: Omar Polo via: Thomas Adam date: Thu Jun 22 17:37:44 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 - 0835bf10ee863d91a617270780cd79c405c6a992 commit + 789434649a5946c62ea73cf86e25f2c14a2c25f5 blob - 4a31b013e208dc44217e5adb1298f296a23afd3e blob + 22ba4bf3e47e8a047ecc9a93f07f9a543a54fb7d --- gotd/gotd.c +++ gotd/gotd.c @@ -68,6 +68,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 { @@ -328,7 +337,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); @@ -700,7 +709,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; @@ -750,11 +759,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); @@ -957,7 +967,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; @@ -1485,8 +1495,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, @@ -1499,6 +1513,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 * @@ -1945,7 +1961,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;