summaryrefslogtreecommitdiff
path: root/usr.sbin/rpki-client/rsync.c
diff options
context:
space:
mode:
authorClaudio Jeker <claudio@cvs.openbsd.org>2024-11-21 13:32:28 +0000
committerClaudio Jeker <claudio@cvs.openbsd.org>2024-11-21 13:32:28 +0000
commit0896bcd68e9fdc5d847f8407e9e78bc9c5dc83e6 (patch)
treeeaf6794f7bbde4fb22b0abe5129766814f8c1445 /usr.sbin/rpki-client/rsync.c
parent78afa2b6e46610459f04390526cdff013f2e4611 (diff)
Rewrite the rpki-client io read handling using the new ibuf_read API.
OK tb@
Diffstat (limited to 'usr.sbin/rpki-client/rsync.c')
-rw-r--r--usr.sbin/rpki-client/rsync.c58
1 files changed, 32 insertions, 26 deletions
diff --git a/usr.sbin/rpki-client/rsync.c b/usr.sbin/rpki-client/rsync.c
index d8612a57ce2..fef15ee4ea2 100644
--- a/usr.sbin/rpki-client/rsync.c
+++ b/usr.sbin/rpki-client/rsync.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rsync.c,v 1.55 2024/11/21 13:30:17 claudio Exp $ */
+/* $OpenBSD: rsync.c,v 1.56 2024/11/21 13:32:27 claudio Exp $ */
/*
* Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv>
*
@@ -227,14 +227,15 @@ proc_rsync(char *prog, char *bind_addr, int fd)
int nprocs = 0, npending = 0, rc = 0;
struct pollfd pfd;
struct msgbuf *msgq;
- struct ibuf *b, *inbuf = NULL;
+ struct ibuf *b;
sigset_t mask, oldmask;
struct rsync *s, *ns;
if (pledge("stdio rpath proc exec unveil", NULL) == -1)
err(1, "pledge");
- if ((msgq = msgbuf_new()) == NULL)
+ if ((msgq = msgbuf_new_reader(sizeof(size_t), io_parse_hdr, NULL)) ==
+ NULL)
err(1, NULL);
pfd.fd = fd;
@@ -370,30 +371,35 @@ proc_rsync(char *prog, char *bind_addr, int fd)
if (!(pfd.revents & POLLIN))
continue;
- b = io_buf_read(fd, &inbuf);
- if (b == NULL)
- continue;
+ switch (ibuf_read(fd, msgq)) {
+ case -1:
+ err(1, "ibuf_read");
+ case 0:
+ errx(1, "ibuf_read: connection closed");
+ }
- /* Read host and module. */
- io_read_buf(b, &id, sizeof(id));
- io_read_str(b, &dst);
- io_read_str(b, &compdst);
- io_read_str(b, &uri);
-
- ibuf_free(b);
-
- if (dst != NULL) {
- rsync_new(id, uri, dst, compdst);
- npending++;
- } else {
- TAILQ_FOREACH(s, &states, entry)
- if (s->id == id)
- break;
- if (s != NULL) {
- if (s->pid != 0)
- kill(s->pid, SIGTERM);
- else
- rsync_free(s);
+ while ((b = io_buf_get(msgq)) != NULL) {
+ /* Read host and module. */
+ io_read_buf(b, &id, sizeof(id));
+ io_read_str(b, &dst);
+ io_read_str(b, &compdst);
+ io_read_str(b, &uri);
+
+ ibuf_free(b);
+
+ if (dst != NULL) {
+ rsync_new(id, uri, dst, compdst);
+ npending++;
+ } else {
+ TAILQ_FOREACH(s, &states, entry)
+ if (s->id == id)
+ break;
+ if (s != NULL) {
+ if (s->pid != 0)
+ kill(s->pid, SIGTERM);
+ else
+ rsync_free(s);
+ }
}
}
}