summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaudio Jeker <claudio@cvs.openbsd.org>2024-11-21 12:58:10 +0000
committerClaudio Jeker <claudio@cvs.openbsd.org>2024-11-21 12:58:10 +0000
commit42eefa5ae8dee3359bc192d794f49c17078e6477 (patch)
treea1ccadd71a0bbbfea0621a74ec73ba4f29f1f5b1
parent47ba2539ec89c842e3972f962f7bf14c238ea60c (diff)
Only ldapd tried to handle fd exhaustion during imsg fd passing.
Remove the getdtablecount code from imsgbuf_read() and instead move the getdtablecount code into ldapd. Handle EMSGSIZE (the error returned when there are not enough free file descriptor slots) inside imsgbuf_read() by retrying the read to receive the data but without fd. A caller expecting an fd should check the return value of imsg_get_fd. OK tb@
-rw-r--r--lib/libutil/Symbols.map1
-rw-r--r--lib/libutil/imsg.c18
2 files changed, 8 insertions, 11 deletions
diff --git a/lib/libutil/Symbols.map b/lib/libutil/Symbols.map
index 4d459dbc60d..aa583d3f9ef 100644
--- a/lib/libutil/Symbols.map
+++ b/lib/libutil/Symbols.map
@@ -70,7 +70,6 @@
imsg_compose_ibuf;
imsg_composev;
imsg_create;
- imsg_fd_overhead;
imsg_forward;
imsg_free;
imsg_get;
diff --git a/lib/libutil/imsg.c b/lib/libutil/imsg.c
index f9497a47ec0..a0031c47778 100644
--- a/lib/libutil/imsg.c
+++ b/lib/libutil/imsg.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: imsg.c,v 1.31 2024/11/21 12:54:52 claudio Exp $ */
+/* $OpenBSD: imsg.c,v 1.32 2024/11/21 12:58:09 claudio Exp $ */
/*
* Copyright (c) 2023 Claudio Jeker <claudio@openbsd.org>
@@ -34,8 +34,6 @@ struct imsg_fd {
int fd;
};
-int imsg_fd_overhead = 0;
-
static int imsg_dequeue_fd(struct imsgbuf *);
void
@@ -77,16 +75,16 @@ imsgbuf_read(struct imsgbuf *imsgbuf)
return (-1);
again:
- if (getdtablecount() + imsg_fd_overhead +
- (int)((CMSG_SPACE(sizeof(int))-CMSG_SPACE(0))/sizeof(int))
- >= getdtablesize()) {
- free(ifd);
- return (1);
- }
-
if ((n = recvmsg(imsgbuf->fd, &msg, 0)) == -1) {
if (errno == EINTR)
goto again;
+ if (errno == EMSGSIZE)
+ /*
+ * Not enough fd slots: fd passing failed, retry
+ * to receive the message without fd.
+ * imsg_get_fd() will return -1 in that case.
+ */
+ goto again;
if (errno == EAGAIN) {
free(ifd);
return (1);