commit 07e7ca184c56b0ed4ad17cf4d6c4693595681b32cb5ad9e329d6f9edb603fe42 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 - 57b04c5f5717bfe99bb599a6c9a311a52b6af0a940e00a45f0c5de1b0383fc59 commit + 07e7ca184c56b0ed4ad17cf4d6c4693595681b32cb5ad9e329d6f9edb603fe42 blob - 47d42d64d53559efda67e77e76f95fe6afa30f0f4ca2b09dc7692e3a5873afd2 blob + 4fdfd416852c0d6bb94fb00014036a60183986476e021b869a754d0ca3251c8d --- 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 - 888e3fe3c5198d74870aa3cda2fc43cdd519ca2c08e0c476afbb3607f8faf1b2 blob + 741b18ac6aef5f2f36cc87921e38806f4b82dd16f769c39fffa7ea95f9bdf5c3 --- 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 - b450d63846b33eaced2364667915dbc1362a5f9db92d5d01fbdda13ec28c321b blob + 81cd28f34519f37e548542996c775b30e14e4d5c7577aa6c3d40e7cf43cb8906 --- 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 - 645553c3a0ad9b171fc23078c1c5ec873da0fa1fc1caa5094e463e77af39679e blob + 3bb42bc9618d5a380599a85baa97fbb1bd468f2067fa8ac42b9012d83e5c753e --- 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 - d096b04dc5cef1fd26924bfdfe3dd5d7c8dee7a84ab83482eadd3939727f5f2e blob + e8aadf9e8147911cf526fafd1f1e19dd2923a5f785ef487ffe249147791f5316 --- 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 - a9857640b2ffb94c07cf3a6d4d17fc6c593cc160a22ce91aece7e853a3afa8c9 blob + 9fefe103f6a098059620849f185849af01892857b79d739bb253e9aa7d7e1485 --- 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 - e213b1a31c96579184508c3ff6413bf1be4521482a131a79808cd0357c5cf320 blob + af3e4ff70e21126acb259f48c607d9323b75beef02bfef8941207c33d870b48c --- 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 - 1ee5fa46f30cf4e407c9213881da38d918d9b729fe04fcb9bd30dbd4ae1fbab9 blob + 8eabeaebcc2363d3edab848528c4716a4a8285e490dd572f922e4e77f514cedb --- 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 - 93dc4879435a5dd6fa838f7b81875faba29209a3cc557adc9b88700deb38817d blob + cc2c05cd23f85ef53758c9781e9b1ca9b4eb87b65f5db743ba05f28b4b45af98 --- 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 - f3a9b7a0f6943faeba1de1041aaeaa759f2c32a7f200317d5bbcd21f86c274af blob + 825650f927d09bb67a2fdffaed1d5025ea7c3b2a454dda233e7a05a4af8123a9 --- 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;