Check somaxconn system settings on macOS, FreeBSD and OpenBSD. (#9972)
Co-authored-by: Yossi Gottlieb <yossigo@gmail.com>
This commit is contained in:
parent
af0b50f83a
commit
2c5573e894
@ -63,6 +63,13 @@
|
|||||||
#define HAVE_TASKINFO 1
|
#define HAVE_TASKINFO 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* Test for somaxconn check */
|
||||||
|
#if defined(__APPLE__) || defined(__FreeBSD__)
|
||||||
|
#define HAVE_SYSCTL_KIPC_SOMAXCONN 1
|
||||||
|
#elif defined(__OpenBSD__)
|
||||||
|
#define HAVE_SYSCTL_KERN_SOMAXCONN 1
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Test for backtrace() */
|
/* Test for backtrace() */
|
||||||
#if defined(__APPLE__) || (defined(__linux__) && defined(__GLIBC__)) || \
|
#if defined(__APPLE__) || (defined(__linux__) && defined(__GLIBC__)) || \
|
||||||
defined(__FreeBSD__) || ((defined(__OpenBSD__) || defined(__NetBSD__)) && defined(USE_BACKTRACE))\
|
defined(__FreeBSD__) || ((defined(__OpenBSD__) || defined(__NetBSD__)) && defined(USE_BACKTRACE))\
|
||||||
|
31
src/server.c
31
src/server.c
@ -64,6 +64,10 @@
|
|||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(HAVE_SYSCTL_KIPC_SOMAXCONN) || defined(HAVE_SYSCTL_KERN_SOMAXCONN)
|
||||||
|
#include <sys/sysctl.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Our shared "common" objects */
|
/* Our shared "common" objects */
|
||||||
|
|
||||||
struct sharedObjectsStruct shared;
|
struct sharedObjectsStruct shared;
|
||||||
@ -2028,7 +2032,7 @@ void adjustOpenFilesLimit(void) {
|
|||||||
/* Check that server.tcp_backlog can be actually enforced in Linux according
|
/* Check that server.tcp_backlog can be actually enforced in Linux according
|
||||||
* to the value of /proc/sys/net/core/somaxconn, or warn about it. */
|
* to the value of /proc/sys/net/core/somaxconn, or warn about it. */
|
||||||
void checkTcpBacklogSettings(void) {
|
void checkTcpBacklogSettings(void) {
|
||||||
#ifdef HAVE_PROC_SOMAXCONN
|
#if defined(HAVE_PROC_SOMAXCONN)
|
||||||
FILE *fp = fopen("/proc/sys/net/core/somaxconn","r");
|
FILE *fp = fopen("/proc/sys/net/core/somaxconn","r");
|
||||||
char buf[1024];
|
char buf[1024];
|
||||||
if (!fp) return;
|
if (!fp) return;
|
||||||
@ -2039,6 +2043,31 @@ void checkTcpBacklogSettings(void) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
#elif defined(HAVE_SYSCTL_KIPC_SOMAXCONN)
|
||||||
|
int somaxconn, mib[3];
|
||||||
|
size_t len = sizeof(int);
|
||||||
|
|
||||||
|
mib[0] = CTL_KERN;
|
||||||
|
mib[1] = KERN_IPC;
|
||||||
|
mib[2] = KIPC_SOMAXCONN;
|
||||||
|
|
||||||
|
if (sysctl(mib, 3, &somaxconn, &len, NULL, 0) == 0) {
|
||||||
|
if (somaxconn > 0 && somaxconn < server.tcp_backlog) {
|
||||||
|
serverLog(LL_WARNING,"WARNING: The TCP backlog setting of %d cannot be enforced because kern.ipc.somaxconn is set to the lower value of %d.", server.tcp_backlog, somaxconn);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#elif defined(HAVE_SYSCTL_KERN_SOMAXCONN)
|
||||||
|
int somaxconn, mib[2];
|
||||||
|
size_t len = sizeof(int);
|
||||||
|
|
||||||
|
mib[0] = CTL_KERN;
|
||||||
|
mib[1] = KERN_SOMAXCONN;
|
||||||
|
|
||||||
|
if (sysctl(mib, 2, &somaxconn, &len, NULL, 0) == 0) {
|
||||||
|
if (somaxconn > 0 && somaxconn < server.tcp_backlog) {
|
||||||
|
serverLog(LL_WARNING,"WARNING: The TCP backlog setting of %d cannot be enforced because kern.somaxconn is set to the lower value of %d.", server.tcp_backlog, somaxconn);
|
||||||
|
}
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user