commit a6ca45d5dd6d6fe622d1a0c2bf771551f13c20dd from: Stefan Sperling via: Thomas Adam date: Mon Oct 24 11:28:33 2022 UTC close parent's end of imsg pipe before waiting for a child process to exit Prevents a dead-lock in 'tog log' where tog wants to exit (e.g. because the user pressed Ctrl-C) while a got-read-pack child process wants to send more commits. Closing the parent's pipe descriptor makes writes to the pipe fail in the child process. The child then unwinds via an ERR_EOF error and exits, instead of forever polling its end of the pipe in order to write more data. ok jamsek commit - 4e80a172c62f9b329f0f876405c8d391358e5e6a commit + a6ca45d5dd6d6fe622d1a0c2bf771551f13c20dd blob - c1e3e0b123933e13467cda9be352c1fc603e4fda blob + 07bd02d8fa88cb026d8119ce8602a088cb502106 --- lib/pack.c +++ lib/pack.c @@ -788,7 +788,7 @@ done: static const struct got_error * pack_stop_privsep_child(struct got_pack *pack) { - const struct got_error *err = NULL; + const struct got_error *err = NULL, *close_err = NULL; if (pack->privsep_child == NULL) return NULL; @@ -796,9 +796,12 @@ pack_stop_privsep_child(struct got_pack *pack) err = got_privsep_send_stop(pack->privsep_child->imsg_fd); if (err) return err; + if (close(pack->privsep_child->imsg_fd) == -1) + close_err = got_error_from_errno("close"); err = got_privsep_wait_for_child(pack->privsep_child->pid); - if (close(pack->privsep_child->imsg_fd) == -1 && err == NULL) - err = got_error_from_errno("close"); + if (close_err && err == NULL) + err = close_err; + imsg_clear(pack->privsep_child->ibuf); free(pack->privsep_child->ibuf); free(pack->privsep_child); pack->privsep_child = NULL;