summaryrefslogtreecommitdiffstats
path: root/lib/maxfd.c
diff options
context:
space:
mode:
authorLorenz Kästle <12514511+RincewindsHat@users.noreply.github.com>2023-10-15 20:07:33 (GMT)
committerLorenz Kästle <12514511+RincewindsHat@users.noreply.github.com>2023-10-15 20:07:33 (GMT)
commit685c2931dfc3cb67b7605eba143598512a66c037 (patch)
tree4d73bf71eb19e7c63f3d649fa969c63104a4b456 /lib/maxfd.c
parent0875351a8385d6587133c2af541d102f31c17a46 (diff)
parentbf70f5f847e3407af572d1768cca747af270b993 (diff)
downloadmonitoring-plugins-685c2931dfc3cb67b7605eba143598512a66c037.tar.gz
Merge branch 'master' into dev/check_ssh-patches
Diffstat (limited to 'lib/maxfd.c')
-rw-r--r--lib/maxfd.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/maxfd.c b/lib/maxfd.c
new file mode 100644
index 0000000..529b356
--- /dev/null
+++ b/lib/maxfd.c
@@ -0,0 +1,26 @@
1#include "./maxfd.h"
2#include <errno.h>
3
4long mp_open_max (void) {
5 long maxfd = 0L;
6 /* Try sysconf(_SC_OPEN_MAX) first, as it can be higher than OPEN_MAX.
7 * If that fails and the macro isn't defined, we fall back to an educated
8 * guess. There's no guarantee that our guess is adequate and the program
9 * will die with SIGSEGV if it isn't and the upper boundary is breached. */
10
11#ifdef _SC_OPEN_MAX
12 errno = 0;
13 if ((maxfd = sysconf (_SC_OPEN_MAX)) < 0) {
14 if (errno == 0)
15 maxfd = DEFAULT_MAXFD; /* it's indeterminate */
16 else
17 die (STATE_UNKNOWN, _("sysconf error for _SC_OPEN_MAX\n"));
18 }
19#elif defined(OPEN_MAX)
20 return OPEN_MAX
21#else /* sysconf macro unavailable, so guess (may be wildly inaccurate) */
22 return DEFAULT_MAXFD;
23#endif
24
25 return(maxfd);
26}