commit 70259cdf1bf2860ee303c2f581cfaa08dba2edef from: Stefan Sperling date: Mon Mar 24 15:43:18 2025 UTC move duplicated gotd_imsg functions into a single source file commit - 9619bad01228458bc938f90c107e32158e635bae commit + 70259cdf1bf2860ee303c2f581cfaa08dba2edef blob - 9040f98a6fc8eb6e53174a016f48165d108d8ec9 blob + 361619b1d58fb83daae092ec7e084966ebc6e6b6 --- gotd/Makefile +++ gotd/Makefile @@ -11,7 +11,7 @@ BINDIR ?= ${PREFIX}/sbin PROG= gotd SRCS= gotd.c auth.c repo_read.c repo_write.c log.c privsep_stub.c \ listen.c imsg.c parse.y secrets.c pack_create.c ratelimit.c \ - deltify.c \ + deltify.c gotd_imsg.c \ bloom.c buf.c date.c deflate.c delta.c delta_cache.c error.c \ gitconfig.c gotconfig.c inflate.c lockfile.c murmurhash2.c \ object.c object_cache.c object_create.c object_idset.c \ blob - b85bcad4dd18d7ddcdec6723568648f59f0ec582 blob + 5b53a41bab02a5df6cb15e49a2d53073c43885c8 --- gotd/imsg.c +++ gotd/imsg.c @@ -39,45 +39,6 @@ #include "gotd.h" -const struct got_error * -gotd_imsg_recv_error(uint32_t *client_id, struct imsg *imsg) -{ - struct gotd_imsg_error ierr; - size_t datalen; - - datalen = imsg->hdr.len - IMSG_HEADER_SIZE; - if (datalen != sizeof(ierr)) - return got_error(GOT_ERR_PRIVSEP_LEN); - memcpy(&ierr, imsg->data, sizeof(ierr)); - - if (client_id) - *client_id = ierr.client_id; - - if (ierr.code == GOT_ERR_ERRNO) - errno = ierr.errno_code; - - return got_error_msg(ierr.code, ierr.msg); -} - -const struct got_error * -gotd_imsg_flush(struct imsgbuf *ibuf) -{ - const struct got_error *err = NULL; - - while (imsgbuf_queuelen(ibuf) > 0) { - err = got_poll_fd(ibuf->fd, POLLOUT, INFTIM); - if (err) - break; - - if (imsgbuf_write(ibuf) == -1) { - err = got_error_from_errno("imsgbuf_write"); - break; - } - } - - return err; -} - static const struct got_error * gotd_imsg_recv(struct imsg *imsg, struct imsgbuf *ibuf, size_t min_datalen) { @@ -125,34 +86,6 @@ gotd_imsg_poll_recv(struct imsg *imsg, struct imsgbuf } int -gotd_imsg_send_error(struct imsgbuf *ibuf, uint32_t peerid, - uint32_t client_id, const struct got_error *err) -{ - const struct got_error *flush_err; - struct gotd_imsg_error ierr; - int ret; - - ierr.code = err->code; - if (err->code == GOT_ERR_ERRNO) - ierr.errno_code = errno; - else - ierr.errno_code = 0; - ierr.client_id = client_id; - strlcpy(ierr.msg, err->msg, sizeof(ierr.msg)); - - ret = imsg_compose(ibuf, GOTD_IMSG_ERROR, peerid, getpid(), -1, - &ierr, sizeof(ierr)); - if (ret == -1) - return -1; - - flush_err = gotd_imsg_flush(ibuf); - if (flush_err) - return -1; - - return 0; -} - -int gotd_imsg_send_error_event(struct gotd_imsgev *iev, uint32_t peerid, uint32_t client_id, const struct got_error *err) { @@ -175,33 +108,7 @@ gotd_imsg_send_error_event(struct gotd_imsgev *iev, ui return 0; } -void -gotd_imsg_event_add(struct gotd_imsgev *iev) -{ - iev->events = EV_READ; - if (imsgbuf_queuelen(&iev->ibuf)) - iev->events |= EV_WRITE; - - event_del(&iev->ev); - event_set(&iev->ev, iev->ibuf.fd, iev->events, iev->handler, iev); - event_add(&iev->ev, NULL); -} - int -gotd_imsg_compose_event(struct gotd_imsgev *iev, uint16_t type, uint32_t peerid, - int fd, void *data, uint16_t datalen) -{ - int ret; - - ret = imsg_compose(&iev->ibuf, type, peerid, getpid(), fd, - data, datalen); - if (ret != -1) - gotd_imsg_event_add(iev); - - return ret; -} - -int gotd_imsg_forward(struct gotd_imsgev *iev, struct imsg *imsg, int fd) { return gotd_imsg_compose_event(iev, imsg->hdr.type, imsg->hdr.peerid, @@ -530,5 +437,3 @@ done: gotd_free_notification_target(target); return err; } - - blob - fd3904e246d951cfb684a57fe8fe4865d5744f73 blob + 1264d96d3c0c3e9065c5303a80a8be4cc6d745a8 --- gotd/libexec/gotsys-apply/Makefile +++ gotd/libexec/gotsys-apply/Makefile @@ -5,8 +5,8 @@ PROG= gotsys-apply SRCS= gotsys-apply.c bloom.c buf.c date.c deflate.c delta.c delta_cache.c \ - error.c gitconfig.c gotconfig.c gotsys_conf.c hash.c imsg.c inflate.c \ - lockfile.c log.c murmurhash2.c object.c object_cache.c \ + error.c gitconfig.c gotconfig.c gotd_imsg.c gotsys_conf.c hash.c \ + inflate.c lockfile.c log.c murmurhash2.c object.c object_cache.c \ object_create.c object_idset.c object_open_io.c object_parse.c \ object_qid.c opentemp.c pack.c path.c pollfd.c privsep_stub.c \ read_gitconfig.c read_gotconfig.c reference.c reference_parse.c \ blob - bd1a2f06ec8bc83e12cc0e7e0b14deef3d80e624 (mode 644) blob + /dev/null --- gotd/libexec/gotsys-apply/imsg.c +++ /dev/null @@ -1,133 +0,0 @@ -/* - * Copyright (c) 2022 Stefan Sperling - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "got_error.h" -#include "got_object.h" -#include "got_path.h" - -#include "got_lib_poll.h" - -#include "gotd.h" - -const struct got_error * -gotd_imsg_recv_error(uint32_t *client_id, struct imsg *imsg) -{ - struct gotd_imsg_error ierr; - size_t datalen; - - datalen = imsg->hdr.len - IMSG_HEADER_SIZE; - if (datalen != sizeof(ierr)) - return got_error(GOT_ERR_PRIVSEP_LEN); - memcpy(&ierr, imsg->data, sizeof(ierr)); - - if (client_id) - *client_id = ierr.client_id; - - if (ierr.code == GOT_ERR_ERRNO) - errno = ierr.errno_code; - - return got_error_msg(ierr.code, ierr.msg); -} - -const struct got_error * -gotd_imsg_flush(struct imsgbuf *ibuf) -{ - const struct got_error *err = NULL; - - while (imsgbuf_queuelen(ibuf) > 0) { - err = got_poll_fd(ibuf->fd, POLLOUT, INFTIM); - if (err) - break; - - if (imsgbuf_write(ibuf) == -1) { - err = got_error_from_errno("imsgbuf_write"); - break; - } - } - - return err; -} - -int -gotd_imsg_send_error(struct imsgbuf *ibuf, uint32_t peerid, - uint32_t client_id, const struct got_error *err) -{ - const struct got_error *flush_err; - struct gotd_imsg_error ierr; - int ret; - - ierr.code = err->code; - if (err->code == GOT_ERR_ERRNO) - ierr.errno_code = errno; - else - ierr.errno_code = 0; - ierr.client_id = client_id; - strlcpy(ierr.msg, err->msg, sizeof(ierr.msg)); - - ret = imsg_compose(ibuf, GOTD_IMSG_ERROR, peerid, getpid(), -1, - &ierr, sizeof(ierr)); - if (ret == -1) - return -1; - - flush_err = gotd_imsg_flush(ibuf); - if (flush_err) - return -1; - - return 0; -} - -void -gotd_imsg_event_add(struct gotd_imsgev *iev) -{ - iev->events = EV_READ; - if (imsgbuf_queuelen(&iev->ibuf)) - iev->events |= EV_WRITE; - - event_del(&iev->ev); - event_set(&iev->ev, iev->ibuf.fd, iev->events, iev->handler, iev); - event_add(&iev->ev, NULL); -} - -int -gotd_imsg_compose_event(struct gotd_imsgev *iev, uint16_t type, uint32_t peerid, - int fd, void *data, uint16_t datalen) -{ - int ret; - - ret = imsg_compose(&iev->ibuf, type, peerid, getpid(), fd, - data, datalen); - if (ret != -1) - gotd_imsg_event_add(iev); - - return ret; -} blob - 9752ec0155d514e96f55ff3de56a8d92612476a2 blob + 39e46c7c142fde6a79dc25cef8856ab78c88c0a6 --- gotd/libexec/gotsys-check/Makefile +++ gotd/libexec/gotsys-check/Makefile @@ -4,8 +4,8 @@ .include "../../..//got-version.mk" PROG= gotsys-check -SRCS= gotsys-check.c error.c gotsys_conf.c hash.c imsg.c parse.y path.c \ - pollfd.c reference_parse.c +SRCS= gotsys-check.c error.c gotd_imsg.c gotsys_conf.c hash.c parse.y \ + path.c pollfd.c reference_parse.c NOMAN = Yes blob - bd1a2f06ec8bc83e12cc0e7e0b14deef3d80e624 (mode 644) blob + /dev/null --- gotd/libexec/gotsys-check/imsg.c +++ /dev/null @@ -1,133 +0,0 @@ -/* - * Copyright (c) 2022 Stefan Sperling - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "got_error.h" -#include "got_object.h" -#include "got_path.h" - -#include "got_lib_poll.h" - -#include "gotd.h" - -const struct got_error * -gotd_imsg_recv_error(uint32_t *client_id, struct imsg *imsg) -{ - struct gotd_imsg_error ierr; - size_t datalen; - - datalen = imsg->hdr.len - IMSG_HEADER_SIZE; - if (datalen != sizeof(ierr)) - return got_error(GOT_ERR_PRIVSEP_LEN); - memcpy(&ierr, imsg->data, sizeof(ierr)); - - if (client_id) - *client_id = ierr.client_id; - - if (ierr.code == GOT_ERR_ERRNO) - errno = ierr.errno_code; - - return got_error_msg(ierr.code, ierr.msg); -} - -const struct got_error * -gotd_imsg_flush(struct imsgbuf *ibuf) -{ - const struct got_error *err = NULL; - - while (imsgbuf_queuelen(ibuf) > 0) { - err = got_poll_fd(ibuf->fd, POLLOUT, INFTIM); - if (err) - break; - - if (imsgbuf_write(ibuf) == -1) { - err = got_error_from_errno("imsgbuf_write"); - break; - } - } - - return err; -} - -int -gotd_imsg_send_error(struct imsgbuf *ibuf, uint32_t peerid, - uint32_t client_id, const struct got_error *err) -{ - const struct got_error *flush_err; - struct gotd_imsg_error ierr; - int ret; - - ierr.code = err->code; - if (err->code == GOT_ERR_ERRNO) - ierr.errno_code = errno; - else - ierr.errno_code = 0; - ierr.client_id = client_id; - strlcpy(ierr.msg, err->msg, sizeof(ierr.msg)); - - ret = imsg_compose(ibuf, GOTD_IMSG_ERROR, peerid, getpid(), -1, - &ierr, sizeof(ierr)); - if (ret == -1) - return -1; - - flush_err = gotd_imsg_flush(ibuf); - if (flush_err) - return -1; - - return 0; -} - -void -gotd_imsg_event_add(struct gotd_imsgev *iev) -{ - iev->events = EV_READ; - if (imsgbuf_queuelen(&iev->ibuf)) - iev->events |= EV_WRITE; - - event_del(&iev->ev); - event_set(&iev->ev, iev->ibuf.fd, iev->events, iev->handler, iev); - event_add(&iev->ev, NULL); -} - -int -gotd_imsg_compose_event(struct gotd_imsgev *iev, uint16_t type, uint32_t peerid, - int fd, void *data, uint16_t datalen) -{ - int ret; - - ret = imsg_compose(&iev->ibuf, type, peerid, getpid(), fd, - data, datalen); - if (ret != -1) - gotd_imsg_event_add(iev); - - return ret; -} blob - /dev/null blob + bd1a2f06ec8bc83e12cc0e7e0b14deef3d80e624 (mode 644) --- /dev/null +++ lib/gotd_imsg.c @@ -0,0 +1,133 @@ +/* + * Copyright (c) 2022 Stefan Sperling + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "got_error.h" +#include "got_object.h" +#include "got_path.h" + +#include "got_lib_poll.h" + +#include "gotd.h" + +const struct got_error * +gotd_imsg_recv_error(uint32_t *client_id, struct imsg *imsg) +{ + struct gotd_imsg_error ierr; + size_t datalen; + + datalen = imsg->hdr.len - IMSG_HEADER_SIZE; + if (datalen != sizeof(ierr)) + return got_error(GOT_ERR_PRIVSEP_LEN); + memcpy(&ierr, imsg->data, sizeof(ierr)); + + if (client_id) + *client_id = ierr.client_id; + + if (ierr.code == GOT_ERR_ERRNO) + errno = ierr.errno_code; + + return got_error_msg(ierr.code, ierr.msg); +} + +const struct got_error * +gotd_imsg_flush(struct imsgbuf *ibuf) +{ + const struct got_error *err = NULL; + + while (imsgbuf_queuelen(ibuf) > 0) { + err = got_poll_fd(ibuf->fd, POLLOUT, INFTIM); + if (err) + break; + + if (imsgbuf_write(ibuf) == -1) { + err = got_error_from_errno("imsgbuf_write"); + break; + } + } + + return err; +} + +int +gotd_imsg_send_error(struct imsgbuf *ibuf, uint32_t peerid, + uint32_t client_id, const struct got_error *err) +{ + const struct got_error *flush_err; + struct gotd_imsg_error ierr; + int ret; + + ierr.code = err->code; + if (err->code == GOT_ERR_ERRNO) + ierr.errno_code = errno; + else + ierr.errno_code = 0; + ierr.client_id = client_id; + strlcpy(ierr.msg, err->msg, sizeof(ierr.msg)); + + ret = imsg_compose(ibuf, GOTD_IMSG_ERROR, peerid, getpid(), -1, + &ierr, sizeof(ierr)); + if (ret == -1) + return -1; + + flush_err = gotd_imsg_flush(ibuf); + if (flush_err) + return -1; + + return 0; +} + +void +gotd_imsg_event_add(struct gotd_imsgev *iev) +{ + iev->events = EV_READ; + if (imsgbuf_queuelen(&iev->ibuf)) + iev->events |= EV_WRITE; + + event_del(&iev->ev); + event_set(&iev->ev, iev->ibuf.fd, iev->events, iev->handler, iev); + event_add(&iev->ev, NULL); +} + +int +gotd_imsg_compose_event(struct gotd_imsgev *iev, uint16_t type, uint32_t peerid, + int fd, void *data, uint16_t datalen) +{ + int ret; + + ret = imsg_compose(&iev->ibuf, type, peerid, getpid(), fd, + data, datalen); + if (ret != -1) + gotd_imsg_event_add(iev); + + return ret; +}