aboutsummaryrefslogtreecommitdiff
path: root/mail/cyrus-imapd34/files/patch-notifyd__notifyd.c
blob: 0719b98c13f663f87222ad0b57309500063a4ce7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
--- notifyd/notifyd.c.orig	2021-05-05 03:21:59 UTC
+++ notifyd/notifyd.c
@@ -50,6 +50,9 @@
 #include <sysexits.h>
 #include <syslog.h>
 #include <sys/types.h>
+#if defined(__FreeBSD__)
+#include <sys/sysctl.h>
+#endif
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <sys/un.h>
@@ -111,6 +114,23 @@ static int do_notify(void)
     unsigned bufsiz;
     socklen_t optlen;
 
+#if defined(__FreeBSD__)
+    size_t maxsockbuf;
+    size_t len = sizeof(maxsockbuf);
+    r = sysctlbyname("kern.ipc.maxsockbuf", &maxsockbuf, &len, NULL, 0);
+    if (r == 0) {
+        bufsiz = MIN(maxsockbuf, NOTIFY_MAXSIZE);
+    } else {
+        syslog(LOG_WARNING, "unable to sysctlbyname(kern.ipc.maxsockbuf): %m");
+        bufsiz = NOTIFY_MAXSIZE;
+    }
+
+    optlen = sizeof(bufsiz);
+    r = setsockopt(soc, SOL_SOCKET, SO_RCVBUF, &bufsiz, optlen);
+    if (r == -1) {
+        syslog(LOG_WARNING, "unable to setsockopt(SO_RCVBUF) on notify socket: %m");
+    }
+#else
     /* Get receive buffer size */
     optlen = sizeof(bufsiz);
     r = getsockopt(soc, SOL_SOCKET, SO_RCVBUF, &bufsiz, &optlen);
@@ -121,6 +141,7 @@ static int do_notify(void)
 
     /* Use minimum of 1/10 of receive buffer size (-overhead) NOTIFY_MAXSIZE */
     bufsiz = MIN(bufsiz / 10 - 32, NOTIFY_MAXSIZE);
+#endif
 
     while (1) {
         method = class = priority = user = mailbox = message = reply = NULL;