commit 5735c9f6fa945e745aa45bc164ccccb7fddbefca from: Stefan Sperling via: Thomas Adam date: Sun Nov 10 11:01:43 2024 UTC tidy up error handling and reporting in repo_write_dispatch() a bit ok op@ commit - 5d7b9e8954738f88485c70d09f14249ebf444e3d commit + 5735c9f6fa945e745aa45bc164ccccb7fddbefca blob - 4f7bf8a96dcfa86f4f474fdb65ef9db15f8727a1 blob + ea922fda862cec518bb34fccb83d41257d6bec44 --- gotd/repo_write.c +++ gotd/repo_write.c @@ -2330,19 +2330,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. */ @@ -2354,19 +2361,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 */