From fc14fc696ff335aaf688511255284c148eddd531 Mon Sep 17 00:00:00 2001 From: Sebastian Reimers Date: Wed, 4 Sep 2024 17:01:33 +0200 Subject: [PATCH] main/fd_listen: return EMFILE if maxfds is reached --- src/main/main.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main/main.c b/src/main/main.c index d61a80399..09895d3c9 100644 --- a/src/main/main.c +++ b/src/main/main.c @@ -610,7 +610,13 @@ int fd_listen(struct re_fhs **fhsp, re_sock_t fd, int flags, fd_h *fh, DEBUG_INFO("fd_listen/new: fd=%d flags=0x%02x\n", fd, flags); - ++re->nfds; + if (++re->nfds > re->maxfds) { + DEBUG_WARNING("fd_listen maxfds reached %d > %d\n", + re->nfds, re->maxfds); + --re->nfds; + err = EMFILE; + goto out; + } } else { if (unlikely(fhs->fd != fd)) { @@ -649,6 +655,7 @@ int fd_listen(struct re_fhs **fhsp, re_sock_t fd, int flags, fd_h *fh, break; } +out: if (err) { mem_deref(fhs); DEBUG_WARNING("fd_listen err: fd=%d flags=0x%02x (%m)\n", fd,