commit 940b434ba83d5c4db2de3ce75baab3b5dd4279d3 from: Stefan Sperling date: Fri Nov 08 10:53:07 2024 UTC tidy up error handling and reporting in repo_write_dispatch() a bit ok op@ commit - 28f88a8012eef7b02f7ada4a4e8a89d1d4342f70 commit + 940b434ba83d5c4db2de3ce75baab3b5dd4279d3 blob - ee4eb5cff4be8f41919997710c1933d9d70f9d98 blob + f0e5419c253f15beee2a1ca1138b1d12778cb3f2 --- gotd/repo_write.c +++ gotd/repo_write.c @@ -2332,19 +2332,26 @@ repo_write_dispatch(int fd, short event, void *arg) if (event & EV_READ) { if ((n = imsg_read(ibuf)) == -1 && errno != EAGAIN) fatal("imsg_read error"); - if (n == 0) /* Connection closed. */ + if (n == 0) { /* Connection closed. */ shut = 1; + goto done; + } } if (event & EV_WRITE) { n = msgbuf_write(&ibuf->w); if (n == -1 && errno != EAGAIN) fatal("msgbuf_write"); - if (n == 0) /* Connection closed. */ + if (n == 0) { /* Connection closed. */ shut = 1; + goto done; + } } - while (err == NULL && check_cancelled(NULL) == NULL) { + while (err == NULL) { + err = check_cancelled(NULL); + if (err) + break; if ((n = imsg_get(ibuf, &imsg)) == -1) fatal("%s: imsg_get", __func__); if (n == 0) /* No more messages. */ @@ -2356,19 +2363,18 @@ repo_write_dispatch(int fd, short event, void *arg) break; default: log_debug("unexpected imsg %d", imsg.hdr.type); + err = got_error(GOT_ERR_PRIVSEP_MSG); break; } imsg_free(&imsg); } - if (!shut && check_cancelled(NULL) == NULL) { - if (err && - gotd_imsg_send_error_event(iev, PROC_REPO_WRITE, - client->id, err) == -1) { - log_warnx("could not send error to parent: %s", - err->msg); - } + if (err && gotd_imsg_send_error_event(iev, PROC_REPO_WRITE, + client->id, err) == -1) + log_warnx("could not send error to parent: %s", err->msg); +done: + if (!shut) { gotd_imsg_event_add(iev); } else { /* This pipe is dead. Remove its event handler */