From bda3cdd3ada6e38f031fcc507c98e83e36f48c97 Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Sun, 20 Mar 2022 15:30:28 +0100 Subject: [PATCH] Increase inotify socket receive buffer size At startup (and reconf) of systems with lots of services there is a risk of losing inotify events, e.g., PID file creation/delete events. This patch increase the receive buffer (doubles it). On Linux the getsockopt() for SO_RCVBUF returns double the set size, due to housekeeping in the kernel. So we don't have to do any adjustments when setting it. Issue #226 Signed-off-by: Joachim Wiberg --- src/iwatch.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/iwatch.c b/src/iwatch.c index f910e124..75f72c68 100644 --- a/src/iwatch.c +++ b/src/iwatch.c @@ -23,6 +23,7 @@ */ #include +#include #include "finit.h" #include "iwatch.h" @@ -39,6 +40,9 @@ static int initialized = 0; int iwatch_init(struct iwatch *iw) { + socklen_t len; + int sz; + if (!iw) { errno = EINVAL; return -1; @@ -51,6 +55,16 @@ int iwatch_init(struct iwatch *iw) _pe("Failed creating inotify descriptor"); return -1; } + + /* + * Double the size of the socket's receive buffer to address + * issues with lost events in some cases, e.g. bootstrap and + * reconf of systems with lots of services. + */ + len = sizeof(sz); + if (!getsockopt(iw->fd, SOL_SOCKET, SO_RCVBUF, &sz, &len)) + setsockopt(iw->fd, SOL_SOCKET, SO_RCVBUF, &sz, sizeof(sz)); + initialized = 1; return iw->fd;