commit c5e96df445562a55ab4860771be8f33067b8e74f from: Stefan Sperling date: Mon Jun 23 13:20:22 2025 UTC use imsgbuf_flush() instead of gotsysd_imsg_flush() in libexec event handlers The gotsysd_imsg_flush() wrapper enforces a sync write by polling the file descriptor and writing data in a loop. Since libevent already does polling for us we can simply use imsgbuf_flush() here instead. commit - 1201b9f16463d60ae02d48c1bddb9d8f7515a824 commit + c5e96df445562a55ab4860771be8f33067b8e74f blob - 51ed9f59144264bfc2401287771f19d939764baa blob + a64bd572c43a0f7cbbd9512d5e44332515d27164 --- gotsysd/libexec/gotsys-apply-conf/gotsys-apply-conf.c +++ gotsysd/libexec/gotsys-apply-conf/gotsys-apply-conf.c @@ -194,13 +194,10 @@ dispatch_gotd(int fd, short event, void *arg) } if (event & EV_WRITE) { - err = gotsysd_imsg_flush(ibuf); - if (err) { - warn("%s", err->msg); + if (imsgbuf_flush(ibuf) == -1) { + warn("imsgbuf_flush"); goto fatal; - } - - if (imsgbuf_queuelen(ibuf) == 0 && flush_and_exit) { + } else if (imsgbuf_queuelen(ibuf) == 0 && flush_and_exit) { event_del(&iev->ev); event_loopexit(NULL); return; blob - 2ef3416d43f078a9e1f325a27741297131f8e5e8 blob + 5ad3f11f5e1c3703357d07a810461d0edd4338cd --- gotsysd/libexec/gotsys-groupadd/gotsys-groupadd.c +++ gotsysd/libexec/gotsys-groupadd/gotsys-groupadd.c @@ -488,13 +488,10 @@ dispatch_event(int fd, short event, void *arg) } if (event & EV_WRITE) { - err = gotsysd_imsg_flush(ibuf); - if (err) { - warn("%s", err->msg); + if (imsgbuf_flush(ibuf) == -1) { + warn("imsgbuf_flush"); goto fatal; - } - - if (imsgbuf_queuelen(ibuf) == 0 && + } else if (imsgbuf_queuelen(ibuf) == 0 && groupadd_state == GROUPADD_STATE_DONE) { event_del(&iev->ev); event_loopexit(NULL); blob - 50a2fee49f2b2af0c8e57f5b73a1e771eb6ee5ee blob + b44b7d433b08727fea3c50ffd0d2a044463d775d --- gotsysd/libexec/gotsys-read-conf/gotsys-read-conf.c +++ gotsysd/libexec/gotsys-read-conf/gotsys-read-conf.c @@ -104,13 +104,10 @@ dispatch_event(int fd, short event, void *arg) } if (event & EV_WRITE) { - err = gotsysd_imsg_flush(ibuf); - if (err) { - warn("%s", err->msg); + if (imsgbuf_flush(ibuf) == -1) { + warn("imsgbuf_flush"); goto fatal; - } - - if (imsgbuf_queuelen(ibuf) == 0 && flush_and_exit) { + } else if (imsgbuf_queuelen(ibuf) == 0 && flush_and_exit) { event_del(&iev->ev); event_loopexit(NULL); return; blob - 44a4f26aab49db9c95a6ec1f6487e7cbd52ea9a5 blob + 27e73fdda9725787a48b1dc27c6b7199ea88e7e5 --- gotsysd/libexec/gotsys-repo-create/gotsys-repo-create.c +++ gotsysd/libexec/gotsys-repo-create/gotsys-repo-create.c @@ -305,13 +305,10 @@ dispatch_event(int fd, short event, void *arg) } if (event & EV_WRITE) { - err = gotsysd_imsg_flush(ibuf); - if (err) { - warn("%s", err->msg); + if (imsgbuf_flush(ibuf) == -1) { + warn("imsgbuf_flush"); goto fatal; - } - - if (imsgbuf_queuelen(ibuf) == 0 && flush_and_exit) { + } else if (imsgbuf_queuelen(ibuf) == 0 && flush_and_exit) { event_del(&iev->ev); event_loopexit(NULL); return; blob - 0989075072b148cbd55533f55e987d9cfbe3f9f9 blob + 06cd0a8b6e99fa0a70e3f77c25f06dd45f74e542 --- gotsysd/libexec/gotsys-rmkeys/gotsys-rmkeys.c +++ gotsysd/libexec/gotsys-rmkeys/gotsys-rmkeys.c @@ -150,13 +150,10 @@ dispatch_event(int fd, short event, void *arg) } if (event & EV_WRITE) { - err = gotsysd_imsg_flush(ibuf); - if (err) { - warn("%s", err->msg); + if (imsgbuf_flush(ibuf) == -1) { + warn("imsgbuf_flush"); goto fatal; - } - - if (imsgbuf_queuelen(ibuf) == 0 && + } else if (imsgbuf_queuelen(ibuf) == 0 && rmkeys_state == RMKEYS_STATE_DONE) { event_del(&iev->ev); event_loopexit(NULL); blob - c4b01162c91455d2b1f77ad8078a8878d130525d blob + 8a0ff30a244348cbe60c6d401f852572ae86d04e --- gotsysd/libexec/gotsys-sshdconfig/gotsys-sshdconfig.c +++ gotsysd/libexec/gotsys-sshdconfig/gotsys-sshdconfig.c @@ -145,13 +145,10 @@ dispatch_event(int fd, short event, void *arg) } if (event & EV_WRITE) { - err = gotsysd_imsg_flush(ibuf); - if (err) { - warn("%s", err->msg); + if (imsgbuf_flush(ibuf) == -1) { + warn("imsgbuf_flush"); goto fatal; - } - - if (imsgbuf_queuelen(ibuf) == 0 && flush_and_exit) { + } else if (imsgbuf_queuelen(ibuf) == 0 && flush_and_exit) { event_del(&iev->ev); event_loopexit(NULL); return; blob - c170ba07f64bc55989149a288a06309d7c1882ae blob + aebb0290f632e8d3ca1b392ea97c9ac34354fdfa --- gotsysd/libexec/gotsys-useradd/gotsys-useradd.c +++ gotsysd/libexec/gotsys-useradd/gotsys-useradd.c @@ -742,13 +742,10 @@ dispatch_event(int fd, short event, void *arg) } if (event & EV_WRITE) { - err = gotsysd_imsg_flush(ibuf); - if (err) { - warn("%s", err->msg); + if (imsgbuf_flush(ibuf) == -1) { + warn("imsgbuf_flush"); goto fatal; - } - - if (imsgbuf_queuelen(ibuf) == 0 && + } else if (imsgbuf_queuelen(ibuf) == 0 && useradd_state == USERADD_STATE_DONE) { event_del(&iev->ev); event_loopexit(NULL); blob - 665a64bec1868de45b0c57de68ad240bc49cc7fb blob + 67d66efcc5b2a413319624cb83ba50a31d6583f2 --- gotsysd/libexec/gotsys-userhome/gotsys-userhome.c +++ gotsysd/libexec/gotsys-userhome/gotsys-userhome.c @@ -216,13 +216,10 @@ dispatch_event(int fd, short event, void *arg) } if (event & EV_WRITE) { - err = gotsysd_imsg_flush(ibuf); - if (err) { - warn("%s", err->msg); + if (imsgbuf_flush(ibuf) == -1) { + warn("imsgbuf_flush"); goto fatal; - } - - if (imsgbuf_queuelen(ibuf) == 0 && + } else if (imsgbuf_queuelen(ibuf) == 0 && userhome_state == USERHOME_STATE_DONE) { event_del(&iev->ev); event_loopexit(NULL); blob - f0151d0367d14d07acf1b831f3adcd574fdbe288 blob + 7edea2411607e0e48f19eef23eaeb963035288dd --- gotsysd/libexec/gotsys-userkeys/gotsys-userkeys.c +++ gotsysd/libexec/gotsys-userkeys/gotsys-userkeys.c @@ -150,13 +150,10 @@ dispatch_event(int fd, short event, void *arg) } if (event & EV_WRITE) { - err = gotsysd_imsg_flush(ibuf); - if (err) { - warn("%s", err->msg); + if (imsgbuf_flush(ibuf) == -1) { + warn("imsgbuf_flush"); goto fatal; - } - - if (imsgbuf_queuelen(ibuf) == 0 && flush_and_exit) { + } else if (imsgbuf_queuelen(ibuf) == 0 && flush_and_exit) { event_del(&iev->ev); event_loopexit(NULL); return; blob - 315eb87b385e8dcb1ed88d46b428a5667016ec8e blob + 7af2e2c8c1f8fc768f8b6b89978e40b5d796ab6e --- gotsysd/libexec/gotsys-write-conf/gotsys-write-conf.c +++ gotsysd/libexec/gotsys-write-conf/gotsys-write-conf.c @@ -379,13 +379,10 @@ dispatch_event(int fd, short event, void *arg) } if (event & EV_WRITE) { - err = gotsysd_imsg_flush(ibuf); - if (err) { - warn("%s", err->msg); + if (imsgbuf_flush(ibuf) == -1) { + warn("imsgbuf_flush"); goto fatal; - } - - if (imsgbuf_queuelen(ibuf) == 0 && flush_and_exit) { + } else if (imsgbuf_queuelen(ibuf) == 0 && flush_and_exit) { event_del(&iev->ev); event_loopexit(NULL); return;